Created
October 29, 2010 13:21
-
-
Save bogdan/653544 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
grammar BooleanGrammar | |
rule andable | |
orable '&' andable { | |
def value(&block) | |
orable.value(&block) && andable.value(&block) | |
end | |
} | |
/ orable | |
end | |
rule orable | |
notable '|' orable { | |
def value(&block) | |
notable.value(&block) || orable.value(&block) | |
end | |
} / notable | |
end | |
rule notable | |
[ \t]* '!' primary { | |
def value(&block) | |
!primary.value(&block) | |
end | |
} / primary | |
end | |
rule primary | |
[ \t]* '(' [ \t]* andable [ \t]* ')' [ \t]* { | |
def value(&block) | |
andable.value(&block) | |
end | |
} / word | |
end | |
rule word | |
[ \t]* [0-9a-zA-Z]+ [ \t]* { | |
def value(&block) | |
block.call(text_value.strip) | |
end | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment