blob: 5197c6ebed412ee26ee4529a8d5ad20c8fb64ece [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2010 Willink Transformations and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* E.D.Willink - initial API and implementation
*******************************************************************************/
// Bug 567161 explains inlining of org.eclipse.xtext.common.Terminals
grammar org.eclipse.ocl.examples.xtext.idioms.Idioms hidden(WS, ML_COMMENT, SL_COMMENT) //with org.eclipse.xtext.common.Terminals
import "platform:/resource/org.eclipse.emf.ecore/model/Ecore.ecore" as ecore
import "platform:/resource/org.eclipse.ocl.examples.xtext.idioms/model/Idioms.ecore"
IdiomsModel:
'model' names+=ID ('.' names+=ID)* ownedWiths+=IdiomsImport* ownedImports+=EPackageImport* (ownedLocatorDeclarations+=LocatorDeclaration | ownedSegmentDeclarations+=SegmentDeclaration | ownedIdioms+=Idiom)* ;
EPackageImport:
'import' ePackage=[ecore::EPackage|STRING] ('as' ^as=ID)? ';'?;
IdiomsImport:
'with' idiomsModel=[IdiomsModel|STRING] ('as' ^as=ID)? ';'?;
LocatorDeclaration:
'locator' name=ID ownedLocator=Locator ';';
Locator:
AnyAssignmentLocator | AnyElementLocator | AssignmentLocator | FinalLocator | KeywordLocator | ReferredLocator | ReturnsLocator;
AnyAssignmentLocator:
{AnyAssignmentLocator} 'any-assignment';
AnyElementLocator:
{AnyElementLocator} 'any-element';
AssignmentLocator:
'assignment' ((ePackage=[ecore::EPackage|ID] '::')? eClass=[ecore::EClass|ID] '::')? eStructuralFeature=[ecore::EStructuralFeature];
FinalLocator:
{FinalLocator} 'final';
KeywordLocator:
string=STRING;
ReturnsLocator:
'returns' (ePackage=[ecore::EPackage|ID] '::')? eClass=[ecore::EClass|ID];
ReferredLocator:
(idiomsModel=[IdiomsModel|ID] '::')? locatorDeclaration=[LocatorDeclaration];
SegmentDeclaration:
'segment' name=ID ownedSegment=Segment ';' ;
Segment:
CustomSegment | HalfNewLineSegment | NewLineSegment | NoSpaceSegment | PopSegment | PostCommentSegment |
PreCommentSegment | PushSegment | SoftNewLineSegment | SoftSpaceSegment | StringSegment | ValueSegment |
WrapAnchorSegment | WrapBeginAllSegment | WrapBeginSomeSegment | WrapEndSegment | WrapHereSegment;
CustomSegment:
'custom' supportClassName=STRING;
HalfNewLineSegment:
{HalfNewLineSegment} 'half-new-line';
NewLineSegment:
{NewLineSegment} 'new-line';
NoSpaceSegment:
{NoSpaceSegment} 'no-space';
PopSegment:
{PopSegment} 'pop';
PostCommentSegment:
{PostCommentSegment} 'post-comment';
PreCommentSegment:
{PreCommentSegment} 'pre-comment';
PushSegment:
{PushSegment} 'push';
SoftNewLineSegment:
{SoftNewLineSegment} 'soft-new-line';
SoftSpaceSegment:
{SoftSpaceSegment} 'soft-space';
StringSegment:
'string' string=STRING printable?='printable';
ValueSegment:
{ValueSegment} 'value';
WrapAnchorSegment:
{WrapAnchorSegment} 'wrap-anchor';
WrapBeginAllSegment:
{WrapBeginAllSegment} 'wrap-begin-all';
WrapBeginSomeSegment:
{WrapBeginSomeSegment} 'wrap-begin-some';
WrapEndSegment:
{WrapEndSegment} 'wrap-end';
WrapHereSegment:
{WrapHereSegment} 'wrap-here';
ReferredSegment:
(idiomsModel=[IdiomsModel|ID] '::')? segmentDeclaration=[SegmentDeclaration];
Idiom:
mixin?='mixin'? 'idiom' name=ID ('for' (forEPackage=[ecore::EPackage|ID] '::')? forEClass=[ecore::EClass])? ('in' inRuleRegex=STRING)?
((ownedSubIdioms+=SubIdiom) | ('{' (ownedSubIdioms+=SubIdiom)* '}'));
SubIdiom:
'at' (all?='all' | 'each')? ownedLocator=Locator ('do' ownedSegments+=(Segment|ReferredSegment)*)? ';';
terminal ID: '^'?('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'_'|'0'..'9')*;
terminal INT returns ecore::EInt: ('0'..'9')+;
terminal STRING:
'"' ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|'"') )* '"' |
"'" ( '\\' . /* 'b'|'t'|'n'|'f'|'r'|'u'|'"'|"'"|'\\' */ | !('\\'|"'") )* "'"
;
terminal ML_COMMENT : '/*' -> '*/';
terminal SL_COMMENT : '//' !('\n'|'\r')* ('\r'? '\n')?;
terminal WS : (' '|'\t'|'\r'|'\n')+;
terminal ANY_OTHER: .;