Add support for parsing 'trait' and 'impl'
This commit is contained in:
parent
d1ba2cb540
commit
5189804c00
5 changed files with 284 additions and 168 deletions
50
spec/ast.txt
50
spec/ast.txt
|
@ -51,6 +51,7 @@ node BoltKeyword;
|
||||||
|
|
||||||
node BoltFnKeyword > BoltToken, BoltKeyword;
|
node BoltFnKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltForeignKeyword > BoltToken, BoltKeyword;
|
node BoltForeignKeyword > BoltToken, BoltKeyword;
|
||||||
|
node BoltForKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltLetKeyword > BoltToken, BoltKeyword;
|
node BoltLetKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltReturnKeyword > BoltToken, BoltKeyword;
|
node BoltReturnKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltLoopKeyword > BoltToken, BoltKeyword;
|
node BoltLoopKeyword > BoltToken, BoltKeyword;
|
||||||
|
@ -63,7 +64,8 @@ node BoltMutKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltEnumKeyword > BoltToken, BoltKeyword;
|
node BoltEnumKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltStructKeyword > BoltToken, BoltKeyword;
|
node BoltStructKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltTypeKeyword > BoltToken, BoltKeyword;
|
node BoltTypeKeyword > BoltToken, BoltKeyword;
|
||||||
node BoltTraitKeyworkd > BoltToken, BoltKeyword;
|
node BoltTraitKeyword > BoltToken, BoltKeyword;
|
||||||
|
node BoltImplKeyword > BoltToken, BoltKeyword;
|
||||||
|
|
||||||
node BoltPunctuated > BoltToken {
|
node BoltPunctuated > BoltToken {
|
||||||
text: String,
|
text: String,
|
||||||
|
@ -198,8 +200,6 @@ node BoltParameter {
|
||||||
|
|
||||||
node BoltDeclaration > BoltSourceElement;
|
node BoltDeclaration > BoltSourceElement;
|
||||||
|
|
||||||
node BoltTypeDeclaration > BoltDeclaration;
|
|
||||||
|
|
||||||
enum BoltDeclarationModifiers {
|
enum BoltDeclarationModifiers {
|
||||||
Mutable = 0x1,
|
Mutable = 0x1,
|
||||||
Public = 0x2,
|
Public = 0x2,
|
||||||
|
@ -207,7 +207,6 @@ enum BoltDeclarationModifiers {
|
||||||
IsForeign = 0x8,
|
IsForeign = 0x8,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
node BoltModule > BoltDeclaration {
|
node BoltModule > BoltDeclaration {
|
||||||
modifiers: BoltDeclarationModifiers,
|
modifiers: BoltDeclarationModifiers,
|
||||||
name: BoltQualName,
|
name: BoltQualName,
|
||||||
|
@ -241,27 +240,42 @@ node BoltImportDeclaration > BoltDeclaration {
|
||||||
symbols: Vec<BoltImportSymbol>,
|
symbols: Vec<BoltImportSymbol>,
|
||||||
}
|
}
|
||||||
|
|
||||||
node BoltRecordDeclarationField {
|
node BoltTraitDeclaration > BoltDeclaration {
|
||||||
|
modifiers: BoltDeclarationModifiers,
|
||||||
name: BoltIdentifier,
|
name: BoltIdentifier,
|
||||||
type: BoltTypeExpression,
|
typeParams: Option<Vec<BoltTypeParameter>>,
|
||||||
|
elements: Vec<BoltDeclaration>,
|
||||||
}
|
}
|
||||||
|
|
||||||
node BoltTypeAliasDeclaration > BoltTypeDeclaration {
|
node BoltImplDeclaration > BoltDeclaration {
|
||||||
|
modifiers: BoltDeclarationModifiers,
|
||||||
|
name: BoltIdentifier,
|
||||||
|
trait: BoltTypeExpression,
|
||||||
|
typeParams: Option<Vec<BoltTypeParameter>>,
|
||||||
|
elements: Vec<BoltDeclaration>,
|
||||||
|
}
|
||||||
|
|
||||||
|
node BoltTypeAliasDeclaration > BoltDeclaration {
|
||||||
modifiers: BoltDeclarationModifiers,
|
modifiers: BoltDeclarationModifiers,
|
||||||
name: BoltIdentifier,
|
name: BoltIdentifier,
|
||||||
typeParams: Option<Vec<BoltTypeParameter>>,
|
typeParams: Option<Vec<BoltTypeParameter>>,
|
||||||
typeExpr: BoltTypeExpression,
|
typeExpr: BoltTypeExpression,
|
||||||
}
|
}
|
||||||
|
|
||||||
node BoltSourceElement;
|
node BoltRecordDeclarationField {
|
||||||
|
name: BoltIdentifier,
|
||||||
|
type: BoltTypeExpression,
|
||||||
|
}
|
||||||
|
|
||||||
node BoltRecordDeclaration > BoltTypeDeclaration {
|
node BoltRecordDeclaration > BoltDeclaration {
|
||||||
modifiers: BoltDeclarationModifiers,
|
modifiers: BoltDeclarationModifiers,
|
||||||
name: BoltQualName,
|
name: BoltQualName,
|
||||||
typeParms: Option<Vec<BoltTypeParameter>>,
|
typeParms: Option<Vec<BoltTypeParameter>>,
|
||||||
fields: Vec<BoltRecordDeclarationField>,
|
fields: Vec<BoltRecordDeclarationField>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node BoltSourceElement;
|
||||||
|
|
||||||
// JavaScript AST definitions
|
// JavaScript AST definitions
|
||||||
|
|
||||||
type JSValue = Int | String | Bool | Void;
|
type JSValue = Int | String | Bool | Void;
|
||||||
|
@ -280,6 +294,17 @@ node JSReturnKeyword > JSToken;
|
||||||
node JSTryKeyword > JSToken;
|
node JSTryKeyword > JSToken;
|
||||||
node JSCatchKeyword > JSToken;
|
node JSCatchKeyword > JSToken;
|
||||||
|
|
||||||
|
node JSCloseBrace > JSToken;
|
||||||
|
node JSCloseBracket > JSToken;
|
||||||
|
node JSCloseParen > JSToken;
|
||||||
|
node JSOpenBrace > JSToken;
|
||||||
|
node JSOpenBracket > JSToken;
|
||||||
|
node JSOpenParen > JSToken;
|
||||||
|
node JSSemi > JSToken;
|
||||||
|
node JSComma > JSToken;
|
||||||
|
node JSDot > JSToken;
|
||||||
|
node JSDotDotDot > JSToken;
|
||||||
|
|
||||||
node JSPattern;
|
node JSPattern;
|
||||||
|
|
||||||
node JSBindPattern > JSPattern {
|
node JSBindPattern > JSPattern {
|
||||||
|
@ -292,14 +317,9 @@ node JSConstantExpression > JSExpression {
|
||||||
value: BoltValue,
|
value: BoltValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
enum JSMemberExpressionModifiers {
|
|
||||||
Computed = 0x1,
|
|
||||||
}
|
|
||||||
|
|
||||||
node JSMemberExpression > JSExpression {
|
node JSMemberExpression > JSExpression {
|
||||||
value: JSExpression,
|
value: JSExpression,
|
||||||
property: JSExpression,
|
property: JSIdentifier,
|
||||||
modifiers: JSMemberExpressionModifiers,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
node JSCallExpression > JSExpression {
|
node JSCallExpression > JSExpression {
|
||||||
|
|
281
src/ast.d.ts
vendored
281
src/ast.d.ts
vendored
|
@ -19,87 +19,91 @@ export const enum SyntaxKind {
|
||||||
BoltLtSign = 21,
|
BoltLtSign = 21,
|
||||||
BoltFnKeyword = 23,
|
BoltFnKeyword = 23,
|
||||||
BoltForeignKeyword = 24,
|
BoltForeignKeyword = 24,
|
||||||
BoltLetKeyword = 25,
|
BoltForKeyword = 25,
|
||||||
BoltReturnKeyword = 26,
|
BoltLetKeyword = 26,
|
||||||
BoltLoopKeyword = 27,
|
BoltReturnKeyword = 27,
|
||||||
BoltYieldKeyword = 28,
|
BoltLoopKeyword = 28,
|
||||||
BoltMatchKeyword = 29,
|
BoltYieldKeyword = 29,
|
||||||
BoltImportKeyword = 30,
|
BoltMatchKeyword = 30,
|
||||||
BoltPubKeyword = 31,
|
BoltImportKeyword = 31,
|
||||||
BoltModKeyword = 32,
|
BoltPubKeyword = 32,
|
||||||
BoltMutKeyword = 33,
|
BoltModKeyword = 33,
|
||||||
BoltEnumKeyword = 34,
|
BoltMutKeyword = 34,
|
||||||
BoltStructKeyword = 35,
|
BoltEnumKeyword = 35,
|
||||||
BoltTypeKeyword = 36,
|
BoltStructKeyword = 36,
|
||||||
BoltTraitKeyworkd = 37,
|
BoltTypeKeyword = 37,
|
||||||
BoltParenthesized = 39,
|
BoltTraitKeyword = 38,
|
||||||
BoltBraced = 40,
|
BoltImplKeyword = 39,
|
||||||
BoltBracketed = 41,
|
BoltParenthesized = 41,
|
||||||
BoltSourceFile = 42,
|
BoltBraced = 42,
|
||||||
BoltQualName = 43,
|
BoltBracketed = 43,
|
||||||
BoltSentence = 44,
|
BoltSourceFile = 44,
|
||||||
BoltReferenceTypeExpression = 46,
|
BoltQualName = 45,
|
||||||
BoltTypeParameter = 47,
|
BoltSentence = 46,
|
||||||
BoltBindPattern = 49,
|
BoltReferenceTypeExpression = 48,
|
||||||
BoltTypePattern = 50,
|
BoltTypeParameter = 49,
|
||||||
BoltExpressionPattern = 51,
|
BoltBindPattern = 51,
|
||||||
BoltTuplePatternElement = 52,
|
BoltTypePattern = 52,
|
||||||
BoltTuplePattern = 53,
|
BoltExpressionPattern = 53,
|
||||||
BoltRecordPatternField = 54,
|
BoltTuplePatternElement = 54,
|
||||||
BoltRecordPattern = 55,
|
BoltTuplePattern = 55,
|
||||||
BoltReferenceExpression = 57,
|
BoltRecordPatternField = 56,
|
||||||
BoltCallExpression = 58,
|
BoltRecordPattern = 57,
|
||||||
BoltYieldExpression = 59,
|
BoltReferenceExpression = 59,
|
||||||
BoltMatchArm = 60,
|
BoltCallExpression = 60,
|
||||||
BoltMatchExpression = 61,
|
BoltYieldExpression = 61,
|
||||||
BoltCase = 62,
|
BoltMatchArm = 62,
|
||||||
BoltCaseExpression = 63,
|
BoltMatchExpression = 63,
|
||||||
BoltBlockExpression = 64,
|
BoltCase = 64,
|
||||||
BoltConstantExpression = 65,
|
BoltCaseExpression = 65,
|
||||||
BoltReturnStatement = 67,
|
BoltBlockExpression = 66,
|
||||||
BoltResumeStatement = 68,
|
BoltConstantExpression = 67,
|
||||||
BoltExpressionStatement = 69,
|
BoltReturnStatement = 69,
|
||||||
BoltParameter = 70,
|
BoltResumeStatement = 70,
|
||||||
BoltModule = 74,
|
BoltExpressionStatement = 71,
|
||||||
BoltFunctionDeclaration = 75,
|
BoltParameter = 72,
|
||||||
BoltVariableDeclaration = 76,
|
BoltModule = 75,
|
||||||
BoltPlainImportSymbol = 78,
|
BoltFunctionDeclaration = 76,
|
||||||
BoltImportDeclaration = 79,
|
BoltVariableDeclaration = 77,
|
||||||
BoltRecordDeclarationField = 80,
|
BoltPlainImportSymbol = 79,
|
||||||
BoltTypeAliasDeclaration = 81,
|
BoltImportDeclaration = 80,
|
||||||
BoltRecordDeclaration = 83,
|
BoltTraitDeclaration = 81,
|
||||||
JSOperator = 86,
|
BoltImplDeclaration = 82,
|
||||||
JSIdentifier = 87,
|
BoltTypeAliasDeclaration = 83,
|
||||||
JSReturnKeyword = 88,
|
BoltRecordDeclarationField = 84,
|
||||||
JSTryKeyword = 89,
|
BoltRecordDeclaration = 85,
|
||||||
JSCatchKeyword = 90,
|
JSOperator = 89,
|
||||||
JSCloseBrace = 91,
|
JSIdentifier = 90,
|
||||||
JSCloseBracket = 92,
|
JSReturnKeyword = 91,
|
||||||
JSCloseParen = 93,
|
JSTryKeyword = 92,
|
||||||
JSOpenBrace = 94,
|
JSCatchKeyword = 93,
|
||||||
JSOpenBracket = 95,
|
JSCloseBrace = 94,
|
||||||
JSOpenParen = 96,
|
JSCloseBracket = 95,
|
||||||
JSSemi = 97,
|
JSCloseParen = 96,
|
||||||
JSComma = 98,
|
JSOpenBrace = 97,
|
||||||
JSDot = 99,
|
JSOpenBracket = 98,
|
||||||
JSDotDotDot = 100,
|
JSOpenParen = 99,
|
||||||
JSBindPattern = 102,
|
JSSemi = 100,
|
||||||
JSConstantExpression = 104,
|
JSComma = 101,
|
||||||
JSMemberExpression = 105,
|
JSDot = 102,
|
||||||
JSCallExpression = 106,
|
JSDotDotDot = 103,
|
||||||
JSBinaryExpression = 107,
|
JSBindPattern = 105,
|
||||||
JSUnaryExpression = 108,
|
JSConstantExpression = 107,
|
||||||
JSNewExpression = 109,
|
JSMemberExpression = 108,
|
||||||
JSSequenceExpression = 110,
|
JSCallExpression = 109,
|
||||||
JSConditionalExpression = 111,
|
JSBinaryExpression = 110,
|
||||||
JSReferenceExpression = 112,
|
JSUnaryExpression = 111,
|
||||||
JSExpressionStatement = 115,
|
JSNewExpression = 112,
|
||||||
JSConditionalStatement = 116,
|
JSSequenceExpression = 113,
|
||||||
JSParameter = 117,
|
JSConditionalExpression = 114,
|
||||||
JSFunctionDeclaration = 120,
|
JSReferenceExpression = 115,
|
||||||
JSArrowFunctionDeclaration = 121,
|
JSExpressionStatement = 118,
|
||||||
JSLetDeclaration = 122,
|
JSConditionalStatement = 119,
|
||||||
JSSourceFile = 123,
|
JSParameter = 120,
|
||||||
|
JSFunctionDeclaration = 123,
|
||||||
|
JSArrowFunctionDeclaration = 124,
|
||||||
|
JSLetDeclaration = 125,
|
||||||
|
JSSourceFile = 126,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,6 +146,7 @@ export type BoltToken
|
||||||
| BoltLtSign
|
| BoltLtSign
|
||||||
| BoltFnKeyword
|
| BoltFnKeyword
|
||||||
| BoltForeignKeyword
|
| BoltForeignKeyword
|
||||||
|
| BoltForKeyword
|
||||||
| BoltLetKeyword
|
| BoltLetKeyword
|
||||||
| BoltReturnKeyword
|
| BoltReturnKeyword
|
||||||
| BoltLoopKeyword
|
| BoltLoopKeyword
|
||||||
|
@ -154,7 +159,8 @@ export type BoltToken
|
||||||
| BoltEnumKeyword
|
| BoltEnumKeyword
|
||||||
| BoltStructKeyword
|
| BoltStructKeyword
|
||||||
| BoltTypeKeyword
|
| BoltTypeKeyword
|
||||||
| BoltTraitKeyworkd
|
| BoltTraitKeyword
|
||||||
|
| BoltImplKeyword
|
||||||
| BoltParenthesized
|
| BoltParenthesized
|
||||||
| BoltBraced
|
| BoltBraced
|
||||||
| BoltBracketed
|
| BoltBracketed
|
||||||
|
@ -233,6 +239,7 @@ export interface BoltLtSign extends SyntaxBase {
|
||||||
export type BoltKeyword
|
export type BoltKeyword
|
||||||
= BoltFnKeyword
|
= BoltFnKeyword
|
||||||
| BoltForeignKeyword
|
| BoltForeignKeyword
|
||||||
|
| BoltForKeyword
|
||||||
| BoltLetKeyword
|
| BoltLetKeyword
|
||||||
| BoltReturnKeyword
|
| BoltReturnKeyword
|
||||||
| BoltLoopKeyword
|
| BoltLoopKeyword
|
||||||
|
@ -245,7 +252,8 @@ export type BoltKeyword
|
||||||
| BoltEnumKeyword
|
| BoltEnumKeyword
|
||||||
| BoltStructKeyword
|
| BoltStructKeyword
|
||||||
| BoltTypeKeyword
|
| BoltTypeKeyword
|
||||||
| BoltTraitKeyworkd
|
| BoltTraitKeyword
|
||||||
|
| BoltImplKeyword
|
||||||
|
|
||||||
|
|
||||||
export interface BoltFnKeyword extends SyntaxBase {
|
export interface BoltFnKeyword extends SyntaxBase {
|
||||||
|
@ -256,6 +264,10 @@ export interface BoltForeignKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltForeignKeyword;
|
kind: SyntaxKind.BoltForeignKeyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface BoltForKeyword extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltForKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
export interface BoltLetKeyword extends SyntaxBase {
|
export interface BoltLetKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltLetKeyword;
|
kind: SyntaxKind.BoltLetKeyword;
|
||||||
}
|
}
|
||||||
|
@ -304,8 +316,12 @@ export interface BoltTypeKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltTypeKeyword;
|
kind: SyntaxKind.BoltTypeKeyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BoltTraitKeyworkd extends SyntaxBase {
|
export interface BoltTraitKeyword extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltTraitKeyworkd;
|
kind: SyntaxKind.BoltTraitKeyword;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BoltImplKeyword extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltImplKeyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BoltPunctuated
|
export type BoltPunctuated
|
||||||
|
@ -498,16 +514,13 @@ export interface BoltParameter extends SyntaxBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BoltDeclaration
|
export type BoltDeclaration
|
||||||
= BoltTypeAliasDeclaration
|
= BoltModule
|
||||||
| BoltRecordDeclaration
|
|
||||||
| BoltModule
|
|
||||||
| BoltFunctionDeclaration
|
| BoltFunctionDeclaration
|
||||||
| BoltVariableDeclaration
|
| BoltVariableDeclaration
|
||||||
| BoltImportDeclaration
|
| BoltImportDeclaration
|
||||||
|
| BoltTraitDeclaration
|
||||||
|
| BoltImplDeclaration
|
||||||
export type BoltTypeDeclaration
|
| BoltTypeAliasDeclaration
|
||||||
= BoltTypeAliasDeclaration
|
|
||||||
| BoltRecordDeclaration
|
| BoltRecordDeclaration
|
||||||
|
|
||||||
|
|
||||||
|
@ -554,10 +567,21 @@ export interface BoltImportDeclaration extends SyntaxBase {
|
||||||
symbols: BoltImportSymbol[];
|
symbols: BoltImportSymbol[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BoltRecordDeclarationField extends SyntaxBase {
|
export interface BoltTraitDeclaration extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltRecordDeclarationField;
|
kind: SyntaxKind.BoltTraitDeclaration;
|
||||||
|
modifiers: BoltDeclarationModifiers;
|
||||||
name: BoltIdentifier;
|
name: BoltIdentifier;
|
||||||
type: BoltTypeExpression;
|
typeParams: BoltTypeParameter[] | null;
|
||||||
|
elements: BoltDeclaration[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BoltImplDeclaration extends SyntaxBase {
|
||||||
|
kind: SyntaxKind.BoltImplDeclaration;
|
||||||
|
modifiers: BoltDeclarationModifiers;
|
||||||
|
name: BoltIdentifier;
|
||||||
|
trait: BoltTypeExpression;
|
||||||
|
typeParams: BoltTypeParameter[] | null;
|
||||||
|
elements: BoltDeclaration[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface BoltTypeAliasDeclaration extends SyntaxBase {
|
export interface BoltTypeAliasDeclaration extends SyntaxBase {
|
||||||
|
@ -568,18 +592,11 @@ export interface BoltTypeAliasDeclaration extends SyntaxBase {
|
||||||
typeExpr: BoltTypeExpression;
|
typeExpr: BoltTypeExpression;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type BoltSourceElement
|
export interface BoltRecordDeclarationField extends SyntaxBase {
|
||||||
= BoltSentence
|
kind: SyntaxKind.BoltRecordDeclarationField;
|
||||||
| BoltReturnStatement
|
name: BoltIdentifier;
|
||||||
| BoltResumeStatement
|
type: BoltTypeExpression;
|
||||||
| BoltExpressionStatement
|
}
|
||||||
| BoltTypeAliasDeclaration
|
|
||||||
| BoltRecordDeclaration
|
|
||||||
| BoltModule
|
|
||||||
| BoltFunctionDeclaration
|
|
||||||
| BoltVariableDeclaration
|
|
||||||
| BoltImportDeclaration
|
|
||||||
|
|
||||||
|
|
||||||
export interface BoltRecordDeclaration extends SyntaxBase {
|
export interface BoltRecordDeclaration extends SyntaxBase {
|
||||||
kind: SyntaxKind.BoltRecordDeclaration;
|
kind: SyntaxKind.BoltRecordDeclaration;
|
||||||
|
@ -589,6 +606,21 @@ export interface BoltRecordDeclaration extends SyntaxBase {
|
||||||
fields: BoltRecordDeclarationField[];
|
fields: BoltRecordDeclarationField[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type BoltSourceElement
|
||||||
|
= BoltSentence
|
||||||
|
| BoltReturnStatement
|
||||||
|
| BoltResumeStatement
|
||||||
|
| BoltExpressionStatement
|
||||||
|
| BoltModule
|
||||||
|
| BoltFunctionDeclaration
|
||||||
|
| BoltVariableDeclaration
|
||||||
|
| BoltImportDeclaration
|
||||||
|
| BoltTraitDeclaration
|
||||||
|
| BoltImplDeclaration
|
||||||
|
| BoltTypeAliasDeclaration
|
||||||
|
| BoltRecordDeclaration
|
||||||
|
|
||||||
|
|
||||||
export type JSToken
|
export type JSToken
|
||||||
= EndOfFile
|
= EndOfFile
|
||||||
| JSOperator
|
| JSOperator
|
||||||
|
@ -829,6 +861,7 @@ export type BoltSyntax
|
||||||
| BoltLtSign
|
| BoltLtSign
|
||||||
| BoltFnKeyword
|
| BoltFnKeyword
|
||||||
| BoltForeignKeyword
|
| BoltForeignKeyword
|
||||||
|
| BoltForKeyword
|
||||||
| BoltLetKeyword
|
| BoltLetKeyword
|
||||||
| BoltReturnKeyword
|
| BoltReturnKeyword
|
||||||
| BoltLoopKeyword
|
| BoltLoopKeyword
|
||||||
|
@ -841,7 +874,8 @@ export type BoltSyntax
|
||||||
| BoltEnumKeyword
|
| BoltEnumKeyword
|
||||||
| BoltStructKeyword
|
| BoltStructKeyword
|
||||||
| BoltTypeKeyword
|
| BoltTypeKeyword
|
||||||
| BoltTraitKeyworkd
|
| BoltTraitKeyword
|
||||||
|
| BoltImplKeyword
|
||||||
| BoltParenthesized
|
| BoltParenthesized
|
||||||
| BoltBraced
|
| BoltBraced
|
||||||
| BoltBracketed
|
| BoltBracketed
|
||||||
|
@ -875,8 +909,10 @@ export type BoltSyntax
|
||||||
| BoltVariableDeclaration
|
| BoltVariableDeclaration
|
||||||
| BoltPlainImportSymbol
|
| BoltPlainImportSymbol
|
||||||
| BoltImportDeclaration
|
| BoltImportDeclaration
|
||||||
| BoltRecordDeclarationField
|
| BoltTraitDeclaration
|
||||||
|
| BoltImplDeclaration
|
||||||
| BoltTypeAliasDeclaration
|
| BoltTypeAliasDeclaration
|
||||||
|
| BoltRecordDeclarationField
|
||||||
| BoltRecordDeclaration
|
| BoltRecordDeclaration
|
||||||
|
|
||||||
|
|
||||||
|
@ -935,6 +971,7 @@ export type Syntax
|
||||||
| BoltLtSign
|
| BoltLtSign
|
||||||
| BoltFnKeyword
|
| BoltFnKeyword
|
||||||
| BoltForeignKeyword
|
| BoltForeignKeyword
|
||||||
|
| BoltForKeyword
|
||||||
| BoltLetKeyword
|
| BoltLetKeyword
|
||||||
| BoltReturnKeyword
|
| BoltReturnKeyword
|
||||||
| BoltLoopKeyword
|
| BoltLoopKeyword
|
||||||
|
@ -947,7 +984,8 @@ export type Syntax
|
||||||
| BoltEnumKeyword
|
| BoltEnumKeyword
|
||||||
| BoltStructKeyword
|
| BoltStructKeyword
|
||||||
| BoltTypeKeyword
|
| BoltTypeKeyword
|
||||||
| BoltTraitKeyworkd
|
| BoltTraitKeyword
|
||||||
|
| BoltImplKeyword
|
||||||
| BoltParenthesized
|
| BoltParenthesized
|
||||||
| BoltBraced
|
| BoltBraced
|
||||||
| BoltBracketed
|
| BoltBracketed
|
||||||
|
@ -981,8 +1019,10 @@ export type Syntax
|
||||||
| BoltVariableDeclaration
|
| BoltVariableDeclaration
|
||||||
| BoltPlainImportSymbol
|
| BoltPlainImportSymbol
|
||||||
| BoltImportDeclaration
|
| BoltImportDeclaration
|
||||||
| BoltRecordDeclarationField
|
| BoltTraitDeclaration
|
||||||
|
| BoltImplDeclaration
|
||||||
| BoltTypeAliasDeclaration
|
| BoltTypeAliasDeclaration
|
||||||
|
| BoltRecordDeclarationField
|
||||||
| BoltRecordDeclaration
|
| BoltRecordDeclaration
|
||||||
| JSOperator
|
| JSOperator
|
||||||
| JSIdentifier
|
| JSIdentifier
|
||||||
|
@ -1039,6 +1079,7 @@ export function createBoltGtSign(span?: TextSpan | null): BoltGtSign;
|
||||||
export function createBoltLtSign(span?: TextSpan | null): BoltLtSign;
|
export function createBoltLtSign(span?: TextSpan | null): BoltLtSign;
|
||||||
export function createBoltFnKeyword(span?: TextSpan | null): BoltFnKeyword;
|
export function createBoltFnKeyword(span?: TextSpan | null): BoltFnKeyword;
|
||||||
export function createBoltForeignKeyword(span?: TextSpan | null): BoltForeignKeyword;
|
export function createBoltForeignKeyword(span?: TextSpan | null): BoltForeignKeyword;
|
||||||
|
export function createBoltForKeyword(span?: TextSpan | null): BoltForKeyword;
|
||||||
export function createBoltLetKeyword(span?: TextSpan | null): BoltLetKeyword;
|
export function createBoltLetKeyword(span?: TextSpan | null): BoltLetKeyword;
|
||||||
export function createBoltReturnKeyword(span?: TextSpan | null): BoltReturnKeyword;
|
export function createBoltReturnKeyword(span?: TextSpan | null): BoltReturnKeyword;
|
||||||
export function createBoltLoopKeyword(span?: TextSpan | null): BoltLoopKeyword;
|
export function createBoltLoopKeyword(span?: TextSpan | null): BoltLoopKeyword;
|
||||||
|
@ -1051,7 +1092,8 @@ export function createBoltMutKeyword(span?: TextSpan | null): BoltMutKeyword;
|
||||||
export function createBoltEnumKeyword(span?: TextSpan | null): BoltEnumKeyword;
|
export function createBoltEnumKeyword(span?: TextSpan | null): BoltEnumKeyword;
|
||||||
export function createBoltStructKeyword(span?: TextSpan | null): BoltStructKeyword;
|
export function createBoltStructKeyword(span?: TextSpan | null): BoltStructKeyword;
|
||||||
export function createBoltTypeKeyword(span?: TextSpan | null): BoltTypeKeyword;
|
export function createBoltTypeKeyword(span?: TextSpan | null): BoltTypeKeyword;
|
||||||
export function createBoltTraitKeyworkd(span?: TextSpan | null): BoltTraitKeyworkd;
|
export function createBoltTraitKeyword(span?: TextSpan | null): BoltTraitKeyword;
|
||||||
|
export function createBoltImplKeyword(span?: TextSpan | null): BoltImplKeyword;
|
||||||
export function createBoltParenthesized(text: string, span?: TextSpan | null): BoltParenthesized;
|
export function createBoltParenthesized(text: string, span?: TextSpan | null): BoltParenthesized;
|
||||||
export function createBoltBraced(text: string, span?: TextSpan | null): BoltBraced;
|
export function createBoltBraced(text: string, span?: TextSpan | null): BoltBraced;
|
||||||
export function createBoltBracketed(text: string, span?: TextSpan | null): BoltBracketed;
|
export function createBoltBracketed(text: string, span?: TextSpan | null): BoltBracketed;
|
||||||
|
@ -1085,8 +1127,10 @@ export function createBoltFunctionDeclaration(modifiers: BoltDeclarationModifier
|
||||||
export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifiers, bindings: BoltPattern, type: BoltTypeExpression | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration;
|
export function createBoltVariableDeclaration(modifiers: BoltDeclarationModifiers, bindings: BoltPattern, type: BoltTypeExpression | null, value: BoltExpression | null, span?: TextSpan | null): BoltVariableDeclaration;
|
||||||
export function createBoltPlainImportSymbol(name: BoltQualName, span?: TextSpan | null): BoltPlainImportSymbol;
|
export function createBoltPlainImportSymbol(name: BoltQualName, span?: TextSpan | null): BoltPlainImportSymbol;
|
||||||
export function createBoltImportDeclaration(file: string, symbols: BoltImportSymbol[], span?: TextSpan | null): BoltImportDeclaration;
|
export function createBoltImportDeclaration(file: string, symbols: BoltImportSymbol[], span?: TextSpan | null): BoltImportDeclaration;
|
||||||
export function createBoltRecordDeclarationField(name: BoltIdentifier, type: BoltTypeExpression, span?: TextSpan | null): BoltRecordDeclarationField;
|
export function createBoltTraitDeclaration(modifiers: BoltDeclarationModifiers, name: BoltIdentifier, typeParams: BoltTypeParameter[] | null, elements: BoltDeclaration[], span?: TextSpan | null): BoltTraitDeclaration;
|
||||||
|
export function createBoltImplDeclaration(modifiers: BoltDeclarationModifiers, name: BoltIdentifier, trait: BoltTypeExpression, typeParams: BoltTypeParameter[] | null, elements: BoltDeclaration[], span?: TextSpan | null): BoltImplDeclaration;
|
||||||
export function createBoltTypeAliasDeclaration(modifiers: BoltDeclarationModifiers, name: BoltIdentifier, typeParams: BoltTypeParameter[] | null, typeExpr: BoltTypeExpression, span?: TextSpan | null): BoltTypeAliasDeclaration;
|
export function createBoltTypeAliasDeclaration(modifiers: BoltDeclarationModifiers, name: BoltIdentifier, typeParams: BoltTypeParameter[] | null, typeExpr: BoltTypeExpression, span?: TextSpan | null): BoltTypeAliasDeclaration;
|
||||||
|
export function createBoltRecordDeclarationField(name: BoltIdentifier, type: BoltTypeExpression, span?: TextSpan | null): BoltRecordDeclarationField;
|
||||||
export function createBoltRecordDeclaration(modifiers: BoltDeclarationModifiers, name: BoltQualName, typeParms: BoltTypeParameter[] | null, fields: BoltRecordDeclarationField[], span?: TextSpan | null): BoltRecordDeclaration;
|
export function createBoltRecordDeclaration(modifiers: BoltDeclarationModifiers, name: BoltQualName, typeParms: BoltTypeParameter[] | null, fields: BoltRecordDeclarationField[], span?: TextSpan | null): BoltRecordDeclaration;
|
||||||
export function createJSOperator(text: string, span?: TextSpan | null): JSOperator;
|
export function createJSOperator(text: string, span?: TextSpan | null): JSOperator;
|
||||||
export function createJSIdentifier(text: string, span?: TextSpan | null): JSIdentifier;
|
export function createJSIdentifier(text: string, span?: TextSpan | null): JSIdentifier;
|
||||||
|
@ -1143,6 +1187,7 @@ export function isBoltLtSign(value: any): value is BoltLtSign;
|
||||||
export function isBoltKeyword(value: any): value is BoltKeyword;
|
export function isBoltKeyword(value: any): value is BoltKeyword;
|
||||||
export function isBoltFnKeyword(value: any): value is BoltFnKeyword;
|
export function isBoltFnKeyword(value: any): value is BoltFnKeyword;
|
||||||
export function isBoltForeignKeyword(value: any): value is BoltForeignKeyword;
|
export function isBoltForeignKeyword(value: any): value is BoltForeignKeyword;
|
||||||
|
export function isBoltForKeyword(value: any): value is BoltForKeyword;
|
||||||
export function isBoltLetKeyword(value: any): value is BoltLetKeyword;
|
export function isBoltLetKeyword(value: any): value is BoltLetKeyword;
|
||||||
export function isBoltReturnKeyword(value: any): value is BoltReturnKeyword;
|
export function isBoltReturnKeyword(value: any): value is BoltReturnKeyword;
|
||||||
export function isBoltLoopKeyword(value: any): value is BoltLoopKeyword;
|
export function isBoltLoopKeyword(value: any): value is BoltLoopKeyword;
|
||||||
|
@ -1155,7 +1200,8 @@ export function isBoltMutKeyword(value: any): value is BoltMutKeyword;
|
||||||
export function isBoltEnumKeyword(value: any): value is BoltEnumKeyword;
|
export function isBoltEnumKeyword(value: any): value is BoltEnumKeyword;
|
||||||
export function isBoltStructKeyword(value: any): value is BoltStructKeyword;
|
export function isBoltStructKeyword(value: any): value is BoltStructKeyword;
|
||||||
export function isBoltTypeKeyword(value: any): value is BoltTypeKeyword;
|
export function isBoltTypeKeyword(value: any): value is BoltTypeKeyword;
|
||||||
export function isBoltTraitKeyworkd(value: any): value is BoltTraitKeyworkd;
|
export function isBoltTraitKeyword(value: any): value is BoltTraitKeyword;
|
||||||
|
export function isBoltImplKeyword(value: any): value is BoltImplKeyword;
|
||||||
export function isBoltPunctuated(value: any): value is BoltPunctuated;
|
export function isBoltPunctuated(value: any): value is BoltPunctuated;
|
||||||
export function isBoltParenthesized(value: any): value is BoltParenthesized;
|
export function isBoltParenthesized(value: any): value is BoltParenthesized;
|
||||||
export function isBoltBraced(value: any): value is BoltBraced;
|
export function isBoltBraced(value: any): value is BoltBraced;
|
||||||
|
@ -1190,17 +1236,18 @@ export function isBoltResumeStatement(value: any): value is BoltResumeStatement;
|
||||||
export function isBoltExpressionStatement(value: any): value is BoltExpressionStatement;
|
export function isBoltExpressionStatement(value: any): value is BoltExpressionStatement;
|
||||||
export function isBoltParameter(value: any): value is BoltParameter;
|
export function isBoltParameter(value: any): value is BoltParameter;
|
||||||
export function isBoltDeclaration(value: any): value is BoltDeclaration;
|
export function isBoltDeclaration(value: any): value is BoltDeclaration;
|
||||||
export function isBoltTypeDeclaration(value: any): value is BoltTypeDeclaration;
|
|
||||||
export function isBoltModule(value: any): value is BoltModule;
|
export function isBoltModule(value: any): value is BoltModule;
|
||||||
export function isBoltFunctionDeclaration(value: any): value is BoltFunctionDeclaration;
|
export function isBoltFunctionDeclaration(value: any): value is BoltFunctionDeclaration;
|
||||||
export function isBoltVariableDeclaration(value: any): value is BoltVariableDeclaration;
|
export function isBoltVariableDeclaration(value: any): value is BoltVariableDeclaration;
|
||||||
export function isBoltImportSymbol(value: any): value is BoltImportSymbol;
|
export function isBoltImportSymbol(value: any): value is BoltImportSymbol;
|
||||||
export function isBoltPlainImportSymbol(value: any): value is BoltPlainImportSymbol;
|
export function isBoltPlainImportSymbol(value: any): value is BoltPlainImportSymbol;
|
||||||
export function isBoltImportDeclaration(value: any): value is BoltImportDeclaration;
|
export function isBoltImportDeclaration(value: any): value is BoltImportDeclaration;
|
||||||
export function isBoltRecordDeclarationField(value: any): value is BoltRecordDeclarationField;
|
export function isBoltTraitDeclaration(value: any): value is BoltTraitDeclaration;
|
||||||
|
export function isBoltImplDeclaration(value: any): value is BoltImplDeclaration;
|
||||||
export function isBoltTypeAliasDeclaration(value: any): value is BoltTypeAliasDeclaration;
|
export function isBoltTypeAliasDeclaration(value: any): value is BoltTypeAliasDeclaration;
|
||||||
export function isBoltSourceElement(value: any): value is BoltSourceElement;
|
export function isBoltRecordDeclarationField(value: any): value is BoltRecordDeclarationField;
|
||||||
export function isBoltRecordDeclaration(value: any): value is BoltRecordDeclaration;
|
export function isBoltRecordDeclaration(value: any): value is BoltRecordDeclaration;
|
||||||
|
export function isBoltSourceElement(value: any): value is BoltSourceElement;
|
||||||
export function isJSToken(value: any): value is JSToken;
|
export function isJSToken(value: any): value is JSToken;
|
||||||
export function isJSOperator(value: any): value is JSOperator;
|
export function isJSOperator(value: any): value is JSOperator;
|
||||||
export function isJSIdentifier(value: any): value is JSIdentifier;
|
export function isJSIdentifier(value: any): value is JSIdentifier;
|
||||||
|
|
|
@ -49,6 +49,11 @@ import {
|
||||||
BoltTypeParameter,
|
BoltTypeParameter,
|
||||||
createBoltTypePattern,
|
createBoltTypePattern,
|
||||||
createBoltTypeParameter,
|
createBoltTypeParameter,
|
||||||
|
BoltTraitDeclaration,
|
||||||
|
createBoltTraitKeyword,
|
||||||
|
createBoltTraitDeclaration,
|
||||||
|
createBoltImplDeclaration,
|
||||||
|
BoltImplDeclaration,
|
||||||
} from "./ast"
|
} from "./ast"
|
||||||
|
|
||||||
import { parseForeignLanguage } from "./foreign"
|
import { parseForeignLanguage } from "./foreign"
|
||||||
|
@ -81,6 +86,8 @@ const KIND_STATEMENT_T0 = uniq([
|
||||||
])
|
])
|
||||||
|
|
||||||
const KIND_DECLARATION_KEYWORD = [
|
const KIND_DECLARATION_KEYWORD = [
|
||||||
|
SyntaxKind.BoltImplKeyword,
|
||||||
|
SyntaxKind.BoltTraitKeyword,
|
||||||
SyntaxKind.BoltFnKeyword,
|
SyntaxKind.BoltFnKeyword,
|
||||||
SyntaxKind.BoltEnumKeyword,
|
SyntaxKind.BoltEnumKeyword,
|
||||||
SyntaxKind.BoltLetKeyword,
|
SyntaxKind.BoltLetKeyword,
|
||||||
|
@ -321,32 +328,6 @@ export class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//parseSyntax(tokens: TokenStream): Syntax {
|
|
||||||
|
|
||||||
// // Assuming first token is 'syntax'
|
|
||||||
// const t0 = tokens.get();
|
|
||||||
// assertToken(t0, SyntaxKind.Bolt
|
|
||||||
|
|
||||||
// const t1 = tokens.get();
|
|
||||||
// if (t1.kind !== SyntaxKind.BoltBraced) {
|
|
||||||
// throw new ParseError(t1, [SyntaxKind.BoltBraced])
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const innerTokens = t1.toTokenStream();
|
|
||||||
|
|
||||||
// const pattern = this.parsePattern(innerTokens)
|
|
||||||
|
|
||||||
// const t2 = innerTokens.get();
|
|
||||||
// if (t2.kind !== SyntaxKind.BoltRArrow) {
|
|
||||||
// throw new ParseError(t2, [SyntaxKind.BoltRArrow]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// const body = this.parseBody(innerTokens);
|
|
||||||
|
|
||||||
// return new Macro(pattern, body)
|
|
||||||
|
|
||||||
//}
|
|
||||||
|
|
||||||
public parseExpression(tokens: BoltTokenStream): BoltExpression {
|
public parseExpression(tokens: BoltTokenStream): BoltExpression {
|
||||||
return this.parseCallOrPrimitiveExpression(tokens)
|
return this.parseCallOrPrimitiveExpression(tokens)
|
||||||
}
|
}
|
||||||
|
@ -358,13 +339,13 @@ export class Parser {
|
||||||
|
|
||||||
const pattern = this.parsePattern(tokens)
|
const pattern = this.parsePattern(tokens)
|
||||||
|
|
||||||
let t0 = tokens.peek(1);
|
let t0 = tokens.peek();
|
||||||
let endNode: BoltSyntax = pattern;
|
let endNode: BoltSyntax = pattern;
|
||||||
if (t0.kind === SyntaxKind.BoltColon) {
|
if (t0.kind === SyntaxKind.BoltColon) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
typeDecl = this.parseTypeExpression(tokens);
|
typeDecl = this.parseTypeExpression(tokens);
|
||||||
endNode = typeDecl;
|
endNode = typeDecl;
|
||||||
t0 = tokens.get();
|
t0 = tokens.peek();
|
||||||
}
|
}
|
||||||
if (t0.kind === SyntaxKind.BoltEqSign) {
|
if (t0.kind === SyntaxKind.BoltEqSign) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
|
@ -472,7 +453,7 @@ export class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public parseGenericTypeParameter(tokens: BoltTokenStream) {
|
public parseGenericTypeParameter(tokens: BoltTokenStream): BoltTypeParameter {
|
||||||
const t0 = tokens.peek();
|
const t0 = tokens.peek();
|
||||||
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
if (t0.kind === SyntaxKind.BoltIdentifier) {
|
||||||
tokens.get();
|
tokens.get();
|
||||||
|
@ -484,7 +465,7 @@ export class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private parseGenericTypeParameters(tokens: BoltTokenStream) {
|
private parseGenericTypeParameters(tokens: BoltTokenStream): BoltTypeParameter[] {
|
||||||
let typeParams: BoltTypeParameter[] = [];
|
let typeParams: BoltTypeParameter[] = [];
|
||||||
const t0 = tokens.get();
|
const t0 = tokens.get();
|
||||||
assertToken(t0, SyntaxKind.BoltLtSign);
|
assertToken(t0, SyntaxKind.BoltLtSign);
|
||||||
|
@ -817,6 +798,57 @@ export class Parser {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public parseTraitDeclaration(tokens: BoltTokenStream): BoltTraitDeclaration {
|
||||||
|
let modifiers = 0;
|
||||||
|
let t0 = tokens.get();
|
||||||
|
const firstToken = t0;
|
||||||
|
if (t0.kind === SyntaxKind.BoltPubKeyword) {
|
||||||
|
modifiers |= BoltDeclarationModifiers.Public;
|
||||||
|
t0 = tokens.get();
|
||||||
|
}
|
||||||
|
assertToken(t0, SyntaxKind.BoltTraitKeyword);
|
||||||
|
const t1 = tokens.get();
|
||||||
|
assertToken(t1, SyntaxKind.BoltIdentifier);
|
||||||
|
let typeParams = null
|
||||||
|
const t2 = tokens.peek();
|
||||||
|
if (t2.kind === SyntaxKind.BoltLtSign) {
|
||||||
|
typeParams = this.parseGenericTypeParameters(tokens);
|
||||||
|
}
|
||||||
|
const t3 = tokens.get();
|
||||||
|
assertToken(t3, SyntaxKind.BoltBraced);
|
||||||
|
const elements = this.parseSourceElementList(createTokenStream(t3));
|
||||||
|
const result = createBoltTraitDeclaration(modifiers, t1 as BoltIdentifier, typeParams, elements as BoltDeclaration[]);
|
||||||
|
setOrigNodeRange(result, firstToken, t3);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public parseImplDeclaration(tokens: BoltTokenStream): BoltImplDeclaration {
|
||||||
|
let modifiers = 0;
|
||||||
|
let t0 = tokens.get();
|
||||||
|
const firstToken = t0;
|
||||||
|
if (t0.kind === SyntaxKind.BoltPubKeyword) {
|
||||||
|
modifiers |= BoltDeclarationModifiers.Public;
|
||||||
|
t0 = tokens.get();
|
||||||
|
}
|
||||||
|
assertToken(t0, SyntaxKind.BoltImplKeyword);
|
||||||
|
const t1 = tokens.get();
|
||||||
|
assertToken(t1, SyntaxKind.BoltIdentifier);
|
||||||
|
const t2 = tokens.get();
|
||||||
|
assertToken(t2, SyntaxKind.BoltForKeyword);
|
||||||
|
const typeExpr = this.parseTypeExpression(tokens);
|
||||||
|
let typeParams = null
|
||||||
|
const t3 = tokens.peek();
|
||||||
|
if (t3.kind === SyntaxKind.BoltLtSign) {
|
||||||
|
typeParams = this.parseGenericTypeParameters(tokens);
|
||||||
|
}
|
||||||
|
const t4 = tokens.get();
|
||||||
|
assertToken(t4, SyntaxKind.BoltBraced);
|
||||||
|
const elements = this.parseSourceElementList(createTokenStream(t4));
|
||||||
|
const result = createBoltImplDeclaration(modifiers, t1 as BoltIdentifier, typeExpr, typeParams, elements as BoltDeclaration[]);
|
||||||
|
setOrigNodeRange(result, firstToken, t4);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public parseDeclaration(tokens: BoltTokenStream): BoltDeclaration {
|
public parseDeclaration(tokens: BoltTokenStream): BoltDeclaration {
|
||||||
let t0 = tokens.peek(1);
|
let t0 = tokens.peek(1);
|
||||||
let i = 1;
|
let i = 1;
|
||||||
|
@ -837,6 +869,10 @@ export class Parser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch (t0.kind) {
|
switch (t0.kind) {
|
||||||
|
case SyntaxKind.BoltImplKeyword:
|
||||||
|
return this.parseImplDeclaration(tokens);
|
||||||
|
case SyntaxKind.BoltTraitKeyword:
|
||||||
|
return this.parseTraitDeclaration(tokens);
|
||||||
case SyntaxKind.BoltTypeKeyword:
|
case SyntaxKind.BoltTypeKeyword:
|
||||||
return this.parseTypeAliasDeclaration(tokens);
|
return this.parseTypeAliasDeclaration(tokens);
|
||||||
case SyntaxKind.BoltModKeyword:
|
case SyntaxKind.BoltModKeyword:
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
|
|
||||||
import XRegExp from "xregexp"
|
|
||||||
|
|
||||||
import { EOF, ScanError } from "./util"
|
import { EOF, ScanError } from "./util"
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
@ -47,6 +45,10 @@ import {
|
||||||
createBoltGtSign,
|
createBoltGtSign,
|
||||||
createBoltModKeyword,
|
createBoltModKeyword,
|
||||||
createBoltTypeKeyword,
|
createBoltTypeKeyword,
|
||||||
|
createBoltForKeyword,
|
||||||
|
createBoltTraitDeclaration,
|
||||||
|
createBoltTraitKeyword,
|
||||||
|
createBoltImplKeyword,
|
||||||
} from "./ast"
|
} from "./ast"
|
||||||
|
|
||||||
export enum PunctType {
|
export enum PunctType {
|
||||||
|
@ -95,11 +97,11 @@ function isOpenPunct(ch: string) {
|
||||||
|
|
||||||
|
|
||||||
function isDigit(ch: string) {
|
function isDigit(ch: string) {
|
||||||
return XRegExp('\\p{Nd}').test(ch)
|
return /[\p{Nd}]/u.test(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isWhiteSpace(ch: string) {
|
function isWhiteSpace(ch: string) {
|
||||||
return ch == '\n' || XRegExp('\\p{Zs}').test(ch)
|
return /[\n\p{Zs}]/u.test(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isNewLine(ch: string) {
|
function isNewLine(ch: string) {
|
||||||
|
@ -107,11 +109,11 @@ function isNewLine(ch: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function isIdentStart(ch: string) {
|
function isIdentStart(ch: string) {
|
||||||
return ch == '_' || XRegExp('\\p{L}').test(ch)
|
return /[_\p{L}]/u.test(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isIdentPart(ch: string) {
|
function isIdentPart(ch: string) {
|
||||||
return ch == '_' || XRegExp('\\p{L}').test(ch)
|
return /[_\p{L}\p{Nd}]/u.test(ch)
|
||||||
}
|
}
|
||||||
|
|
||||||
function isSymbol(ch: string) {
|
function isSymbol(ch: string) {
|
||||||
|
@ -290,6 +292,9 @@ export class Scanner {
|
||||||
case 'fn': return createBoltFnKeyword(span);
|
case 'fn': return createBoltFnKeyword(span);
|
||||||
case 'return': return createBoltReturnKeyword(span);
|
case 'return': return createBoltReturnKeyword(span);
|
||||||
case 'yield': return createBoltYieldKeyword(span);
|
case 'yield': return createBoltYieldKeyword(span);
|
||||||
|
case 'for': return createBoltForKeyword(span);
|
||||||
|
case 'trait': return createBoltTraitKeyword(span);
|
||||||
|
case 'impl': return createBoltImplKeyword(span);
|
||||||
case 'type': return createBoltTypeKeyword(span);
|
case 'type': return createBoltTypeKeyword(span);
|
||||||
case 'foreign': return createBoltForeignKeyword(span);
|
case 'foreign': return createBoltForeignKeyword(span);
|
||||||
case 'let': return createBoltPubKeyword(span);
|
case 'let': return createBoltPubKeyword(span);
|
||||||
|
|
|
@ -297,6 +297,14 @@ export function describeKind(kind: SyntaxKind): string {
|
||||||
return "';'";
|
return "';'";
|
||||||
case SyntaxKind.JSComma:
|
case SyntaxKind.JSComma:
|
||||||
return "','";
|
return "','";
|
||||||
|
case SyntaxKind.BoltTraitKeyword:
|
||||||
|
return "'trait'";
|
||||||
|
case SyntaxKind.BoltTraitKeyword:
|
||||||
|
return "'impl'";
|
||||||
|
case SyntaxKind.BoltImplKeyword:
|
||||||
|
return "'trait'";
|
||||||
|
case SyntaxKind.BoltForKeyword:
|
||||||
|
return "'for'";
|
||||||
default:
|
default:
|
||||||
throw new Error(`failed to describe ${kindToString(kind)}`)
|
throw new Error(`failed to describe ${kindToString(kind)}`)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue