Skip to content

Commit

Permalink
Support array constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
pplam committed Jun 27, 2022
1 parent 6760758 commit 95ea3b0
Show file tree
Hide file tree
Showing 5 changed files with 727,231 additions and 702,508 deletions.
12 changes: 12 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ module.exports = grammar({
$._dollar_quoted_string_content,
$._dollar_quoted_string_end_tag,
],
word: $ => $._unquoted_identifier,

rules: {
source_file: $ => repeat($._statement),
Expand Down Expand Up @@ -1225,11 +1226,21 @@ module.exports = grammar({
$.string,
$._identifier,
$.function_call,
$.array_constructor,
),
"::",
field("type", $._type),
),

array_constructor: $ =>
seq(
token(prec(1, kw("ARRAY"))),
choice(
seq("[", commaSep($._expression), "]"),
seq("(", $.select_statement, ")"),
),
),

// http://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment/36328890#36328890
comment: $ =>
token(
Expand Down Expand Up @@ -1309,6 +1320,7 @@ module.exports = grammar({
$.select_subexpression,
$.at_time_zone_expression,
$.rows_from_expression,
$.array_constructor,
),
},
});
Expand Down
98 changes: 98 additions & 0 deletions src/grammar.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "sql",
"word": "_unquoted_identifier",
"rules": {
"source_file": {
"type": "REPEAT",
Expand Down Expand Up @@ -11607,6 +11608,10 @@
{
"type": "SYMBOL",
"name": "function_call"
},
{
"type": "SYMBOL",
"name": "array_constructor"
}
]
},
Expand All @@ -11624,6 +11629,95 @@
}
]
},
"array_constructor": {
"type": "SEQ",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[aA][rR][rR][aA][yY]"
},
"named": false,
"value": "ARRAY"
}
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_expression"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "select_statement"
},
{
"type": "STRING",
"value": ")"
}
]
}
]
}
]
},
"comment": {
"type": "TOKEN",
"content": {
Expand Down Expand Up @@ -12141,6 +12235,10 @@
{
"type": "SYMBOL",
"name": "rows_from_expression"
},
{
"type": "SYMBOL",
"name": "array_constructor"
}
]
}
Expand Down
Loading

0 comments on commit 95ea3b0

Please sign in to comment.