Comparing version 0.1.10-20191220221610.commit-f2fdf6a to 0.1.10-20191224220334.commit-a4d2296
@@ -445,4 +445,4 @@ "use strict"; | ||
}, | ||
SyntaxError(_) { | ||
return null; | ||
SyntaxError(node) { | ||
return new NodeError_1.PositionCapableError(node.errors[0].message, node); | ||
}, | ||
@@ -534,3 +534,7 @@ StructDirective(astNode) { | ||
if (visitor[astNode.type]) { | ||
return visitor[astNode.type](astNode); | ||
const x = visitor[astNode.type](astNode); | ||
if (!x) { | ||
throw new NodeError_1.PositionCapableError('Error visiting node ' + astNode.type, astNode); | ||
} | ||
return x; | ||
} | ||
@@ -537,0 +541,0 @@ else { |
@@ -15,2 +15,3 @@ import { Nodes } from '../nodes'; | ||
buffer?: Uint8Array; | ||
sourceMap: string | null; | ||
constructor(document: Nodes.DocumentNode, parsingContext: ParsingContext); | ||
@@ -17,0 +18,0 @@ validate(optimize?: boolean, debug?: boolean): Promise<{ |
@@ -346,2 +346,3 @@ "use strict"; | ||
this.parsingContext = parsingContext; | ||
this.sourceMap = null; | ||
findAllErrors_1.failWithErrors(`Compilation`, parsingContext); | ||
@@ -375,3 +376,5 @@ try { | ||
const module = binaryen.readBinary(binary.buffer); | ||
module.runPasses(['duplicate-function-elimination']); | ||
if (!debug) { | ||
module.runPasses(['duplicate-function-elimination']); | ||
} | ||
module.runPasses(['remove-unused-module-elements']); | ||
@@ -381,17 +384,37 @@ if (module.validate() === 0) { | ||
} | ||
let last = module.emitBinary(); | ||
if (optimize) { | ||
do { | ||
module.optimize(); | ||
let next = module.emitBinary(); | ||
if (next.length >= last.length) { | ||
// a if (next.length > last.length) { | ||
// a this.parsingContext.system.write('Last converge was suboptimial.\n'); | ||
// a } | ||
break; | ||
} | ||
last = next; | ||
} while (true); | ||
if (debug) { | ||
let last = module.emitBinary('sourceMap.map'); | ||
if (optimize) { | ||
do { | ||
module.optimize(); | ||
let next = module.emitBinary('sourceMap.map'); | ||
if (next.binary.length >= last.binary.length) { | ||
// a if (next.length > last.length) { | ||
// a this.parsingContext.system.write('Last converge was suboptimial.\n'); | ||
// a } | ||
break; | ||
} | ||
last = next; | ||
} while (true); | ||
} | ||
this.buffer = last.binary; | ||
this.sourceMap = last.sourceMap; | ||
} | ||
this.buffer = last; | ||
else { | ||
let last = module.emitBinary(); | ||
if (optimize) { | ||
do { | ||
module.optimize(); | ||
let next = module.emitBinary(); | ||
if (next.length >= last.length) { | ||
// a if (next.length > last.length) { | ||
// a this.parsingContext.system.write('Last converge was suboptimial.\n'); | ||
// a } | ||
break; | ||
} | ||
last = next; | ||
} while (true); | ||
} | ||
this.buffer = last; | ||
} | ||
module.dispose(); | ||
@@ -398,0 +421,0 @@ return {}; |
@@ -86,3 +86,3 @@ "use strict"; | ||
function processFunctionDecorations(node, parsingContext) { | ||
if (node.decorators && node.decorators.length) { | ||
if (node && node.decorators && node.decorators.length) { | ||
node.decorators.forEach($ => { | ||
@@ -109,3 +109,3 @@ switch ($.decoratorName.name) { | ||
function rejectDecorator(node, parsingContext) { | ||
if (node.decorators && node.decorators.length) { | ||
if (node && node.decorators && node.decorators.length) { | ||
node.decorators.forEach($ => { | ||
@@ -138,20 +138,22 @@ parsingContext.messageCollector.error(`Unknown decorator "${$.decoratorName.name}" for ${node.nodeName}`, $.decoratorName.astNode); | ||
else { | ||
rejectDecorator(node, parsingContext); | ||
if (node instanceof nodes_1.Nodes.ImplDirective) { | ||
overloadFunctions(node, parsingContext); | ||
} | ||
else if (node instanceof nodes_1.Nodes.TraitDirectiveNode) { | ||
node.directives.forEach($ => { | ||
if ($ instanceof nodes_1.Nodes.FunDirectiveNode) { | ||
if ($.functionNode.body) { | ||
parsingContext.messageCollector.error(`Unexpected function body. Traits only accept signatures.`, $.functionNode.body.astNode); | ||
if (node) { | ||
rejectDecorator(node, parsingContext); | ||
if (node instanceof nodes_1.Nodes.ImplDirective) { | ||
overloadFunctions(node, parsingContext); | ||
} | ||
else if (node instanceof nodes_1.Nodes.TraitDirectiveNode) { | ||
node.directives.forEach($ => { | ||
if ($ instanceof nodes_1.Nodes.FunDirectiveNode) { | ||
if ($.functionNode.body) { | ||
parsingContext.messageCollector.error(`Unexpected function body. Traits only accept signatures.`, $.functionNode.body.astNode); | ||
} | ||
if ($.decorators.length > 0) { | ||
$.decorators.forEach($ => { | ||
parsingContext.messageCollector.error(`Unexpected decorator. Traits only accept signatures.`, $.astNode); | ||
}); | ||
} | ||
} | ||
if ($.decorators.length > 0) { | ||
$.decorators.forEach($ => { | ||
parsingContext.messageCollector.error(`Unexpected decorator. Traits only accept signatures.`, $.astNode); | ||
}); | ||
} | ||
} | ||
}); | ||
overloadFunctions(node, parsingContext); | ||
}); | ||
overloadFunctions(node, parsingContext); | ||
} | ||
} | ||
@@ -158,0 +160,0 @@ } |
@@ -66,2 +66,3 @@ import { Nodes } from './nodes'; | ||
allocationSize: StackType; | ||
stackSize: StackType; | ||
}; | ||
@@ -83,2 +84,3 @@ getSchemaValue(name: string): number; | ||
byteSize: StackType; | ||
stackSize: StackType; | ||
allocationSize: StackType; | ||
@@ -137,2 +139,3 @@ }; | ||
byteSize: StackType; | ||
stackSize: StackType; | ||
}; | ||
@@ -139,0 +142,0 @@ getSchemaValue(name: string, ctx: Scope): any; |
@@ -241,3 +241,4 @@ "use strict"; | ||
byteSize: StackType.of('u32', NativeTypes.i32, 4), | ||
allocationSize: StackType.of('u32', NativeTypes.i32, 4) | ||
allocationSize: StackType.of('u32', NativeTypes.i32, 4), | ||
stackSize: StackType.of('u32', NativeTypes.i32, 4) | ||
}; | ||
@@ -249,2 +250,5 @@ } | ||
} | ||
else if (name === 'stackSize') { | ||
return this.byteSize; | ||
} | ||
else if (name === 'allocationSize') { | ||
@@ -293,2 +297,3 @@ return this.byteSize; | ||
byteSize: StackType.of('u32', NativeTypes.i32, 4), | ||
stackSize: StackType.of('u32', NativeTypes.i32, 4), | ||
allocationSize: StackType.of('u32', NativeTypes.i32, 4) | ||
@@ -301,2 +306,5 @@ }; | ||
} | ||
else if (name === 'stackSize') { | ||
return 8; | ||
} | ||
else if (name === 'allocationSize') { | ||
@@ -580,3 +588,4 @@ return 8; | ||
return { | ||
byteSize: u32 | ||
byteSize: u32, | ||
stackSize: u32 | ||
}; | ||
@@ -605,2 +614,5 @@ } | ||
} | ||
else if (name === 'stackSize') { | ||
return 8; | ||
} | ||
throw new Error(`Cannot read schema property ${name} of ${this.inspect(10)}`); | ||
@@ -688,2 +700,3 @@ } | ||
result['allocationSize'] = u32; | ||
result['stackSize'] = u32; | ||
const properties = this.getOrderedProperties(); | ||
@@ -707,3 +720,6 @@ properties.forEach(prop => { | ||
if (baseType instanceof StructType) { | ||
if (name === 'allocationSize') { | ||
if (name === 'stackSize') { | ||
return 8; | ||
} | ||
else if (name === 'allocationSize') { | ||
const properties = this.getOrderedProperties(); | ||
@@ -731,3 +747,3 @@ let offset = 0; | ||
const fn = getNonVoidFunction(TypeHelpers.getNodeType(prop.name), ctx); | ||
offset += fn.returnType.getSchemaValue('allocationSize', ctx); | ||
offset += fn.returnType.getSchemaValue('stackSize', ctx); | ||
} | ||
@@ -734,0 +750,0 @@ return offset; |
import { Parser, IRule } from 'ebnf'; | ||
export declare const grammar = "\n{ws=explicit}\n\nDocument ::= WS* Directives WS* EOF? {ws=implicit}\nDirectives ::= Directive WS* Directives? WS* {pin=1,recoverUntil=DIRECTIVE_RECOVERY,fragment=true}\n\nDirective ::= FunctionDirective\n | ValDirective\n | VarDirective\n | StructDirective\n | TypeDirective\n | EnumDirective\n | TraitDirective\n | ImportDirective\n | EffectDirective\n | ImplDirective {fragment=true}\n\nImplInnerDirective::= FunctionDirective\n | ValDirective\n | VarDirective {fragment=true}\n\nImportDirective ::= IMPORT_KEYWORD QName (WS+ 'as' WS+ NameIdentifier)? {pin=1}\nFunctionDirective ::= (&'#[' Decorators)? PrivateModifier? FunDeclaration {pin=3}\nValDirective ::= PrivateModifier? ValDeclaration {pin=2}\nVarDirective ::= PrivateModifier? VarDeclaration {pin=2}\nTypeDirective ::= PrivateModifier? TYPE_KEYWORD NameIdentifier WS* (&('=') ValueType)? {pin=2}\nEnumDirective ::= PrivateModifier? ENUM_KEYWORD NameIdentifier WS* OPEN_BRACKET TypeDeclElements? WS* CLOSE_BRACKET {pin=2}\nTraitDirective ::= PrivateModifier? TRAIT_KEYWORD NameIdentifier WS* OPEN_BRACKET TraitDeclElements? WS* CLOSE_BRACKET {pin=2}\nEffectDirective ::= PrivateModifier? EFFECT_KEYWORD EffectDeclaration {pin=2,recoverUntil=DIRECTIVE_RECOVERY}\nStructDirective ::= PrivateModifier? STRUCT_KEYWORD StructDeclaration {pin=2,recoverUntil=DIRECTIVE_RECOVERY}\nImplDirective ::= PrivateModifier? IMPL_KEYWORD Reference WS* (FOR_KEYWORD WS* Reference WS*)? NamespaceElementList {pin=2,recoverUntil=DIRECTIVE_RECOVERY}\n\nDecorators ::= Decorator+ {pin=1}\nDecorator ::= OPEN_DECORATION WS* NameIdentifier (WS+ Literal)* WS* CLOSE_ARRAY WS* {pin=1}\n\nPrivateModifier ::= PRIVATE_KEYWORD\nLoopExpression ::= LOOP_KEYWORD WS* Expression {pin=1}\nContinueStatement ::= CONTINUE_KEYWORD {pin=1}\nBreakStatement ::= BREAK_KEYWORD {pin=1}\nValDeclaration ::= VAL_KEYWORD NameIdentifier OfType? WS* Assign {pin=1,recoverUntil=BLOCK_RECOVERY}\nVarDeclaration ::= VAR_KEYWORD NameIdentifier OfType? WS* Assign {pin=1,recoverUntil=BLOCK_RECOVERY}\nFunDeclaration ::= FUN_KEYWORD FunctionName WS* TypeParameters? FunctionParamsList WS* (&':' OfType WS*)? (&'=' FunAssignExpression)? {pin=1,recoverUntil=BLOCK_RECOVERY}\nMatchExpression ::= MATCH_KEYWORD WS* AssignExpression WS* MatchBody {pin=1}\nCaseCondition ::= CASE_KEYWORD NameIdentifier WS+ IF_KEYWORD WS* Expression WS* THIN_ARROW WS* Expression {pin=5}\nCaseLiteral ::= CASE_KEYWORD Literal WS* THIN_ARROW WS* Expression {pin=3}\nCaseIs ::= CASE_KEYWORD (NameIdentifier WS+)? 'is' WS+ Reference WS* DeconstructStruct? THIN_ARROW WS* Expression {pin=4}\nCaseElse ::= ELSE_KEYWORD WS* (NameIdentifier WS+)? THIN_ARROW WS* Expression {pin=1}\nIfExpression ::= IF_KEYWORD WS* IfBody WS* Expression (WS* ElseExpression)? {pin=1}\nElseExpression ::= ELSE_KEYWORD WS* Expression {pin=1,fragment=true}\nWasmExpression ::= WASM_KEYWORD WS* OPEN_BRACKET WS* SAtom* WS* CLOSE_BRACKET WS* EOF? {pin=1}\nStructLiteral ::= STRUCT_LITERAL_KEYWORD WS* StructParamsList {pin=2}\nStackLiteral ::= STACK_LITERAL_KEYWORD WS* OPEN_BRACKET WS* (NameLiteralPair WS*)* CLOSE_BRACKET WS* {pin=2}\nInjectedLiteral ::= INJECTED_LITERAL_KEYWORD {pin=1}\n\nIfBody ::= OPEN_PAREN WS* Expression WS* CLOSE_PAREN {pin=3,recoverUntil=CLOSE_PAREN,fragment=true}\nMatchElements ::= (CaseCondition | CaseIs | CaseLiteral | CaseElse) WS* {fragment=true}\n\nUnknownExpression ::= '???'\nValueType ::= '=' WS* (Type | StructLiteral | StackLiteral | InjectedLiteral) {fragment=true}\n\nTypeVariableList ::= TypeVariable NthTypeVariable? WS*\nNthTypeVariable ::= ',' WS* TypeVariable WS* {fragment=true}\nTypeVariable ::= [A-Z]([A-Za-z0-9_])*\nTypeParameters ::= '<' WS* TypeVariableList? '>' WS* {pin=1}\n\nAssign ::= '=' WS* (Expression | UnknownExpression) {pin=1,fragment=true}\nFunAssignExpression ::= '=' WS* (Expression | WasmExpression | UnknownExpression) {pin=1}\nOfType ::= COLON WS* (FunctionEffect WS*)? Type WS* {pin=1,fragment=true,recoverUntil=NEXT_ARG_RECOVERY}\n\nStructParamsList ::= OPEN_BRACKET WS* (!'}' ParameterList)? WS* CLOSE_BRACKET {pin=1,recoverUntil=BRACKET_RECOVERY}\nFunctionParamsList::= OPEN_PAREN WS* ParameterList? WS* CLOSE_PAREN {pin=1,recoverUntil=PAREN_RECOVERY}\nParameterList ::= Parameter (&',' NthParameter)* {fragment=true}\nNthParameter ::= ',' WS* Parameter WS* {pin=1,fragment=true,recoverUntil=NEXT_ARG_RECOVERY}\nParameter ::= NameIdentifier WS* (&':' OfType)? WS* {pin=1,recoverUntil=NEXT_ARG_RECOVERY}\n\nStructDeclaration ::= NameIdentifier WS* (&'(' FunctionParamsList)? {pin=1}\nEffectMemberDeclaration ::= NameIdentifier WS* FunctionParamsList OfType {pin=1}\nTraitDeclElements ::= (WS* FunctionDirective)*\nTypeDeclElements ::= (WS* StructDeclaration)*\nEffectElements ::= (WS* EffectMemberDeclaration)* {fragment=true}\n\nFunctionName ::= NameIdentifier | FunOperator\n\nFunOperator ::= ( BitNotPreOperator\n | MinusPreOperator\n | AsKeyword\n | IsKeyword\n | MulOperator\n | AddOperator\n | ShiftOperator\n | RelOperator\n | EqOperator\n | BitAndOperator\n | BitXorOperator\n | BitOrOperator\n | AndKeyword\n | OrKeyword\n | NotPreOperator\n | '[]'\n )\n\nNamespaceElementList ::= OPEN_BRACKET (WS* ImplInnerDirective)* WS* CLOSE_BRACKET {pin=1,recoverUntil=BLOCK_RECOVERY}\n\nEffectDeclaration ::= NameIdentifier WS* TypeParameters? EffectElementList {pin=1}\nEffectElementList ::= OPEN_BRACKET EffectElements? WS* CLOSE_BRACKET {pin=1,recoverUntil=BLOCK_RECOVERY}\n\nFunctionEffect ::= '<' WS* (Type WS*)? '>' {pin=1}\nType ::= UnionType\nUnionType ::= IntersectionType (WS* '|' WS* IntersectionType)* {simplifyWhenOneChildren=true}\nIntersectionType ::= AtomType (WS* '&' WS* AtomType)* {simplifyWhenOneChildren=true}\nAtomType ::= TypeParen | FunctionTypeLiteral | Reference {fragment=true}\nTypeParen ::= OPEN_PAREN WS* Type WS* CLOSE_PAREN {pin=1}\n\nFunctionTypeLiteral ::= 'fun' WS* TypeParameters? FunctionTypeParameters WS* THIN_ARROW WS* Type {pin=1}\nFunctionTypeParameters::= OPEN_PAREN WS* (FunctionTypeParameter (WS* ',' WS* FunctionTypeParameter)* WS*)? CLOSE_PAREN {pin=1,recoverUntil=PAREN_RECOVERY}\nFunctionTypeParameter ::= (NameIdentifier WS* ':')? WS* Type\n\nExpression ::= &('if') IfExpression\n | &('m') MatchExpression\n | &('l') LoopExpression\n | &('b') BreakStatement\n | &('c') ContinueStatement\n | AssignExpression {fragment=true}\n\nStatement ::= ValDeclaration\n | VarDeclaration\n | FunDeclaration\n | Expression {fragment=true}\n\n\n\nAssignExpression ::= OrExpression (WS* AssignmentKeyword WS* OrExpression)* {simplifyWhenOneChildren=true}\nOrExpression ::= AndExpression (WS* OrKeyword WS* AndExpression)* {simplifyWhenOneChildren=true}\nAndExpression ::= BitOrExpression (WS* AndKeyword WS* BitOrExpression)* {simplifyWhenOneChildren=true}\nBitOrExpression ::= BitXorExpression (WS* BitOrOperator WS* BitXorExpression)* {simplifyWhenOneChildren=true}\nBitXorExpression ::= BitAndExpression (WS* BitXorOperator WS* BitAndExpression)* {simplifyWhenOneChildren=true}\nBitAndExpression ::= EqExpression (WS* BitAndOperator WS* EqExpression)* {simplifyWhenOneChildren=true}\nEqExpression ::= RelExpression (WS* EqOperator WS* RelExpression)* {simplifyWhenOneChildren=true}\nRelExpression ::= ShiftExpression (WS* RelOperator WS* ShiftExpression)* {simplifyWhenOneChildren=true}\nShiftExpression ::= AddExpression (WS* ShiftOperator WS* AddExpression)* {simplifyWhenOneChildren=true}\nAddExpression ::= MulExpression (WS* AddOperator WS* MulExpression)* {simplifyWhenOneChildren=true}\nMulExpression ::= IsExpression (WS* MulOperator WS* IsExpression)* {simplifyWhenOneChildren=true}\nIsExpression ::= AsExpression (WS* IsKeyword WS* Type)* {simplifyWhenOneChildren=true}\nAsExpression ::= UnaryExpression (WS* AsKeyword WS* Type)* {simplifyWhenOneChildren=true}\nUnaryExpression ::= NegExpression | BinNegExpression | UnaryMinus | AtomicExpression {simplifyWhenOneChildren=true}\nAtomicExpression ::= Value (WS* (&'.' MemberExpression | &'(' CallArguments | &'[' IndexExpression))* {simplifyWhenOneChildren=true,pin=1}\n\nBinMemberOperator ::= '.^' | '.'\nMemberExpression ::= BinMemberOperator NameIdentifier {pin=1}\nIndexExpression ::= OPEN_ARRAY WS* Expression WS* CLOSE_ARRAY {pin=1}\n\nNegExpression ::= '!' AtomicExpression {pin=1}\nBinNegExpression ::= '~' AtomicExpression {pin=1}\nUnaryMinus ::= '-' AtomicExpression {pin=2}\n\nValue ::= ( Literal\n | Reference\n | &'(' ParenExpression\n | &'{' CodeBlock\n ) {fragment=true,pin=1}\n\nParenExpression ::= OPEN_PAREN WS* Expression WS* CLOSE_PAREN {pin=1,recoverUntil=CLOSE_PAREN}\n\nCodeBlock ::= OPEN_BRACKET WS* (Statement (NEW_LINE WS* Statement)* WS*)? CLOSE_BRACKET {pin=1,recoverUntil=BLOCK_RECOVERY}\n\n/* Pattern matching */\nMatchBody ::= OPEN_BRACKET WS* MatchElements* CLOSE_BRACKET {pin=1,recoverUntil=MATCH_RECOVERY}\n\nDeconstructStruct ::= OPEN_PAREN WS* (NameIdentifier WS* NthNameIdentifier*)? CLOSE_PAREN WS* {pin=1}\nNthNameIdentifier ::= ',' WS* NameIdentifier WS* {fragment=true}\n\n/* Function call */\nCallArguments ::= OPEN_PAREN Arguments? CLOSE_PAREN {pin=1,recoverUntil=PAREN_RECOVERY}\nArguments ::= WS* Expression WS* NthArgument* {fragment=true}\nNthArgument ::= ',' WS* Expression WS* {pin=1,fragment=true,recoverUntil=NEXT_ARG_RECOVERY}\n\nReference ::= QName\n\nBooleanLiteral ::= TRUE_KEYWORD | FALSE_KEYWORD\nPostfixNumber ::= (HexLiteral | NumberLiteral) Reference? {pin=1,simplifyWhenOneChildren=true}\nNumberLiteral ::= !('0x') (\"0\" | [1-9] [0-9]*) (\".\" [0-9]+)? ((\"e\" | \"E\") ( \"-\" | \"+\" )? (\"0\" | [1-9] [0-9]*))? {pin=2}\nNegNumberLiteral ::= '-'? NumberLiteral {pin=2}\nHexLiteral ::= \"0x\" [0-9A-Fa-f]+ {pin=1}\nStringLiteral ::= STRING_DELIMITER ((![\\\\\"] [#x20-#xFFFF])* | ('\\\\' (STRING_DELIMITER | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HEXDIG HEXDIG HEXDIG HEXDIG)?))* STRING_DELIMITER\nLiteral ::= StringLiteral\n | PostfixNumber\n | BooleanLiteral {fragment=true}\n\nNameIdentifier ::= !KEYWORD '$'? [A-Za-z_]([A-Za-z0-9_$])* {pin=3}\nQName ::= NameIdentifier ('::' NameIdentifier)* {pin=1}\n\nNameLiteralPair ::= NameIdentifier WS* '=' WS* Literal {pin=1}\n\nSExpression ::= OPEN_PAREN WS* SSymbol WS* SAtom* WS* CLOSE_PAREN WS* {pin=1}\n\nSAtom ::= ( QName\n | SExpression\n | NegNumberLiteral\n | HexLiteral) WS* {fragment=true}\n\nSSymbol ::= [a-zA-Z][a-zA-Z0-9_./]* {pin=1}\n\n/* Keywords */\n\nKEYWORD ::= TRUE_KEYWORD\n | FALSE_KEYWORD\n | IF_KEYWORD\n | ELSE_KEYWORD\n | CASE_KEYWORD\n | VAR_KEYWORD\n | VAL_KEYWORD\n | TYPE_KEYWORD\n | ENUM_KEYWORD\n | TRAIT_KEYWORD\n | EFFECT_KEYWORD\n | IMPL_KEYWORD\n | FOR_KEYWORD\n | IMPORT_KEYWORD\n | FUN_KEYWORD\n | STRUCT_KEYWORD\n | PRIVATE_KEYWORD\n | MATCH_KEYWORD\n | LOOP_KEYWORD\n | CONTINUE_KEYWORD\n | BREAK_KEYWORD\n | RESERVED_WORDS\n\n/* Tokens */\n\nWASM_KEYWORD ::= '%wasm' {pin=1}\nSTRUCT_LITERAL_KEYWORD ::= '%struct' {pin=1}\nSTACK_LITERAL_KEYWORD ::= '%stack' {pin=1}\nINJECTED_LITERAL_KEYWORD::= '%injected' {pin=1}\n\nFUN_KEYWORD ::= 'fun' WS+\nVAL_KEYWORD ::= 'val' WS+\nVAR_KEYWORD ::= 'var' WS+\nEFFECT_KEYWORD ::= 'effect' WS+\nIMPL_KEYWORD ::= 'impl' WS+\nFOR_KEYWORD ::= 'for' WS+\nIMPORT_KEYWORD ::= 'import' WS+\nSTRUCT_KEYWORD ::= 'struct' WS+\nPRIVATE_KEYWORD ::= 'private' WS+\nTYPE_KEYWORD ::= 'type' WS+\nENUM_KEYWORD ::= 'enum' WS+\nTRAIT_KEYWORD ::= 'trait' WS+\nCASE_KEYWORD ::= 'case' WS+\n\nLOOP_KEYWORD ::= 'loop' ![A-Za-z0-9_$]\nCONTINUE_KEYWORD ::= 'continue' ![a-zA-Z0-9_$]\nBREAK_KEYWORD ::= 'break' ![A-Za-z0-9_$]\nTRUE_KEYWORD ::= 'true' ![A-Za-z0-9_$]\nFALSE_KEYWORD ::= 'false' ![A-Za-z0-9_$]\nIF_KEYWORD ::= 'if' ![A-Za-z0-9_$]\nELSE_KEYWORD ::= 'else' ![A-Za-z0-9_$]\nMATCH_KEYWORD ::= 'match' ![A-Za-z0-9_$]\n\n\n\nRESERVED_WORDS ::= ( 'abstract'\n | 'async'\n | 'await'\n | 'class'\n | 'const'\n | 'declare'\n | 'defer'\n | 'delete'\n | 'do'\n | 'extends'\n | 'finally'\n | 'for'\n | 'import'\n | 'is'\n | 'in'\n | 'let'\n | 'new'\n | 'package'\n | 'protected'\n | 'public'\n | 'try'\n | 'using'\n | 'while'\n | 'yield'\n ) ![A-Za-z0-9_$]\n\n/* OPERATORS, ORDERED BY PRECEDENCE https://introcs.cs.princeton.edu/java/11precedence/ */\n\nAssignmentKeyword ::= '=' !'='\nNotPreOperator ::= '!' !'='\nBitNotPreOperator ::= '~' !'='\nMinusPreOperator ::= '-' !'-'\nAsKeyword ::= 'as' ![A-Za-z0-9_]\nIsKeyword ::= 'is' ![A-Za-z0-9_]\nMulOperator ::= '**' | '*' | '/' | '%'\nAddOperator ::= '++' | '+' | '-'\nShiftOperator ::= '>>>' | '>>' | '<<'\nRelOperator ::= '>=' | '<=' | '>' | '<'\nEqOperator ::= '===' | '!==' | '~=' | '==' | '!='\nBitAndOperator ::= '&' !'&'\nBitXorOperator ::= '^'\nBitOrOperator ::= '|' !'|'\nAndKeyword ::= '&&' ![A-Za-z0-9_]\nOrKeyword ::= '||' ![A-Za-z0-9_]\n\n\nDIRECTIVE_RECOVERY::= &(FUN_KEYWORD | VAL_KEYWORD | VAR_KEYWORD | STRUCT_KEYWORD | PRIVATE_KEYWORD | EFFECT_KEYWORD | IMPL_KEYWORD | ENUM_KEYWORD | RESERVED_WORDS)\nNEXT_ARG_RECOVERY ::= &(',' | ')')\nPAREN_RECOVERY ::= &(')')\nBRACKET_RECOVERY ::= &('}')\nMATCH_RECOVERY ::= &('}' | 'case' | 'else')\nBLOCK_RECOVERY ::= &('}' | NEW_LINE)\nOPEN_PAREN ::= '('\nCLOSE_PAREN ::= ')'\nOPEN_ARRAY ::= '['\nOPEN_DECORATION ::= '#[' {pin=1}\nCLOSE_ARRAY ::= ']' {pin=1}\nSTRING_DELIMITER ::= '\"' {pin=1}\nOPEN_BRACKET ::= '{'\nCLOSE_BRACKET ::= '}'\nTHIN_ARROW ::= '->'\nCOLON ::= ':'\nOPEN_DOC_COMMENT ::= '/*'\nCLOSE_DOC_COMMENT ::= '*/'\nDOC_COMMENT ::= !CLOSE_DOC_COMMENT [#x00-#xFFFF]\n\nCOMMENT ::= '//' (![#x0A#x0D] [#x00-#xFFFF])* EOL\nMULTI_COMMENT ::= OPEN_DOC_COMMENT DOC_COMMENT* CLOSE_DOC_COMMENT {pin=1}\nWS ::= COMMENT | MULTI_COMMENT | [#x20#x09#x0A#x0D]+ {fragment=true}\nEOL ::= [#x0A#x0D]+\nHEXDIG ::= [a-fA-F0-9]\nNEW_LINE ::= [#x20#x09]* (EOL | COMMENT)\n\n"; | ||
export declare const grammar = "\n{ws=explicit}\n\nDocument ::= WS* Directives WS* EOF?\nDirectives ::= Directive WS* Directives? WS* {pin=1,recoverUntil=DIRECTIVE_RECOVERY,fragment=true}\n\nDirective ::= FunctionDirective\n | ValDirective\n | VarDirective\n | StructDirective\n | TypeDirective\n | EnumDirective\n | TraitDirective\n | ImportDirective\n | EffectDirective\n | ImplDirective {fragment=true}\n\nImplInnerDirective::= FunctionDirective\n | ValDirective\n | VarDirective {fragment=true}\n\nImportDirective ::= IMPORT_KEYWORD QName (WS+ 'as' WS+ NameIdentifier)? {pin=1}\nFunctionDirective ::= (&'#[' Decorators)? PrivateModifier? FunDeclaration {pin=3}\nValDirective ::= PrivateModifier? ValDeclaration {pin=2}\nVarDirective ::= PrivateModifier? VarDeclaration {pin=2}\nTypeDirective ::= PrivateModifier? TYPE_KEYWORD NameIdentifier WS* (&('=') ValueType)? {pin=2}\nEnumDirective ::= PrivateModifier? ENUM_KEYWORD NameIdentifier WS* OPEN_BRACKET TypeDeclElements? WS* CLOSE_BRACKET {pin=2}\nTraitDirective ::= PrivateModifier? TRAIT_KEYWORD NameIdentifier WS* OPEN_BRACKET TraitDeclElements? WS* CLOSE_BRACKET {pin=2}\nEffectDirective ::= PrivateModifier? EFFECT_KEYWORD EffectDeclaration {pin=2,recoverUntil=DIRECTIVE_RECOVERY}\nStructDirective ::= PrivateModifier? STRUCT_KEYWORD StructDeclaration {pin=2,recoverUntil=DIRECTIVE_RECOVERY}\nImplDirective ::= PrivateModifier? IMPL_KEYWORD Reference WS* (FOR_KEYWORD WS* Reference WS*)? NamespaceElementList {pin=2,recoverUntil=DIRECTIVE_RECOVERY}\n\nDecorators ::= Decorator+ {pin=1}\nDecorator ::= OPEN_DECORATION WS* NameIdentifier (WS+ Literal)* WS* CLOSE_ARRAY WS* {pin=1}\n\nPrivateModifier ::= PRIVATE_KEYWORD\nLoopExpression ::= LOOP_KEYWORD WS* Expression {pin=1}\nContinueStatement ::= CONTINUE_KEYWORD {pin=1}\nBreakStatement ::= BREAK_KEYWORD {pin=1}\nValDeclaration ::= VAL_KEYWORD NameIdentifier OfType? WS* Assign {pin=1,recoverUntil=BLOCK_RECOVERY}\nVarDeclaration ::= VAR_KEYWORD NameIdentifier OfType? WS* Assign {pin=1,recoverUntil=BLOCK_RECOVERY}\nFunDeclaration ::= FUN_KEYWORD FunctionName WS* TypeParameters? FunctionParamsList WS* (&':' OfType WS*)? (&'=' FunAssignExpression)? {pin=1,recoverUntil=BLOCK_RECOVERY}\nMatchExpression ::= MATCH_KEYWORD WS* AssignExpression WS* MatchBody {pin=1}\nCaseCondition ::= CASE_KEYWORD NameIdentifier WS+ IF_KEYWORD WS* Expression WS* THIN_ARROW WS* Expression {pin=5}\nCaseLiteral ::= CASE_KEYWORD Literal WS* THIN_ARROW WS* Expression {pin=3}\nCaseIs ::= CASE_KEYWORD (NameIdentifier WS+)? 'is' WS+ Reference WS* DeconstructStruct? THIN_ARROW WS* Expression {pin=4}\nCaseElse ::= ELSE_KEYWORD WS* (NameIdentifier WS+)? THIN_ARROW WS* Expression {pin=1}\nIfExpression ::= IF_KEYWORD WS* IfBody WS* Expression (WS* ElseExpression)? {pin=1}\nElseExpression ::= ELSE_KEYWORD WS* Expression {pin=1,fragment=true}\nWasmExpression ::= WASM_KEYWORD WS* OPEN_BRACKET WS* SAtom* WS* CLOSE_BRACKET WS* EOF? {pin=1}\nStructLiteral ::= STRUCT_LITERAL_KEYWORD WS* StructParamsList {pin=2}\nStackLiteral ::= STACK_LITERAL_KEYWORD WS* OPEN_BRACKET WS* (NameLiteralPair WS*)* CLOSE_BRACKET WS* {pin=2}\nInjectedLiteral ::= INJECTED_LITERAL_KEYWORD {pin=1}\n\nIfBody ::= OPEN_PAREN WS* Expression WS* CLOSE_PAREN {pin=3,recoverUntil=CLOSE_PAREN,fragment=true}\nMatchElements ::= (CaseCondition | CaseIs | CaseLiteral | CaseElse) WS* {fragment=true}\n\nUnknownExpression ::= '???'\nValueType ::= '=' WS* (Type | StructLiteral | StackLiteral | InjectedLiteral) {fragment=true}\n\nTypeVariableList ::= TypeVariable NthTypeVariable? WS*\nNthTypeVariable ::= ',' WS* TypeVariable WS* {fragment=true}\nTypeVariable ::= [A-Z]([A-Za-z0-9_])*\nTypeParameters ::= '<' WS* TypeVariableList? '>' WS* {pin=1}\n\nAssign ::= '=' WS* (Expression | UnknownExpression) {pin=1,fragment=true}\nFunAssignExpression ::= '=' WS* (Expression | WasmExpression | UnknownExpression) {pin=1}\nOfType ::= COLON WS* (FunctionEffect WS*)? Type WS* {pin=1,fragment=true,recoverUntil=NEXT_ARG_RECOVERY}\n\nStructParamsList ::= OPEN_BRACKET WS* (!'}' ParameterList)? WS* CLOSE_BRACKET {pin=1,recoverUntil=BRACKET_RECOVERY}\nFunctionParamsList::= OPEN_PAREN WS* ParameterList? WS* CLOSE_PAREN {pin=1,recoverUntil=PAREN_RECOVERY}\nParameterList ::= Parameter (&',' NthParameter)* {fragment=true}\nNthParameter ::= ',' WS* Parameter WS* {pin=1,fragment=true,recoverUntil=NEXT_ARG_RECOVERY}\nParameter ::= NameIdentifier WS* (&':' OfType)? WS* {pin=1,recoverUntil=NEXT_ARG_RECOVERY}\n\nStructDeclaration ::= NameIdentifier WS* (&'(' FunctionParamsList)? {pin=1}\nEffectMemberDeclaration ::= NameIdentifier WS* FunctionParamsList OfType {pin=1}\nTraitDeclElements ::= (WS* FunctionDirective)*\nTypeDeclElements ::= (WS* StructDeclaration)*\nEffectElements ::= (WS* EffectMemberDeclaration)* {fragment=true}\n\nFunctionName ::= NameIdentifier | FunOperator\n\nFunOperator ::= ( BitNotPreOperator\n | MinusPreOperator\n | AsKeyword\n | IsKeyword\n | MulOperator\n | AddOperator\n | ShiftOperator\n | RelOperator\n | EqOperator\n | BitAndOperator\n | BitXorOperator\n | BitOrOperator\n | AndKeyword\n | OrKeyword\n | NotPreOperator\n | '[]'\n )\n\nNamespaceElementList ::= OPEN_BRACKET (WS* ImplInnerDirective)* WS* CLOSE_BRACKET {pin=1,recoverUntil=BLOCK_RECOVERY}\n\nEffectDeclaration ::= NameIdentifier WS* TypeParameters? EffectElementList {pin=1}\nEffectElementList ::= OPEN_BRACKET EffectElements? WS* CLOSE_BRACKET {pin=1,recoverUntil=BLOCK_RECOVERY}\n\nFunctionEffect ::= '<' WS* (Type WS*)? '>' {pin=1}\nType ::= UnionType\nUnionType ::= IntersectionType (WS* '|' WS* IntersectionType)* {simplifyWhenOneChildren=true}\nIntersectionType ::= AtomType (WS* '&' WS* AtomType)* {simplifyWhenOneChildren=true}\nAtomType ::= TypeParen | FunctionTypeLiteral | Reference {fragment=true}\nTypeParen ::= OPEN_PAREN WS* Type WS* CLOSE_PAREN {pin=1}\n\nFunctionTypeLiteral ::= 'fun' WS* TypeParameters? FunctionTypeParameters WS* THIN_ARROW WS* Type {pin=1}\nFunctionTypeParameters::= OPEN_PAREN WS* (FunctionTypeParameter (WS* ',' WS* FunctionTypeParameter)* WS*)? CLOSE_PAREN {pin=1,recoverUntil=PAREN_RECOVERY}\nFunctionTypeParameter ::= (NameIdentifier WS* ':')? WS* Type\n\nExpression ::= &('if') IfExpression\n | &('m') MatchExpression\n | &('l') LoopExpression\n | &('b') BreakStatement\n | &('c') ContinueStatement\n | AssignExpression {fragment=true}\n\nStatement ::= ValDeclaration\n | VarDeclaration\n | FunDeclaration\n | Expression {fragment=true}\n\n\n\nAssignExpression ::= OrExpression (WS* AssignmentKeyword WS* OrExpression)* {simplifyWhenOneChildren=true}\nOrExpression ::= AndExpression (WS* OrKeyword WS* AndExpression)* {simplifyWhenOneChildren=true}\nAndExpression ::= BitOrExpression (WS* AndKeyword WS* BitOrExpression)* {simplifyWhenOneChildren=true}\nBitOrExpression ::= BitXorExpression (WS* BitOrOperator WS* BitXorExpression)* {simplifyWhenOneChildren=true}\nBitXorExpression ::= BitAndExpression (WS* BitXorOperator WS* BitAndExpression)* {simplifyWhenOneChildren=true}\nBitAndExpression ::= EqExpression (WS* BitAndOperator WS* EqExpression)* {simplifyWhenOneChildren=true}\nEqExpression ::= RelExpression (WS* EqOperator WS* RelExpression)* {simplifyWhenOneChildren=true}\nRelExpression ::= ShiftExpression (WS* RelOperator WS* ShiftExpression)* {simplifyWhenOneChildren=true}\nShiftExpression ::= AddExpression (WS* ShiftOperator WS* AddExpression)* {simplifyWhenOneChildren=true}\nAddExpression ::= MulExpression (WS* AddOperator WS* MulExpression)* {simplifyWhenOneChildren=true}\nMulExpression ::= IsExpression (WS* MulOperator WS* IsExpression)* {simplifyWhenOneChildren=true}\nIsExpression ::= AsExpression (WS* IsKeyword WS* Type)* {simplifyWhenOneChildren=true}\nAsExpression ::= UnaryExpression (WS* AsKeyword WS* Type)* {simplifyWhenOneChildren=true}\nUnaryExpression ::= NegExpression | BinNegExpression | UnaryMinus | AtomicExpression {simplifyWhenOneChildren=true}\nAtomicExpression ::= Value (WS* (&'.' MemberExpression | &'(' CallArguments | &'[' IndexExpression))* {simplifyWhenOneChildren=true,pin=1}\n\nBinMemberOperator ::= '.^' | '.'\nMemberExpression ::= BinMemberOperator NameIdentifier {pin=1}\nIndexExpression ::= OPEN_ARRAY WS* Expression WS* CLOSE_ARRAY {pin=1}\n\nNegExpression ::= '!' AtomicExpression {pin=1}\nBinNegExpression ::= '~' AtomicExpression {pin=1}\nUnaryMinus ::= '-' AtomicExpression {pin=2}\n\nValue ::= ( Literal\n | Reference\n | &'(' ParenExpression\n | &'{' CodeBlock\n ) {fragment=true,pin=1}\n\nParenExpression ::= OPEN_PAREN WS* Expression WS* CLOSE_PAREN {pin=1,recoverUntil=CLOSE_PAREN}\n\nCodeBlock ::= OPEN_BRACKET WS* (Statement (NEW_LINE WS* Statement)* WS*)? CLOSE_BRACKET {pin=1,recoverUntil=BLOCK_RECOVERY}\n\n/* Pattern matching */\nMatchBody ::= OPEN_BRACKET WS* MatchElements* CLOSE_BRACKET {pin=1,recoverUntil=MATCH_RECOVERY}\n\nDeconstructStruct ::= OPEN_PAREN WS* (NameIdentifier WS* NthNameIdentifier*)? CLOSE_PAREN WS* {pin=1}\nNthNameIdentifier ::= ',' WS* NameIdentifier WS* {fragment=true}\n\n/* Function call */\nCallArguments ::= OPEN_PAREN Arguments? CLOSE_PAREN {pin=1,recoverUntil=PAREN_RECOVERY}\nArguments ::= WS* Expression WS* NthArgument* {fragment=true}\nNthArgument ::= ',' WS* Expression WS* {pin=1,fragment=true,recoverUntil=NEXT_ARG_RECOVERY}\n\nReference ::= QName\n\nBooleanLiteral ::= TRUE_KEYWORD | FALSE_KEYWORD\nPostfixNumber ::= (HexLiteral | NumberLiteral) Reference? {pin=1,simplifyWhenOneChildren=true}\nNumberLiteral ::= !('0x') (\"0\" | [1-9] [0-9]*) (\".\" [0-9]+)? ((\"e\" | \"E\") ( \"-\" | \"+\" )? (\"0\" | [1-9] [0-9]*))? {pin=2}\nNegNumberLiteral ::= '-'? NumberLiteral {pin=2}\nHexLiteral ::= \"0x\" [0-9A-Fa-f]+ {pin=1}\nStringLiteral ::= STRING_DELIMITER ((![\\\\\"] [#x20-#xFFFF])* | ('\\\\' (STRING_DELIMITER | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HEXDIG HEXDIG HEXDIG HEXDIG)?))* STRING_DELIMITER\nLiteral ::= StringLiteral\n | PostfixNumber\n | BooleanLiteral {fragment=true}\n\nNameIdentifier ::= !KEYWORD '$'? [A-Za-z_]([A-Za-z0-9_$])* {pin=3}\nQName ::= NameIdentifier ('::' NameIdentifier)* {pin=1}\n\nNameLiteralPair ::= NameIdentifier WS* '=' WS* Literal {pin=1}\n\nSExpression ::= OPEN_PAREN WS* SSymbol WS* SAtom* WS* CLOSE_PAREN WS* {pin=1}\n\nSAtom ::= ( QName\n | SExpression\n | NegNumberLiteral\n | HexLiteral) WS* {fragment=true}\n\nSSymbol ::= [a-zA-Z][a-zA-Z0-9_./]* {pin=1}\n\n/* Keywords */\n\nKEYWORD ::= TRUE_KEYWORD\n | FALSE_KEYWORD\n | IF_KEYWORD\n | ELSE_KEYWORD\n | CASE_KEYWORD\n | VAR_KEYWORD\n | VAL_KEYWORD\n | TYPE_KEYWORD\n | ENUM_KEYWORD\n | TRAIT_KEYWORD\n | EFFECT_KEYWORD\n | IMPL_KEYWORD\n | FOR_KEYWORD\n | IMPORT_KEYWORD\n | FUN_KEYWORD\n | STRUCT_KEYWORD\n | PRIVATE_KEYWORD\n | MATCH_KEYWORD\n | LOOP_KEYWORD\n | CONTINUE_KEYWORD\n | BREAK_KEYWORD\n | RESERVED_WORDS\n\n/* Tokens */\n\nWASM_KEYWORD ::= '%wasm' {pin=1}\nSTRUCT_LITERAL_KEYWORD ::= '%struct' {pin=1}\nSTACK_LITERAL_KEYWORD ::= '%stack' {pin=1}\nINJECTED_LITERAL_KEYWORD::= '%injected' {pin=1}\n\nFUN_KEYWORD ::= 'fun' WS+\nVAL_KEYWORD ::= 'val' WS+\nVAR_KEYWORD ::= 'var' WS+\nEFFECT_KEYWORD ::= 'effect' WS+\nIMPL_KEYWORD ::= 'impl' WS+\nFOR_KEYWORD ::= 'for' WS+\nIMPORT_KEYWORD ::= 'import' WS+\nSTRUCT_KEYWORD ::= 'struct' WS+\nPRIVATE_KEYWORD ::= 'private' WS+\nTYPE_KEYWORD ::= 'type' WS+\nENUM_KEYWORD ::= 'enum' WS+\nTRAIT_KEYWORD ::= 'trait' WS+\nCASE_KEYWORD ::= 'case' WS+\n\nLOOP_KEYWORD ::= 'loop' ![A-Za-z0-9_$]\nCONTINUE_KEYWORD ::= 'continue' ![a-zA-Z0-9_$]\nBREAK_KEYWORD ::= 'break' ![A-Za-z0-9_$]\nTRUE_KEYWORD ::= 'true' ![A-Za-z0-9_$]\nFALSE_KEYWORD ::= 'false' ![A-Za-z0-9_$]\nIF_KEYWORD ::= 'if' ![A-Za-z0-9_$]\nELSE_KEYWORD ::= 'else' ![A-Za-z0-9_$]\nMATCH_KEYWORD ::= 'match' ![A-Za-z0-9_$]\n\n\n\nRESERVED_WORDS ::= ( 'abstract'\n | 'async'\n | 'await'\n | 'class'\n | 'const'\n | 'declare'\n | 'defer'\n | 'delete'\n | 'do'\n | 'extends'\n | 'finally'\n | 'for'\n | 'import'\n | 'is'\n | 'in'\n | 'let'\n | 'new'\n | 'package'\n | 'protected'\n | 'public'\n | 'try'\n | 'using'\n | 'while'\n | 'yield'\n ) ![A-Za-z0-9_$]\n\n/* OPERATORS, ORDERED BY PRECEDENCE https://introcs.cs.princeton.edu/java/11precedence/ */\n\nAssignmentKeyword ::= '=' !'='\nNotPreOperator ::= '!' !'='\nBitNotPreOperator ::= '~' !'='\nMinusPreOperator ::= '-' !'-'\nAsKeyword ::= 'as' ![A-Za-z0-9_]\nIsKeyword ::= 'is' ![A-Za-z0-9_]\nMulOperator ::= '**' | '*' | '/' | '%'\nAddOperator ::= '++' | '+' | '-'\nShiftOperator ::= '>>>' | '>>' | '<<'\nRelOperator ::= '>=' | '<=' | '>' | '<'\nEqOperator ::= '===' | '!==' | '~=' | '==' | '!='\nBitAndOperator ::= '&' !'&'\nBitXorOperator ::= '^'\nBitOrOperator ::= '|' !'|'\nAndKeyword ::= '&&' ![A-Za-z0-9_]\nOrKeyword ::= '||' ![A-Za-z0-9_]\n\n\nDIRECTIVE_RECOVERY::= &(FUN_KEYWORD | VAL_KEYWORD | VAR_KEYWORD | STRUCT_KEYWORD | PRIVATE_KEYWORD | EFFECT_KEYWORD | IMPL_KEYWORD | ENUM_KEYWORD | RESERVED_WORDS)\nNEXT_ARG_RECOVERY ::= &(',' | ')')\nPAREN_RECOVERY ::= &(')')\nBRACKET_RECOVERY ::= &('}')\nMATCH_RECOVERY ::= &('}' | 'case' | 'else')\nBLOCK_RECOVERY ::= &('}' | NEW_LINE)\nOPEN_PAREN ::= '('\nCLOSE_PAREN ::= ')'\nOPEN_ARRAY ::= '['\nOPEN_DECORATION ::= '#[' {pin=1}\nCLOSE_ARRAY ::= ']' {pin=1}\nSTRING_DELIMITER ::= '\"' {pin=1}\nOPEN_BRACKET ::= '{'\nCLOSE_BRACKET ::= '}'\nTHIN_ARROW ::= '->'\nCOLON ::= ':'\nOPEN_DOC_COMMENT ::= '/*'\nCLOSE_DOC_COMMENT ::= '*/'\nDOC_COMMENT ::= !CLOSE_DOC_COMMENT [#x00-#xFFFF]\n\nCOMMENT ::= '//' (![#x0A#x0D] [#x00-#xFFFF])* EOL\nMULTI_COMMENT ::= OPEN_DOC_COMMENT DOC_COMMENT* CLOSE_DOC_COMMENT {pin=1}\nWS ::= COMMENT | MULTI_COMMENT | [#x20#x09#x0A#x0D]+ {fragment=true}\nEOL ::= [#x0A#x0D]+\nHEXDIG ::= [a-fA-F0-9]\nNEW_LINE ::= [#x20#x09]* (EOL | COMMENT)\n\n"; | ||
export declare const RULES: IRule[]; | ||
export declare const parser: Parser; |
@@ -7,3 +7,3 @@ "use strict"; | ||
Document ::= WS* Directives WS* EOF? {ws=implicit} | ||
Document ::= WS* Directives WS* EOF? | ||
Directives ::= Directive WS* Directives? WS* {pin=1,recoverUntil=DIRECTIVE_RECOVERY,fragment=true} | ||
@@ -10,0 +10,0 @@ |
@@ -14,2 +14,3 @@ "use strict"; | ||
const loadFromMD_1 = require("./utils/loadFromMD"); | ||
const nodePrinter_1 = require("./utils/nodePrinter"); | ||
function mkdirRecursive(dir) { | ||
@@ -41,2 +42,3 @@ // we explicitly don't use `path.sep` to have it platform independent; | ||
'--debug': Boolean, | ||
'--desugar': Boolean, | ||
'--run': '--test' | ||
@@ -49,2 +51,3 @@ }, { | ||
const DEBUG = !!args['--debug']; | ||
const DESUGAR = !!args['--desugar']; | ||
const file = args._[0]; | ||
@@ -101,6 +104,9 @@ let customAssertions = {}; | ||
const optimize = !args['--no-optimize']; | ||
await codeGen.validate(optimize, DEBUG); | ||
await codeGen.validate(optimize, DEBUG || args['--wast']); | ||
if (args['--wast']) { | ||
NodeSystem_1.nodeSystem.writeFile(outFileFullWithoutExtension + '.wast', codeGen.emitText()); | ||
} | ||
if (codeGen.sourceMap) { | ||
NodeSystem_1.nodeSystem.writeFile(NodeSystem_1.nodeSystem.resolvePath(outPath, 'sourceMap.map'), codeGen.sourceMap); | ||
} | ||
if (!codeGen.buffer) { | ||
@@ -144,2 +150,12 @@ throw new errorPrinter_1.LysError('Could not generate WASM binary'); | ||
NodeSystem_1.nodeSystem.writeFile(outFileFullWithoutExtension + '.js', src.join('\n')); | ||
if (DESUGAR) { | ||
parsingContext.modulesInContext.forEach(module => { | ||
if (module.fileName.startsWith(NodeSystem_1.nodeSystem.cwd)) { | ||
const relativePath = NodeSystem_1.nodeSystem.relative(NodeSystem_1.nodeSystem.cwd, module.fileName); | ||
const targetFile = NodeSystem_1.nodeSystem.resolvePath(outPath + '/desugar/', relativePath); | ||
mkdirRecursive(path_1.dirname(targetFile)); | ||
NodeSystem_1.nodeSystem.writeFile(targetFile, nodePrinter_1.printNode(module)); | ||
} | ||
}); | ||
} | ||
if (args['--test']) { | ||
@@ -182,10 +198,25 @@ const testInstance = await testEnvironment_1.generateTestInstance(codeGen.buffer, libs); | ||
} | ||
let totalTime = 0; | ||
let totalTests = 0; | ||
let totalPass = 0; | ||
const summarizeItem = (result) => { | ||
totalTime += result.endTime - result.startTime; | ||
totalTests++; | ||
if (result.passed) { | ||
totalPass++; | ||
} | ||
result.tests && result.tests.forEach(summarizeItem); | ||
}; | ||
const summarize = (results) => { | ||
results.forEach(summarizeItem); | ||
}; | ||
if (testResults && testResults.length) { | ||
summarize(testResults); | ||
NodeSystem_1.nodeSystem.writeFile('_lys_test_results.json', JSON.stringify(testResults, null, 2)); | ||
if (testResults.some($ => !$.passed)) { | ||
console.error(colors_1.formatColorAndReset('\n\n Some tests failed.\n\n', colors_1.ForegroundColors.Red)); | ||
if (totalPass !== totalTests) { | ||
console.error(colors_1.formatColorAndReset(`\n\n Some tests failed. Passed: ${totalPass} Failed: ${totalTests - totalPass} (${(totalTime / 1000).toFixed(2)}s)\n\n`, colors_1.ForegroundColors.Red)); | ||
process.exit(1); | ||
} | ||
else { | ||
console.error(colors_1.formatColorAndReset('\n\n All tests passed.\n\n', colors_1.ForegroundColors.Green)); | ||
console.error(colors_1.formatColorAndReset(`\n\n All tests passed. Passed: ${totalPass} Failed: ${totalTests - totalPass} (${(totalTime / 1000).toFixed(2)}s)\n\n`, colors_1.ForegroundColors.Green)); | ||
} | ||
@@ -192,0 +223,0 @@ } |
{ | ||
"name": "lys", | ||
"version": "0.1.10-20191220221610.commit-f2fdf6a", | ||
"version": "0.1.10-20191224220334.commit-a4d2296", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
908399
10357