From ef5d1760a3580a919508ba26ff49324d47cd966b Mon Sep 17 00:00:00 2001 From: yyc12345 Date: Wed, 1 Nov 2023 10:31:17 +0800 Subject: [PATCH] add lexer and parser for export function binding generation --- CodeGen/BMapBindings/ExpFctsLexer.g4 | 23 +++++++++++++++++++++++ CodeGen/BMapBindings/ExpFctsParser.g4 | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 CodeGen/BMapBindings/ExpFctsLexer.g4 create mode 100644 CodeGen/BMapBindings/ExpFctsParser.g4 diff --git a/CodeGen/BMapBindings/ExpFctsLexer.g4 b/CodeGen/BMapBindings/ExpFctsLexer.g4 new file mode 100644 index 0000000..a705b40 --- /dev/null +++ b/CodeGen/BMapBindings/ExpFctsLexer.g4 @@ -0,0 +1,23 @@ +lexer grammar ExpFctsLexer; + +// keywords +EXPFCTS_EXPORT: 'LIBCMO_EXPORT' ; +EXPFCTS_FILE_DECL: 'BMPARAM_FILE_DECL' ; +EXPFCTS_MESHTRANS_DECL: 'BMPARAM_MESHTRANS_DECL' ; +EXPFCTS_OBJECT_DECL: 'BMPARAM_OBJECT_DECL' ; +EXPFCTS_PARAM_IN: 'BMPARAM_IN' ; +EXPFCTS_PARAM_OUT: 'BMPARAM_OUT' ; + +// symbols +EXPFCTS_LPARENTHESES: '(' ; +EXPFCTS_RPARENTHESES: ')' ; +EXPFCTS_COMMA: ',' ; +EXPFCTS_SEMICOLON: ';' ; +EXPFCTS_STAR: '*' ; +EXPFCTS_DOUBLE_COLON: '::' ; + +// identifider +EXPFCTS_IDENTIFIER: [_a-zA-Z][_a-zA-Z0-9]* ; + +// remove whitespace and line break +EXPFCTS_WS: [ \t\n\r\f]+ -> skip ; diff --git a/CodeGen/BMapBindings/ExpFctsParser.g4 b/CodeGen/BMapBindings/ExpFctsParser.g4 new file mode 100644 index 0000000..9bbae20 --- /dev/null +++ b/CodeGen/BMapBindings/ExpFctsParser.g4 @@ -0,0 +1,21 @@ +parser grammar ExpFctsParser; +options { tokenVocab = ExpFctsLexer; } + +program: fctDecl* ; + +fctDecl + : EXPFCTS_EXPORT varType EXPFCTS_IDENTIFIER '(' (fctArg (',' fctArg)*)? ')' ';' + ; + +fctArg + : EXPFCTS_FILE_DECL '(' EXPFCTS_IDENTIFIER ')' # fctArgFileDecl + | EXPFCTS_MESHTRANS_DECL '(' EXPFCTS_IDENTIFIER ')' #fctArgMeshTransDecl + | EXPFCTS_OBJECT_DECL '(' EXPFCTS_IDENTIFIER ',' EXPFCTS_IDENTIFIER ')' # fctArgObjDecl + | EXPFCTS_PARAM_IN '(' varType ',' EXPFCTS_IDENTIFIER ')' # fctArgParamIn + | EXPFCTS_PARAM_OUT '(' varType ',' EXPFCTS_IDENTIFIER ')' # fctArgParamOut + ; + +varType + : EXPFCTS_IDENTIFIER ('::' EXPFCTS_IDENTIFIER)* '*'? + ; +