Skip to content

Commit

Permalink
parser: add query_definition
Browse files Browse the repository at this point in the history
  • Loading branch information
jkbz64 committed Jan 26, 2024
1 parent ec8b306 commit 1e1428f
Show file tree
Hide file tree
Showing 5 changed files with 64,677 additions and 60,686 deletions.
31 changes: 31 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ module.exports = grammar({
extras: ($) => [$.comment, $.include, /[\s\f\uFEFF\u2060\u200B]|\\\r?\n/],
word: ($) => $.identifier,
supertypes: ($) => [$._expression, $._statement],
conflicts: ($) => [
[
$.variable_definition,
$.buffer_definition,
$.query_definition,
$.temp_table_definition
]
],

rules: {
source_code: ($) => repeat($._statement),
Expand Down Expand Up @@ -241,6 +249,7 @@ module.exports = grammar({
buffer_definition: ($) =>
seq(
choice(kw("DEFINE"), kw("DEF")),
repeat(choice($.scope_tuning, $.access_tuning)),
kw("BUFFER"),
field("name", $.identifier),
kw("FOR"),
Expand All @@ -249,6 +258,27 @@ module.exports = grammar({
$._terminator
),

query_definition_tuning: ($) =>
choice(
seq(kw("CACHE"), $.number_literal),
"SCROLLING",
kw("RCODE-INFORMATION")
),
query_fields: ($) => seq("(", repeat($.identifier), ")"),
query_definition: ($) =>
seq(
choice(kw("DEFINE"), kw("DEF")),
repeat(choice($.scope_tuning, $.access_tuning)),
kw("QUERY"),
field("name", $.identifier),
kw("FOR"),
$.identifier,
optional(seq(kw("FIELDS"), $.query_fields)),
optional(seq(kw("EXCEPT"), $.query_fields)),
repeat($.query_definition_tuning),
$._terminator
),

/// Function
function_call_statement: ($) => seq($.function_call, $._terminator),
_function_call_arguments: ($) =>
Expand Down Expand Up @@ -958,6 +988,7 @@ module.exports = grammar({
$.variable_definition,
$.variable_assignment,
$.buffer_definition,
$.query_definition,
$.stream_definition,
$.procedure_statement,
$.procedure_parameter_definition,
Expand Down
278 changes: 277 additions & 1 deletion src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,22 @@
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "scope_tuning"
},
{
"type": "SYMBOL",
"name": "access_tuning"
}
]
}
},
{
"type": "ALIAS",
"content": {
Expand Down Expand Up @@ -2053,6 +2069,255 @@
}
]
},
"query_definition_tuning": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[cC][aA][cC][hH][eE]"
}
}
},
"named": false,
"value": "CACHE"
},
{
"type": "SYMBOL",
"name": "number_literal"
}
]
},
{
"type": "STRING",
"value": "SCROLLING"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[rR][cC][oO][dD][eE][--][iI][nN][fF][oO][rR][mM][aA][tT][iI][oO][nN]"
}
}
},
"named": false,
"value": "RCODE-INFORMATION"
}
]
},
"query_fields": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "STRING",
"value": ")"
}
]
},
"query_definition": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[dD][eE][fF][iI][nN][eE]"
}
}
},
"named": false,
"value": "DEFINE"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[dD][eE][fF]"
}
}
},
"named": false,
"value": "DEF"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "scope_tuning"
},
{
"type": "SYMBOL",
"name": "access_tuning"
}
]
}
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[qQ][uU][eE][rR][yY]"
}
}
},
"named": false,
"value": "QUERY"
},
{
"type": "FIELD",
"name": "name",
"content": {
"type": "SYMBOL",
"name": "identifier"
}
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[fF][oO][rR]"
}
}
},
"named": false,
"value": "FOR"
},
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[fF][iI][eE][lL][dD][sS]"
}
}
},
"named": false,
"value": "FIELDS"
},
{
"type": "SYMBOL",
"name": "query_fields"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 1,
"content": {
"type": "PATTERN",
"value": "[eE][xX][cC][eE][pP][tT]"
}
}
},
"named": false,
"value": "EXCEPT"
},
{
"type": "SYMBOL",
"name": "query_fields"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "query_definition_tuning"
}
},
{
"type": "SYMBOL",
"name": "_terminator"
}
]
},
"function_call_statement": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -8627,6 +8892,10 @@
"type": "SYMBOL",
"name": "buffer_definition"
},
{
"type": "SYMBOL",
"name": "query_definition"
},
{
"type": "SYMBOL",
"name": "stream_definition"
Expand Down Expand Up @@ -8756,7 +9025,14 @@
"value": "[\\s\\f\\uFEFF\\u2060\\u200B]|\\\\\\r?\\n"
}
],
"conflicts": [],
"conflicts": [
[
"variable_definition",
"buffer_definition",
"query_definition",
"temp_table_definition"
]
],
"precedences": [],
"externals": [
{
Expand Down
Loading

0 comments on commit 1e1428f

Please sign in to comment.