Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************
- * Copyright (c) 2015 itemis AG (http://www.itemis.eu) 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
- *******************************************************************************/
- grammar org.eclipse.xtext.example.homeautomation.RuleEngine with org.eclipse.xtext.xbase.Xbase
- import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
- generate ruleEngine "http://www.eclipse.org/Xtext/example/RuleEngine"
- Model:
- declarations+=Declaration*;
- Declaration:
- Device | Rule;
- Device:
- 'Device' name=ID 'can' 'be'
- (states+=State (',' states+=State)*)?;
- State:
- name=ID ;
- Rule:
- 'Rule' description=STRING
- 'when' deviceState=[State|QualifiedName]
- 'then' thenPart=XBlockExpression;
- // We modify the concrete syntax of two Xbase expressions and make them indentation-aware
- @Override
- XBlockExpression returns xbase::XExpression:
- {xbase::XBlockExpression}
- BEGIN
- (expressions+=XExpressionOrVarDeclaration ';'?)*
- END;
- @Override
- XSwitchExpression returns xbase::XExpression:
- {xbase::XSwitchExpression}
- 'switch' (=>('(' declaredParam=JvmFormalParameter ':') switch=XExpression ')'
- | =>(declaredParam=JvmFormalParameter ':')? switch=XExpression)
- BEGIN
- (cases+=XCasePart)*
- ('default' ':' default=XExpression )?
- END;
- // The following synthetic tokens are used for the indentation-aware blocks
- terminal BEGIN: 'synthetic:BEGIN'; // increase indentation
- terminal END: 'synthetic:END'; // decrease indentation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement