Skip to content

Instantly share code, notes, and snippets.

@bogdan
Created October 29, 2010 13:21
Show Gist options
  • Save bogdan/653544 to your computer and use it in GitHub Desktop.
Save bogdan/653544 to your computer and use it in GitHub Desktop.
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