Skip to content
Snippets Groups Projects
Commit 194a384f authored by Johannes Mey's avatar Johannes Mey
Browse files

massive improvement of parser

parent 4d2d2d42
No related branches found
No related tags found
No related merge requests found
......@@ -102,16 +102,27 @@ Comment comment =
{
yyValue = new Comment(new Opt<CommentContent>());
}
/ SS SEMICOLON
{
yyValue = new Comment(new Opt<CommentContent>());
}
;
// =============================================================================
// Clause 2
// =============================================================================
//// // TODO MISSING RULE 201
//// // R201
//// Program ::= ProgramUnit* ;
Program program =
u:(program_unit)+
{
yyValue = new Program(new List().addAll(u.list()));
}
;
//// // R202
//// abstract ProgramUnit ;
//// abstract ProgramUnit ::= Postamble:Comment* ;
ProgramUnit program_unit =
main_program
/ external_subprogram
......@@ -124,17 +135,13 @@ ProgramUnit program_unit =
//// FunctionSubprogram_ExternalSubprogram:ExternalSubprogram ::= FunctionSubprogram ;
//// SubroutineSubprogram_ExternalSubprogram:ExternalSubprogram ::= SubroutineSubprogram ;
ExternalSubprogram external_subprogram =
f:function_subprogram
{
yyValue = new FunctionSubprogram_ExternalSubprogram(f);
}
/ s:subroutine_subprogram
f:function_subprogram ec:(comment)*
{
yyValue = new SubroutineSubprogram_ExternalSubprogram(s);
yyValue = new FunctionSubprogram_ExternalSubprogram(new List().addAll(ec.list()), f);
}
/ c:comment
/ s:subroutine_subprogram ec:(comment)*
{
yyValue = new CommentExternalSubprogram(c);
yyValue = new SubroutineSubprogram_ExternalSubprogram(new List().addAll(ec.list()), s);
}
;
......@@ -298,12 +305,13 @@ DeclarationConstruct declaration_construct =
;
//// // R208
//// ExecutionPart ::= ExecutableConstruct ExecutionPartConstruct* ;
//// // TODO: simplification: the first ExecutionPartConstruct must be an ExecutableConstruct
//// ExecutionPart ::= ExecutionPartConstruct* ;
ExecutionPart execution_part =
ec:executable_construct el:(execution_part_construct)*
el:(execution_part_construct)+
{
List el_list = new List().addAll(el.list());
yyValue = new ExecutionPart(ec, el_list);
yyValue = new ExecutionPart(el_list);
}
;
......@@ -313,6 +321,7 @@ ExecutionPart execution_part =
//// FormatStmt_ExecutionPartConstruct:ExecutionPartConstruct ::= FormatStmt ;
//// EntryStmt_ExecutionPartConstruct:ExecutionPartConstruct ::= EntryStmt ;
ExecutionPartConstruct execution_part_construct =
<BEGINNING>
l:label p2:format_stmt
{
p2.setLabel(l);
......@@ -702,6 +711,7 @@ DeclarationTypeSpec declaration_type_spec_without_kind =
//// Real_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [KindSelector] ;
//// Double_IntrinsicTypeSpec:IntrinsicTypeSpec ;
//// Complex_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [KindSelector] ;
//// DoubleComplex_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [KindSelector] ;
//// Character_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [CharSelector] ;
//// Logical_IntrinsicTypeSpec:IntrinsicTypeSpec ::= [KindSelector] ;
IntrinsicTypeSpec intrinsic_type_spec =
......@@ -724,6 +734,11 @@ IntrinsicTypeSpec intrinsic_type_spec =
Opt<KindSelector> k_opt = (k==null) ? new Opt<KindSelector>() : new Opt<KindSelector>(k);
yyValue = new Complex_IntrinsicTypeSpec(k_opt);
}
/ DOUBLE_COMPLEX k:(kind_selector)?
{
Opt<KindSelector> k_opt = (k==null) ? new Opt<KindSelector>() : new Opt<KindSelector>(k);
yyValue = new DoubleComplex_IntrinsicTypeSpec(k_opt);
}
/ CHARACTER c:(char_selector)?
{
Opt<CharSelector> c_opt = (c==null) ? new Opt<CharSelector>() : new Opt<CharSelector>(c);
......@@ -866,7 +881,7 @@ Sign sign =
;
//// // R412
//// SignedRealLiteralConstant ::= [Sign] RealLiteralConstant ;
//// SignedRealLiteralConstant ::= [Sign] RealLiteralConstant:AbstractRealLiteralConstant ;
SignedRealLiteralConstant signed_real_literal_constant =
s:(sign)? c:real_literal_constant
{
......@@ -876,38 +891,80 @@ SignedRealLiteralConstant signed_real_literal_constant =
;
//// // R413
//// RealLiteralConstant:LiteralConstant ::= Significand [Exponent] [KindParam] ;
RealLiteralConstant real_literal_constant =
s:significand e:(EXPONENT_LETTER yyValue:exponent)? k:(UNDERSCORE yyValue:kind_param)? SS
//// abstract AbstractRealLiteralConstant:LiteralConstant ::= Significand [Exponent] [KindParam] ;
//// RealLiteralConstant:AbstractRealLiteralConstant ;
//// DoubleLiteralConstant:AbstractRealLiteralConstant ;
AbstractRealLiteralConstant real_literal_constant =
s:significand E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<Exponent> e_opt = new Opt<Exponent>(e);
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new RealLiteralConstant(s, e_opt, k_opt);
}
/ s:significand D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<Exponent> e_opt = new Opt<Exponent>(e);
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new DoubleLiteralConstant(s, e_opt, k_opt);
}
/ s:significand k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<Exponent> e_opt = (e==null) ? new Opt<Exponent>() : new Opt<Exponent>(e);
Opt<Exponent> e_opt = new Opt<Exponent>();
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new RealLiteralConstant(s, e_opt, k_opt);
}
/ d:DIGITS EXPONENT_LETTER e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
/ d:DIGITS E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new RealLiteralConstant(new Significand(d), new Opt<Exponent>(e), k_opt);
}
/ d:DIGITS D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new DoubleLiteralConstant(new Significand(d), new Opt<Exponent>(e), k_opt);
}
;
RealLiteralConstant real_literal_constant_without_dot =
s:significand EXPONENT_LETTER e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
AbstractRealLiteralConstant real_literal_constant_without_dot =
s:significand E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<Exponent> e_opt = new Opt<Exponent>(e);
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new RealLiteralConstant(s, e_opt, k_opt);
}
/ s:significand D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<Exponent> e_opt = new Opt<Exponent>(e);
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new DoubleLiteralConstant(s, e_opt, k_opt);
}
/ s:significand_without_dot E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<Exponent> e_opt = (e==null) ? new Opt<Exponent>() : new Opt<Exponent>(e);
Opt<Exponent> e_opt = new Opt<Exponent>(e);
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new RealLiteralConstant(s, e_opt, k_opt);
}
/ s:significand_without_dot e:(EXPONENT_LETTER yyValue:exponent)? k:(UNDERSCORE yyValue:kind_param)? SS
/ s:significand_without_dot D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<Exponent> e_opt = new Opt<Exponent>(e);
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new DoubleLiteralConstant(s, e_opt, k_opt);
}
/ s:significand_without_dot k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<Exponent> e_opt = (e==null) ? new Opt<Exponent>() : new Opt<Exponent>(e);
Opt<Exponent> e_opt = new Opt<Exponent>();
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new RealLiteralConstant(s, e_opt, k_opt);
}
/ d:DIGITS EXPONENT_LETTER e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
/ d:DIGITS E e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new RealLiteralConstant(new Significand(d), new Opt<Exponent>(e), k_opt);
}
/ d:DIGITS D e:exponent k:(UNDERSCORE yyValue:kind_param)? SS
{
Opt<KindParam> k_opt = (k==null) ? new Opt<KindParam>() : new Opt<KindParam>(k);
yyValue = new DoubleLiteralConstant(new Significand(d), new Opt<Exponent>(e), k_opt);
}
;
//// // R414
......@@ -1942,14 +1999,17 @@ UpperCobound upper_cobound =
//// ExplicitShapeArraySpec:ArraySpec ::= ExplicitShapeSpec* ;
//// AssumedShapeArraySpec:ArraySpec ::= AssumedShapeSpec* ;
//// DeferredShapeArraySpec:ArraySpec ::= DeferredShapeSpec* ;
//// // TODO DeferredShapeArraySpec is not recognized, because the syntax is subsumed by (cont.)
//// // AssumedShapeArraySpec. This has to be rewritten later.
//// AssumedSizeSpecArraySpec:ArraySpec ::= AssumedSizeSpec ;
//// ImpliedShapeSpecArraySpec:ArraySpec ::= ImpliedShapeSpec* ;
ArraySpec array_spec =
d:deferred_shape_spec dl:(COMMA yyValue:deferred_shape_spec)*
{
yyValue = new DeferredShapeArraySpec(new List().add(d).addAll(dl.list()));
}
/ a:assumed_size_spec
// d:deferred_shape_spec dl:(COMMA yyValue:deferred_shape_spec)*
// {
// yyValue = new DeferredShapeArraySpec(new List().add(d).addAll(dl.list()));
// }
///
a:assumed_size_spec
{
yyValue = new AssumedSizeSpecArraySpec(a);
}
......@@ -2811,7 +2871,7 @@ CoindexedNamedObject coindexed_named_object =
ArrayElement array_element =
p:part_ref PERCENT a:array_element
{
a.getDataRef().getPartRefList().add(p);
a.getDataRef().getPartRefList().insertChild(p,0);
yyValue = a;
}
/ p:part_ref_with_subscript
......@@ -3136,7 +3196,7 @@ Primary primary_without_dot =
Designator_OR_FunctionReference designator_OR_function_reference =
pr:part_ref PERCENT df:designator_OR_function_reference
{
((Designator_OR_FunctionReference) df).getDataRef().getPartRefList().add(pr);
((Designator_OR_FunctionReference) df).getDataRef().getPartRefList().insertChild(pr,0);
yyValue = df;
}
/ pr:(part_ref_without_subscript/part_ref) LPAREN l:substring_range_OR_actual_arg_spec_list RPAREN LPAREN s:substring_range RPAREN
......@@ -4479,6 +4539,7 @@ ForallStmt forall_stmt =
//// // R801
//// Block ::= ExecutionPartConstruct* ;
Block block =
<BEGINNING>
el:(execution_part_construct)*
{
yyValue = new Block(new List().addAll(el.list()));
......@@ -4650,7 +4711,7 @@ DoWhileConstruct do_while_construct =
;
//// // R815
//// abstract DoStmt:AbstractStmt ::= [DoConstructName:Name];
//// abstract DoStmt:AbstractStmt ::= [DoConstructName:Name] [GotoLabel:Label];
DoStmt do_stmt =
infinite_do_stmt
/ simple_do_stmt
......@@ -4660,41 +4721,45 @@ DoStmt do_stmt =
//// InfiniteDoStmt:DoStmt ;
InfiniteDoStmt infinite_do_stmt =
n:(yyValue:name COLON)? DO l:label? lnc:comment
l:label? n:(yyValue:name COLON)? DO g:label? lnc:comment
{
Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n);
Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l);
yyValue = new InfiniteDoStmt(l_opt, lnc, n_opt);
Opt<Label> g_opt = (g==null) ? new Opt<Label>() : new Opt<Label>(g);
yyValue = new InfiniteDoStmt(l_opt, lnc, n_opt, g_opt);
}
;
//// SimpleDoStmt:DoStmt ::= SimpleLoopControl;
SimpleDoStmt simple_do_stmt =
n:(yyValue:name COLON)? DO l:label? c:simple_loop_control lnc:comment
l:label? n:(yyValue:name COLON)? DO g:label? c:simple_loop_control lnc:comment
{
Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n);
Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l);
yyValue = new SimpleDoStmt(l_opt, lnc, n_opt, c);
Opt<Label> g_opt = (g==null) ? new Opt<Label>() : new Opt<Label>(g);
yyValue = new SimpleDoStmt(l_opt, lnc, n_opt, g_opt, c);
}
;
//// DoConcurrentStmt:DoStmt ::= ConcurrentLoopControl ;
DoConcurrentStmt do_concurrent_stmt =
n:(yyValue:name COLON)? DO l:label? c:concurrent_loop_control lnc:comment
l:label? n:(yyValue:name COLON)? DO g:label? c:concurrent_loop_control lnc:comment
{
Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n);
Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l);
yyValue = new DoConcurrentStmt(l_opt, lnc, n_opt, c);
Opt<Label> g_opt = (g==null) ? new Opt<Label>() : new Opt<Label>(g);
yyValue = new DoConcurrentStmt(l_opt, lnc, n_opt, g_opt, c);
}
;
//// DoWhileStmt:DoStmt ::= WhileLoopControl ;
DoWhileStmt do_while_stmt =
n:(yyValue:name COLON)? DO l:label? c:while_loop_control lnc:comment
l:label? n:(yyValue:name COLON)? DO g:label? c:while_loop_control lnc:comment
{
Opt<Name> n_opt = (n==null) ? new Opt<Name>() : new Opt<Name>(n);
Opt<Label> l_opt = (l==null) ? new Opt<Label>() : new Opt<Label>(l);
yyValue = new DoWhileStmt(l_opt, lnc, n_opt, c);
Opt<Label> g_opt = (g==null) ? new Opt<Label>() : new Opt<Label>(g);
yyValue = new DoWhileStmt(l_opt, lnc, n_opt, g_opt, c);
}
;
......@@ -6198,6 +6263,7 @@ V v =
//// BlankInterpControlEditDesc:ControlEditDesc ::= BlankInterpEditDesc ;
//// RoundControlEditDesc:ControlEditDesc ::= RoundEditDesc ;
//// DecimalControlEditDesc:ControlEditDesc ::= DecimalEditDesc ;
//// // TODO what about SignedIntLiteralEditDesc ?
ControlEditDesc control_edit_desc =
r:(yyValue:r)? SLASH
{
......@@ -6383,13 +6449,13 @@ CharStringEditDesc char_string_edit_desc =
//// // R1101
//// MainProgram:ProgramUnit ::= [ProgramStmt] [SpecificationPart] [ExecutionPart] [InternalSubprogramPart] EndProgramStmt ;
MainProgram main_program =
p: program_stmt? s:specification_part e:execution_part? i:internal_subprogram_part? x:end_program_stmt
p: program_stmt? s:specification_part e:execution_part? i:internal_subprogram_part? x:end_program_stmt ec:(comment)*
{
Opt<ProgramStmt> p_opt = (p==null) ? new Opt<ProgramStmt>() : new Opt<ProgramStmt>(p);
Opt<SpecificationPart> s_opt = (s==null) ? new Opt<SpecificationPart>() : new Opt<SpecificationPart>(s);
Opt<ExecutionPart> e_opt = (e==null) ? new Opt<ExecutionPart>() : new Opt<ExecutionPart>(e);
Opt<InternalSubprogramPart> i_opt = (i==null) ? new Opt<InternalSubprogramPart>() : new Opt<InternalSubprogramPart>(i);
yyValue = new MainProgram(p_opt, s_opt, e_opt, i_opt, x);
yyValue = new MainProgram(new List().addAll(ec.list()), p_opt, s_opt, e_opt, i_opt, x);
}
;
......@@ -6421,11 +6487,11 @@ EndProgramStmt end_program_stmt =
//// // R1104
//// Module:ProgramUnit ::= ModuleStmt [SpecificationPart] [ModuleSubprogramPart] EndModuleStmt ;
Module module =
m:module_stmt s:specification_part i:(module_subprogram_part)? e:end_module_stmt
m:module_stmt s:specification_part i:(module_subprogram_part)? e:end_module_stmt ec:(comment)*
{
Opt<SpecificationPart> s_opt = (s==null) ? new Opt<SpecificationPart>() : new Opt<SpecificationPart>(s);
Opt<ModuleSubprogramPart> i_opt = (i==null) ? new Opt<ModuleSubprogramPart>() : new Opt<ModuleSubprogramPart>(i);
yyValue = new Module(m, s_opt, i_opt, e);
yyValue = new Module(new List().addAll(ec.list()), m, s_opt, i_opt, e);
}
;
......@@ -6462,6 +6528,7 @@ ModuleSubprogramPart module_subprogram_part =
//// FunctionModuleSubprogram:ModuleSubprogram ::= FunctionSubprogram ;
//// SubroutineModuleSubprogram:ModuleSubprogram ::= SubroutineSubprogram ;
//// SeparateModuleModuleSubprogram:ModuleSubprogram ::= SeparateModuleSubprogram ;
//// CommentModuleSubprogram:ModuleSubprogram ::= Comment ;
ModuleSubprogram module_subprogram =
f:function_subprogram
{
......@@ -6475,6 +6542,10 @@ ModuleSubprogram module_subprogram =
{
yyValue = new SeparateModuleModuleSubprogram(p);
}
/ c:comment
{
yyValue = new CommentModuleSubprogram(c);
}
;
//// // R1109
......@@ -6555,10 +6626,10 @@ Only only =
//// // R1120
//// BlockData:ProgramUnit ::= BlockDataStmt [SpecificationPart] EndBlockDataStmt ;
BlockData block_data =
b:block_data_stmt s:specification_part x:end_block_data_stmt
b:block_data_stmt s:specification_part x:end_block_data_stmt ec:(comment)*
{
Opt<SpecificationPart> s_opt = (s==null) ? new Opt<SpecificationPart>() : new Opt<SpecificationPart>(s);
yyValue = new BlockData(b, s_opt, x);
yyValue = new BlockData(new List().addAll(ec.list()), b, s_opt, x);
}
;
......@@ -6880,7 +6951,7 @@ CallStmt call_stmt =
ProcedureDesignator procedure_designator =
p:part_ref PERCENT d:procedure_designator
{
d.getDataRef().getPartRefList().add(p);
d.getDataRef().getPartRefList().insertChild(p,0);
yyValue = d;
}
/ n:name
......
......@@ -2,11 +2,11 @@ module FortranParser();
modify OpenMp;
//// Root ::= Preamble:Comment* ProgramUnit Postamble:Comment* ;
//// Root ::= Preamble:Comment* Program ;
public Root root =
bc:(comment)* s:program_unit ec:(comment)*
bc:(comment)* s:program
{
yyValue = new Root(new List().addAll(bc.list()), s, new List().addAll(ec.list()));
yyValue = new Root(new List().addAll(bc.list()), s);
}
;
......@@ -76,6 +76,7 @@ transient void DELIM = D E L I M SS;
transient void DIMENSION = D I M E N S I O N SS;
transient void DIRECT = D I R E C T SS;
transient void DO = D O SS;
transient void DOUBLE_COMPLEX = D O U B L E SS C O M P L E X SS;
transient void DOUBLE_PRECISION = D O U B L E SS P R E C I S I O N SS;
transient void ELEMENTAL = E L E M E N T A L SS;
transient void ELSE = E L S E SS;
......@@ -223,3 +224,4 @@ transient void COMMA = "," SS;
transient void COLONCOLON = "::" SS;
transient void ASTERISK = "*" SS;
transient void EXCLAMATIONMARK = "!";
transient void SEMICOLON = ";";
module OpenAcc();
modify Fortran2008;
modify ConditionalLines;
import OpenAccTokens;
// allow OpenACC constructs as executable_constructs
......
This diff is collapsed.
aspect Printing {
// abstract Slot ::= SlotName ;
// SlotName ::= <String> ;
// SlotExpr:Expr ::= ExprSlot ;
// ExprSlot:Slot ;
public void SlotName.prettyPrint(PrettyPrinter s) {
s.append(getString());
public void SlotExpr.prettyPrint(PrettyPrinter s) {
s.append("#");
s.append(getSlotName());
s.append("#");
}
public void Slot.prettyPrint(PrettyPrinter s) {
public void SlotIntLiteralConstant.prettyPrint(PrettyPrinter s) {
s.append("#");
getSlotName().prettyPrint(s);
s.append(getSlotName());
s.append("#");
}
public void SlotExpr.prettyPrint(PrettyPrinter s) {
getExprSlot().prettyPrint(s);
public void SlotBlock.prettyPrint(PrettyPrinter s) {
s.append("#");
s.append(getSlotName());
s.append("#");
s.lb();
}
public void SlotIntLiteralConstant.prettyPrint(PrettyPrinter s) {
getIntLiteralConstantSlot().prettyPrint(s);
public void SlotVariable.prettyPrint(PrettyPrinter s) {
s.append("#");
s.append(getSlotName());
s.append("#");
}
public void SlotVariable.prettyPrint(PrettyPrinter s) {
getVariableSlot().prettyPrint(s);
public void SlotDoConstruct.prettyPrint(PrettyPrinter s) {
s.append("#");
s.append(getSlotName());
s.append("#");
}
public void SlotExecutableConstruct.prettyPrint(PrettyPrinter s) {
getExecutableConstructSlot().prettyPrint(s);
s.append("#");
s.append(getSlotName());
s.append("#");
s.lb();
}
public void SlotExecutionPartConstruct.prettyPrint(PrettyPrinter s) {
s.append("#");
s.append(getSlotName());
s.append("#");
s.lb();
}
public void SlotForName.prettyPrint(PrettyPrinter s) {
getNameSlot().prettyPrint(s);
s.append("#");
s.append(getString());
s.append("#");
}
}
\ No newline at end of file
......@@ -19,55 +19,158 @@ body {
{
sb.append(line).append("\n");
}
System.out.println(preProcess(sb.toString()));
StringReader processedReader = new StringReader(preProcess(sb.toString()));
StringReader processedReader = new StringReader(removeLineBreaks(sb.toString()));
return new SlottableFortranParser(processedReader, file);
}
private static String preProcess(String content) {
String text = "";
private enum State {
Normal,Error,SChar,DChar,ComAmbi,Pragma,Comment,Cont,ContStart,ContSpace,ContAmbi,ContCom,ContPrag,ContinuedSCharBeginning,ContinuedSCharEnd,ContinuedDCharBeginning,ContinuedDCharEnd;
static public final Integer length = 1 + ContinuedDCharEnd.ordinal();
}
boolean continuedPragma = false;
boolean previousContinuedPragma = false;
public static class SuccessorState {
boolean continued = false;
boolean previousContinued = false;
private final State state;
private final Character replacement;
private final boolean keep;
for (String line : content.split("\n")) {
previousContinuedPragma = continuedPragma;
continuedPragma = false;
public SuccessorState(State state) {
this.state = state;
this.replacement = null;
this.keep = true;
}
previousContinued = continued;
continued = false;
public SuccessorState(State state, boolean keep) {
this.state = state;
this.replacement = null;
this.keep = keep;
}
line = trimRight(line);
if (line.startsWith("!$")) {
if (line.endsWith(" &")) {
continuedPragma = true;
line = trimRight(line.substring(0, line.length() - 2)) + " ";
} else {
line = line + "\n";
public SuccessorState(State state, Character replacement) {
this.state = state;
this.replacement = replacement;
this.keep = true;
}
} else if (line.startsWith("!")) {
line = line + "\n";
} else {
if (line.endsWith(" &")) {
continued = true;
line = trimRight(line.substring(0, line.length() - 2)) + " ";
} else {
line = line + "\n";
public State getState() {
return state;
}
public Character getReplacement() {
return replacement;
}
if (previousContinuedPragma) {
line = trimLeft(line.replaceFirst("!\\$\\w+& ", ""));
} else if (previousContinued) {
line = trimLeft(line);
public boolean getKeep() {
return keep;
}
}
public static String removeLineBreaks(String content) {
// state,character
SuccessorState table[][] = new SuccessorState[State.length][256];
int s = State.Normal.ordinal();
table[s][0] = new SuccessorState(State.Normal);
table[s]['!'] = new SuccessorState(State.ComAmbi);
table[s]['\"'] = new SuccessorState(State.DChar);
table[s]['\''] = new SuccessorState(State.SChar);
table[s]['&'] = new SuccessorState(State.Cont, false);
table[s][';'] = new SuccessorState(State.Normal, '\n');
s = State.ComAmbi.ordinal();
table[s][0] = new SuccessorState(State.Comment);
table[s]['$'] = new SuccessorState(State.Pragma);
s = State.Pragma.ordinal();
table[s][0] = new SuccessorState(State.Pragma);
table[s]['\n'] = new SuccessorState(State.Normal);
table[s]['&'] = new SuccessorState(State.Cont, false);
s = State.Comment.ordinal();
table[s][0] = new SuccessorState(State.Comment);
table[s]['\n'] = new SuccessorState(State.Normal);
s = State.SChar.ordinal();
table[s][0] = new SuccessorState(State.SChar);
table[s]['\''] = new SuccessorState(State.Normal);
table[s]['&'] = new SuccessorState(State.ContinuedSCharBeginning, false);
s = State.DChar.ordinal();
table[s][0] = new SuccessorState(State.DChar);
table[s]['\"'] = new SuccessorState(State.Normal);
table[s]['&'] = new SuccessorState(State.ContinuedDCharBeginning, false);
s = State.Cont.ordinal();
table[s][0] = new SuccessorState(State.Cont, false);
table[s]['\n'] = new SuccessorState(State.ContStart, false);
s = State.ContStart.ordinal();
table[s][0] = new SuccessorState(State.Normal);
table[s]['\n'] = new SuccessorState(State.ContStart, false);
table[s]['\t'] = new SuccessorState(State.ContStart);
table[s][' '] = new SuccessorState(State.ContStart);
table[s]['!'] = new SuccessorState(State.ContAmbi, false);
s = State.ContAmbi.ordinal();
table[s][0] = new SuccessorState(State.ContCom, false);
table[s]['$'] = new SuccessorState(State.ContPrag, false);
table[s]['\n'] = new SuccessorState(State.ContStart, false);
s = State.ContCom.ordinal();
table[s][0] = new SuccessorState(State.ContCom, false);
table[s]['\n'] = new SuccessorState(State.ContStart, false);
s = State.ContPrag.ordinal();
table[s][0] = new SuccessorState(State.ContPrag, false);
table[s][' '] = new SuccessorState(State.Normal);
table[s]['&'] = new SuccessorState(State.Normal, ' ');
s = State.ContinuedSCharBeginning.ordinal();
table[s][0] = new SuccessorState(State.ContinuedSCharBeginning, false);
table[s]['\n'] = new SuccessorState(State.ContinuedSCharEnd, false);
s = State.ContinuedDCharBeginning.ordinal();
table[s][0] = new SuccessorState(State.ContinuedDCharBeginning, false);
table[s]['\n'] = new SuccessorState(State.ContinuedDCharEnd, false);
s = State.ContinuedSCharEnd.ordinal();
table[s][0] = new SuccessorState(State.ContinuedSCharEnd, false);
table[s][' '] = new SuccessorState(State.ContinuedSCharEnd, false);
table[s]['\t'] = new SuccessorState(State.ContinuedSCharEnd, false);
table[s]['&'] = new SuccessorState(State.SChar, false);
s = State.ContinuedDCharEnd.ordinal();
table[s][0] = new SuccessorState(State.ContinuedSCharEnd, false);
table[s][' '] = new SuccessorState(State.ContinuedDCharEnd, false);
table[s]['\t'] = new SuccessorState(State.ContinuedDCharEnd, false);
table[s]['&'] = new SuccessorState(State.DChar, false);
State state = State.Normal;
StringBuilder r = new StringBuilder();
for (char c: content.toCharArray()) {
if (c > 255) {
c = 0;
}
SuccessorState t = table[state.ordinal()][c];
if (t == null) {
t = table[state.ordinal()][0];
}
state = t.getState();
if (t.getKeep()) {
Character replacement = t.getReplacement();
if (replacement == null) {
r.append(c);
} else {
r.append(replacement);
}
text = text + line;
}
return text;
}
return r.toString();
}
private static String trimRight(String s) {
......@@ -88,116 +191,116 @@ body {
// lift invisibility of potential fragments to public
public Expr expr := ... ;
public ExecutableConstruct executable_construct := ... ;
public ExecutionPartConstruct execution_part_construct := ... ;
public Name name := ... ;
public Block block := ... ;
public DoConstruct do_construct := ... ;
// == Slots ====================================================================
transient void NUMBERSIGN = "#";
//// abstract Slot ::= SlotName ;
//// SlotName ::= <String> ;
SlotName slot_name =
l:LETTERS
{
yyValue = new SlotName(l);
}
String slot_name =
yyValue:LETTERS
;
// == Expression Slots =========================================================
//// SlotExpr:Expr ::= ExprSlot ;
//// SlotExpr:Expr ::= <SlotName:String> ;
Expr expr +=
<ExprSlot> s:expr_slot
<ExprSlot> NUMBERSIGN n:slot_name (COLON E X P R)? NUMBERSIGN
{
yyValue = new SlotExpr(s);
yyValue = new SlotExpr(n);
}
/ <BEGINNING> ...
;
//// ExprSlot:Slot ;
ExprSlot expr_slot =
NUMBERSIGN n:slot_name NUMBERSIGN
// == DoConstruct Slots =========================================================
//// SlotDoConstruct:DoConstruct ::= <SlotName:String> ;
DoConstruct do_construct +=
<ExprSlot> NUMBERSIGN n:slot_name (COLON (D O C O N S T R U C T / S I M P L E D O C O N S T R U C T / O M P D O C O N S T R U C T / A C C L O O P C O N S T R U C T))? NUMBERSIGN LB
{
yyValue = new ExprSlot(n);
yyValue = new SlotDoConstruct(n);
}
/ <BEGINNING> ...
;
// == Variable Slots ===========================================================
// == Block Slots ===========================================================
//// SlotVariable:Variable ::= VariableSlot ;
Variable variable +=
<VariableSlot> s:variable_slot
//// SlotBlock:Block ::= <SlotName:String> ;
Block block +=
<BlockSlot> NUMBERSIGN n:slot_name (COLON B L O C K)? NUMBERSIGN LB
{
yyValue = new SlotVariable(s);
yyValue = new SlotBlock(new List(), n);
}
/ <BEGINNING> ...
;
//// VariableSlot:Slot ;
VariableSlot variable_slot =
NUMBERSIGN n:slot_name NUMBERSIGN
// == Variable Slots ===========================================================
//// SlotVariable:Variable ::= <SlotName:String> ;
Variable variable +=
<VariableSlot> NUMBERSIGN n:slot_name (COLON V A R I A B L E)? NUMBERSIGN
{
yyValue = new VariableSlot(n);
yyValue = new SlotVariable(n);
}
/ <BEGINNING> ...
;
// == Int Literal Slots ========================================================
//// SlotIntLiteralConstant:IntLiteralConstant ::= IntLiteralConstantSlot ;
//// SlotIntLiteralConstant:IntLiteralConstant ::= <SlotName:String> ;
IntLiteralConstant int_literal_constant +=
<IntLiteralConstantSlot> s:int_literal_constant_slot
<IntLiteralConstantSlot> NUMBERSIGN n:slot_name (COLON I N T L I T E R A L C O N S T A N T)? NUMBERSIGN
{
yyValue = new SlotIntLiteralConstant(new DigitString(""), new Opt<KindParam>(), s);
yyValue = new SlotIntLiteralConstant(new DigitString(""), new Opt<KindParam>(), n);
}
/ <BEGINNING> ...
;
//// IntLiteralConstantSlot:Slot ;
IntLiteralConstantSlot int_literal_constant_slot =
NUMBERSIGN n:slot_name NUMBERSIGN SS
{
yyValue = new IntLiteralConstantSlot(n);
}
;
// == Action Statement Slots ===================================================
// == Executable Construct Slots ===================================================
//// SlotExecutableConstruct:ExecutableConstruct ::= ExecutableConstructSlot ;
//// SlotExecutableConstruct:ExecutableConstruct ::= <SlotName:String> ;
ExecutableConstruct executable_construct +=
<ExecutableConstructSlot> s:executable_construct_slot
<ExecutableConstructSlot> NUMBERSIGN n:slot_name (COLON (E X E C U T A B L E C O N S T R U C T / A C C P A R A L L E L C O N S T R U C T / A C C D A T A C O N S T R U C T))? NUMBERSIGN LB
{
yyValue = new SlotExecutableConstruct(s);
yyValue = new SlotExecutableConstruct(n);
}
/ <BEGINNING> ...
;
//// ExecutableConstructSlot:Slot ;
ExecutableConstructSlot executable_construct_slot =
NUMBERSIGN n:slot_name NUMBERSIGN LB
// == Execution Part Construct Slots ===================================================
//// SlotExecutionPartConstruct:ExecutionPartConstruct ::= <SlotName:String> ;
ExecutionPartConstruct execution_part_construct +=
<ExecutionPartConstructSlot> NUMBERSIGN n:slot_name (COLON E X E C U T I O N P A R T C O N S T R U C T)? NUMBERSIGN LB
{
yyValue = new ExecutableConstructSlot(n);
yyValue = new SlotExecutionPartConstruct(n);
}
/ <BEGINNING> ...
;
// == Name Slots ===================================================
//// SlotForName:Name ::= NameSlot ;
//// SlotForName:Name ;
Name name +=
<NameSlot> s:name_slot
NUMBERSIGN n:slot_name (COLON F O R N A M E)? NUMBERSIGN SS
{
yyValue = new SlotForName("", s);
yyValue = new SlotForName(n);
}
/ <BEGINNING> ...
;
//// NameSlot:Slot ;
NameSlot name_slot =
NUMBERSIGN n:slot_name NUMBERSIGN SS
// ====================================================================
// LISTS
// ====================================================================
public List<ExecutableConstruct> executable_construct_list =
l:executable_construct*
{
yyValue = new NameSlot(n);
yyValue = new List<ExecutableConstruct>().addAll(l.list());
}
;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment