class ERLE::Parser

Constants

FALSE
FLOAT
IGNORE
INTEGER
TRUE
UNPARSED

Public Class Methods

new(source, opts = {}) click to toggle source
Calls superclass method
# File lib/erle/parser.rb, line 36
def initialize(source, opts = {})
  opts ||= {}
  # source = convert_encoding source
  super source
end

Public Instance Methods

parse() click to toggle source
# File lib/erle/parser.rb, line 44
def parse
  reset
  obj = nil

  until_done do
    if eos?
      raise_parsing_error
    else
      obj = parse_value
      UNPARSED.equal?(obj) and raise_parsing_error
    end
  end

  eos? or raise_parsing_error
  obj
end
parse_value() click to toggle source
# File lib/erle/parser.rb, line 95
def parse_value
  # TODO: handle symbols
  skip_ignore

  case
  when scan(TRUE)
    true
  when scan(FALSE)
    false
  when !eos? && scan(ERLE::Registry.openings_regex) # TODO: Take out !eos?
    regex, term_class = ERLE::Registry.open_find(matched)
    term_str = term_class.parse(self)
  else
    term_class, regex = ERLE::Registry.pattern_find do |p|
      match?(p)
    end

    if term_class
      term_class.parse(self)
    else
      UNPARSED
    end
  end
end
peekaboo(peek = 30, back = 30) click to toggle source
# File lib/erle/parser.rb, line 75
def peekaboo(peek = 30, back = 30)
  string[pos-back, peek+back]
end
raise_parsing_error(message = "source is not valid Erlang!") click to toggle source
# File lib/erle/parser.rb, line 79
def raise_parsing_error(message = "source is not valid Erlang!")
  # warn "Parsing =>\n#{string}"
  raise ParserError, "Parsing =>\n#{string}\n#{message}"
end
raise_unexpected_token(followup=nil) click to toggle source
# File lib/erle/parser.rb, line 89
def raise_unexpected_token(followup=nil)
  message = "Unexpected token at:\n#{whereami?}"
  message += "\n#{followup}" if followup
  raise ParserError, message
end
skip_ignore() click to toggle source
# File lib/erle/parser.rb, line 61
def skip_ignore
  skip(IGNORE)
end
until_done() { || ... } click to toggle source
# File lib/erle/parser.rb, line 65
def until_done
  result = nil
  while !eos?
    skip_ignore
    result = yield if block_given?
    skip_ignore
  end
  result
end
whereami?(peek = 30, back = 30) click to toggle source
# File lib/erle/parser.rb, line 84
def whereami?(peek = 30, back = 30)
  back = [back, string.length - pos].sort[0]
  "#{peekaboo(peek, back)}'\n#{"─" * (back)}┘"
end