Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy Kitchen
committed
Jun 15, 2010
1 parent
9c42219
commit 63f6f2a
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
include Rasta | ||
|
||
def list1 | ||
number = t(/[0-9]+/) | ||
word = t(/[A-Za-z]+/) | ||
|
||
atom = number | word | ||
space = t(" ").star | ||
|
||
l = t("[") >> space | ||
r = space >> t("]") | ||
sep = space >> t(",") >> space | ||
|
||
list = l >> atom >> (sep >> atom).star >> r | ||
end | ||
|
||
def list2 | ||
number = t(/[0-9]+/).mk_i | ||
word = t(/[A-Za-z]+/).mk_s | ||
|
||
atom = number | word | ||
space = t(" ").star.drop | ||
|
||
l = drop(t("[") >> space) | ||
r = drop(space >> t("]")) | ||
sep = space >> t(",").drop >> space | ||
|
||
list = unbox(l >> flat(atom >> (unbox(sep >> atom)).star) >> r) | ||
end | ||
|
||
def list3 | ||
number = t(/[0-9]+/).mk_i | ||
word = t(/[A-Za-z]+/).mk_s | ||
|
||
atom = number | word | ||
space = t(" ").star.drop | ||
|
||
l = drop(t("[") >> space) | ||
r = drop(space >> t("]")) | ||
sep = space >> t(",").drop >> space | ||
|
||
list = unbox( | ||
l >> flat(ref{list} >> (unbox(sep >> ref{list})).star) >> r | ||
) | atom | ||
|
||
list.mk_a | ||
end | ||
|
||
def list_of(atom, sep) | ||
flat(atom >> (unbox(sep.drop >> atom)).star) | ||
end | ||
|
||
def list4 | ||
number = t(/[0-9]+/).mk_i | ||
word = t(/[A-Za-z]+/).mk_s | ||
|
||
atom = number | word | ||
space = t(" ").star.drop | ||
|
||
l = drop(t("[") >> space) | ||
r = drop(space >> t("]")) | ||
sep = space >> t(",") >> space | ||
|
||
# list = unbox(l >> ref{list}.mk_list(sep) >> r) | atom | ||
list = unbox(l >> list_of(ref{list}, sep) >> r) | atom | ||
|
||
list.mk_a | ||
end |