Permalink
Browse files

Renamed Rule#&& and Rule#|| to Rule#& and Rule#|. Also allow Strings …

…to be used as parsing rules.
  • Loading branch information...
bakkdoor committed Oct 8, 2011
1 parent c1ae01a commit 575d241628c5fbff7c69f2fb284bc2de7e7f0273
Showing with 19 additions and 11 deletions.
  1. +16 −7 lib/parsing.fy
  2. +3 −4 tests/parsing.fy
View
@@ -6,11 +6,11 @@ class Parsing {
}
}
- def || other_rule {
+ def | other_rule {
OrRule new: to_rule and: (other to_rule)
}
- def && other {
+ def & other {
AndRule new: to_rule and: (other to_rule)
}
@@ -32,14 +32,22 @@ class Parsing {
}
}
- class Regexp {
+ class RegexpParsing {
include: Rules
def to_rule {
Rule new: self
}
}
+ class StringParsing {
+ include: Rules
+
+ def to_rule {
+ Regexp new(self) to_rule
+ }
+ }
+
class Rule {
include: Rules
read_write_slots: ['name, 'pattern, 'action]
@@ -148,16 +156,16 @@ class Parsing {
rule = @rule
if: @max then: {
@min upto: @max do: {
- rule = rule && @rule
+ rule = rule & @rule
}
- rule = rule && (@rule not)
+ rule = rule & (@rule not)
rule action: @action
val = rule parse: string offset: offset
@offset = rule offset + offset
return val
} else: {
@min times: {
- rule = rule && @rule
+ rule = rule & @rule
}
@offset = offset
vals = []
@@ -176,4 +184,5 @@ class Parsing {
}
}
-Regexp include: Parsing Regexp
+Regexp include: Parsing RegexpParsing
+String include: Parsing StringParsing
View
@@ -22,18 +22,17 @@ FancySpec describe: Parsing with: {
}
it: "creates a simple ast" when: {
- c = /class/
space = /\s+/
- identifier = space && /(\S+)/ #&& (space optional)
- class_def = c && identifier ==> |_ classname| {
+ identifier = space & /(\S+)/ #& (space optional)
+ class_def = "class" & identifier ==> |_ classname| {
('class_def, classname[1] to_sym)
}
class_def parse: "class Foo" . is: ('class_def, 'Foo)
}
it: "parses optional rules" when: {
- opt = /a/ optional ==> {
+ opt = "a" optional ==> {
'yes
}

0 comments on commit 575d241

Please sign in to comment.