github.com/orteth01/up@v0.2.0/internal/logs/parser/grammar.peg (about) 1 package parser 2 3 import "github.com/apex/up/internal/logs/parser/ast" 4 5 type parser Peg { 6 stack []ast.Node 7 } 8 9 Query <- _ Expr _ EOF 10 11 PrimaryExpr 12 <- Number { p.AddNumber(text) } 13 / Severity { p.AddLevel(text) } 14 / Id { p.AddField(text) } 15 / String { p.AddString(text) } 16 / LPAR Expr RPAR { p.AddExpr() } 17 18 TupleExpr 19 <- LPAR 20 Expr { p.AddTupleValue() } 21 (COMMA 22 Expr { p.AddTupleValue() } 23 )* 24 RPAR 25 26 InExpr 27 <- IN { p.AddTuple() } 28 TupleExpr { p.AddBinary(ast.IN) } 29 30 NotInExpr 31 <- NOT IN { p.AddTuple() } 32 TupleExpr { p.AddBinary(ast.IN); p.AddUnary(ast.LNOT) } 33 34 PostfixExpr 35 <- PrimaryExpr ( 36 DOT Id { p.AddMember(text) } 37 / LBRK Number RBRK { p.AddSubscript(text) } 38 / InExpr 39 / NotInExpr 40 )* 41 42 UnaryExpr 43 <- PostfixExpr 44 / BANG RelationalExpr { p.AddUnary(ast.NOT) } 45 46 RelationalExpr 47 <- UnaryExpr ( 48 GE UnaryExpr { p.AddBinary(ast.GE) } 49 / GT UnaryExpr { p.AddBinary(ast.GT) } 50 / LE UnaryExpr { p.AddBinary(ast.LE) } 51 / LT UnaryExpr { p.AddBinary(ast.LT) } 52 )* 53 54 EqualityExpr 55 <- RelationalExpr ( 56 EQEQ RelationalExpr { p.AddBinary(ast.EQ) } 57 / NE RelationalExpr { p.AddBinary(ast.NE) } 58 / EQ RelationalExpr { p.AddBinary(ast.EQ) } 59 / CONTAINS RelationalExpr { p.AddBinaryContains() } 60 )* 61 62 LogicalAndExpr <- 63 EqualityExpr ( 64 AND EqualityExpr { p.AddBinary(ast.AND) } 65 / ANDAND EqualityExpr { p.AddBinary(ast.AND) } 66 / _ EqualityExpr { p.AddBinary(ast.AND) } 67 )* 68 69 LogicalOrExpr <- 70 LogicalAndExpr ( 71 OR LogicalAndExpr { p.AddBinary(ast.OR) } 72 / OROR LogicalAndExpr { p.AddBinary(ast.OR) } 73 )* 74 75 LowNotExpr <- 76 LogicalOrExpr 77 / NOT LogicalOrExpr { p.AddUnary(ast.LNOT) } 78 79 Expr <- LowNotExpr 80 81 # 82 # Strings 83 # 84 85 String 86 <- (["] < StringChar* > ["] _)+ 87 88 StringChar 89 <- Escape / ![\"\n\\] . 90 91 Escape 92 <- SimpleEscape 93 / OctalEscape 94 / HexEscape 95 / UniversalCharacter 96 97 SimpleEscape 98 <- '\\' ['\"?\\abfnrtv] 99 100 OctalEscape 101 <- '\\' [0-7][0-7]?[0-7]? 102 103 HexEscape 104 <- '\\x' HexDigit+ 105 106 UniversalCharacter 107 <- '\\u' HexQuad 108 / '\\U' HexQuad HexQuad 109 110 HexQuad 111 <- HexDigit HexDigit HexDigit HexDigit 112 113 HexDigit 114 <- [a-f] / [A-F] / [0-9] 115 116 # 117 # Numeric 118 # 119 120 Number 121 <- < Float > _ 122 / < Integer > _ 123 124 Integer 125 <- [0-9]* 126 127 Float 128 <- Fraction Exponent? 129 / [0-9]+ Exponent 130 131 Fraction 132 <- [0-9]* '.' [0-9]+ 133 / [0-9]+ '.' 134 135 Exponent 136 <- [eE][+\-]? [0-9]+ 137 138 # 139 # Identifiers 140 # 141 142 Id 143 <- !Keyword < IdCharNoDigit IdChar* > _ 144 145 IdChar 146 <- [a-z] / [A-Z] / [0-9] / [_] 147 148 IdCharNoDigit 149 <- [a-z] / [A-Z] / [_] 150 151 # 152 # Severity 153 # 154 155 Severity 156 <- DEBUG 157 / INFO 158 / WARN 159 / ERROR 160 / FATAL 161 162 # 163 # Keywords 164 # 165 166 IN <- 'in' !IdChar _ 167 OR <- 'or' !IdChar _ 168 AND <- 'and' !IdChar _ 169 NOT <- 'not' !IdChar _ 170 CONTAINS <- 'contains' !IdChar _ 171 172 DEBUG <- < 'debug' > !IdChar _ 173 INFO <- < 'info' > !IdChar _ 174 WARN <- < 'warn' > !IdChar _ 175 ERROR <- < 'error' > !IdChar _ 176 FATAL <- < 'fatal' > !IdChar _ 177 178 Keyword 179 <- ( 'or' 180 / 'and' 181 / 'not' 182 / 'contains' 183 / 'debug' 184 / 'info' 185 / 'warn' 186 / 'error' 187 / 'fatal' 188 / 'in' 189 ) !IdChar 190 191 # 192 # Punctuators 193 # 194 195 EQ <- '=' _ 196 LBRK <- '[' _ 197 RBRK <- ']' _ 198 LPAR <- '(' _ 199 RPAR <- ')' _ 200 DOT <- '.' _ 201 BANG <- '!' ![=] _ 202 LT <- '<' ![=] _ 203 GT <- '>' ![=] _ 204 LE <- '<=' _ 205 EQEQ <- '==' _ 206 GE <- '>=' _ 207 NE <- '!=' _ 208 ANDAND <- '&&' _ 209 OROR <- '||' _ 210 COMMA <- ',' _ 211 212 # 213 # Whitespace 214 # 215 216 _ 217 <- Whitespace* 218 219 Whitespace 220 <- ' ' / '\t' / EOL 221 222 EOL 223 <- '\r\n' / '\n' / '\r' 224 225 EOF 226 <- !.