eclipse-langium/langium

Language Server Crash:

Closed this issue · 0 comments

When I add the following grammar rule, the Langium language server crashes in VSCode (also in the Langium Playground);

terminal D_BYTE_CHAR_STR returns string:
    '"' D_BYTE_CHAR_VALUE* '"';

Langium version: 3.1.1
Package name:

Steps To Reproduce

  1. Given this grammar:
grammar StructuredText

entry StructuredTextModel:
    (functionBlock=FunctionBlock | 
    (
        'BUILDIN'
        'FUNCTIONS' ':' buildin+=Intr_Function*
        'BUILDIN_END'
    ))
    ;

FunctionBlock:
    'FUNCTION_BLOCK' name=ID
      inputs=Inputs_List
      outputs=Outputs_List
      (localVariables=InternalVars_List)?
      ((statements+=Stmt)?';')*
    'END_FUNCTION_BLOCK'
    ;

Inputs_List:
    'VAR_INPUT'
    ((items+=Var_Decl_Init))*
    'END_VAR'
    ;

Outputs_List:
    'VAR_OUTPUT'
    ((items+=Output_Var_Decl_Init))+ 
    'END_VAR'
    ;

InternalVars_List:
    'VAR'
    ((items+=Local_Var_Decl_Init))*
    'END_VAR'
    ;

Var_Decl_Init:
    variables+=Variable_Primary (',' variables+=Variable_Primary)* ':'
    typeName=Native_Type_Name
    (':=' initialValue=Constant)? ';'
    ;

Output_Var_Decl_Init:
    variables+=Variable_Primary (',' variables+=Variable_Primary)* ':'
    typeName=Native_Type_Name 
    (':=' initialValue=Constant)? ';'
    ;

Local_Var_Decl_Init:
    (param ?='PARAM')?
    variables+=Variable_Primary (',' variables+=Variable_Primary)* ':'
    typeName=Native_Type_Name
    (':=' initialValue=Constant)? ';'
;

Variable_Primary infers PrimaryVariable:
    name=Variable_Name
    ;

Variable_Name returns string:
    ID | 'E' | 'e'
    ;

Native_Type_Name returns string: // enum in xtext, but not in langium
    'NUMERIC' | 'BOOL' | 'STRING' | 'ENUM' | 'ACSOURCE'
    ;

Constant:
    Numeric_Literal | String_Literal | Bool_Literal
    ;

Numeric_Literal infers NumericLiteral:
    Real_Literal | Int_Literal  
    ;

Real_Literal returns number:
    Signed_Int '.' UNSIGNED_INT ('E' Signed_Int)?
    ;

Int_Literal infers IntLiteral:
    {infer IntLiteral}
    ('LINT#')?
    value=Signed_Int
    ;

Signed_Int returns number:
    ('+' | '-')? UNSIGNED_INT
;

String_Literal infers StringLiteral:
    {infer StringLiteral}
    (type=String_Type_Name (length=UNSIGNED_INT)? '#')?
    value=Char_Str
    ;

String_Type_Name returns string:
    'STRING' | 'WSTRING' | 'CHAR' | 'WCHAR'
    ;

Char_Str infers CharStr:
    S_BYTE_CHAR_STR | D_BYTE_CHAR_STR
    ;

Stmt:
    Assign_Stmt | Func_Call | If_Stmt
    ;

Assign_Stmt:
    variables+=[PrimaryVariable | Variable_Name] (',' variables+=[PrimaryVariable | Variable_Name])*
    ':='
    expression=Expression
    ;

Func_Call:
    function=[Intr_Function] 
    '(' (args+=Expression (',' params+=Expression)*)? ')'
    ;

If_Stmt:
    'IF'  body=Control_Flow_If_Statement
      (elseif+=ELSIF_Clause)*
        (else=ELSE_Clause)?    
    'END_IF'
    ;

Control_Flow_If_Statement:
    condition=Expression
    'THEN'
    ((then+=Stmt)?';')*
    ;

ELSIF_Clause:
    'ELSIF' body=Control_Flow_If_Statement
    ;

ELSE_Clause:
    'ELSE'
    ((statements+=Stmt)?';')*
    ;

Expression: 
    Or_Expression
    ;

Or_Expression infers Expression:
    Xor_Expr ({BinaryExpression.left=current} 'OR' right=Xor_Expr)*
    ;

Xor_Expr infers Expression:
    And_Expr ({BinaryExpression.left=current} 'XOR' right=And_Expr)*
    ;

And_Expr infers Expression:
    Compare_Expr ({BinaryExpression.left=current} 'AND' right=Compare_Expr)*
    ;

Compare_Expr infers Expression:
    Equ_Expr ({BinaryExpression.left=current} operator=Compare_Operator right=Equ_Expr)*                                                                                         
    ;

Equ_Expr infers Expression:
    Add_Expr ({BinaryExpression.left=current} operator=Equ_Operator right=Add_Expr)*
    ;

Add_Expr infers Expression:
    Term ({BinaryExpression.left=current} operator=Add_Operator right=Term)*
    ;

Term infers Expression:
    Power_Expr ({BinaryExpression.left=current} operator=Term_Operator right=Power_Expr)*
    ;

Power_Expr infers Expression:
    Unary_Expr ({BinaryExpression.left=current} operator='**' right=Unary_Expr)*
    ;

Unary_Expr infers Expression: 
    operator=('NOT' | '-' | '+') 
    expression=PrimaryExpression | PrimaryExpression | 
    Constant
    ;

PrimaryExpression:
    Variable_Reference | Func_Call | Parenthesized_Expression
    ;

Variable_Reference:
    variable=[PrimaryVariable | Variable_Name]
    ;

Parenthesized_Expression:
    '(' expression=Expression ')'
    ;   



Intr_Function:
    name=ID allowedTypes+=Native_Type_Name ('|' allowedTypes+=Native_Type_Name)*
    ;



// Enum_Name:
//     (ID | 'E' )
//     ;



/************************************************************************
                                literals
*************************************************************************/

Real_Value returns number:
    Signed_Int '.' UNSIGNED_INT ('E' Signed_Int)?
    ;  

Bool_Literal infers BoolLiteral:
    {infer BoolLiteral}
    ('BOOL#')? (value?='TRUE' | 'FALSE')
    ;

terminal UNSIGNED_INT returns number:
	DIGIT ('_'? DIGIT)*
;

terminal S_BYTE_CHAR_STR returns string: 
    '\'' S_BYTE_CHAR_VALUE* '\'';



terminal fragment DIGIT: '0'..'9';

terminal fragment HEX_DIGIT: '0'..'9' | 'a'..'f' | 'A'..'F';

terminal fragment S_BYTE_CHAR_VALUE:
	COMMON_CHAR_VALUE | '$\'' | '"' | '$' HEX_DIGIT HEX_DIGIT
;

terminal fragment COMMON_CHAR_VALUE:
	(' ' | '!' | '#' | '%' | '&' | '('..'/' | '0'..'9' | ':'..'@' | 'A'..'Z' | '['..'`' | 'a'..'z' | '{'..'~' | '$$' | '$L' | '$N' | '$P' | '$R' | '$T')
;

hidden terminal WS: /\s+/;
terminal ID: /[_a-zA-Z][\w_]*/;
terminal INT returns number: /[0-9]+/;
//terminal STRING: /"(\\.|[^"\\])*"|'(\\.|[^'\\])*'/;

hidden terminal ML_COMMENT: /\/\*[\s\S]*?\*\//;
hidden terminal SL_COMMENT: /\/\/[^\n\r]*/;

Add the D_BYTE_CHAR_STR rule shown above.

  1. An unhandled error occurs in the worker (the same error occurs in the VSCode extension, causing the extension to crash five times and stop trying)

In the browser, the worker displays the following unhandled error:

image

In the VSCode extension, the following error is shown in the Output window:

Error: Missing rule reference.
    at Ta (c:\Users\me\.vscode\extensions\langium.langium-vscode-3.1.1\out\language-server\main.cjs:48:6232)
    at c:\Users\me\.vscode\extensions\langium.langium-vscode-3.1.1\out\language-server\main.cjs:48:6928
    at Array.map (<anonymous>)
    at FP (c:\Users\me\.vscode\extensions\langium.langium-vscode-3.1.1\out\language-server\main.cjs:48:6921)
    at Ta (c:\Users\me\.vscode\extensions\langium.langium-vscode-3.1.1\out\language-server\main.cjs:48:6165)
    at cn (c:\Users\me\.vscode\extensions\langium.langium-vscode-3.1.1\out\language-server\main.cjs:48:5984)
    at HT (c:\Users\me\.vscode\extensions\langium.langium-vscode-3.1.1\out\language-server\main.cjs:190:10124)
    at c:\Users\me\.vscode\extensions\langium.langium-vscode-3.1.1\out\language-server\main.cjs:190:9876
    at Array.map (<anonymous>)
    at HT (c:\Users\me\.vscode\extensions\langium.langium-vscode-3.1.1\out\language-server\main.cjs:190:9869)

Node.js v20.9.0
[Error - 10:59:32 AM] Server process exited with code 1.
[Error - 10:59:32 AM] The Langium server crashed 5 times in the last 3 minutes. The server will not be restarted. See the output for more information.

The current behavior

The language server crashes

The expected behavior

The error is handled, and if a required grammar element is missing, the editor indicates this condition.