Permalink
Browse files

Parsing context.

  • Loading branch information...
vic committed Aug 25, 2011
1 parent 3377700 commit febbac97c67e012741c58e40d662e514233c437b
Showing with 85 additions and 58 deletions.
  1. +13 −13 lib/akin/grammar.kpeg
  2. +34 −34 lib/akin/grammar.rb
  3. +35 −6 lib/akin/parser.rb
  4. +3 −5 spec/spec_helper.rb
View
@@ -58,7 +58,7 @@ sstr = p:p quoted(:text, & "\""):b ~text_node(p, b)
quoted(t,q) = q quoted_inner(t,q)*:b q {b}
-quoted_inner(t,q) = p:p "#{" - block(h)?:b - "}" {b}
+quoted_inner(t,q) = p:p "#{" - block(ctx)?:b - "}" {b}
| p:p < ("\\" escape | ("\\" q | "\\#" | &!((q | "#{")) .))+ >
~n(p, t, text)
@@ -97,17 +97,17 @@ cons_left(h) = expr(h):a sp* "::" !&(":"|";"|".") {a}
cons(h) = cons_left(h):a - chain_val(h):b ~n(p, :cons, a, b)
-args = p:p left_brace:l - (comma(h) | block(h) | {[]}):a - right_brace(l)
+args = p:p left_brace:l - (comma(ctx) | block(ctx) | {[]}):a - right_brace(l)
~n(p, l.join, *Array(a))
msg(h) = kmsg(h) | emsg(h)
kmsg(h) = kmsg(h):a sp* (&("::") | ":" &(";"|".")) {a}
- | part(h):a w kmsg(h | a.pos):m ~n(a.pos, :msg, a, *m.args)
+ | part(h):a w kmsg(h.at?(a.pos)):m ~n(a.pos, :msg, a, *m.args)
| part(h):a ~n(a.pos, :msg, a)
-part(h) = part(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p }
- | part(h):p sp+ part_head(h | p.pos):e { p.args.push *Array(e) ; p }
+part(h) = part(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p }
+ | part(h):p sp+ part_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p }
| p:p keyargs:k ~n(p, k.first, k.last.name, *k.last.args)
| p:p keyword:k ~n(p, k, nil)
@@ -119,22 +119,22 @@ ph_comma(h) = expr(h):a w "," - ph_comma(h):b { b.unshift a ; b }
emsg(h) = emsg(h):a sp* (&("::") | ":" &(";"|".")) {a}
| (epart(h) | spart(h)):a ~n(a.pos, :msg, a)
-epart(h) = epart(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p }
- | epart(h):p sp+ epart_head(h | p.pos):e { p.args.push *Array(e) ; p }
+epart(h) = epart(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p }
+ | epart(h):p sp+ epart_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p }
| args:a ":" !&":" ~n(a.pos, nil, a.name, *a.args)
-spart(h) = spart(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p }
- | spart(h):p sp* epart_head(h | p.pos):e { p.args.push *Array(e) ; p }
+spart(h) = spart(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p }
+ | spart(h):p sp* epart_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p }
| p:p ":" (sp|nl|sheebang) ~n(p, nil, nil)
epart_head(h) = ph_comma(h) | expr(h) | {[]}
-expr(h) = value(h):e &{ e.pos.column > h.column } {e}
+expr(h) = value(h):e &{ e.pos.column > h.pos.column } {e}
chain(h) = chain(h):a w "." - chain(h):b ~chain_cont(a, b)
| operator:a !&brace o w chain(h):b
~n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))
- | chain_val(h):a sp* chain(a.pos):b ~chain_cont(a, b)
+ | chain_val(h):a sp* chain(h.at(a.pos)):b ~chain_cont(a, b)
| chain_val(h)
chain_val(h) = cons(h) | expr(h)
@@ -197,6 +197,6 @@ number_escapes = /[xX]/ < /[0-9a-fA-F]{1,5}/ > { [text.to_i(16)].pack("U") }
| /[uU]/ < /[0-9a-fA-F]{4}/ > { [text.to_i(16)].pack("U") }
-root = - block(h)?:b - eof {b}
-unit = - chain(h):c {c}
+root = - block(ctx)?:b - eof {b}
+unit = - chain(ctx):c {c}
eof = !.
View
@@ -1490,7 +1490,7 @@ def _quoted(t,q)
return _tmp
end
- # quoted_inner = (p:p "#{" - block(h)?:b - "}" {b} | p:p < ("\\" escape | ("\\" q | "\\#" | &(!(q | "#{")) .))+ > {n(p, t, text)})
+ # quoted_inner = (p:p "#{" - block(ctx)?:b - "}" {b} | p:p < ("\\" escape | ("\\" q | "\\#" | &(!(q | "#{")) .))+ > {n(p, t, text)})
def _quoted_inner(t,q)
_save = self.pos
@@ -1515,7 +1515,7 @@ def _quoted_inner(t,q)
break
end
_save2 = self.pos
- _tmp = apply_with_args(:_block, h)
+ _tmp = apply_with_args(:_block, ctx)
@result = nil unless _tmp
unless _tmp
_tmp = true
@@ -2909,7 +2909,7 @@ def _cons(h)
return _tmp
end
- # args = p:p left_brace:l - (comma(h) | block(h) | {[]}):a - right_brace(l) {n(p, l.join, *Array(a))}
+ # args = p:p left_brace:l - (comma(ctx) | block(ctx) | {[]}):a - right_brace(l) {n(p, l.join, *Array(a))}
def _args
_save = self.pos
@@ -2934,10 +2934,10 @@ def _args
_save1 = self.pos
while true # choice
- _tmp = apply_with_args(:_comma, h)
+ _tmp = apply_with_args(:_comma, ctx)
break if _tmp
self.pos = _save1
- _tmp = apply_with_args(:_block, h)
+ _tmp = apply_with_args(:_block, ctx)
break if _tmp
self.pos = _save1
@result = begin; []; end
@@ -2992,7 +2992,7 @@ def _msg(h)
return _tmp
end
- # kmsg = (kmsg(h):a sp* (&"::" | ":" &(";" | ".")) {a} | part(h):a w kmsg(h | a.pos):m {n(a.pos, :msg, a, *m.args)} | part(h):a {n(a.pos, :msg, a)})
+ # kmsg = (kmsg(h):a sp* (&"::" | ":" &(";" | ".")) {a} | part(h):a w kmsg(h.at?(a.pos)):m {n(a.pos, :msg, a, *m.args)} | part(h):a {n(a.pos, :msg, a)})
def _kmsg(h)
_save = self.pos
@@ -3084,7 +3084,7 @@ def _kmsg(h)
self.pos = _save8
break
end
- _tmp = apply_with_args(:_kmsg, h | a.pos)
+ _tmp = apply_with_args(:_kmsg, h.at?(a.pos))
m = @result
unless _tmp
self.pos = _save8
@@ -3126,7 +3126,7 @@ def _kmsg(h)
return _tmp
end
- # part = (part(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p } | part(h):p sp+ part_head(h | p.pos):e { p.args.push *Array(e) ; p } | p:p keyargs:k {n(p, k.first, k.last.name, *k.last.args)} | p:p keyword:k {n(p, k, nil)})
+ # part = (part(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | part(h):p sp+ part_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | p:p keyargs:k {n(p, k.first, k.last.name, *k.last.args)} | p:p keyword:k {n(p, k, nil)})
def _part(h)
_save = self.pos
@@ -3150,7 +3150,7 @@ def _part(h)
self.pos = _save1
break
end
- _tmp = apply_with_args(:_block, h | p.pos)
+ _tmp = apply_with_args(:_block, h.at?(p.pos))
e = @result
unless _tmp
self.pos = _save1
@@ -3190,7 +3190,7 @@ def _part(h)
self.pos = _save2
break
end
- _tmp = apply_with_args(:_part_head, h | p.pos)
+ _tmp = apply_with_args(:_part_head, h.at?(p.pos))
e = @result
unless _tmp
self.pos = _save2
@@ -3511,7 +3511,7 @@ def _emsg(h)
return _tmp
end
- # epart = (epart(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p } | epart(h):p sp+ epart_head(h | p.pos):e { p.args.push *Array(e) ; p } | args:a ":" !(&":") {n(a.pos, nil, a.name, *a.args)})
+ # epart = (epart(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | epart(h):p sp+ epart_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | args:a ":" !(&":") {n(a.pos, nil, a.name, *a.args)})
def _epart(h)
_save = self.pos
@@ -3535,7 +3535,7 @@ def _epart(h)
self.pos = _save1
break
end
- _tmp = apply_with_args(:_block, h | p.pos)
+ _tmp = apply_with_args(:_block, h.at?(p.pos))
e = @result
unless _tmp
self.pos = _save1
@@ -3575,7 +3575,7 @@ def _epart(h)
self.pos = _save2
break
end
- _tmp = apply_with_args(:_epart_head, h | p.pos)
+ _tmp = apply_with_args(:_epart_head, h.at?(p.pos))
e = @result
unless _tmp
self.pos = _save2
@@ -3632,7 +3632,7 @@ def _epart(h)
return _tmp
end
- # spart = (spart(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p } | spart(h):p sp* epart_head(h | p.pos):e { p.args.push *Array(e) ; p } | p:p ":" (sp | nl | sheebang) {n(p, nil, nil)})
+ # spart = (spart(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | spart(h):p sp* epart_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | p:p ":" (sp | nl | sheebang) {n(p, nil, nil)})
def _spart(h)
_save = self.pos
@@ -3656,7 +3656,7 @@ def _spart(h)
self.pos = _save1
break
end
- _tmp = apply_with_args(:_block, h | p.pos)
+ _tmp = apply_with_args(:_block, h.at?(p.pos))
e = @result
unless _tmp
self.pos = _save1
@@ -3690,7 +3690,7 @@ def _spart(h)
self.pos = _save2
break
end
- _tmp = apply_with_args(:_epart_head, h | p.pos)
+ _tmp = apply_with_args(:_epart_head, h.at?(p.pos))
e = @result
unless _tmp
self.pos = _save2
@@ -3778,7 +3778,7 @@ def _epart_head(h)
return _tmp
end
- # expr = value(h):e &{ e.pos.column > h.column } {e}
+ # expr = value(h):e &{ e.pos.column > h.pos.column } {e}
def _expr(h)
_save = self.pos
@@ -3790,7 +3790,7 @@ def _expr(h)
break
end
_save1 = self.pos
- _tmp = begin; e.pos.column > h.column ; end
+ _tmp = begin; e.pos.column > h.pos.column ; end
self.pos = _save1
unless _tmp
self.pos = _save
@@ -3808,7 +3808,7 @@ def _expr(h)
return _tmp
end
- # chain = (chain(h):a w "." - chain(h):b {chain_cont(a, b)} | operator:a !(&brace) o w chain(h):b {n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))} | chain_val(h):a sp* chain(a.pos):b {chain_cont(a, b)} | chain_val(h))
+ # chain = (chain(h):a w "." - chain(h):b {chain_cont(a, b)} | operator:a !(&brace) o w chain(h):b {n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))} | chain_val(h):a sp* chain(h.at(a.pos)):b {chain_cont(a, b)} | chain_val(h))
def _chain(h)
_save = self.pos
@@ -3916,7 +3916,7 @@ def _chain(h)
self.pos = _save5
break
end
- _tmp = apply_with_args(:_chain, a.pos)
+ _tmp = apply_with_args(:_chain, h.at(a.pos))
b = @result
unless _tmp
self.pos = _save5
@@ -4996,7 +4996,7 @@ def _number_escapes
return _tmp
end
- # root = - block(h)?:b - eof {b}
+ # root = - block(ctx)?:b - eof {b}
def _root
_save = self.pos
@@ -5007,7 +5007,7 @@ def _root
break
end
_save1 = self.pos
- _tmp = apply_with_args(:_block, h)
+ _tmp = apply_with_args(:_block, ctx)
@result = nil unless _tmp
unless _tmp
_tmp = true
@@ -5040,7 +5040,7 @@ def _root
return _tmp
end
- # unit = - chain(h):c {c}
+ # unit = - chain(ctx):c {c}
def _unit
_save = self.pos
@@ -5050,7 +5050,7 @@ def _unit
self.pos = _save
break
end
- _tmp = apply_with_args(:_chain, h)
+ _tmp = apply_with_args(:_chain, ctx)
c = @result
unless _tmp
self.pos = _save
@@ -5110,7 +5110,7 @@ def _eof
Rules[:_qstr] = rule_info("qstr", "p:p \"'\" < (\"\\\\\" escape | \"\\\\'\" | !(&\"'\") .)* > \"'\" {n(p, :text, text)}")
Rules[:_sstr] = rule_info("sstr", "p:p quoted(:text, &\"\\\"\"):b {text_node(p, b)}")
Rules[:_quoted] = rule_info("quoted", "q quoted_inner(t, q)*:b q {b}")
- Rules[:_quoted_inner] = rule_info("quoted_inner", "(p:p \"\#{\" - block(h)?:b - \"}\" {b} | p:p < (\"\\\\\" escape | (\"\\\\\" q | \"\\\\\#\" | &(!(q | \"\#{\")) .))+ > {n(p, t, text)})")
+ Rules[:_quoted_inner] = rule_info("quoted_inner", "(p:p \"\#{\" - block(ctx)?:b - \"}\" {b} | p:p < (\"\\\\\" escape | (\"\\\\\" q | \"\\\\\#\" | &(!(q | \"\#{\")) .))+ > {n(p, t, text)})")
Rules[:_mstr] = rule_info("mstr", "p:p \"\\\"\\\"\\\"\" mstr_inner*:b \"\\\"\\\"\\\"\" {text_node(p, b)}")
Rules[:_mstr_inner] = rule_info("mstr_inner", "(p:p \"\#{\" - block(h)?:b - \"}\" {b} | p:p < (\"\\\\\" escape | (\"\\\\\\\"\\\"\\\"\" | !(&(\"\\\"\\\"\\\"\" | \"\#{\")) . | . &\"\\\"\\\"\\\"\"))+ > {n(p, :text, text)})")
Rules[:_opchr] = rule_info("opchr", "/[\\~\\!@\\\#\\$%\\^\\&\\|\\?\\<\\>*\\/+=-]/")
@@ -5126,24 +5126,24 @@ def _eof
Rules[:_tuple] = rule_info("tuple", "comma(h):c {n(p, :tuple, *c)}")
Rules[:_cons_left] = rule_info("cons_left", "expr(h):a sp* \"::\" !(&(\":\" | \";\" | \".\")) {a}")
Rules[:_cons] = rule_info("cons", "cons_left(h):a - chain_val(h):b {n(p, :cons, a, b)}")
- Rules[:_args] = rule_info("args", "p:p left_brace:l - (comma(h) | block(h) | {[]}):a - right_brace(l) {n(p, l.join, *Array(a))}")
+ Rules[:_args] = rule_info("args", "p:p left_brace:l - (comma(ctx) | block(ctx) | {[]}):a - right_brace(l) {n(p, l.join, *Array(a))}")
Rules[:_msg] = rule_info("msg", "(kmsg(h) | emsg(h))")
- Rules[:_kmsg] = rule_info("kmsg", "(kmsg(h):a sp* (&\"::\" | \":\" &(\";\" | \".\")) {a} | part(h):a w kmsg(h | a.pos):m {n(a.pos, :msg, a, *m.args)} | part(h):a {n(a.pos, :msg, a)})")
- Rules[:_part] = rule_info("part", "(part(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p } | part(h):p sp+ part_head(h | p.pos):e { p.args.push *Array(e) ; p } | p:p keyargs:k {n(p, k.first, k.last.name, *k.last.args)} | p:p keyword:k {n(p, k, nil)})")
+ Rules[:_kmsg] = rule_info("kmsg", "(kmsg(h):a sp* (&\"::\" | \":\" &(\";\" | \".\")) {a} | part(h):a w kmsg(h.at?(a.pos)):m {n(a.pos, :msg, a, *m.args)} | part(h):a {n(a.pos, :msg, a)})")
+ Rules[:_part] = rule_info("part", "(part(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | part(h):p sp+ part_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | p:p keyargs:k {n(p, k.first, k.last.name, *k.last.args)} | p:p keyword:k {n(p, k, nil)})")
Rules[:_part_head] = rule_info("part_head", "!(&keypart) (ph_comma(h) | expr(h) | {[]})")
Rules[:_ph_comma] = rule_info("ph_comma", "(expr(h):a w \",\" - ph_comma(h):b { b.unshift a ; b } | expr(h):a w \",\" - expr(h):b { [a,b] })")
Rules[:_emsg] = rule_info("emsg", "(emsg(h):a sp* (&\"::\" | \":\" &(\";\" | \".\")) {a} | (epart(h) | spart(h)):a {n(a.pos, :msg, a)})")
- Rules[:_epart] = rule_info("epart", "(epart(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p } | epart(h):p sp+ epart_head(h | p.pos):e { p.args.push *Array(e) ; p } | args:a \":\" !(&\":\") {n(a.pos, nil, a.name, *a.args)})")
- Rules[:_spart] = rule_info("spart", "(spart(h):p o w block(h | p.pos):e { p.args.push *Array(e) ; p } | spart(h):p sp* epart_head(h | p.pos):e { p.args.push *Array(e) ; p } | p:p \":\" (sp | nl | sheebang) {n(p, nil, nil)})")
+ Rules[:_epart] = rule_info("epart", "(epart(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | epart(h):p sp+ epart_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | args:a \":\" !(&\":\") {n(a.pos, nil, a.name, *a.args)})")
+ Rules[:_spart] = rule_info("spart", "(spart(h):p o w block(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | spart(h):p sp* epart_head(h.at?(p.pos)):e { p.args.push *Array(e) ; p } | p:p \":\" (sp | nl | sheebang) {n(p, nil, nil)})")
Rules[:_epart_head] = rule_info("epart_head", "(ph_comma(h) | expr(h) | {[]})")
- Rules[:_expr] = rule_info("expr", "value(h):e &{ e.pos.column > h.column } {e}")
- Rules[:_chain] = rule_info("chain", "(chain(h):a w \".\" - chain(h):b {chain_cont(a, b)} | operator:a !(&brace) o w chain(h):b {n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))} | chain_val(h):a sp* chain(a.pos):b {chain_cont(a, b)} | chain_val(h))")
+ Rules[:_expr] = rule_info("expr", "value(h):e &{ e.pos.column > h.pos.column } {e}")
+ Rules[:_chain] = rule_info("chain", "(chain(h):a w \".\" - chain(h):b {chain_cont(a, b)} | operator:a !(&brace) o w chain(h):b {n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))} | chain_val(h):a sp* chain(h.at(a.pos)):b {chain_cont(a, b)} | chain_val(h))")
Rules[:_chain_val] = rule_info("chain_val", "(cons(h) | expr(h))")
Rules[:_block] = rule_info("block", "(chain(h):a sp* t - block(h):b {n(a.pos, :block, a, *Array(b.name == :block && b.args || b))} | chain(h))")
Rules[:_escape] = rule_info("escape", "(number_escapes | escapes)")
Rules[:_escapes] = rule_info("escapes", "(\"n\" { \"\\n\" } | \"s\" { \" \" } | \"r\" { \"\\r\" } | \"t\" { \"\\t\" } | \"v\" { \"\\v\" } | \"f\" { \"\\f\" } | \"b\" { \"\\b\" } | \"a\" { \"\\a\" } | \"e\" { \"\\e\" } | \"\\\\\" { \"\\\\\" } | \"\\\"\" { \"\\\"\" } | \"BS\" { \"\\b\" } | \"HT\" { \"\\t\" } | \"LF\" { \"\\n\" } | \"VT\" { \"\\v\" } | \"FF\" { \"\\f\" } | \"CR\" { \"\\r\" } | \"SO\" { \"\\016\" } | \"SI\" { \"\\017\" } | \"EM\" { \"\\031\" } | \"FS\" { \"\\034\" } | \"GS\" { \"\\035\" } | \"RS\" { \"\\036\" } | \"US\" { \"\\037\" } | \"SP\" { \" \" } | \"NUL\" { \"\\000\" } | \"SOH\" { \"\\001\" } | \"STX\" { \"\\002\" } | \"ETX\" { \"\\003\" } | \"EOT\" { \"\\004\" } | \"ENQ\" { \"\\005\" } | \"ACK\" { \"\\006\" } | \"BEL\" { \"\\a\" } | \"DLE\" { \"\\020\" } | \"DC1\" { \"\\021\" } | \"DC2\" { \"\\022\" } | \"DC3\" { \"\\023\" } | \"DC4\" { \"\\024\" } | \"NAK\" { \"\\025\" } | \"SYN\" { \"\\026\" } | \"ETB\" { \"\\027\" } | \"CAN\" { \"\\030\" } | \"SUB\" { \"\\032\" } | \"ESC\" { \"\\e\" } | \"DEL\" { \"\\177\" } | < . > { \"\\\\\" + text })")
Rules[:_number_escapes] = rule_info("number_escapes", "(/[xX]/ < /[0-9a-fA-F]{1,5}/ > { [text.to_i(16)].pack(\"U\") } | < /\\d{1,6}/ > { [text.to_i].pack(\"U\") } | /[oO]/ < /[0-7]{1,7}/ > { [text.to_i(16)].pack(\"U\") } | /[uU]/ < /[0-9a-fA-F]{4}/ > { [text.to_i(16)].pack(\"U\") })")
- Rules[:_root] = rule_info("root", "- block(h)?:b - eof {b}")
- Rules[:_unit] = rule_info("unit", "- chain(h):c {c}")
+ Rules[:_root] = rule_info("root", "- block(ctx)?:b - eof {b}")
+ Rules[:_unit] = rule_info("unit", "- chain(ctx):c {c}")
Rules[:_eof] = rule_info("eof", "!.")
end
View
@@ -29,17 +29,46 @@ def current_position(o = pos)
Position.new(current_line(o), current_column(o))
end
- def h
- Position.new(0, 0)
+ def ctx
+ Context.new Position.new(0, 0)
end
- class Position
- attr_accessor :line, :column
+ class Context < Struct.new(:pos)
+
+ def self.attr(name, val = true)
+ attr_accessor name
+ module_eval "
+ #{"def"} #{name}?
+ !!(@#{name} ||= #{val})
+ end
+ #{"def"} #{name}!
+ @#{name} = !#{name}?
+ end
+ #{"def"} #{name}(val = #{val})
+ o = dup
+ o.#{name} = val
+ o
+ end
+ "
+ end
+
+ def at?(pos)
+ o = dup
+ o.pos = @pos | pos
+ o
+ end
- def initialize(line = nil, column = nil)
- @line, @column = line, column
+ def at(pos)
+ o = dup
+ o.pos = pos
+ o
end
+ attr :keymsg
+ attr :comma
+ end
+
+ class Position < Struct.new(:line, :column)
def |(other)
if @line.nil? || @line.zero?
other
View
@@ -2,14 +2,12 @@
shared_context 'grammar' do
- def o(line = 0, column = 0)
- Akin::Grammar::Position.new(line, column)
- end
-
def c(code, rule = :root, fail_on_error = false, *args)
parser = Akin::Grammar.new(code)
method = "_"+rule.to_s.gsub('-', '_hyphen_')
- args.push(o) if parser.method(method).arity > 0 && args.empty?
+ if parser.method(method).arity > 0 && args.empty?
+ args.push(parser.ctx)
+ end
ok = parser.__send__(method, *args)
parser.raise_error if fail_on_error && !ok
ok && parser.result

0 comments on commit febbac9

Please sign in to comment.