Skip to content

Commit

Permalink
Simplified cons rule.
Browse files Browse the repository at this point in the history
  • Loading branch information
vic committed Aug 24, 2011
1 parent 06db136 commit 8f875b7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 64 deletions.
3 changes: 1 addition & 2 deletions lib/akin/grammar.kpeg
Expand Up @@ -93,8 +93,7 @@ tuple(h) = comma(h):c ~n(p, :tuple, *c)


cons_left(h) = expr(h):a sp* "::" !&(":"|";"|".") {a} cons_left(h) = expr(h):a sp* "::" !&(":"|";"|".") {a}


cons(h) = cons_left(h):a - cons(h):b ~n(p, :cons, a, b) cons(h) = cons_left(h):a - chain_val(h):b ~n(p, :cons, a, b)
| cons_left(h):a - expr(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(h) | block(h) | {[]}):a - right_brace(l)
~n(p, l.join, *Array(a)) ~n(p, l.join, *Array(a))
Expand Down
86 changes: 24 additions & 62 deletions lib/akin/grammar.rb
Expand Up @@ -2766,73 +2766,35 @@ def _cons_left(h)
return _tmp return _tmp
end end


# cons = (cons_left(h):a - cons(h):b {n(p, :cons, a, b)} | cons_left(h):a - expr(h):b {n(p, :cons, a, b)}) # cons = cons_left(h):a - chain_val(h):b {n(p, :cons, a, b)}
def _cons(h) def _cons(h)


_save = self.pos _save = self.pos
while true # choice while true # sequence

_tmp = apply_with_args(:_cons_left, h)
_save1 = self.pos a = @result
while true # sequence unless _tmp
_tmp = apply_with_args(:_cons_left, h) self.pos = _save
a = @result
unless _tmp
self.pos = _save1
break
end
_tmp = apply(:__hyphen_)
unless _tmp
self.pos = _save1
break
end
_tmp = apply_with_args(:_cons, h)
b = @result
unless _tmp
self.pos = _save1
break
end
@result = begin; n(p, :cons, a, b); end
_tmp = true
unless _tmp
self.pos = _save1
end
break break
end # end sequence end

_tmp = apply(:__hyphen_)
break if _tmp unless _tmp
self.pos = _save self.pos = _save

_save2 = self.pos
while true # sequence
_tmp = apply_with_args(:_cons_left, h)
a = @result
unless _tmp
self.pos = _save2
break
end
_tmp = apply(:__hyphen_)
unless _tmp
self.pos = _save2
break
end
_tmp = apply_with_args(:_expr, h)
b = @result
unless _tmp
self.pos = _save2
break
end
@result = begin; n(p, :cons, a, b); end
_tmp = true
unless _tmp
self.pos = _save2
end
break break
end # end sequence end

_tmp = apply_with_args(:_chain_val, h)
break if _tmp b = @result
self.pos = _save unless _tmp
self.pos = _save
break
end
@result = begin; n(p, :cons, a, b); end
_tmp = true
unless _tmp
self.pos = _save
end
break break
end # end choice end # end sequence


set_failed_rule :_cons unless _tmp set_failed_rule :_cons unless _tmp
return _tmp return _tmp
Expand Down Expand Up @@ -3775,7 +3737,7 @@ def _eof
Rules[:_comma] = rule_info("comma", "(comma_left(h):a w comma(h):b { b.unshift a ; b } | comma_left(h):a w block(h):b { [a,b] } | comma_left(h):a &(sp* (\".\" | \",\" | t | brace)) {[a]})") Rules[:_comma] = rule_info("comma", "(comma_left(h):a w comma(h):b { b.unshift a ; b } | comma_left(h):a w block(h):b { [a,b] } | comma_left(h):a &(sp* (\".\" | \",\" | t | brace)) {[a]})")
Rules[:_tuple] = rule_info("tuple", "comma(h):c {n(p, :tuple, *c)}") 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_left] = rule_info("cons_left", "expr(h):a sp* \"::\" !(&(\":\" | \";\" | \".\")) {a}")
Rules[:_cons] = rule_info("cons", "(cons_left(h):a - cons(h):b {n(p, :cons, a, b)} | cons_left(h):a - expr(h):b {n(p, :cons, a, b)})") 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(h) | block(h) | {[]}):a - right_brace(l) {n(p, l.join, *Array(a))}")
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[:_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 keyargs:k {n(p, k.first, k.last.name, *k.last.args)} | p:p keyword:k {n(p, k, nil)})") 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 keyargs:k {n(p, k.first, k.last.name, *k.last.args)} | p:p keyword:k {n(p, k, nil)})")
Expand Down

0 comments on commit 8f875b7

Please sign in to comment.