/******************************************************************************* * Copyright (c) 2017, 2018 Armines * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License 2.0 which is available at * https://www.eclipse.org/legal/epl-2.0/ * * This Source Code may also be made available under the following Secondary * Licenses when the conditions for such availability set forth in the Eclipse * Public License, v. 2.0 are satisfied: GNU General Public License, version 3 * which is available at https://www.gnu.org/licenses/gpl-3.0.txt * * Contributors: * fmdkdd - initial implementation *******************************************************************************/ grammar org.atlanmod.emfviews.vpdl.Vpdl with org.eclipse.xtext.common.Terminals generate vpdl "http://www.atlanmod.org/emfviews/vpdl/0.3.0" import "http://www.eclipse.org/emf/2002/Ecore" as ecore // Grammar for an SQL-like language to create model viewpoints // to use with EMFViews View: K_CREATE K_VIEW name=ID K_AS select=Select from=From where=Where?; Select: K_SELECT features+=SelectFeature (',' features+=SelectFeature)* ','?; SelectFeature: metamodel=[Metamodel] '.' class=[ecore::EClass] rest=SelectFeatureRest; SelectFeatureRest: '.' features+=Attribute | features+=Relation | '[' features+=Feature (',' features+=Feature)* ','? ']' | features+=AllAttributes; Feature: Attribute | Relation; AllAttributes: wildcard='.*'; Attribute: attribute=[ecore::EStructuralFeature]; Relation: K_JOIN metamodelRight=[Metamodel] '.' classRight=[ecore::EClass] K_AS name=ID; From: K_FROM metamodels+=Metamodel (',' metamodels+=Metamodel)* ','?; Metamodel: nsURI=STRING K_AS name=ID; Where: K_WHERE rules+=Rule (',' rules+=Rule)* ','? ; Rule: condition=BoolExpr K_FOR relation=[Relation] ; K_CREATE: 'create' | 'CREATE'; K_VIEW: 'view' | 'VIEW'; K_AS: 'as' | 'AS'; K_FOR: 'for' | 'FOR'; K_JOIN: 'join' | 'JOIN'; K_FROM: 'from' | 'FROM'; K_WHERE: 'where' | 'WHERE'; K_SELECT: 'select' | 'SELECT'; // Boolean expression grammar for the WHERE clause BoolExpr: BoolExprSimple ({Comparison.left=current} op=BoolOp right=BoolExprSimple)* ; BoolExprSimple returns BoolExpr: Constant | Nav | '(' BoolExpr ')' ; Constant: {IntLiteral} value=INT | {BoolLiteral} value=BOOL | {StringLiteral} value=STRING ; terminal BOOL: 'true' | 'false'; Nav: start=ID ('.' body+=NavRest)*; NavRest: NavFeature | MethodCall; NavFeature: name=ID; MethodCall: method=ID '(' (args+=MethodArg (',' args+=MethodArg)*)? ')'; MethodArg: BoolExpr | Lambda; Lambda: arg=ID '|' body=BoolExpr; enum BoolOp: EQ='=' | NEQ='<>' | LT='<' | LTEQ='<=' | GT='>' | GTEQ='>=' | AND='and' | OR='or' ;