add lexer and parser for export function binding generation

This commit is contained in:
yyc12345 2023-11-01 10:31:17 +08:00
parent 99383779b3
commit ef5d1760a3
2 changed files with 44 additions and 0 deletions

View File

@ -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 ;

View File

@ -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)* '*'?
;