Skip to content

Instantly share code, notes, and snippets.

@shekohex
Created March 14, 2019 17:24
Show Gist options
  • Save shekohex/a26e95fdbdde6392950eba69baba5ac7 to your computer and use it in GitHub Desktop.
Save shekohex/a26e95fdbdde6392950eba69baba5ac7 to your computer and use it in GitHub Desktop.
Simple boolean expression parser Roles using pest.rs https://pest.rs
AND = { "." }
NOT = { "`" }
OR = { "+" }
SEP = _{ (NEWLINE | WHITE_SPACE) }
VAR_NAME = { (ASCII_ALPHA ~ ASCII_DIGIT*) }
VAR = { VAR_NAME ~ SEP* ~ NOT? ~ SEP* }
EXP = { VAR ~ SEP* ~ ((OR | AND) ~ SEP* ~ VAR ~ SEP*)* }
FUNC = { VAR ~ SEP* ~ "=" ~ SEP* ~ EXP+ }
ROOT = _{ SOI ~ NEWLINE* ~ (FUNC | ANY) ~ NEWLINE* ~ EOI }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment