Permalink
Browse files

Dont assume activation is round-bracketed unless explicitly made so.

  • Loading branch information...
1 parent 58cd723 commit cc14e4b8c8651f025ecb96b41d3e2aa131b6064e @vic committed Aug 17, 2011
Showing with 58 additions and 58 deletions.
  1. +2 −2 lib/akin/grammar.kpeg
  2. +6 −6 lib/akin/grammar.rb
  3. +50 −50 spec/grammar_spec.rb
View
4 lib/akin/grammar.kpeg
@@ -102,7 +102,7 @@ msg(h) = msg(h):a sp* ":" &(":"|";"|".") {a}
part(h) = 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, "()")
+ | p:p keyword:k ~n(p, k, nil)
part_head(h) = sp+ !&keyword (ph_comma(h) | expr(h) | {[]})
@@ -126,7 +126,7 @@ chain_cont(h) = chain_val(h):a {(h | a.pos || h()).incr}:i sp*
if a.name == :act
a.args.push *Array(c); a
else
- n(a.pos, :act, a, "()", *Array(c))
+ n(a.pos, :act, a, nil, *Array(c))
end
}
View
12 lib/akin/grammar.rb
@@ -2850,7 +2850,7 @@ def _msg(h)
set_failed_rule :_msg unless _tmp
return _tmp
end
-
+
# 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)})
def _part(h)
@@ -2961,7 +2961,7 @@ def _part(h)
unless _tmp
self.pos = _save4
break
- end
+ end
@result = begin; n(p, k, nil); end
_tmp = true
unless _tmp
@@ -3343,7 +3343,7 @@ def _chain(h)
set_failed_rule :_chain unless _tmp
return _tmp
end
-
+
# 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 }
def _chain_cont(h)
@@ -3421,7 +3421,7 @@ def _chain_cont(h)
@result = begin;
if a.name == :act
a.args.push *Array(c); a
- else
+ else
n(a.pos, :act, a, nil, *Array(c))
end
; end
@@ -3641,12 +3641,12 @@ 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 - cons(h):b {n(p, :cons, a, b)} | cons_left(h):a - expr(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[:_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[:_expr] = rule_info("expr", "value(h):e &{ e.pos.column > h.column } {e}")
+ 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)} | 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) | 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 }")
Rules[:_chain_val] = rule_info("chain_val", "(cons(h) | expr(h))")
View
100 spec/grammar_spec.rb
@@ -106,19 +106,19 @@
describe 'message' do
it 'parses one part' do
- s(':foo', :msg).should == [:msg, ["foo", "()"]]
+ s(':foo', :msg).should == [:msg, ["foo", nil]]
end
it 'parses a part with args' do
s(':foo(bar)', :msg).should == [:msg, ["foo", "()", [:name, "bar"]]]
end
it 'parses a part with head' do
- s(':foo bar', :msg).should == [:msg, ["foo", "()", [:name, "bar"]]]
+ s(':foo bar', :msg).should == [:msg, ["foo", nil, [:name, "bar"]]]
end
it 'parses a part with head and commas' do
- s(':foo bar, baz', :msg).should == [:msg, ["foo", "()",
+ s(':foo bar, baz', :msg).should == [:msg, ["foo", nil,
[:name, "bar"],
[:name, "baz"]]]
end
@@ -138,60 +138,60 @@
it 'parses a two parts message' do
s(':foo bar :baz bat', :msg).should ==
- [:msg, ["foo", "()", [:name, "bar"]],
- ["baz", "()", [:name, "bat"]]]
+ [:msg, ["foo", nil, [:name, "bar"]],
+ ["baz", nil, [:name, "bat"]]]
end
it 'parses an empty part and second path with head' do
s(':foo :baz bat', :msg).should ==
- [:msg, ["foo", "()"],
- ["baz", "()", [:name, "bat"]]]
+ [:msg, ["foo", nil],
+ ["baz", nil, [:name, "bat"]]]
end
it 'parses three empty parts' do
s(':foo :baz :bat', :msg).should ==
- [:msg, ["foo", "()"],
- ["baz", "()"],
- ["bat", "()"]]
+ [:msg, ["foo", nil],
+ ["baz", nil],
+ ["bat", nil]]
end
it 'parses three empty parts second having args' do
s(':foo :baz(a, b) :bat', :msg).should ==
- [:msg, ["foo", "()"],
+ [:msg, ["foo", nil],
["baz", "()", [:name, "a"], [:name, "b"]],
- ["bat", "()"]]
+ ["bat", nil]]
end
it 'parses second arg having commas' do
s(':foo :baz a, b :bat c', :msg).should ==
- [:msg, ["foo", "()"],
- ["baz", "()",
+ [:msg, ["foo", nil],
+ ["baz", nil,
[:name, "a"],
[:name, "b"]],
- ["bat", "()",
+ ["bat", nil,
[:name, "c"]]]
end
it 'parses second arg having cons' do
s(':foo :baz (a: b) :bat c', :msg).should ==
- [:msg, ["foo", "()"],
- ["baz", "()",
+ [:msg, ["foo", nil],
+ ["baz", nil,
[:act, nil, "()", [:cons, [:name, "a"], [:name, "b"]]]],
- ["bat", "()", [:name, "c"]]]
+ ["bat", nil, [:name, "c"]]]
end
it 'allow head to have commas' do
code = ":foo a,\n b"
s(code, :msg).should ==
- [:msg, ["foo", "()",
+ [:msg, ["foo", nil,
[:name, "a"],
[:name, "b"]]]
end
it 'parses head on same line as a single argument' do
code = ":foo a\n b"
s(code, :msg).should ==
- [:msg, ["foo", "()",
+ [:msg, ["foo", nil,
[:name, "a"],
[:name, "b"]]]
end
@@ -209,7 +209,7 @@
it 'parses until dot is found' do
code = ":foo ."
s(code, :chain).should ==
- [:msg, ["foo", "()"]]
+ [:msg, ["foo", nil]]
end
it 'parses binary op' do
@@ -250,47 +250,47 @@
it 'parses a message but doesnt include non-nested identifier' do
code = "d :foo a\nb"
s(code, :block).should ==
- [:block, [:chain, [:name, "d"], [:msg, ["foo", "()", [:name, "a"]]]],
+ [:block, [:chain, [:name, "d"], [:msg, ["foo", nil, [:name, "a"]]]],
[:name, "b"]]
end
it 'parses first message but doesnt include non-nested identifier' do
code = ":foo a\nb"
s(code, :block).should ==
- [:block, [:msg, ["foo", "()", [:name, "a"]]],
+ [:block, [:msg, ["foo", nil, [:name, "a"]]],
[:name, "b"]]
end
it 'parses two parts on same column as single message' do
code = ":foo a\n:bar b"
s(code, :block).should ==
- [:msg, ["foo", "()", [:name, "a"]],
- ["bar", "()", [:name, "b"]]]
+ [:msg, ["foo", nil, [:name, "a"]],
+ ["bar", nil, [:name, "b"]]]
end
it 'parses two parts on same column as single message' do
code = "m :foo a\n:bar b"
s(code, :block).should ==
[:chain, [:name, "m"],
- [:msg, ["foo", "()", [:name, "a"]],
- ["bar", "()", [:name, "b"]]]]
+ [:msg, ["foo", nil, [:name, "a"]],
+ ["bar", nil, [:name, "b"]]]]
end
it 'parses two parts on same column as single message until non-part' do
code = "m :foo a\n:bar b\nbaz\n:bat c"
s(code, :block).should ==
[:block, [:chain, [:name, "m"],
- [:msg, ["foo", "()", [:name, "a"]],
- ["bar", "()", [:name, "b"]]]],
+ [:msg, ["foo", nil, [:name, "a"]],
+ ["bar", nil, [:name, "b"]]]],
[:name, "baz"],
- [:msg, ["bat", "()", [:name, "c"]]]]
+ [:msg, ["bat", nil, [:name, "c"]]]]
end
it 'parses message until semicolon-dot is found' do
code = "a :b c :. d"
s(code, :block).should ==
[:chain, [:name, "a"],
- [:msg, ["b", "()", [:name, "c"]]],
+ [:msg, ["b", nil, [:name, "c"]]],
[:name, "d"]]
end
@@ -299,15 +299,15 @@
s(code, :block).should ==
[:block,
[:chain, [:name, "a"],
- [:msg, ["b", "()", [:name, "c"]]]],
+ [:msg, ["b", nil, [:name, "c"]]]],
[:name, "d"]]
end
it 'parses message until semicolon-semicolon is found' do
code = "a :b c :: d"
s(code, :root).should ==
[:chain, [:name, "a"],
- [:cons, [:msg, ["b", "()", [:name, "c"]]], [:name, "d"]]]
+ [:cons, [:msg, ["b", nil, [:name, "c"]]], [:name, "d"]]]
end
end
@@ -377,8 +377,8 @@
CODE
s(code, :root).should ==
[:chain, [:name, "Point"],
- [:msg, ["x", "()", [:name, "a"]],
- ["y", "()", [:name, "b"]]]]
+ [:msg, ["x", nil, [:name, "a"]],
+ ["y", nil, [:name, "b"]]]]
end
it 'parses a pair of two identifiers' do
@@ -422,9 +422,9 @@
CODE
s(code, :root).should ==
[:chain, [:name, "a"],
- [:msg, ["b", "()", [:name, "c"], [:name, "d"]],
- ["e", "()", [:name, "f"],
- [:msg, ["g", "()", [:name, "h"]]]]]]
+ [:msg, ["b", nil, [:name, "c"], [:name, "d"]],
+ ["e", nil, [:name, "f"],
+ [:msg, ["g", nil, [:name, "h"]]]]]]
end
it 'parses nested blocks until semicolon' do
@@ -436,8 +436,8 @@
CODE
s(code, :root).should ==
[:block, [:chain, [:name, "a"],
- [:msg, ["b", "()", [:name, "u"]], ["c", "()", [:name, "e"]]]],
- [:msg, ["d", "()"]]]
+ [:msg, ["b", nil, [:name, "u"]], ["c", nil, [:name, "e"]]]],
+ [:msg, ["d", nil]]]
end
@@ -450,8 +450,8 @@
CODE
s(code, :root).should ==
[:chain, [:chain, [:name, "a"],
- [:msg, ["b", "()", [:name, "u"]], ["c", "()", [:name, "e"]]]],
- [:msg, ["d", "()"]]]
+ [:msg, ["b", nil, [:name, "u"]], ["c", nil, [:name, "e"]]]],
+ [:msg, ["d", nil]]]
end
@@ -468,15 +468,15 @@
[:chain, [:name, "a"],
[:msg, ["b", "()", [:name, "c"], [:name, "d"]],
["e", "()", [:name, "f"],
- [:msg, ["g", "()", [:name, "h"]]]]]]
+ [:msg, ["g", nil, [:name, "h"]]]]]]
end
it 'parses message with opchars' do
code = "a :< b :> c"
s(code, :root).should ==
[:chain, [:name, "a"],
- [:msg, ["<", "()", [:name, "b"]],
- [">", "()", [:name, "c"]]]]
+ [:msg, ["<", nil, [:name, "b"]],
+ [">", nil, [:name, "c"]]]]
end
it 'parses a chain of unicode names' do
@@ -519,7 +519,7 @@
s(code, :root).should ==
[:chain,
[:name, "a"],
- [:act, [:name, "foo"], "()", [:name, "bar"]]]
+ [:act, [:name, "foo"], nil, [:name, "bar"]]]
end
it 'are not parsed if found dot terminator' do
@@ -563,7 +563,7 @@
s(code, :root).should ==
[:chain,
[:name, "a"],
- [:act, [:name, "foo"], "()", [:name, "bar"], [:name, "baz"]]]
+ [:act, [:name, "foo"], nil, [:name, "bar"], [:name, "baz"]]]
end
@@ -574,7 +574,7 @@
s(code, :root).should ==
[:chain,
[:name, "a"],
- [:act, [:name, "foo"], "()", [:name, "bar"]]]
+ [:act, [:name, "foo"], nil, [:name, "bar"]]]
end
it 'allows args to have many lines' do
@@ -585,7 +585,7 @@
s(code, :root).should ==
[:chain,
[:name, "a"],
- [:act, [:name, "foo"], "()", [:name, "bar"], [:name, "baz"]]]
+ [:act, [:name, "foo"], nil, [:name, "bar"], [:name, "baz"]]]
end
it 'allows args to have many lines ignoring white space between comma' do
@@ -597,7 +597,7 @@
s(code, :root).should ==
[:chain,
[:name, "a"],
- [:act, [:name, "foo"], "()", [:name, "bar"], [:name, "baz"]]]
+ [:act, [:name, "foo"], nil, [:name, "bar"], [:name, "baz"]]]
end
it 'allows nested block with curly act' do

0 comments on commit cc14e4b

Please sign in to comment.