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



49
50
51
52
53
54
55
56
# File 'opal/lib/opal/parser/patch.rb', line 49

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



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'opal/lib/opal/parser/patch.rb', line 60

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



164
165
166
# File 'opal/lib/opal/parser/patch.rb', line 164

def string_value(token)
  value(token)
end