Permalink
Browse files

fixed minor bugs and added some tests

  • Loading branch information...
1 parent 5968ac2 commit 2730e0cf9dc8f725179e62013c5f0d3b50e12770 @uberj committed Apr 12, 2013
Showing with 22 additions and 7 deletions.
  1. +6 −5 parsley/invdsl.parsley
  2. +4 −0 parsley/invdsl.py
  3. +12 −2 parsley/tests.py
View
@@ -11,14 +11,15 @@
# - compile
ws = ' '*
+wss = ' '+
not_ws = :c ?(c not in (' ', '\t')) -> c
letter = :c ?('a' <= c <= 'z' or 'A' <= c <= 'Z') -> c
special = '_' | '.' | '-' | ':' | ','
# Lexical Operators
NOT = '!'
-AND = <letter+>:and_ ?(and_.lower() == 'and') -> self.AND_op
-OR = <letter+>:or_ ?(or_.lower() == 'or') -> self.OR_op
+AND = <letter+>:and_ ?(and_ == 'AND') -> self.AND_op
+OR = <letter+>:or_ ?(or_ == 'OR') -> self.OR_op
# Directive
EQ = '=:'
@@ -30,7 +31,7 @@ DRCT = <d_lhs+>:d EQ <d_rhs+>:v -> self.directive(d, v)
RE = '/' <(not_ws)+>:r -> self.regexpr(r)
# Regular text
-text = (~OR ~AND ~NOT (letterOrDigit | special ))+
+text = (~OR ~AND ~NOT <(letterOrDigit | special )+>:t) -> t
TEXT = <text+>:t -> self.text(t)
@@ -52,13 +53,13 @@ parens = '(' ws expr:e ws ')' -> e
# 3) e_or
# x AND y <-- Explicit AND
-e_and = AND:op ws value:v -> (op, v)
+e_and = AND:op wss value:v -> (op, v)
# x y <-- Implicit AND
i_and = (' '+ ~OR ~AND) value:v -> (self.AND_op, v)
# x OR y <-- Explicit OR
-e_or = OR:op ws expr_2:v -> (op, v)
+e_or = OR:op wss expr_2:v -> (op, v)
# Compile
View
@@ -3,6 +3,10 @@
from ometa.grammar import OMeta
from ometa.runtime import OMetaBase
+from ometa.grammar import TreeTransformerGrammar
+from ometa.runtime import TreeTransformerBase
+
+
fname = 'invdsl.parsley'
name = 'InvDSL'
View
@@ -88,7 +88,7 @@ def test1(self):
self.assertTrue(callable(self.parse(t)))
def test2(self):
- t = 'aND'
+ t = 'AND'
self.assertTrue(callable(self.parse(t)))
@@ -100,7 +100,7 @@ def test1(self):
self.assertTrue(callable(self.parse(t)))
def test2(self):
- t = 'oR'
+ t = 'OR'
self.assertTrue(callable(self.parse(t)))
@@ -215,6 +215,16 @@ def test26(self):
out = "(('type', 'foo.bar') AND (NOT ('type', 'baz')))"
self.assertEqual(out, self.parse(t))
+ def test27(self):
+ t = "mozillaecuador.org OR mozillaecuador.org"
+ out = "(mozillaecuador.org OR mozillaecuador.org)"
+ self.assertEqual(out, self.parse(t))
+
+ def test28(self):
+ t = "mozillaecuadOR.org"
+ out = "mozillaecuadOR.org"
+ self.assertEqual(out, self.parse(t))
+
if __name__ == '__main__':
unittest.main()

0 comments on commit 2730e0c

Please sign in to comment.