summaryrefslogtreecommitdiffstats
path: root/vendor/pest_derive/examples/calc.pest
blob: 9f2cc3b744bc5ac0143dc89da4347a51a3352fcc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
WHITESPACE   =  _{ " " | "\t" | NEWLINE }

 program      =   { SOI ~ expr ~ EOI }
   expr       =   { prefix* ~ primary ~ postfix* ~ (infix ~ prefix* ~ primary ~ postfix* )* }
     infix    =  _{ add | sub | mul | div | pow }
       add    =   { "+" } // Addition
       sub    =   { "-" } // Subtraction
       mul    =   { "*" } // Multiplication
       div    =   { "/" } // Division
       pow    =   { "^" } // Exponentiation
     prefix   =  _{ neg }
       neg    =   { "-" } // Negation
     postfix  =  _{ fac }
       fac    =   { "!" } // Factorial
     primary  =  _{ int | "(" ~ expr ~ ")" }
       int    =  @{ (ASCII_NONZERO_DIGIT ~ ASCII_DIGIT+ | ASCII_DIGIT) }