Permalink
Browse files

Added more unicode tests

  • Loading branch information...
1 parent 582d24c commit 06db1365fb52cf1b0d1d85a79cc6507a1cdd9dbe @vic committed Aug 24, 2011
Showing with 18 additions and 5 deletions.
  1. +2 −2 lib/akin/grammar.kpeg
  2. +3 −3 lib/akin/grammar.rb
  3. +13 −0 spec/grammar_spec.rb
View
@@ -99,7 +99,7 @@ cons(h) = cons_left(h):a - cons(h):b ~n(p, :cons, a, b)
args = p:p left_brace:l - (comma(h) | block(h) | {[]}):a - right_brace(l)
~n(p, l.join, *Array(a))
-msg(h) = msg(h):a sp* (&"::" | ":" &(":"|";"|".")) {a}
+msg(h) = 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)
@@ -119,7 +119,7 @@ chain(h) = 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
+ | chain_val(h):a sp* chain(a.pos):b
~n(a.pos, :chain, a, *Array(b.name == :chain && b.args || b))
| chain_val(h)
View
@@ -3340,7 +3340,7 @@ def _expr(h)
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))
+ # 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) | chain_val(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)
_save = self.pos
@@ -3436,7 +3436,7 @@ def _chain(h)
_save5 = self.pos
while true # sequence
- _tmp = apply_with_args(:_expr, h)
+ _tmp = apply_with_args(:_chain_val, h)
a = @result
unless _tmp
self.pos = _save5
@@ -3782,7 +3782,7 @@ def _eof
Rules[:_part_head] = rule_info("part_head", "sp+ !(&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[:_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] = 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) | chain_val(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))")
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))")
View
@@ -505,6 +505,19 @@
[:chain, [:name, "मूल"], [:name, "नकल"]]
end
+ it 'parses a unicode keyword message' do
+ code = "浪: 人"
+ s(code, :root).should ==
+ [:msg,
+ ["", nil, [:name, ""]]]
+ end
+
+ it 'parses a unicode cons' do
+ code = "浪::人"
+ s(code, :root).should ==
+ [:cons, [:name, ""], [:name, ""]]
+ end
+
it 'allows operators chaining' do
code = <<-CODE
a + b - c

0 comments on commit 06db136

Please sign in to comment.