class Parser::Builders::Default

Public Instance Methods

check_lvar_name(name, loc) click to toggle source
# 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) click to toggle source

Taken From: github.com/whitequark/parser/blob/a7c638b7b205db9213a56897b41a8e5620df766e/lib/parser/builders/default.rb#L388

# 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) click to toggle source
# File lib/opal/parser/patch.rb, line 165
def string_value(token)
  value(token)
end