Skip to content
Browse files

Simplified chain rule.

  • Loading branch information...
1 parent cc14e4b commit 1166fa38751d1ec7396afdef28ad398fd0f91c0b @vic committed Aug 16, 2011
Showing with 16 additions and 67 deletions.
  1. +0 −1 lib/akin/grammar.kpeg
  2. +16 −66 lib/akin/grammar.rb
View
1 lib/akin/grammar.kpeg
@@ -112,7 +112,6 @@ ph_comma(h) = expr(h):a w "," - ph_comma(h):b { b.unshift a ; b }
expr(h) = value(h):e &{ e.pos.column > h.column } {e}
chain(h) = chain(h):a w "." - chain(h):b ~n(a.pos, :chain, a, b)
- | chain(h):a sp* "." - chain(h)?:b { b && n(a.pos, :chain, a, b) || a }
| operator:a !&brace o w chain(h):b
~n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))
| chain_cont(h)
View
82 lib/akin/grammar.rb
@@ -3156,7 +3156,7 @@ def _expr(h)
set_failed_rule :_expr unless _tmp
return _tmp
end
-
+
# chain = (chain(h):a w "." - chain(h):b {n(a.pos, :chain, a, b)} | operator:a !(&brace) o w chain(h):b {n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))} | chain_cont(h) | expr(h):a sp* chain(a.pos):b {n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))} | chain_val(h))
def _chain(h)
@@ -3204,92 +3204,42 @@ def _chain(h)
self.pos = _save
_save2 = self.pos
- while true # sequence
+ while true # sequence
_tmp = apply(:_operator)
a = @result
unless _tmp
self.pos = _save2
break
- end
- while true
- _tmp = apply(:_sp)
- break unless _tmp
- end
- _tmp = true
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = match_string(".")
- unless _tmp
- self.pos = _save2
- break
- end
- _tmp = apply(:__hyphen_)
- unless _tmp
- self.pos = _save2
- break
+ end
_save3 = self.pos
- _save4 = self.pos
- _tmp = apply_with_args(:_chain, h)
- @result = nil unless _tmp
- unless _tmp
- _tmp = true
- self.pos = _save4
- end
- b = @result
- unless _tmp
- self.pos = _save2
- break
- end
- @result = begin; b && n(a.pos, :chain, a, b) || a ; end
- _tmp = true
- unless _tmp
- self.pos = _save2
- end
- break
- end # end sequence
-
- break if _tmp
- self.pos = _save
-
- _save5 = self.pos
- while true # sequence
- _tmp = apply(:_operator)
- a = @result
- unless _tmp
- self.pos = _save5
- break
- end
- _save6 = self.pos
_save4 = self.pos
- _tmp = apply(:_brace)
+ _tmp = apply(:_brace)
self.pos = _save4
- _tmp = _tmp ? nil : true
+ _tmp = _tmp ? nil : true
self.pos = _save3
- unless _tmp
+ unless _tmp
self.pos = _save2
break
end
_tmp = apply(:_o)
- unless _tmp
+ unless _tmp
self.pos = _save2
break
end
_tmp = apply(:_w)
- unless _tmp
+ unless _tmp
self.pos = _save2
break
end
_tmp = apply_with_args(:_chain, h)
b = @result
- unless _tmp
+ unless _tmp
self.pos = _save2
break
end
@result = begin; n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b)); end
_tmp = true
- unless _tmp
+ unless _tmp
self.pos = _save2
end
break
@@ -3300,12 +3250,12 @@ def _chain(h)
_tmp = apply_with_args(:_chain_cont, h)
break if _tmp
self.pos = _save
-
+
_save5 = self.pos
while true # sequence
_tmp = apply_with_args(:_expr, h)
a = @result
- unless _tmp
+ unless _tmp
self.pos = _save5
break
end
@@ -3314,19 +3264,19 @@ def _chain(h)
break unless _tmp
end
_tmp = true
- unless _tmp
+ unless _tmp
self.pos = _save5
break
end
_tmp = apply_with_args(:_chain, a.pos)
b = @result
- unless _tmp
+ unless _tmp
self.pos = _save5
break
end
@result = begin; n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b)); end
_tmp = true
- unless _tmp
+ unless _tmp
self.pos = _save5
end
break
@@ -3645,7 +3595,7 @@ def _eof
Rules[:_msg] = rule_info("msg", "(msg(h):a sp* \":\" &(\":\" | \";\" | \".\") {a} | part(h):a w msg(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 part_head(h | p.pos):e { p.args.push *Array(e) ; p } | p:p keyword:k args:a {n(p, k, a.name, *a.args)} | p:p keyword:k {n(p, k, nil)})")
Rules[:_part_head] = rule_info("part_head", "sp+ !(&keyword) (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[:_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[:_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 {n(a.pos, :chain, a, b)} | operator:a !(&brace) o w chain(h):b {n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))} | chain_cont(h) | expr(h):a sp* chain(a.pos):b {n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))} | chain_val(h))")
Rules[:_chain_cont] = rule_info("chain_cont", "chain_val(h):a {(h | a.pos || h()).incr}:i sp* (comma(h) | (nl | sheebang) - block(i)):c { if a.name == :act a.args.push *Array(c); a else n(a.pos, :act, a, nil, *Array(c)) end }")

0 comments on commit 1166fa3

Please sign in to comment.
Something went wrong with that request. Please try again.