Class: Parser::Builders::Default

Inherits:
Object
  • Object
show all
Defined in:
opal/lib/opal/parser/patch.rb,
opal/lib/opal/parser/patch.rb

Direct Known Subclasses

Opal::AST::Builder

Instance Method Summary collapse

Instance Method Details

#check_lvar_name(name, loc) ⇒ Object



43
44
45
46
47
48
49
50
# File 'opal/lib/opal/parser/patch.rb', line 43

def check_lvar_name(name, loc)
  # https://javascript.info/regexp-unicode
  if name =~ `new RegExp('^[\\p{Ll}|_][\\p{L}\\p{Nl}\\p{Nd}_]*$', 'u')`
    # OK
  else
    diagnostic :error, :lvar_name, { name: name }, loc
  end
end

#dedent_string(node, dedent_level) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'opal/lib/opal/parser/patch.rb', line 54

def dedent_string(node, dedent_level)
  unless dedent_level.nil?
    dedenter = ::Parser::Lexer::Dedenter.new(dedent_level)

    case node.type
    when :str
      node = node.updated(nil, [dedenter.dedent(node.children.first)])
    when :dstr, :xstr
      children = node.children.map do |str_node|
        if str_node.type == :str
          str_node = str_node.updated(nil, [dedenter.dedent(str_node.children.first)])
          next nil if str_node.children.first.empty?
        else
          dedenter.interrupt
        end
        str_node
      end

      node = node.updated(nil, children.compact)
    end
  end

  node
end

#string_value(token) ⇒ Object



158
159
160
# File 'opal/lib/opal/parser/patch.rb', line 158

def string_value(token)
  value(token)
end