module RBNF
Constants
- DEFS
Namespace for defined forms.
- VERSION
Private Class Methods
[](s)
click to toggle source
# File lib/rbnf.rb, line 70 def [](s) Term.new s end
def(name)
click to toggle source
Takes a symbol <name> and a block and defines a new form <name> to be the contents of the block. Note that this method can’t handle recursive form definition; use ::define
for that instead.
# File lib/rbnf.rb, line 77 def def(name) DEFS[name] = Def.new name, yield end
define(name,&b)
click to toggle source
Takes a symbol <name> and a block and defines a new form <name> to be the contents of the block. In contrast to ::def
this method can handle recursive definition, at the cost of building a new AST each time a match is attempted on the new form.
# File lib/rbnf.rb, line 85 def define(name,&b) DEFS[name] = Def.new name, ->(s){b.call=~s} end
dememoize()
click to toggle source
method_missing(sym,*as)
click to toggle source
Calls superclass method
# File lib/rbnf.rb, line 94 def method_missing(sym,*as) DEFS.has_key?(sym) ? DEFS[sym] : super end
Public Instance Methods
=~(s)
click to toggle source
String match with memoization.
# File lib/rbnf.rb, line 43 def =~(s) @memo.has_key?(s) ? @memo[s] : (@memo[s] = match s) end
Also aliased as: []
alt(f)
click to toggle source
“a” | “b”
# File lib/rbnf.rb, line 18 def alt(f) Alt.new self, ebnify(f) end
Also aliased as: /
cat(f)
click to toggle source
“a” , “b”
# File lib/rbnf.rb, line 13 def cat(f) Cat.new self, ebnify(f) end
Also aliased as: +
except(f)
click to toggle source
a - “b”
# File lib/rbnf.rb, line 23 def except(f) Except.new self, ebnify(f) end
Also aliased as: -
group()
click to toggle source
( “a” )
# File lib/rbnf.rb, line 38 def group Group.new self end
opt()
click to toggle source
- “a”
# File lib/rbnf.rb, line 8 def opt Opt.new self end
Also aliased as: -@
rep()
click to toggle source
{ “a” }
# File lib/rbnf.rb, line 28 def rep Rep.new self end
Also aliased as: +@
rep_n(n)
click to toggle source
b * “a”
# File lib/rbnf.rb, line 33 def rep_n(n) RepN.new self, n end
Also aliased as: *
Private Instance Methods
ebnify(s)
click to toggle source
# File lib/rbnf.rb, line 61 def ebnify(s) RBNF===s ? s : RBNF[s] end
heads(s)
click to toggle source
# File lib/rbnf.rb, line 65 def heads(s) Enumerator.new {|y| (0..s.size).each {|i| y<<s.slice(0,i)}} end