class GenText::Compile

Constants

ActionCode
Capture
CheckCode
Choice
ChoiceAlternative
Context

@!visibility private

GenCode
GenNumber
GenString
Grammar
INF

—- Utils —-

Repeat
RuleCall
RuleDefinition
Seq

Public Instance Methods

call(*args) click to toggle source

@param (see Parse#call) @return the program as an Array of [:method_id, *args] where

<code>method_id</code> is ID of {VM}'s method. The program may raise
{CheckFailed}.
Calls superclass method
# File lib/gen_text/compile.rb, line 12
def call(*args)
  super(*args).to_vm_code
end

Private Instance Methods

choice_alternative_start(first) click to toggle source

Returns probability or :auto.

# File lib/gen_text/compile.rb, line 371
def choice_alternative_start(first)
  _{
    (_{ slash } or _{ pipe }) and
    probability = (
      _{
        lbracket and
        x = ufloat and opt { percent and act { x /= 100.0 } } and
        rbracket and
        x
      } or
      :auto
    )
  } or
  (if first then :auto else nil end)
end
code(start) click to toggle source

Parses “#{start} #{code_part} } #{whitespace_and_comments}”. Returns the code_part.

# File lib/gen_text/compile.rb, line 489
def code(start)
  p = pos and
  scan(start) and c = code_part and
  (rbrace or raise Expected.new(p, "`}' at the end")) and
  c
end
gen_number() click to toggle source
# File lib/gen_text/compile.rb, line 449
def gen_number
  n1 = number and n2 = opt { ellipsis and number } and
  act { n2 = (n2.first or n1) } and
  _(GenNumber[n1, n2])
end
string0(quote) click to toggle source
# File lib/gen_text/compile.rb, line 519
def string0(quote)
  p = pos and scan(quote) and
  s = many {
    _{ scan(/\\n/) and "\n" } or
    _{ scan(/\\t/) and "\t" } or
    _{ scan(/\\e/) and "\e" } or
    _{ scan("\\") and scan(/./) } or
    scan(/[^#{quote}]/)
  }.join and
  (scan(quote) or raise Expected.new(p, "`#{quote}' at the end")) and s
end
times() click to toggle source
# File lib/gen_text/compile.rb, line 434
def times
  _{ uint } or
  _{ inf and INF }
end
to_seq_subexprs(e) click to toggle source
# File lib/gen_text/compile.rb, line 394
def to_seq_subexprs(e)
  case e
  when Seq then e.subexprs
  else [e]
  end
end
whitespace_and_comments() click to toggle source
# File lib/gen_text/compile.rb, line 561
def whitespace_and_comments
  many {
    _{ scan(/\s+/) } or
    _{ scan("//") and scan(/[^\n]*\n/m) } or
    _{
      p = pos and scan("/*") and
      many { not_follows { scan("*/") } and scan(/./m) } and
      (scan("*/") or raise Expected.new(p, "`*/' at the end"))
    }
  }
end