mirror of
https://github.com/danbulant/lang-surrealql
synced 2026-05-24 12:35:33 +00:00
improved grammar and code highlight
This commit is contained in:
parent
002b2d19be
commit
b7aece5302
2 changed files with 76 additions and 36 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
@top Script {
|
@top Script {
|
||||||
(statement SEMI)*
|
(statement Semi)*
|
||||||
statement
|
statement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,15 +59,21 @@ StringPrefix {
|
||||||
Integer { int }
|
Integer { int }
|
||||||
Decimal { int !int ("." int)? "dec" }
|
Decimal { int !int ("." int)? "dec" }
|
||||||
Float { int !int (("." int) "f"? | "f" ) }
|
Float { int !int (("." int) "f"? | "f" ) }
|
||||||
Duration { int ("d" | "h" | "m" | "s" | "ms" | "us" | "ns") }
|
Duration { int DurationUnit }
|
||||||
|
DurationUnit {
|
||||||
|
"d" | "h" | "m" | "s" | "ms" | "us" | "ns"
|
||||||
|
}
|
||||||
|
|
||||||
number { Decimal | Float | Integer }
|
number { Decimal | Float | Integer }
|
||||||
|
|
||||||
Array {
|
Array {
|
||||||
"[" (expression (COMMA expression)*)? "]"
|
"[" (expression (Comma expression)*)? "]"
|
||||||
|
}
|
||||||
|
Property {
|
||||||
|
identifier
|
||||||
}
|
}
|
||||||
Object {
|
Object {
|
||||||
"{" (identifier ":" expression (COMMA identifier ":" expression)*)? "}"
|
"{" (Property ":" expression (Comma Property ":" expression)*)? "}"
|
||||||
}
|
}
|
||||||
Namespace {
|
Namespace {
|
||||||
identifier
|
identifier
|
||||||
|
|
@ -76,7 +82,7 @@ FunctionName {
|
||||||
identifier
|
identifier
|
||||||
}
|
}
|
||||||
FunctionCall {
|
FunctionCall {
|
||||||
(Namespace "::" )? FunctionName "(" (expression (COMMA expression)*)? ")"
|
(Namespace "::" )* FunctionName "(" (expression (Comma expression)*)? ")"
|
||||||
}
|
}
|
||||||
Constant {
|
Constant {
|
||||||
(Namespace "::")?
|
(Namespace "::")?
|
||||||
|
|
@ -104,9 +110,9 @@ BinaryExpression {
|
||||||
Comparison | "@" identifier "@"
|
Comparison | "@" identifier "@"
|
||||||
) expression |
|
) expression |
|
||||||
expression !exp Raise expression |
|
expression !exp Raise expression |
|
||||||
expression !times (Divide | Multiply) expression |
|
expression !times (DivideOrMultiply) expression |
|
||||||
expression !plus (Add | Subtract) expression |
|
expression !plus (AddOrSubtract) expression |
|
||||||
expression !dot (".*"+ | ("." "*."*) expression) |
|
expression !dot (("." "*")+ | ("." "*")* "." expression) |
|
||||||
expression? !dot "->" expression |
|
expression? !dot "->" expression |
|
||||||
expression !array ("[" expression "]")
|
expression !array ("[" expression "]")
|
||||||
}
|
}
|
||||||
|
|
@ -114,17 +120,20 @@ BinaryExpression {
|
||||||
ReturnStatement {
|
ReturnStatement {
|
||||||
kw<"return"> expression
|
kw<"return"> expression
|
||||||
}
|
}
|
||||||
|
maybeTransaction {
|
||||||
|
kw<"transaction">?
|
||||||
|
}
|
||||||
BeginStatement {
|
BeginStatement {
|
||||||
kw<"begin"> kw<"transaction">?
|
kw<"begin"> maybeTransaction
|
||||||
}
|
}
|
||||||
BreakStatement {
|
BreakStatement {
|
||||||
kw<"break">
|
kw<"break">
|
||||||
}
|
}
|
||||||
CancelStatement {
|
CancelStatement {
|
||||||
kw<"cancel"> kw<"transaction">?
|
kw<"cancel"> maybeTransaction
|
||||||
}
|
}
|
||||||
CommitStatement {
|
CommitStatement {
|
||||||
kw<"commit"> kw<"transaction">?
|
kw<"commit"> maybeTransaction
|
||||||
}
|
}
|
||||||
ContinueStatement {
|
ContinueStatement {
|
||||||
kw<"continue">
|
kw<"continue">
|
||||||
|
|
@ -172,16 +181,16 @@ maybeBy {
|
||||||
kw<"by">?
|
kw<"by">?
|
||||||
}
|
}
|
||||||
selectWith {
|
selectWith {
|
||||||
("with" (kw<"noindex"> | kw<"index"> identifier (COMMA identifier)))?
|
("with" (kw<"noindex"> | kw<"index"> identifier (Comma identifier)))?
|
||||||
}
|
}
|
||||||
maybeOnly {
|
maybeOnly {
|
||||||
kw<"only">?
|
kw<"only">?
|
||||||
}
|
}
|
||||||
selectOrder {
|
selectOrder {
|
||||||
("order" maybeBy orderBy (COMMA orderBy)*)?
|
("order" maybeBy orderBy (Comma orderBy)*)?
|
||||||
}
|
}
|
||||||
selectFrom {
|
selectFrom {
|
||||||
("from" maybeOnly expression (COMMA expression)*)?
|
("from" maybeOnly expression (Comma expression)*)?
|
||||||
}
|
}
|
||||||
Where {
|
Where {
|
||||||
"where" expression
|
"where" expression
|
||||||
|
|
@ -189,13 +198,13 @@ Where {
|
||||||
SelectStatement {
|
SelectStatement {
|
||||||
kw<"select">
|
kw<"select">
|
||||||
maybeValue
|
maybeValue
|
||||||
(Field (COMMA Field)*)
|
(Field (Comma Field)*)
|
||||||
("omit" Field (COMMA Field)*)?
|
("omit" Field (Comma Field)*)?
|
||||||
selectFrom
|
selectFrom
|
||||||
selectWith
|
selectWith
|
||||||
Where?
|
Where?
|
||||||
("split" maybeAt expression)?
|
("split" maybeAt expression)?
|
||||||
("group" maybeBy expression (COMMA expression)*)?
|
("group" maybeBy expression (Comma expression)*)?
|
||||||
selectOrder
|
selectOrder
|
||||||
("limit" maybeBy expression)?
|
("limit" maybeBy expression)?
|
||||||
("start" maybeAt expression)?
|
("start" maybeAt expression)?
|
||||||
|
|
@ -204,6 +213,20 @@ SelectStatement {
|
||||||
("explain" kw<"full">?)?
|
("explain" kw<"full">?)?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ForStatement {
|
||||||
|
kw<"for"> expression "in" expression "{" (statement Semi)* statement "}"
|
||||||
|
}
|
||||||
|
|
||||||
|
// IfStatement {
|
||||||
|
// kw<"if"> expression "then"? expression
|
||||||
|
// ("else" "if" expression "then"? expression)*
|
||||||
|
// ("else" expression)?
|
||||||
|
// }
|
||||||
|
|
||||||
|
Bool { kw<"true"> | kw<"false"> }
|
||||||
|
None { kw<"none"> }
|
||||||
|
Null { kw<"null"> }
|
||||||
|
|
||||||
expression {
|
expression {
|
||||||
String |
|
String |
|
||||||
number |
|
number |
|
||||||
|
|
@ -217,7 +240,10 @@ expression {
|
||||||
RecordID |
|
RecordID |
|
||||||
Column |
|
Column |
|
||||||
ParenthesizedExpression |
|
ParenthesizedExpression |
|
||||||
BinaryExpression
|
BinaryExpression |
|
||||||
|
Bool |
|
||||||
|
None |
|
||||||
|
Null
|
||||||
}
|
}
|
||||||
ParenthesizedExpression {
|
ParenthesizedExpression {
|
||||||
"(" (expression | statement) ")"
|
"(" (expression | statement) ")"
|
||||||
|
|
@ -236,7 +262,9 @@ statement[@isGroup=Statement] {
|
||||||
ShowStatement |
|
ShowStatement |
|
||||||
LetStatement |
|
LetStatement |
|
||||||
InfoStatement |
|
InfoStatement |
|
||||||
SelectStatement
|
SelectStatement |
|
||||||
|
ForStatement // |
|
||||||
|
// IfStatement
|
||||||
}
|
}
|
||||||
|
|
||||||
@local tokens {
|
@local tokens {
|
||||||
|
|
@ -254,7 +282,6 @@ statement[@isGroup=Statement] {
|
||||||
int { @digit+ }
|
int { @digit+ }
|
||||||
|
|
||||||
identifier { $[a-zA-Z] $[a-zA-Z0-9_]* }
|
identifier { $[a-zA-Z] $[a-zA-Z0-9_]* }
|
||||||
columnIdentifier { identifier | "*" }
|
|
||||||
|
|
||||||
RIDDelim { "`" }
|
RIDDelim { "`" }
|
||||||
RIDStart { "⟨" }
|
RIDStart { "⟨" }
|
||||||
|
|
@ -264,8 +291,10 @@ statement[@isGroup=Statement] {
|
||||||
|
|
||||||
Divide { "/" | "÷" }
|
Divide { "/" | "÷" }
|
||||||
Multiply { "*" | "×" }
|
Multiply { "*" | "×" }
|
||||||
|
DivideOrMultiply { Divide | Multiply }
|
||||||
Add { "+" }
|
Add { "+" }
|
||||||
Subtract { "-" }
|
Subtract { "-" }
|
||||||
|
AddOrSubtract { Add | Subtract }
|
||||||
Raise { "**" }
|
Raise { "**" }
|
||||||
|
|
||||||
Escape {
|
Escape {
|
||||||
|
|
@ -275,8 +304,8 @@ statement[@isGroup=Statement] {
|
||||||
stringContentSingle { ![\\']+ }
|
stringContentSingle { ![\\']+ }
|
||||||
stringContentDouble { ![\\"]+ }
|
stringContentDouble { ![\\"]+ }
|
||||||
|
|
||||||
COMMA { "," }
|
Comma { "," }
|
||||||
SEMI { ";" }
|
Semi { ";" }
|
||||||
Comparison {
|
Comparison {
|
||||||
"??" | "?:" |
|
"??" | "?:" |
|
||||||
"=" | "IS" |
|
"=" | "IS" |
|
||||||
|
|
@ -310,7 +339,9 @@ statement[@isGroup=Statement] {
|
||||||
"->"
|
"->"
|
||||||
|
|
||||||
@precedence { "/*", LineComment, Divide }
|
@precedence { "/*", LineComment, Divide }
|
||||||
|
@precedence { "/*", LineComment, DivideOrMultiply}
|
||||||
@precedence { LineComment, Subtract }
|
@precedence { LineComment, Subtract }
|
||||||
|
@precedence { LineComment, AddOrSubtract }
|
||||||
}
|
}
|
||||||
|
|
||||||
@detectDelim
|
@detectDelim
|
||||||
|
|
@ -17,22 +17,31 @@ export let parser = baseParser.configure({
|
||||||
Statement: continuedIndent()
|
Statement: continuedIndent()
|
||||||
}),
|
}),
|
||||||
styleTags({
|
styleTags({
|
||||||
Keyword: t.keyword,
|
"StringPrefix as asc desc": t.keyword,
|
||||||
Type: t.typeName,
|
Escape: t.escape,
|
||||||
Builtin: t.standard(t.name),
|
|
||||||
Bits: t.number,
|
|
||||||
Bytes: t.string,
|
|
||||||
Bool: t.bool,
|
Bool: t.bool,
|
||||||
Null: t.null,
|
"DivideOrMultiply AddOrSubtract": t.arithmeticOperator,
|
||||||
Number: t.number,
|
"let <future>": t.definitionKeyword,
|
||||||
String: t.string,
|
Namespace: t.namespace,
|
||||||
Identifier: t.name,
|
FunctionName: t.function(t.variableName),
|
||||||
QuotedIdentifier: t.special(t.string),
|
Variable: t.variableName,
|
||||||
SpecialVar: t.special(t.name),
|
"*": t.atom,
|
||||||
|
Integer: t.integer,
|
||||||
|
"Decimal Float": t.float,
|
||||||
|
Duration: t.number,
|
||||||
LineComment: t.lineComment,
|
LineComment: t.lineComment,
|
||||||
BlockComment: t.blockComment,
|
BlockComment: t.blockComment,
|
||||||
Operator: t.operator,
|
String: t.string,
|
||||||
"Semi Punctuation": t.punctuation,
|
"return break ForStatement/for if else then": t.controlKeyword,
|
||||||
|
"DurationUnit": t.unit,
|
||||||
|
"None Null": t.null,
|
||||||
|
"RecordID": t.special(t.variableName),
|
||||||
|
"Comparison @": t.compareOperator,
|
||||||
|
"And Or": t.logicOperator,
|
||||||
|
"BinaryExpression/. ->": t.derefOperator,
|
||||||
|
": :: ..=": t.punctuation,
|
||||||
|
"Column Property": t.propertyName,
|
||||||
|
"Semi Comma": t.separator,
|
||||||
"( )": t.paren,
|
"( )": t.paren,
|
||||||
"{ }": t.brace,
|
"{ }": t.brace,
|
||||||
"[ ]": t.squareBracket
|
"[ ]": t.squareBracket
|
||||||
|
|
@ -40,7 +49,7 @@ export let parser = baseParser.configure({
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
const language = LRLanguage.define({
|
export const language = LRLanguage.define({
|
||||||
name: "surrealql",
|
name: "surrealql",
|
||||||
parser: parser,
|
parser: parser,
|
||||||
languageData: {
|
languageData: {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue