From df920d4cf19ca0957161c96a6802366810e56f16 Mon Sep 17 00:00:00 2001 From: "Frank.R.Wu" Date: Mon, 1 Nov 2021 17:11:32 +0800 Subject: [PATCH] feat: add keyword of functions add keyword "view" for functions, to record functions that don't change contract status after execution --- .gitignore | 3 ++- input/JavaScriptLexer.g4 | 6 +++++- input/YJSParser.g4 | 12 ++++++------ 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 0384afc..6b7772b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /gen/ -/input/JavaScriptLexer.tokens \ No newline at end of file +/input/JavaScriptLexer.tokens +/input/gen \ No newline at end of file diff --git a/input/JavaScriptLexer.g4 b/input/JavaScriptLexer.g4 index c7d17c3..f292e5a 100644 --- a/input/JavaScriptLexer.g4 +++ b/input/JavaScriptLexer.g4 @@ -147,11 +147,15 @@ AtLeastOnce: 'AT_LEAST_ONCE'; AtMostOnce: 'AT_MOST_ONCE'; OnlyOnce: 'ONLY_ONCE'; -// Event Global or Local +/// Event Global or Local Global: 'global'; Local: 'local'; +/// Function Type + +View: 'view'; + /// Future Reserved Words Class: 'class'; diff --git a/input/YJSParser.g4 b/input/YJSParser.g4 index e8e01a5..69116bb 100644 --- a/input/YJSParser.g4 +++ b/input/YJSParser.g4 @@ -63,11 +63,6 @@ clzOrFunctionDeclaration |functionDeclaration |eventDeclaration ; -eventSemantics - :AtLeastOnce - |AtMostOnce - |OnlyOnce - ; eventDeclaration :Event eventGlobalOrLocal? Identifier SemiColon |Event eventGlobalOrLocal? Identifier '(' eventSemantics? ')' SemiColon @@ -76,6 +71,11 @@ eventGlobalOrLocal :Global |Local ; +eventSemantics + :AtLeastOnce + |AtMostOnce + |OnlyOnce + ; sourceElement : statement ; @@ -213,7 +213,7 @@ debuggerStatement ; functionDeclaration - : annotations? Export? Function Identifier '(' formalParameterList? ')' '{' functionBody '}' + : annotations? Export? Function Identifier '(' formalParameterList? ')' View '{' functionBody '}' ; classDeclaration