Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.73 KB | None | 0 0
  1. /*******************************************************************************
  2.  * Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
  3.  * All rights reserved. This program and the accompanying materials
  4.  * are made available under the terms of the Eclipse Public License v1.0
  5.  * which accompanies this distribution, and is available at
  6.  * http://www.eclipse.org/legal/epl-v10.html
  7.  *******************************************************************************/
  8. grammar org.eclipse.xtext.example.homeautomation.RuleEngine with org.eclipse.xtext.xbase.Xbase
  9.  
  10. import "http://www.eclipse.org/xtext/xbase/Xbase" as xbase
  11. generate ruleEngine "http://www.eclipse.org/Xtext/example/RuleEngine"
  12.  
  13. Model:
  14.     declarations+=Declaration*;
  15.  
  16. Declaration:
  17.     Device | Rule;
  18.  
  19. Device:
  20.     'Device' name=ID 'can' 'be'
  21.         (states+=State (',' states+=State)*)?;
  22.  
  23. State:
  24.     name=ID ;
  25.  
  26. Rule:
  27.     'Rule' description=STRING
  28.         'when' deviceState=[State|QualifiedName]
  29.         'then' thenPart=XBlockExpression;
  30.  
  31. // We modify the concrete syntax of two Xbase expressions and make them indentation-aware
  32. @Override
  33. XBlockExpression returns xbase::XExpression:
  34.     {xbase::XBlockExpression}
  35.     BEGIN
  36.         (expressions+=XExpressionOrVarDeclaration ';'?)*
  37.     END;
  38.  
  39. @Override
  40. XSwitchExpression returns xbase::XExpression:
  41.     {xbase::XSwitchExpression}
  42.     'switch' (=>('(' declaredParam=JvmFormalParameter ':') switch=XExpression ')'
  43.         | =>(declaredParam=JvmFormalParameter ':')? switch=XExpression)
  44.     BEGIN
  45.         (cases+=XCasePart)*
  46.         ('default' ':' default=XExpression )?
  47.     END;
  48.  
  49. // The following synthetic tokens are used for the indentation-aware blocks
  50. terminal BEGIN: 'synthetic:BEGIN';  // increase indentation
  51. terminal END: 'synthetic:END';      // decrease indentation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement