#-----------------------------------------------------------------------------* # # @file gtl_module_parser.galgas # # @section desc File description # # Parsing of GTL modules. # # @section copyright Copyright # # Goil OIL compiler, part of Trampoline RTOS # # Trampoline is copyright (c) CNRS, University of Nantes, # Ecole Centrale de Nantes # Trampoline is protected by the French intellectual property law. # # This software is distributed under the GNU Public Licence V2. # Check the LICENSE file in the root directory of Trampoline # # $Date$ # $Rev$ # $Author$ # $URL$ # #-----------------------------------------------------------------------------* syntax gtl_module_parser (gtl_scanner) { rule !@gtlExpression expression rule !@gtlInstruction instruction rule ?@gtlContext context ?!@library lib rule !@gtlArgumentList arguments #-----------------------------------------------------------------------------* # Instruction list in a setter, getter or function or any control instruction #-----------------------------------------------------------------------------* rule !@gtlInstructionList instructionList { instructionList = .emptyList repeat while ?let @gtlInstruction instruction instructionList += !instruction # let @string templateString = @string.retrieveAndResetTemplateString while ?let @gtlInstruction instruction instructionList += !instruction# # let @string templateString = @string.retrieveAndResetTemplateString end } #-----------------------------------------------------------------------------* # Start symbol of a module #-----------------------------------------------------------------------------* rule ?@gtlContext context ?!@library lib { repeat while !context !?lib end repeat while ?let @gtlFunction aFunction [!?lib putFunction ![aFunction name] !aFunction] while ?let @gtlGetter aGetter [!?lib putGetter ![aGetter typedName] !aGetter] while ?let @gtlSetter aSetter [!?lib putSetter ![aSetter typedName] !aSetter] end } #-----------------------------------------------------------------------------* # function definition #-----------------------------------------------------------------------------* rule !@gtlFunction function { $func$ $identifier$ ?let @lstring functionName let @location where = .here ?let @gtlArgumentList arguments $identifier$ ?let @lstring returnVariable ?let @gtlInstructionList instructionList $end$ $func$ function = .new { !where !functionName !arguments !instructionList !returnVariable } } #-----------------------------------------------------------------------------* # getter definition #-----------------------------------------------------------------------------* rule !@gtlGetter aGetter { $getter$ $@$ $identifier$ ?let @lstring targetType $identifier$ ?let @lstring getterName let @location where = .here ?let @gtlArgumentList arguments $identifier$ ?let @lstring returnVariable ?let @gtlInstructionList instructionList $end$ $getter$ aGetter = .new { !where !getterName !arguments !instructionList !returnVariable ![targetType gtlType] } } #-----------------------------------------------------------------------------* # setter definition #-----------------------------------------------------------------------------* rule !@gtlSetter aSetter { $setter$ $@$ $identifier$ ?let @lstring targetType $identifier$ ?let @lstring getterName let @location where = .here ?let @gtlArgumentList arguments ?let @gtlInstructionList instructionList $end$ $setter$ aSetter = .new { !where !getterName !arguments !instructionList ![targetType gtlType] } } #-----------------------------------------------------------------------------* # if ... elsif ... else ... end if instruction in a module #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { @gtlThenElsifStatementList thenElsifList = .emptyList @gtlInstructionList elseList = .emptyList $if$ let @location where = .here repeat ?let @gtlExpression condition $then$ ?let @gtlInstructionList instructionList thenElsifList += !condition !instructionList while $elsif$ end #--- else select $else$ ?elseList or end #--- $end$ $if$ instruction = @gtlIfStatementInstruction.new { !where !signature(!where) !thenElsifList !elseList } } #-----------------------------------------------------------------------------* # foreach instruction in a module #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { @gtlInstructionList beforeList = .emptyList let @gtlInstructionList doList @gtlInstructionList betweenList = .emptyList @gtlInstructionList afterList = .emptyList let @lstring indexName let @lstring variableName $foreach$ let @location where = .here $identifier$ ?var @lstring keyName select $,$ $identifier$ ?variableName or variableName = keyName keyName = .new { !"" !where } end select $($ $identifier$ ?indexName $)$ or indexName = .new { !"INDEX" !.here } end $in$ ?let @gtlExpression iterable #--- before block select $before$ ?beforeList or end #--- do block $do$ ?doList #--- between block select $between$ ?betweenList or end #--- after block select $after$ ?afterList or end #--- $end$ $foreach$ instruction = @gtlForeachStatementInstruction.new { !where !signature(!where) !keyName !variableName !indexName !iterable !beforeList !betweenList !afterList !doList } } #-----------------------------------------------------------------------------* # for instruction in a module #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { let @gtlInstructionList doList @gtlInstructionList betweenList = .emptyList @gtlExpressionList iterable = .emptyList $for$ let @location where = .here if [option gtl_options.warnDeprecated value] then warning .here : "for var in expression, ..., expression is deprecated" fixit { replace "foreach var in @( expression, ..., expression )" } end $identifier$ ?let @lstring variableName $in$ repeat ?let @gtlExpression expression iterable += !expression while $,$ end #--- Do block $do$ ?doList #--- between block select $between$ ?betweenList or end #--- $end$ $for$ instruction = @gtlForStatementInstruction.new { !where !signature(!where) !variableName !iterable !betweenList !doList } } #-----------------------------------------------------------------------------* # loop instruction in a module #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { @gtlInstructionList beforeList = .emptyList @gtlInstructionList betweenList = .emptyList @gtlInstructionList afterList = .emptyList @sint64 direction = 1 $loop$ let @location where = .here @gtlExpression step = @gtlTerminal.new { !where !@gtlInt.new { !where !emptylstring() !1 } } $identifier$ ?let @lstring variableName $from$ ?let @gtlExpression start select or $up$ or $down$ direction = -1 end $to$ ?let @gtlExpression stop select $step$ ?step or end #--- before block select $before$ ?beforeList or end #--- do block $do$ ?let @gtlInstructionList doList #--- between block select $between$ ?betweenList or end #--- after block select $after$ ?afterList or end #--- $end$ $loop$ instruction = @gtlLoopStatementInstruction.new { !where !signature(!where) !variableName !start !stop !step !direction !beforeList !betweenList !afterList !doList } } #-----------------------------------------------------------------------------* # repat instruction in a module #-----------------------------------------------------------------------------* rule !@gtlInstruction instruction { let @gtlExpression limit $repeat$ let @location where = .here select $($ ?limit $)$ or limit = @gtlTerminal.new { !.here !@gtlInt.new{ !.here !emptylstring() ![@uint.max{} bigint] } } end ?let @gtlInstructionList continueList $while$ ?let @gtlExpression condition $do$ ?let @gtlInstructionList doList $end$ $repeat$ instruction = @gtlRepeatStatementInstruction.new { !where !signature(!where) !limit !condition !continueList !doList } } }