Permalink
Fetching contributors…
Cannot retrieve contributors at this time
executable file 256 lines (218 sloc) 7.88 KB
/*******************************************************************************
* Copyright (c) 2012 BMW Car IT and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*******************************************************************************/
/**
* @author Birgit Engelmann - Initial contribution and API
*/
grammar org.jnario.feature.Feature with org.eclipse.xtend.core.Xtend
import "http://www.eclipse.org/Xtext/Xbase/XAnnotations" as xannotations
import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
import "http://www.eclipse.org/xtext/xbase/Xtype" as xtype
import "http://www.eclipse.org/xtend" as xtend
import "http://www.eclipse.org/xtext/common/JavaVMTypes" as types
import "http://www.org/Jnario"
import "http://www.org/jnario/feature/Feature"
import "http://www.eclipse.org/emf/2002/Ecore" as ecore
FeatureFile returns xtend::XtendFile:
{FeatureFile}
('package' package=QualifiedName)?
importSection=XImportSection?
xtendTypes+=Feature?
;
Feature returns xtend::XtendClass:
{Feature}
(annotations+=XAnnotation)*
name=FEATURE_TEXT
description=TEXT?
members+=Background?
members+=Scenario*;
Background:
{Background}
name=BACKGROUND_TEXT
(members+=Member)*
(members+=(Given|GivenReference) members+=(And|AndReference|But|ButReference)*)?;
Scenario :
{Scenario}
name=SCENARIO_TEXT
(members+=Member)*
(members+=(Given|GivenReference) members+=(And|AndReference|But|ButReference)*)?
(members+=(When|WhenReference) members+=(And|AndReference|But|ButReference)*)?
(members+=(Then|ThenReference) members+=(And|AndReference|But|ButReference)*)?;
Member returns xtend::XtendMember :
{xtend::XtendMember} annotations+=XAnnotation*
(
(
{xtend::XtendField.annotationInfo = current} modifiers+=CommonModifier*
(
modifiers+=FieldModifier modifiers+=CommonModifier*
type=JvmTypeReference? name=ValidID
|
modifiers+='extension' (modifiers+=FieldModifier | modifiers+=CommonModifier)*
type=JvmTypeReference name=ValidID?
|
modifiers+=FieldModifier (modifiers+=CommonModifier)* modifiers+='extension' (modifiers+=CommonModifier)*
type=JvmTypeReference name=ValidID?
|
type=JvmTypeReference name=ValidID
) ('=' initialValue=XExpression)? ';'?
)
);
GivenReference:
{GivenReference}
reference=[Given|GIVEN_TEXT]
;
Given:
{Given}
name=GIVEN_TEXT expression=BlockExpression
;
WhenReference:
{WhenReference}
reference=[When|WHEN_TEXT]
;
When:
{When}
name=WHEN_TEXT expression=BlockExpression
;
ThenReference:
{ThenReference}
reference=[Then|THEN_TEXT]
;
Then:
{Then}
name=THEN_TEXT expression=BlockExpression;
AndReference:
{AndReference}
reference=[And|AND_TEXT]
;
And:
{And}
name=AND_TEXT expression=BlockExpression
;
ButReference:
{ButReference}
reference=[But|BUT_TEXT]
;
But:
{But}
name=BUT_TEXT expression=BlockExpression
;
/*
* artificial node to simplify folding
*/
BlockExpression returns xbase::XBlockExpression:
(expressions+=XExpressionOrVarDeclaration ';'?)+;
//ExampleTable:
// name=EXAMPLE_TEXT
// columns+=ExampleColumn+ EXAMPLE_ROW_END
// (rows += ExampleRow)*;
//
//
//ExampleColumn:
// (PIPE | PIPE_SPACES) type=JvmTypeReference? name=ValidID ;
//
//ExampleRow:
// ((PIPE | PIPE_SPACES) cells+=XExpression)+ EXAMPLE_ROW_END;
XPrimaryExpression returns xbase::XExpression:
XConstructorCall |
XBlockExpression |
XSwitchExpression |
XSynchronizedExpression |
XFeatureCall |
XLiteral |
XIfExpression |
XForLoopExpression |
XBasicForLoopExpression |
XWhileExpression |
XDoWhileExpression |
XThrowExpression |
XReturnExpression |
XTryCatchFinallyExpression |
XParenthesizedExpression |
Assertion;
XRelationalExpression returns xbase::XExpression:
XOtherOperatorExpression
(
=>({Should.leftOperand=current}
( feature=[types::JvmIdentifiableElement|Should])) rightOperand=XOtherOperatorExpression |
=>({ShouldThrow.expression=current} (('should' 'throw') | 'throws')) type=JvmTypeReference |
=>({xbase::XInstanceOfExpression.expression=current} 'instanceof') type=JvmTypeReference |
=>({xbase::XBinaryOperation.leftOperand=current} feature=[types::JvmIdentifiableElement|OpCompare]) rightOperand=XOtherOperatorExpression)*;
Should:
'should' 'not'? ID
;
Assertion:
{Assertion}
'assert' expression=XExpression;
XConstructorCall returns xbase::XExpression:
XbaseConstructorCall (=>({xtend::AnonymousClass.constructorCall=current} '{') members+=AnonymousMember* '}')?
;
AnonymousMember returns xtend::XtendMember:
{xtend::XtendMember} annotations+=XAnnotation*
(
(
{xtend::XtendField.annotationInfo = current} modifiers+=CommonModifier*
(
modifiers+=FieldModifier modifiers+=CommonModifier*
type=JvmTypeReference? name=ValidID
|
modifiers+='extension' (modifiers+=FieldModifier | modifiers+=CommonModifier)*
type=JvmTypeReference name=ValidID?
|
modifiers+=FieldModifier (modifiers+=CommonModifier)* modifiers+='extension' (modifiers+=CommonModifier)*
type=JvmTypeReference name=ValidID?
|
type=JvmTypeReference name=ValidID
) ('=' initialValue=XExpression)? ';'?
) | (
{xtend::XtendFunction.annotationInfo = current} modifiers+=CommonModifier*
modifiers+=MethodModifier (modifiers+=CommonModifier | modifiers+=MethodModifier)*
('<' typeParameters+=JvmTypeParameter (',' typeParameters+=JvmTypeParameter)* '>')?
(
=>(returnType=JvmTypeReference createExtensionInfo=CreateExtensionInfo name=ValidID '(')
| =>(returnType=JvmTypeReference name=FunctionID '(')
| =>(returnType=TypeReferenceNoTypeArgs name=FunctionID '(')
| =>(createExtensionInfo=CreateExtensionInfo name=ValidID '(')
| name=FunctionID '('
)
(parameters+=Parameter (',' parameters+=Parameter)*)? ')'
('throws' exceptions+=JvmTypeReference (',' exceptions+=JvmTypeReference)*)?
(expression=XBlockExpression | expression=RichString | ';')?
)
)
;
terminal BACKGROUND_TEXT: "Background:" MNL;
terminal SCENARIO_TEXT: "Scenario:" MNL;
terminal FEATURE_TEXT: "Feature" COLON -> (BACKGROUND_TEXT|SCENARIO_TEXT);
terminal GIVEN_TEXT: 'Given ' STEP_WITH_ARGS;
terminal WHEN_TEXT: 'When ' STEP_WITH_ARGS;
terminal THEN_TEXT: 'Then ' STEP_WITH_ARGS;
terminal AND_TEXT: 'And ' STEP_WITH_ARGS;
terminal BUT_TEXT: 'But ' STEP_WITH_ARGS;
// this is a dummy token that will be generated by a custom TokenSource
terminal TEXT: '____dummy____'+;
terminal fragment STEP_WITH_ARGS: !('\r'|'\n')* '\r'? (('\n' SPACES RICH_TEXT? SPACES) | EOF);
terminal fragment MNL: !('\r'|'\n')* NL;
terminal fragment COLON: SPACES ':';
terminal fragment NL: '\r'? '\n'?;
terminal fragment SPACES: (' '|'\t')*;
terminal RICH_TEXT : "'''" IN_RICH_STRING* ("'''"| ("'" "'"?)? EOF);
terminal RICH_TEXT_START : "'''" IN_RICH_STRING* ("'" "'"?)? '«';
terminal RICH_TEXT_END : '»' IN_RICH_STRING* ("'''"| ("'" "'"?)? EOF) ;
terminal RICH_TEXT_INBETWEEN : '»' IN_RICH_STRING* ("'" "'"?)? '«';
terminal COMMENT_RICH_TEXT_INBETWEEN: "««" !('\n'|'\r')* ('\r'? '\n' IN_RICH_STRING* ("'" "'"?)? '«')?;
terminal COMMENT_RICH_TEXT_END: "««" !('\n'|'\r')* (('\r'? '\n' IN_RICH_STRING* ("'''"| ("'" "'"?)? EOF)) | EOF);
terminal fragment IN_RICH_STRING :
"''" !('«'|"'")
| "'" !('«'|"'")
| !('«'|"'");
/**
* Dummy rule, for "better" downwards compatibility, since GrammarAccess generates non-static inner classes,
* which makes downstream grammars break on classloading, when a rule is removed.
*/
StaticQualifier:
(ValidID '::')+
;