At the Phoenix HL7 meeting as decision was made to look at updating the GELLO grammar without making wholesale changes to the language. The current grammar is not correct and does not allow a parser to be built. MedicalObjects is leading this work.
The grammar below is the the latest candidate grammar. It is LALR(1). Medical-Objects is working on an open source GELLO editor that uses this grammar. Please email us if you are interested in trying this out before its official release.
This grammar follows the conventions set in the original version. The inclusion of method names in the grammar is unusual, but we have left those elements unchanged. The main change, of any significance, is the inclusion of an optional "in" keyword to allow disambiguation of the Let statements from the final expression when the final expression starts with a '+', a '-' or a '('. In normal use it is not required. This maintains backward compatibility with all the published GELLO examples.
GELLOExpression::= OuterExpression
OuterExpression::= Declarative+ ( ExpressionNP? | <IN> Expression ) | Expression
Declarative::= LetStatement | ContextNavigationStatement
InnerExpression::= LetStatement+ (ExpressionNP | <IN> Expression) | Expression
LetStatement::= <LET> <ID> ":" DataTypes <EQUAL> Expression
IfStatement::= <IF> Expression <THEN> InnerExpression <ELSE> InnerExpression <ENDIF>
ContextNavigationStatement::= ContextStatement | PackageStatement
ContextStatement::= <CONTEXT> ClassName ContextBlock | <CONTEXT> Alias ":" ClassName ContextBlock
ContextBlock::= ( ContextBody | DefinitionBody+ )
ContextBody::= <SELF> "." Expression | Expression
DefinitionBody::= <DEF> ":" <ID> ":" DataTypes <EQUAL> InnerExpression | <DEF> ":" <ID> "(" FormalParams? ")" ":" DataTypes <EQUAL> InnerExpression | <DEF> ":" <ID> (":" DataTypes)? <ARROW> <ID> "(" <ID>? "|" <ID>? ")"<EQUAL> InnerExpression
FormalParams::= <ID> ":" DataTypes ("," FormalParams )?
Alias::= <ID>
PackageStatement::= <PACKAGE> PackageName ContextStatement+ <ENDPACKAGE>
PackageName::= Name
Literal::= <STRING_LITERAL> | <INTEGER_LITERAL> | <REAL_LITERAL> | <TRUE> | <FALSE> | <UNKNOWN> | <NULL> | CollectionLiteral | TupleLiteral | "#" <ID>
CollectionLiteral::= CollectionType? "{" ( CollectionLiteralElement ( "," CollectionLiteralElement )* )? "}"
CollectionLiteralElement::= Expression ( ".." Expression )?
TupleLiteral::= <TUPLE> "{" TupleLiteralElement ( "," TupleLiteralElement )* "}"
TupleLiteralElement::= <ID> (":" DataTypes)? <EQUAL> Expression
DataTypes::= GELLOType | ModelTypes
GELLOType::= BasicType | CollectionType ("(" DataTypes ")")? | TupleType | EnumerationType
BasicType::= <INTEGER> | <STRING> | <REAL> | <BOOLEAN> ModelTypes::= ClassName
CollectionType::= <SET> | <BAG> | <SEQUENCE>
TupleType::= <TUPLE> "(" TupleTypeElement ( "," TupleTypeElement )* ")"
TupleTypeElement::= <ID> ":" DataTypes
EnumerationType::= <ENUM> "(" <ID> ( "," <ID> )* ")"
ClassName::= NameWithPath
NameWithPath::= Name ( "::" Name )*
Name::= <ID> ( "." <ID>)*
Expression::= ConditionalExpression
ConditionalExpression::= OrExpression
OrExpression::= ConditionalAndExpression (<OR> ConditionalAndExpression | <XOR> ConditionalAndExpression)*
ConditionalAndExpression::= ComparisonExpression (<AND> ComparisonExpression)*
ComparisonExpression::= AddExpression (<EQUAL> AddExpression | <NEQ> AddExpression | <LT> AddExpression | <LEQ> AddExpression | <GT> AddExpression | <GEQ> AddExpression)*
AddExpression::= MultiplyExpression (<MINUS> MultiplyExpression | <PLUS> MultiplyExpression)*
MultiplyExpression::= UnaryExpression (<TIMES> UnaryExpression | <DIVIDE> UnaryExpression | <MAX> UnaryExpression | <MIN> UnaryExpression | <INTDIV> UnaryExpression | <MOD> UnaryExpression )*
UnaryExpression::= PrimaryExpression | <NOT> UnaryExpression | <MINUS> UnaryExpression | <PLUS> UnaryExpression
PrimaryExpression::= Literal | Operand | ReferenceToInstance | IfStatement | "(" Expression ")"
ExpressionNP::= ConditionalExpressionNP
ConditionalExpressionNP::= OrExpressionNP
OrExpressionNP::= ConditionalAndExpressionNP (<OR> ConditionalAndExpression | <XOR> ConditionalAndExpression)*
ConditionalAndExpressionNP::= ComparisonExpressionNP (<AND> ComparisonExpression)*
ComparisonExpressionNP::= AddExpressionNP (<EQUAL> AddExpression | <NEQ> AddExpression | <LT> AddExpression | <LEQ> AddExpression | <GT> AddExpression | <GEQ> AddExpression)*
AddExpressionNP::= MultiplyExpressionNP(<MINUS> MultiplyExpression | <PLUS> MultiplyExpression)*
MultiplyExpressionNP::= UnaryExpressionNP (<TIMES> UnaryExpression | <DIVIDE> UnaryExpression | <MAX> UnaryExpression | <MIN> UnaryExpression | <INTDIV> UnaryExpression | <MOD> UnaryExpression )*
UnaryExpressionNP::= PrimaryExpressionNP | <NOT> UnaryExpression
PrimaryExpressionNP::= Literal | Operand | ReferenceToInstance | IfStatement
Operand::= <ID> | Operand "." <ID> | Operand "." StringOperation | Operand "." TupleOperation | Operand "." StringOrTupleSize | Operand "(" ParameterList ")" | Operand "[" ExpressionList "]" | Operand <ARROW> CollectionBody | CollectionLiteral <ARROW> CollectionBody
CollectionBody::= NonParamExp | SelectionExp | QuantifierExp | SingleObjExp | ListObjExp | GetExp | SetExp | IterateExp | JoinExp
SelectionExp::= <SELECT> "(" CExp ")" | <REJECT> "(" CExp ")" | <COLLECT> "(" CExp ")"
QuantifierExp::= <FORALL> "(" CExp ")" | <EXISTS> "(" CExp ")"
CExp::= ConditionalExpression | ConditionalExpressionWithIterator | ConditionalExpressionWithIteratorType
ConditionalExpressionWithIterator::= <ID> "|" ConditionalExpression
ConditionalExpressionWithIteratorType::= <ID> ":" DataTypes "|" ConditionalExpression
NonParamExp::= <SIZE> "(" ")" | <ISEMPTY> "(" ")" | <NOTEMPTY> "(" ")" | <SUM> "(" ")" | <REVERSE> "(" ")" | <MIN> "(" ")" | <MAX> "(" ")" | <FLATTEN> "(" ")" | <AVERAGE> "(" ")" | <MEAN> "(" ")" | <MEDIAN> "(" ")" | <MODE> "(" ")" | <STDEV> "(" ")" | <VARIANCE> "(" ")" | <DISTINCT> "(" ")"
SingleObjExp::= <COUNT> "(" Object ")" | <INCLUDES> "(" Object ")" | <INCLUDING> "(" Object ")" | <EXCLUDING> "(" Object ")"
ListObjExp::= <INCLUDESALL> "(" ObjectList ")" | <SORTBY> "(" PropertyList ")"
GetExp::= <FIRSTN> "(" Expression ")" | <LASTN> "(" Expression ")" | <ELEMAT> "(" Expression ")" | <LIKE> "(" Expression ")" | <NOTLIKE> "(" Expression ")" | <BETWEEN> "(" Expression "," Expression ")"
SetExp::= <INTERSECTION> "(" Expression ")" | <UNION> "(" Expression ")"
IterateExp::= <ITERATE> "(" IterateParameterList ")"
JoinExp::= <JOIN> "(" ParameterList ";" ParameterList ";" ConditionalExpression ";" ParameterList ")"
StringOperation::= StrConcat | StrToUpper | StrToLower | Substring
StringOrTupleSize::= <SIZE> "(" ")"
StrConcat::= <CONCAT> "(" Expression ")"
StrToUpper::= <TOUPPER> "(" ")"
StrToLower::= <TOLOWER> "(" ")"
Substring::= <SUBSTRING> "(" Expression "," Expression ")"
TupleOperation::= TupleGetValue | TupleGetElemName | TupleGetElemType
TupleGetValue::= <GETVALUE> "(" TupleElemName ")"
TupleGetElemName::= <GETELEMNAME> "(" Expression ")"
TupleGetElemType::= <GETELEMTYPE> "(" Expression ")"
IterateParameterList::= <ID> (":" DataTypes)? ";" <ID> ":" DataTypes <EQUAL> Expression "|" Expression
ParameterList::= ExpressionList?
ExpressionList::= Expression ("," Expression)*
ObjectList::= Object ("," Object)*
Object::= Expression
PropertyList::= Property ("," Property)*
Property::= Name
TupleElemName::= Name
ReferenceToInstance::= <FACTORY> "." <ID> "(" ParameterList ")"
<DECIMAL_LITERAL: (["0"-"9"])+ >
<EXPONENT: ["e", "E"] (["+","-"])? (["0"-"9"])+>
<INTEGER_LITERAL: <DECIMAL_LITERAL>>
<REAL_LITERAL: <DECIMAL_LITERAL> "." (["0"-"9"])* (<EXPONENT>)? | "." (["0"-"9"])+ (<EXPONENT>)? >
<STRING_LITERAL: ('\"' (~[ '\"' , "\n", "\r"])* '\"' | "\'" (~[ "\'" , "\n", "\r"])* "\'" ) >
<ID: ["a"-"z","A"-"Z"] (["a"-"z","A"-"Z","0"-"9"] | "_"(["a"-"z","A"-"Z","0"-"9"])+)* >
<BAG: "Bag">
<BOOLEAN: "Boolean">
<ENUM: "Enum">
<INTEGER: "Integer">
<REAL: "Real">
<SEQUENCE: "Sequence">
<SET: "Set">
<STRING: "String">
<SELF: "Self">
<TUPLE: "Tuple" >
<AND: "&" | "and" >
<ARROW: "->" >
<AVERAGE: "average" >
<BETWEEN: "between" >
<COLLECT: "collect" >
<CONCAT: "concat" >
<COUNT: "count" >
<DEF: "Def" | "def" >
<DISTINCT: "distinct" >
<DIVIDE: "/" >
<ELEMAT: "elemAt" >
<EXCLUDING: "excluding" >
<EXISTS: "exists" >
<FACTORY: "factory" >
<FALSE: "false" | "False" >
<FIRSTN: "firstN" >
<FLATTEN: "flatten" >
<FORALL: "forAll" >
<EQUAL: "=" >
<GEQ: ">=" >
<GETELEMNAME: "getElemName" >
<GETELEMTYPE: "getElemType" >
<GETVALUE: "getValue" >
<GT: ">" >
<INCLUDES: "includes" >
<INCLUDESALL: "includesAll" >
<INCLUDING: "including" >
<INTDIV: "div" >
<INTERSECTION: "intersection" >
<ISEMPTY: "isEmpty" >
<ITERATE: "iterate" >
<JOIN: "join" >
<LASTN: "lastN" >
<LEQ: "<=" >
<LIKE: "like" >
<LT: "<" >
<MAX: "max" >
<MEAN: "mean">
<MEDIAN: "median" >
<MIN: "min" >
<MINUS: "-" >
<MOD: "mod" >
<MODE: "mode" >
<NEQ: "!=" | "<>" >
<NOT: "!" | "not" >
<NOTEMPTY: "notEmpty" >
<NOTLIKE: "notlike" >
<OR: "or" >
<PLUS: "+" >
<REJECT: "reject" >
<REVERSE: "reverse" >
<SELECT: "select" >
<SIZE: "size" >
<SORTBY: "sortBy" >
<STDEV: "stdev" >
<SUBSTRING: "substring" >
<SUM: "sum" >
<TIMES: "*" >
<TOLOWER: "toLower" >
<TOUPPER: "toUpper">
<TRUE: "true" | "True" >
<UNION: "union" >
<UNKNOWN: "unknown" | "Unknown" >
<VARIANCE: "variance" >
<XOR: "*|" | "xor" >
<CONTEXT: "context" | "Context">
<ELSE: "else" >
<ENDPACKAGE: "endPackage" | "EndPackage" | "endpackage">
<ENDIF: "endif" >
<IF: "If" | "if" >
<LET: "Let" | "let" >
<PACKAGE: "Package" | "package">
<THEN: "then" >
<IN: "in" >
<NULL: "null" >
|