Skip to content

Commit

Permalink
Implemented rewriter for :: operator. Added specs
Browse files Browse the repository at this point in the history
  • Loading branch information
vic committed Jul 13, 2010
1 parent 89ba16d commit 54d868a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/akin/parser/rewrite.ik
@@ -1,2 +1,3 @@
Akin Parser Rewrite = Origin mimic
use("akin/parser/rewrite/colon")
use("akin/parser/rewrite/dcolon")
33 changes: 33 additions & 0 deletions lib/akin/parser/rewrite/dcolon.ik
@@ -0,0 +1,33 @@

Akin Parser Rewrite DColon = Origin mimic
Akin Parser Rewrite DColon do(

rewrite = method(chain,
m = chain
while(m,
if(m next && m next next && m next dcolonArgOp?,
m = m next next
chain = process(m previous) first
)
if(m body && m body message, rewrite(m body message))
m = m next)
chain
)

process = method(dcolon,
first = dcolon firstInLine findForward(white? not)
into = dcolon next findForward(white? not)
upto = dcolon previous

nl = first previous
nl next = into
into previous = nl

first previous = nil
upto next = nil

into appendArgument(first)
into
)

)
4 changes: 3 additions & 1 deletion lib/akin/tokenizer/message.ik
Expand Up @@ -21,7 +21,8 @@ Akin Tokenizer Message do(
dot? = method(name == :("."))
colon? = method(name == :(":"))
semicolon? = method(name == :(";"))

dcolon? = method(name == :("::"))

comma? = method(name == :(","))

end? = method(dot? || semicolon?)
Expand All @@ -34,6 +35,7 @@ Akin Tokenizer Message do(
punctuation? = method(terminator? || separator? || enumerator?)

colonArgOp? = method(colon? && body nil?)
dcolonArgOp? = method(dcolon? && body nil?)

cell("[]") = method(index, at(index))

Expand Down
29 changes: 29 additions & 0 deletions spec/parser/rewrite/dcolon_spec.ik
@@ -0,0 +1,29 @@
use("ispec")

use("akin")
use("akin/parser")

describe("Akin Parser",

parse = fn(txt,
tokens = Akin Tokenizer parseText(txt)
Akin Parser Rewrite DColon rewrite(tokens))

it("should append previous message as argument to next",
msg = parse("foo :: baz")
msg code should == "baz(foo )"
)

it("should append previous messages as argument to next",
msg = parse("hello\n foo, bar :: baz")
msg code should == "hello\n baz(foo, bar )"
)

it("should handle chained :: operators",
msg = parse("foo, bar :: if(hello) :: if(bye)")
msg code should == "if(bye,if(hello,foo, bar ) )"
)


)

1 change: 1 addition & 0 deletions spec/parser_spec.ik
@@ -1,5 +1,6 @@

use(System currentDirectory +"/parser/rewrite/colon_spec.ik")
use(System currentDirectory +"/parser/rewrite/dcolon_spec.ik")



0 comments on commit 54d868a

Please sign in to comment.