Skip to content

Instantly share code, notes, and snippets.

@kthoms
Created March 8, 2013 05:39
Show Gist options
  • Save kthoms/5114439 to your computer and use it in GitHub Desktop.
Save kthoms/5114439 to your computer and use it in GitHub Desktop.
LWC13: QlDsl.xtext, Step2
grammar org.eclipse.xtext.example.ql.QlDsl with org.eclipse.xtext.xbase.Xbase
generate qlDsl "http://www.eclipse.org/xtext/example/ql/QlDsl"
/* The top-most container of QL files is a Questionnaire */
Questionnaire:
imports+=Import*
forms+=Form*;
/* Allows importing of qualified names of types */
Import:
'import' importedNamespace=QualifiedName;
/* QL consists of questions grouped in a top-level form construct. */
Form:
"form" name=ID "{"
element += FormElement*
"}";
/* Abstract rule for elements contained in a Form */
FormElement:
Question | ConditionalQuestionGroup
;
/**
* - Each question identified by a name that at the same time represents the result of the question.
* - A question has a label that contains the actual question text presented to the user.
* - Every question has a type.
* - A question can optionally be associated to an expression:
* this makes the question computed
*/
Question:
name=ID ":" label=STRING type=JvmTypeReference expression=XParenthesizedExpression?
;
/**
* Groups questions within a block, optionally made conditional with an if-condition.
*/
ConditionalQuestionGroup: {ConditionalQuestionGroup}
("if" condition=XParenthesizedExpression)? "{"
element += FormElement*
"}"
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment