Commit 4e48d8de authored by Philip Makedonski's avatar Philip Makedonski
Browse files

+ proposed workaround for multiple comment and annotation fragments due to upstream issues

+ corresponding formatter adjustments
parent b49dba90
Loading
Loading
Loading
Loading
Loading
+48 −24
Original line number Diff line number Diff line
@@ -50,12 +50,30 @@ PackageableElement returns tdl::PackageableElement:
//Element : Abstract

fragment AnnotationFragment returns tdl::Element:
    (annotation+=Annotation)*
	'@' 
	//Workaround for upstream issue
	( 
		annotation+=Annotation
		| 
		('[' annotation+=Annotation (',' annotation+=Annotation)+ ']')
	)
;

fragment CommentFragment returns tdl::Element:
	'Note' 
	//Workaround for upstream issue
	( 
		comment+=SingleComment
		| 
		('[' comment+=MultiComment (',' comment+=MultiComment)+ ']')
	)
;


fragment AnnotationCommentFragment returns tdl::Element:
    (comment+=Comment)*
    (annotation+=Annotation)*
    CommentFragment?
    AnnotationFragment?
    //(annotation+=Annotation)*
;

fragment NameFragment returns tdl::Element:
@@ -65,7 +83,7 @@ fragment NameFragment returns tdl::Element:
fragment WithCommentFragment returns tdl::Element:
    'with'
    BEGIN
        (comment+=Comment)+
        CommentFragment
    END
;

@@ -89,13 +107,19 @@ ElementImport returns tdl::ElementImport:
    'from' importedPackage=[tdl::Package|QIdentifier]
;

Comment returns tdl::Comment:
    'Note' (name=NIdentifier)? 
SingleComment returns tdl::Comment:
    (name=NIdentifier)? 
    ':' body=EString
;

MultiComment returns tdl::Comment:
    (name=NIdentifier ':')? 
    body=EString
;


Annotation returns tdl::Annotation:
    '@' key=[tdl::AnnotationType|AIdentifier]
    key=[tdl::AnnotationType|AIdentifier]
    (':' value=EString)?
;

@@ -246,7 +270,7 @@ ProcedureSignature returns tdl::ProcedureSignature:
;

ProcedureParameter returns tdl::ProcedureParameter:
    AnnotationFragment
    AnnotationFragment?
    kind=ParameterKind
    dataType=[tdl::DataType|Identifier]
    name=Identifier
@@ -257,7 +281,7 @@ enum ParameterKind returns tdl::ParameterKind:
    In = 'in' | Out = 'out' | Exception = 'exception';

FormalParameter returns tdl::FormalParameter:
    AnnotationFragment
    AnnotationFragment?
    dataType=[tdl::DataType|Identifier]
    name=Identifier
    WithCommentFragment?
@@ -729,7 +753,7 @@ fragment WithBehaviourFragment returns tdl::Behaviour:
    BEGIN
        NameFragment?
        ObjectiveFragment?
        (comment+=Comment)*
        CommentFragment?
    END
;

@@ -742,7 +766,7 @@ Block returns tdl::Block:
    //NOTE: No annotations or comments
    ('[' 
//    	('@' annotation+=PICSAnnotation)? //TODO: Exception for PICS? seems not enough
		AnnotationFragment
		AnnotationFragment?
    	guard+=LocalExpression ( ',' guard+=LocalExpression)* 
	']')?
    BEGIN
@@ -773,7 +797,7 @@ fragment WithCombinedFragment returns tdl::CombinedBehaviour:
    BEGIN
        NameFragment?
        ObjectiveFragment?
        (comment+=Comment)*
        CommentFragment?
        (periodic+=PeriodicBehaviour //)*
        | exceptional+=ExceptionalBehaviour)*
    END
@@ -788,23 +812,23 @@ SingleCombinedBehaviour returns tdl::SingleCombinedBehaviour:
;

CompoundBehaviour returns tdl::CompoundBehaviour:
    AnnotationFragment
    AnnotationFragment?
    block=Block
;

BoundedLoopBehaviour returns tdl::BoundedLoopBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'repeat' numIteration+=LocalLoopExpression (',' numIteration+=LocalLoopExpression)*
    block=Block
;

UnboundedLoopBehaviour returns tdl::UnboundedLoopBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'while' block=Block
;

OptionalBehaviour returns tdl::OptionalBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'optionally' block=Block
;

@@ -815,7 +839,7 @@ MultipleCombinedBehaviour returns tdl::MultipleCombinedBehaviour:
;

ConditionalBehaviour returns tdl::ConditionalBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'if' block+=Block
    (=>('else' block+=Block)
    | (('else' 'if' block+=Block)* 
@@ -823,13 +847,13 @@ ConditionalBehaviour returns tdl::ConditionalBehaviour:
;

AlternativeBehaviour returns tdl::AlternativeBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'alternatively' block+=Block
    ('or' block+=Block)+ 
;

ParallelBehaviour returns tdl::ParallelBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'run' block+=Block 
    ('in' 'parallel' 'to' block+=Block)
    ('and' block+=Block)*
@@ -840,7 +864,7 @@ ExceptionalBehaviour returns tdl::ExceptionalBehaviour:
;

DefaultBehaviour returns tdl::DefaultBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'default' 
    ('on' guardedComponent=[tdl::ComponentInstance|Identifier])?
    block=Block
@@ -848,7 +872,7 @@ DefaultBehaviour returns tdl::DefaultBehaviour:
;

InterruptBehaviour returns tdl::InterruptBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'interrupt'
    ('on' guardedComponent=[tdl::ComponentInstance|Identifier])?
    block=Block
@@ -856,7 +880,7 @@ InterruptBehaviour returns tdl::InterruptBehaviour:
;

PeriodicBehaviour returns tdl::PeriodicBehaviour:
    AnnotationFragment
    AnnotationFragment?
    'every'
    (period+=LocalExpression (',' period+=LocalExpression)*)
    block=Block
@@ -1496,7 +1520,7 @@ fragment EventOccurrenceSpecificationFragment returns to::EventOccurrenceSpecifi
        (',' oppositeEntityReference+=OppositeEntityReference)*
    )?
    EventTimingSuffix?
    (comment+=Comment)*
    CommentFragment?
;

EntityReference returns to::EntityReference:
@@ -1708,7 +1732,7 @@ fragment EventTemplateOccurrenceFragment returns to::EventTemplateOccurrence:
        ('argument' 'replaced' 'by' occurrenceArgument=Argument)?
    END
    )?
    (comment+=Comment)*
    CommentFragment?
;

EntityBinding returns to::EntityBinding:
+40 −6
Original line number Diff line number Diff line
@@ -381,21 +381,55 @@ public class TDLtxFormatter extends AbstractJavaFormatter {
		//withKeyword.getNextSemanticRegion();
		//		var rbs = this.textRegionExtensions.regionFor(e).ruleCallTo(this._grammarAccess.());
			
		
		ISemanticRegion noteKeyword = this.textRegionExtensions.regionFor(e).keyword("Note");
		if (noteKeyword!=null) {
			doc.prepend(noteKeyword, newLine());
		}
		ISemanticRegion atKeyword = this.textRegionExtensions.regionFor(e).keyword("@");
		if (atKeyword!=null) {
			doc.prepend(atKeyword, newLine());
		}
		for (Comment c : e.getComment()) {
			if (e.getComment().size() > 1) {
				doc.prepend(c, newLine());
				doc.surround(c, indent());
			} else {
				if (!(e instanceof Member)) {
					doc.surround(c, indent());
				}
				if (!(e instanceof EntityReference)) {
					doc.append(c, newLine());
				}
			}
			doc.format(c);
		}
		
		for (Annotation a : e.getAnnotation()) {
			if (e.getAnnotation().size() > 1) {
				doc.prepend(a, newLine());
				doc.surround(a, indent());
			} else {
				doc.append(a, newLine());
			}
			doc.format(a); 
		}
		

		List<ISemanticRegion> closeItems = this.textRegionExtensions.allRegionsFor(e).keywords("]");
		for (ISemanticRegion r : closeItems) {
			doc.surround(r, newLine());
		}
		
//		List<ISemanticRegion> comments = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.get);
//		if (!comments.isEmpty()) {
//			doc.append(comments.get(0), newLine());
//		}
//		List<ISemanticRegion> annotations = this.textRegionExtensions.regionFor(e).ruleCallsTo(this._grammarAccess.getAnnotationFragmentRule());
//		if (!annotations.isEmpty()) {
//			doc.surround(annotations.get(0), newLine());
//		}
		
	}

	protected void format(org.etsi.mts.tdl.TestDescription e, IFormattableDocument doc) {