Module: Prattle::AST

Defined in:
lib/prattle/ast/nil.rb,
lib/prattle/ast/node.rb,
lib/prattle/ast/self.rb,
lib/prattle/ast/true.rb,
lib/prattle/ast/false.rb,
lib/prattle/ast/block.rb,
lib/prattle/ast/global.rb,
lib/prattle/ast/string.rb,
lib/prattle/ast/symbol.rb,
lib/prattle/ast/assign.rb,
lib/prattle/ast/number.rb,
lib/prattle/ast/variable.rb,
lib/prattle/ast/operator.rb,
lib/prattle/ast/unary_send.rb,
lib/prattle/ast/keyword_send.rb,
lib/prattle/ast/cascade_send.rb,
lib/prattle/ast/array_literal.rb

Defined Under Namespace

Classes: ArrayLiteral, Assign, Block, CascadeSend, False, KeywordSend, Nil, Node, Number, Operator, Self, String, Symbol, True, UnarySend, Variable

Class Method Summary (collapse)

Class Method Details

+ (Object) grammar(g)



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/prattle/ast/global.rb', line 3

def self.grammar(g)
  g.sp = g.kleene g.any(" ", "\n")
  g.sig_sp = g.many g.any(" ", "\n")
  g.method_name = /~?[a-zA-Z][a-zA-Z0-9]*[?!]?/

  g.grouped = g.seq("(", :sp, g.t(:expression), :sp, ")")
  g.level1 = g.any(:true, :false, :self, :nil, :number,
                   :string, :symbol, :variable, :grouped,
                   :block, :array_literal)

  g.level2 = g.any(:unary_send, :level1)

  g.level3 = g.any(:operator, :level2)

  g.expression = g.any(:cascade_send, :keyword_send, :assign, :level3)

  g.expressions = g.seq(:expression, :sp,
                        g.kleene(
                          g.seq(:sp, ".", :sp, g.t(:expression), :sp))) {
                            |x,_,m|
                            m = Array(m)
                            m.unshift x
                            m
                          }

  g.root = g.expressions
end