Skip to content
Snippets Groups Projects
Verified Commit 049a0d36 authored by Denis Smirnov's avatar Denis Smirnov
Browse files

feat: add functions to the grammar

parent 3849c292
No related branches found
No related tags found
1 merge request!1414sbroad import
...@@ -10,8 +10,8 @@ Query = _{ Except | UnionAll | Select | Values | Insert } ...@@ -10,8 +10,8 @@ Query = _{ Except | UnionAll | Select | Values | Insert }
^"on" ~ Condition)? ~ (^"where" ~ Selection)? ^"on" ~ Condition)? ~ (^"where" ~ Selection)?
} }
Projection = { ((Asterisk | Column) ~ ("," ~ (Asterisk | Column))*?) } Projection = { ((Asterisk | Column) ~ ("," ~ (Asterisk | Column))*?) }
Column = { Row | Alias | Value | Reference } Column = { Alias | Value }
Alias = {(Value | Reference) ~ ^"as" ~ AliasName } Alias = {Value ~ ^"as" ~ AliasName }
AliasName = @{ Name } AliasName = @{ Name }
Reference = { (ScanName ~ "." ~ ColumnName) | ColumnName } Reference = { (ScanName ~ "." ~ ColumnName) | ColumnName }
ColumnName = @{ Name } ColumnName = @{ Name }
...@@ -31,9 +31,9 @@ Query = _{ Except | UnionAll | Select | Values | Insert } ...@@ -31,9 +31,9 @@ Query = _{ Except | UnionAll | Select | Values | Insert }
Values = { ^"values" ~ ValuesRow ~ ("," ~ ValuesRow)*? } Values = { ^"values" ~ ValuesRow ~ ("," ~ ValuesRow)*? }
ValuesRow = { Row } ValuesRow = { Row }
Expr = _{ Or | And | Unary | Between | Cmp | Primary | Parentheses } Expr = _{ Or | And | Unary | Between | Cmp | Primary | Parentheses }
Parentheses = _{ "(" ~ Expr ~ ")" } Parentheses = _{ "(" ~ Expr ~ ")" }
Primary = _{ SubQuery | Value | Reference } Primary = _{ SubQuery | Value }
Unary = _{ IsNull | IsNotNull} Unary = _{ IsNull | IsNotNull}
IsNull = { Primary ~ ^"is" ~ ^"null" } IsNull = { Primary ~ ^"is" ~ ^"null" }
IsNotNull = { Primary ~ ^"is" ~ ^"not" ~ ^"null" } IsNotNull = { Primary ~ ^"is" ~ ^"not" ~ ^"null" }
...@@ -73,6 +73,10 @@ Expr = _{ Or | And | Unary | Between | Cmp | Primary | Parentheses } ...@@ -73,6 +73,10 @@ Expr = _{ Or | And | Unary | Between | Cmp | Primary | Parentheses }
OrLeft = _{ AndRight } OrLeft = _{ AndRight }
OrRight = _{ Or | OrLeft } OrRight = _{ Or | OrLeft }
Function = { FunctionName ~ ("(" ~ FunctionArgs ~ ")") }
FunctionName = @{ Name }
FunctionArgs = { (Expr ~ ("," ~ Expr)*)? }
NameString = @{ !(WHITESPACE* ~ Keyword ~ WHITESPACE) ~ ('А' .. 'Я' | 'а' .. 'я' | 'A' .. 'Z' | 'a'..'z' | "-" | "_" | ASCII_DIGIT)+ } NameString = @{ !(WHITESPACE* ~ Keyword ~ WHITESPACE) ~ ('А' .. 'Я' | 'а' .. 'я' | 'A' .. 'Z' | 'a'..'z' | "-" | "_" | ASCII_DIGIT)+ }
String = @{ !(WHITESPACE* ~ Keyword ~ WHITESPACE) ~ (Character | ("'" ~ "'") | "\"")* } String = @{ !(WHITESPACE* ~ Keyword ~ WHITESPACE) ~ (Character | ("'" ~ "'") | "\"")* }
...@@ -88,7 +92,7 @@ Punctuation = _{ ...@@ -88,7 +92,7 @@ Punctuation = _{
} }
Other = _{ "\\" | "/" | "@" | "%" | "&" | "*" | "#" | WHITESPACE } Other = _{ "\\" | "/" | "@" | "%" | "&" | "*" | "#" | WHITESPACE }
Value = _{ Parameter | Row | True | False | Null | Decimal | Double | Unsigned | Integer | SingleQuotedString } Value = _{ Parameter | Row | True | False | Null | Decimal | Double | Unsigned | Integer | SingleQuotedString | Function | Reference }
True = @{ ^"true" } True = @{ ^"true" }
False = @{ ^"false" } False = @{ ^"false" }
Null = @{ ^"null" } Null = @{ ^"null" }
...@@ -98,8 +102,8 @@ Value = _{ Parameter | Row | True | False | Null | Decimal | Double | Unsigned | ...@@ -98,8 +102,8 @@ Value = _{ Parameter | Row | True | False | Null | Decimal | Double | Unsigned |
Unsigned = @{ ASCII_DIGIT+ } Unsigned = @{ ASCII_DIGIT+ }
SingleQuotedString = _{ "'" ~ String ~ "'" } SingleQuotedString = _{ "'" ~ String ~ "'" }
Row = { Row = {
("(" ~ (Value | Reference) ~ ("," ~ (Value | Reference))* ~ ")") ("(" ~ Value ~ ("," ~ Value)* ~ ")")
| (^"row" ~ "(" ~ (Value | Reference) ~ ("," ~ (Value | Reference))* ~ ")") | (^"row" ~ "(" ~ Value ~ ("," ~ Value)* ~ ")")
} }
Parameter = @{ "?" } Parameter = @{ "?" }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment