class Atomy::Grammar

Public Instance Methods

continue?(x) click to toggle source
# File lib/atomy/grammar.rb, line 43
def continue?(x)
  y = current_position
  y[0] >= x[0] && y[1] > x[1]
end
current_column(x = pos) click to toggle source
# File lib/atomy/grammar.rb, line 39
def current_column(x = pos)
  current_position(x)[1]
end
current_line(x = pos) click to toggle source
# File lib/atomy/grammar.rb, line 35
def current_line(x = pos)
  current_position(x)[0]
end
current_position(target = pos) click to toggle source
# File lib/atomy/grammar.rb, line 18
def current_position(target = pos)
  cur_offset = 0
  cur_line = 0

  line_lengths.each do |len|
    cur_line += 1
    return [cur_line, target - cur_offset] if cur_offset + len > target
    cur_offset += len
  end

  [cur_line, cur_offset]
end
line_lengths() click to toggle source
# File lib/atomy/grammar.rb, line 31
def line_lengths
  @line_lengths ||= lines.collect { |l| l.size }
end
make(what, line, *args) click to toggle source
# File lib/atomy/grammar.rb, line 12
def make(what, line, *args)
  node = send(what, *args)
  node.line ||= line
  node
end
set_lang(n) click to toggle source
# File lib/atomy/grammar.rb, line 48
def set_lang(n)
  require "atomy/codeloader"
  @_grammar_lang = Atomy::CodeLoader.require("#{n}/language/parser")::Parser.new(nil)
end