Skip to content

Commit

Permalink
Fix the definition of interfaces for typescript (#4297)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanru authored Nov 4, 2024
1 parent e688a18 commit 5ed2a3a
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
4 changes: 2 additions & 2 deletions javascript/typescript/CSharp/TypeScriptParserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ protected bool notLineTerminator()
return !here(LineTerminator);
}

protected bool notOpenBraceAndNotFunction()
protected bool notOpenBraceAndNotFunctionAndNotInterface()
{
int nextTokenType = _input.LT(1).Type;
return nextTokenType != OpenBrace && nextTokenType != Function_;
return nextTokenType != OpenBrace && nextTokenType != Function_ && nextTokenType != Interface;
}

protected bool closeBrace()
Expand Down
6 changes: 3 additions & 3 deletions javascript/typescript/Cpp/TypeScriptParserBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ bool TypeScriptParserBase::notLineTerminator()
return !here(TypeScriptParser::LineTerminator);
}

bool TypeScriptParserBase::notOpenBraceAndNotFunction()
bool TypeScriptParserBase::notOpenBraceAndNotFunctionAndNotInterface()
{
int nextTokenType = _input->LT(1)->getType();
return nextTokenType != TypeScriptParser::OpenBrace && nextTokenType != TypeScriptParser::Function_;

return nextTokenType != TypeScriptParser::OpenBrace && nextTokenType != TypeScriptParser::Function_
&& nextTokenType != TypeScriptParser::Interface;
}

bool TypeScriptParserBase::closeBrace()
Expand Down
2 changes: 1 addition & 1 deletion javascript/typescript/Cpp/TypeScriptParserBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class TypeScriptParserBase : public antlr4::Parser {
bool n(std::string str);
bool next(std::string str);
bool notLineTerminator();
bool notOpenBraceAndNotFunction();
bool notOpenBraceAndNotFunctionAndNotInterface();
bool closeBrace();
bool here(int type);
bool lineTerminatorAhead();
Expand Down
5 changes: 3 additions & 2 deletions javascript/typescript/Java/TypeScriptParserBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ protected boolean notLineTerminator() {
return !here(TypeScriptParser.LineTerminator);
}

protected boolean notOpenBraceAndNotFunction() {
protected boolean notOpenBraceAndNotFunctionAndNotInterface() {
int nextTokenType = _input.LT(1).getType();
return nextTokenType != TypeScriptParser.OpenBrace && nextTokenType != TypeScriptParser.Function_;
return nextTokenType != TypeScriptParser.OpenBrace && nextTokenType != TypeScriptParser.Function_
&& nextTokenType != TypeScriptParser.Interface;
}

protected boolean closeBrace() {
Expand Down
5 changes: 3 additions & 2 deletions javascript/typescript/TypeScript/TypeScriptParserBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export default abstract class TypeScriptParserBase extends Parser {
return !this.here(TypeScriptParser.LineTerminator);
}

protected notOpenBraceAndNotFunction():boolean {
protected notOpenBraceAndNotFunctionAndNotInterface():boolean {
const nextTokenType:number = this._input.LT(1).type;
return nextTokenType != TypeScriptParser.OpenBrace && nextTokenType != TypeScriptParser.Function_;
return nextTokenType != TypeScriptParser.OpenBrace && nextTokenType != TypeScriptParser.Function_
&& nextTokenType != TypeScriptParser.Interface;
}

protected closeBrace():boolean {
Expand Down
18 changes: 9 additions & 9 deletions javascript/typescript/TypeScriptParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,14 @@ sourceElement

statement
: block
| variableStatement
| variableStatement
| importStatement
| exportStatement
| emptyStatement_
| abstractDeclaration //ADDED
| classDeclaration
| functionDeclaration
| expressionStatement
| expressionStatement
| interfaceDeclaration //ADDED
| namespaceDeclaration //ADDED
| ifStatement
Expand Down Expand Up @@ -476,7 +476,7 @@ emptyStatement_
;

expressionStatement
: {this.notOpenBraceAndNotFunction()}? expressionSequence SemiColon?
: {this.notOpenBraceAndNotFunctionAndNotInterface()}? expressionSequence SemiColon?
;

ifStatement
Expand Down Expand Up @@ -752,11 +752,11 @@ singleExpression
| '-' singleExpression # UnaryMinusExpression
| '~' singleExpression # BitNotExpression
| '!' singleExpression # NotExpression
| Await singleExpression # AwaitExpression
| <assoc = right> singleExpression '**' singleExpression # PowerExpression
| Await singleExpression # AwaitExpression
| <assoc = right> singleExpression '**' singleExpression # PowerExpression
| singleExpression ('*' | '/' | '%') singleExpression # MultiplicativeExpression
| singleExpression ('+' | '-') singleExpression # AdditiveExpression
| singleExpression '??' singleExpression # CoalesceExpression
| singleExpression '??' singleExpression # CoalesceExpression
| singleExpression ('<<' | '>' '>' | '>' '>' '>') singleExpression # BitShiftExpression
| singleExpression ('<' | '>' | '<=' | '>=') singleExpression # RelationalExpression
| singleExpression Instanceof singleExpression # InstanceofExpression
Expand Down Expand Up @@ -801,7 +801,7 @@ assignable
;

anonymousFunction
: functionDeclaration
: functionDeclaration
| Async? Function_ '*'? '(' formalParameterList? ')' typeAnnotation? '{' functionBody '}'
| arrowFunctionDeclaration
;
Expand Down Expand Up @@ -833,7 +833,7 @@ assignmentOperator
| '^='
| '|='
| '**='
| '??='
| '??='
;

literal
Expand Down Expand Up @@ -964,7 +964,7 @@ keyword
| Static
| Yield
| Async
| Await
| Await
| ReadOnly
| From
| As
Expand Down

0 comments on commit 5ed2a3a

Please sign in to comment.