Class: Parser::Builders::Default

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

Direct Known Subclasses

Opal::AST::Builder

Instance Method Summary collapse

Instance Method Details

#check_lvar_name(name, loc) ⇒ Object



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

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



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

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



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

def string_value(token)
  value(token)
end