mirror of
https://gitee.com/ssssssss-team/magic-api.git
synced 2026-06-09 10:23:53 +08:00
支持throw语法
This commit is contained in:
@@ -17,7 +17,7 @@ export const HighLightOptions = {
|
||||
[/[a-zA-Z_$][\w$]*[\s]?/, {
|
||||
cases: {
|
||||
'@builtinFunctions': 'predefined',
|
||||
"~(new|var|if|else|for|in|return|import|break|continue|as|null|true|false|try|catch|finally|async|while|exit|asc|desc|ASC|DESC|assert|let|const)[\\s]?": {token: "keywords"},
|
||||
"~(new|var|if|else|for|in|return|import|break|continue|as|null|true|false|try|catch|finally|async|while|exit|asc|desc|ASC|DESC|assert|let|const|throw)[\\s]?": {token: "keywords"},
|
||||
"~(select|from|left|join|on|and|or|order|by|where|group|having|SELECT|FROM|LEFT|JOIN|ON|AND|OR|ORDER|BY|WHERE|GROUP|HAVING)[\\s]{1}": {token: "keywords"},
|
||||
"@default": "identifier"
|
||||
}
|
||||
|
||||
@@ -253,6 +253,17 @@ class Exit extends Node {
|
||||
}
|
||||
}
|
||||
|
||||
class Throw extends Node {
|
||||
constructor(span, value) {
|
||||
super(span)
|
||||
this.value = value
|
||||
}
|
||||
|
||||
expressions() {
|
||||
return [this.value]
|
||||
}
|
||||
}
|
||||
|
||||
class Assert extends Node {
|
||||
constructor(span, condition, values) {
|
||||
super(span)
|
||||
@@ -646,5 +657,6 @@ export {
|
||||
LinqSelect,
|
||||
WholeLiteral,
|
||||
ClassConverter,
|
||||
LanguageExpression
|
||||
LanguageExpression,
|
||||
Throw
|
||||
}
|
||||
@@ -34,10 +34,11 @@ import {
|
||||
VarDefine,
|
||||
VariableAccess,
|
||||
WhileStatement,
|
||||
WholeLiteral
|
||||
WholeLiteral,
|
||||
Throw
|
||||
} from './ast.js'
|
||||
|
||||
export const keywords = ["import", "as", "var", "let", "const", "return", "break", "continue", "if", "for", "in", "new", "true", "false", "null", "else", "try", "catch", "finally", "async", "while", "exit", "and", "or", /*"assert"*/];
|
||||
export const keywords = ["import", "as", "var", "let", "const", "return", "break", "continue", "if", "for", "in", "new", "true", "false", "null", "else", "try", "catch", "finally", "async", "while", "exit", "and", "or", "throw"/*"assert"*/];
|
||||
export const linqKeywords = ["from", "join", "left", "group", "by", "as", "having", "and", "or", "in", "where", "on"];
|
||||
const binaryOperatorPrecedence = [
|
||||
[TokenType.Assignment],
|
||||
@@ -121,6 +122,8 @@ export class Parser {
|
||||
result = new Break(this.stream.consume().getSpan());
|
||||
} else if (this.stream.match("exit", false)) {
|
||||
result = this.parseExit();
|
||||
} else if (this.stream.match("throw", false)) {
|
||||
result = this.parseThrow();
|
||||
} else if (this.stream.match("assert", false)) {
|
||||
result = this.parseAssert();
|
||||
} else {
|
||||
@@ -165,6 +168,12 @@ export class Parser {
|
||||
}
|
||||
}
|
||||
|
||||
parseThrow() {
|
||||
let opening = this.stream.consume().getSpan();
|
||||
let expression = this.parseExpression();
|
||||
return new Throw(new Span(opening, this.stream.getPrev().getSpan()), expression);
|
||||
}
|
||||
|
||||
parseExit() {
|
||||
let opening = this.stream.expect("exit").getSpan();
|
||||
let expressionList = [];
|
||||
|
||||
Reference in New Issue
Block a user