lib/gisele/language/syntax/grammar.citrus in gisele-0.2.0 vs lib/gisele/language/syntax/grammar.citrus in gisele-0.3.0

- old
+ new

@@ -1,35 +1,28 @@ grammar Gisele::Language::Syntax::Grammar ### Units - rule unit - ((spacing task_def)* spacing) - <Gisele::Language::Syntax::Unit> + rule unit_def + (spacing task_def (spaces task_def)* spacing) + <Gisele::Language::Syntax::UnitDef> end ### Task definitions rule task_def - ('task' spaces task_name spaces (task_signature spaces)? (task_refinement spaces)? 'end') + ('task' spaces task_name spaces + (some_def spaces)* + (explicit_statement spaces)? + 'end') <Gisele::Language::Syntax::TaskDef> end - rule task_signature - (task_signature_element (spaces task_signature_element)*) - <Gisele::Language::Syntax::TaskSignature> + rule some_def + fluent_def | trackvar_def | task_def end - rule task_signature_element - fluent_def | trackvar_def - end - - rule task_refinement - ('refinement' spaces process_statement spaces 'end') - <Gisele::Language::Syntax::TaskRefinement> - end - ### Process statements rule process_statement implicit_seq_st | explicit_statement end @@ -44,28 +37,46 @@ <Gisele::Language::Syntax::StList> end rule explicit_statement if_st + | case_st | while_st | seq_st | par_st | task_call_st end + rule case_st + ('case' spaces (var_ref spaces)? + (when_clause spaces)+ + (else_clause spaces)? + 'end') + <Gisele::Language::Syntax::CaseSt> + end + + rule when_clause + ('when' spaces bool_expr spaces process_statement) + <Gisele::Language::Syntax::WhenClause> + end + rule if_st - ('if' spaces bool_expr spaces process_statement spaces elsif_clause* else_clause? 'end') + ('if' spaces bool_expr spaces + process_statement spaces + (elsif_clause spaces)* + (else_clause spaces)? + 'end') <Gisele::Language::Syntax::IfSt> end rule elsif_clause - ('elsif' spaces bool_expr spaces process_statement spaces) + ('elsif' spaces bool_expr spaces process_statement) <Gisele::Language::Syntax::ElsifClause> end rule else_clause - ('else' spaces process_statement spaces) + ('else' spaces process_statement) <Gisele::Language::Syntax::ElseClause> end rule while_st ('while' spaces bool_expr spaces process_statement spaces 'end') @@ -111,11 +122,11 @@ <Gisele::Language::Syntax::BoolNot> | bool_term end rule bool_term - bool_paren | bool_lit | bool_varref + bool_paren | bool_lit | var_ref end rule bool_paren ('(' spacing expr:bool_or spacing ')') <Gisele::Language::Syntax::BoolParen> @@ -124,15 +135,10 @@ rule bool_lit (boolean_literal) <Gisele::Language::Syntax::BoolLit> end - rule bool_varref - (variable_name) - <Gisele::Language::Syntax::VarRef> - end - ### Variables rule variable_def trackvar_def | fluent_def end @@ -149,10 +155,15 @@ rule initially_def (spaces 'initially' spaces lit:boolean_literal){ lit.value } end + rule var_ref + (variable_name) + <Gisele::Language::Syntax::VarRef> + end + ### Events rule event_set ('{' spacing (event (spacing ',' spacing event)*)? spacing '}') <Gisele::Language::Syntax::EventSet> @@ -171,15 +182,15 @@ rule task_name [A-Z] [A-Za-z0-9_]* end rule variable_name - [a-z] [A-Za-z0-9_]* + !(reserved_word spaces) [a-z] [A-Za-z0-9_]* end rule event_name - [a-z] [a-z0-9_]* + !(reserved_word spaces) [a-z] [a-z0-9_]* end ### Literals rule boolean_literal @@ -198,6 +209,28 @@ rule spacing (comment | [ \t\n])* end -end \ No newline at end of file + ### Reserved Words + rule reserved_word + "if" + | "else" + | "elsif" + | "when" + | "while" + | "seq" + | "par" + | "task" + | "refinement" + | "fluent" + | "trackvar" + | "initially" + | "end" + | "not" + | "or" + | "and" + | "true" + | "false" + end + +end