Commit ddfb9d40 authored by Igor Dejanovic's avatar Igor Dejanovic

textX meta-language based on Xtext. WIP.

parent e49cebde
This diff is collapsed.
DOMMLiteModel:
"model" name=ID (shortDesc=STRING)? (longDesc=STRING)?
((dataTypes+=UserDataType)|
(constraintTypes+=ConstraintType))*
packages*=Package;
PackageElement:
Package|Classifier;
Classifier:
Entity|Service|ValueObject|Exception|DataType|ConstraintType;
DataType:
BuildInDataType|UserDataType|Enumeration;
ConstraintType:
ValidatorType|TagType;
ValidatorType:
UserValidatorType|BuildInValidatorType;
TagType:
UserTagType|BuildInTagType;
Feature:
Property|Operation;
TypedElement:
Feature|Parameter;
NamedElement:
DOMMLiteModel|PackageElement|FeatureCompartment|OperationCompartment|EnumerationLiteral|TypedElement;
/* Ugradeni elementi modela ne bi trebalo da se definisu u modelu vec trebaju biti automatski prisutni u svakom modelu*/
BuildInDataType:
"buildinDataType" name=ID
(shortDesc=STRING)? (longDesc=STRING)?;
BuildInValidatorType:
"buildinValidator" name=ID
("("(parameters+=ConstraintTypeParameter)?(","parameters+=ConstraintTypeParameter)* ")")?
("appliesTo"
((appliesToEntity?="_entity") |
(appliesToProperty?="_prop") |
(appliesToParameter?="_param") |
(appliesToOperation?="_op") |
(appliesToService?="_service") |
(appliesToValueObject?="_valueObject"))*)?
(shortDesc=STRING)? (longDesc=STRING)?;
BuildInTagType:
"buildinTagType" name=ID
("("(parameters+=ConstraintTypeParameter)?(","parameters+=ConstraintTypeParameter)* ")")?
("appliesTo"
((appliesToEntity?="_entity") |
(appliesToProperty?="_prop") |
(appliesToParameter?="_param") |
(appliesToOperation?="_op") |
(appliesToService?="_service") |
(appliesToValueObject?="_valueObject"))*)?
(shortDesc=STRING)? (longDesc=STRING)?;
UserDataType:
"dataType" name=ID (shortDesc=STRING)? (longDesc=STRING)?;
UserTagType:
"tagType" name=ID
("("(parameters+=ConstraintTypeParameter)?(","parameters+=ConstraintTypeParameter)* ")")?
("appliesTo"
((appliesToEntity?="_entity") |
(appliesToProperty?="_prop") |
(appliesToParameter?="_param") |
(appliesToOperation?="_op") |
(appliesToService?="_service") |
(appliesToValueObject?="_valueObject"))*)?
(shortDesc=STRING)? (longDesc=STRING)?;
UserValidatorType:
"validatorType" name=ID
("("(parameters+=ConstraintTypeParameter)?(","parameters+=ConstraintTypeParameter)* ")")?
("appliesTo"
((appliesToEntity?="_entity") |
(appliesToProperty?="_prop") |
(appliesToParameter?="_param") |
(appliesToOperation?="_op") |
(appliesToService?="_service") |
(appliesToValueObject?="_valueObject"))*)?
(shortDesc=STRING)? (longDesc=STRING)?;
Enum ConstraintTypeParameter:
string="_string"|
int="_int" |
ref="_ref" |
ellipsis="..."
;
Package:
"package" name=ID (shortDesc=STRING)? (longDesc=STRING)? "{"
(packageElements+=PackageElement)*
"}";
Entity:
"entity" name=ID
("extends" extends=[Entity])?
("depends" depends+=[Service] ("," depends+=[Service])*)?
(shortDesc=STRING)? (longDesc=STRING)?
"{"
key=BusinessKey
("repr" repr+=ReprParameter ("+" repr+=ReprParameter)*)?
("[" constraints+=ConstraintSpec ("," constraints+=ConstraintSpec)* "]")?
(features+=Feature)*
(featureCompartments+=FeatureCompartment)*
"}";
ReprParameter:
ReprParameterStr|ReprParameterRef;
ReprParameterStr:
paramValue=STRING;
ReprParameterRef:
paramValue=[Property];
BusinessKey:
"key" "{"
(properties+=Property)+
"}";
ConstraintSpec:
type=[ConstraintType] ("(" (parameters+=ConstraintParameter)? ("," parameters+=ConstraintParameter)* ")")?
;
ConstraintParameter:
ConstraintIntParameter|ConstraintRefParameter|ConstraintStrParameter
;
ConstraintStrParameter:
paramValue=STRING
;
ConstraintIntParameter:
paramValue=INT
;
ConstraintRefParameter:
paramValue = [Property]
;
Exception:
"exception" name=ID (shortDesc=STRING)? (longDesc=STRING)? "{"
(properties+=Property)*
"}";
FeatureCompartment:
"compartment" name=ID (shortDesc=STRING)? (longDesc=STRING)? "{"
(features+=Feature)*
"}";
Service:
"service" name=ID
("extends" extends=[Service])?
("depends" depends+=[Service] ("," depends+=[Service])*)?
(shortDesc=STRING)? (longDesc=STRING)?
"{"
("[" constraints+=ConstraintSpec ("," constraints+=ConstraintSpec)* "]")?
(operations+=Operation)*
(operationCompartmens+=OperationCompartment)*
"}";
OperationCompartment:
"compartment" name=ID (shortDesc=STRING)? (longDesc=STRING)? "{"
(operations+=Operation)*
"}";
ValueObject:
"valueObject" name=ID
("extends" extends=[ValueObject])?
("depends" depends+=[Entity] ("," depends+=[Entity])*)?
(shortDesc=STRING)? (longDesc=STRING)?
"{"
("[" constraints+=ConstraintSpec ("," constraints+=ConstraintSpec)* "]")?
(properties+=Property)*
"}";
Operation:
"op" ( (ordered?="ordered") |
(unique?="unique") |
(required?="required"))*
type=[Classifier] (many?="[" (multiplicity=INT)? "]")?
name=ID "("(parameters+=Parameter)?(","parameters+=Parameter)* ")"
("throws" exceptions+=[Exception] ("," exceptions+=[Exception])?)?
("[" constraints+=ConstraintSpec ("," constraints+=ConstraintSpec)* "]")?
(shortDesc=STRING)? (longDesc=STRING)?;
/*
Atribut i referenca su objedinjeni u jedinstvenom konceptu property
*/
Property:
"prop"
( (ordered?="ordered") |
(unique?="unique") |
(readonly?="readonly") |
(required?="required") )*
(containment?="+")?
type=[Classifier] (many?="[" (multiplicity=INT)? "]")? name=ID
("<>" oppositeEnd=[Property])?
("[" constraints+=ConstraintSpec ("," constraints+=ConstraintSpec)* "]")?
(shortDesc=STRING)? (longDesc=STRING)?
;
Parameter:
( (ordered?="ordered") |
(unique?="unique") |
(required?="required") )*
type=[Classifier] (many?="[" (multiplicity=INT)? "]")? name=ID
("[" constraints+=ConstraintSpec ("," constraints+=ConstraintSpec)* "]")?
(shortDesc=STRING)? (longDesc=STRING)?
;
Enumeration:
"enum" name=ID (shortDesc=STRING)? (longDesc=STRING)? "{"
(literals+=EnumerationLiteral)+
"}";
EnumerationLiteral:
name=ID value=STRING (shortDesc=STRING)? (longDesc=STRING)?;
// Enum DataType:
// Str="string"|Integer="int"|Boolean="bool"|DateTime="datetime"|Void="void"|Float="float";
# This is a reference example file that demonstrates all
# features of pyflies language
# base abstract test
# Used to specify timings for each test in the
# experiment
test base {
tmin 3000
tmax 5000
twait 3000
}
# test definition for simple visual
# this test is non-abstract (defines visual simple test type)
# but will not be used directly in experiment definition.
# It will be used as a base for all visual simple tests
# in this experiment.
test mytest:visual_simple {
shape square
size large
color white
}
# Inheritance.
# This test definition is non-abstract.
# It inherits definition from base and mytest
# therefore it does not need to specify test type or
# timing settings.
test mytest_3 < base, mytest {
trials 3
}
# This test is same as previous but defines
# a 30 trials to run.
test mytest_30< base, mytest {
trials 30
}
# Experiment consist of a sequence of blocks
# (tests, introductions, sequences and randomize).
experiment {
# subject block will collect data about
# the subject under experiment.
# A user will be presented with the GUI form to
# fill it. Experimenter may fill this on behalf of the subject.
# The form of the each subject line is:
# Variable_name, type, optional label
# Type can be: str, int, float or enumerated list
subject {
full_name str "First and last name"
age int
gender [Male, Female] "Gender"
}
# This is here just to show that test may be
# put under experiment directly.
# If the tests run in sequence (without randomization)
# this is an easiest way to define it.
test mytest_3
randomize {
# Following two sequences will
# be randomized.
# Sequence block will be performed in
# the order of definition.
sequence {
# This is an introduction to the following test.
# Introduction is text between ======== separators.
# Separator consist of at least 3 '=' characters.
================
Welcome
-------
In the following test you will be presented with a blank screen
where a white square will appear after a few seconds.
You should react by pressing the space bar as fast as you can when
the square appears.
This is a practice test with 3 trials.
Afterwards the real test will run with 30 trials.
Press space bar
================
# This test will run in practice mode.
# This mode tells experiment runner
# not to collect any sample data.
test mytest_3 practice
================
Real test with 30 trials
------------------------
Press space bar
================
# This is the real test run. Samples will be collected.
Test mytest_30
}
# This is here just to show that randomize block should contain
# more than 1 block. Those block runs will be randomized.
sequence {
test mytest_3 practice
=======
This is heading
---------------
This is just to show another introduction screen.
=======
test mytest_30
}
}
}
/*
This is a TextX definition of pyFlies DSL for Reaction Time test
experiments definition.
Author: Igor R. Dejanovic <igor DOT dejanovic AT gmail DOT com>
Copyright: (c) 2014 Igor R. Dejanovic <igor DOT dejanovic AT gmail DOT com>
License: MIT License
*/
PyFliesModel:
TestDef* Experiment
;
TestDef:
"test" name=ID (":" test_type=TestType)? ( "<" inherits*={[TestDef] ","} )? "{"
TestParam*
"}"
;
TestType:
name=ID
;
TestParam:
name=ID TestParamValue label=TestParamLabel?
;
TestParamValue:
(value=ID|FLOAT|INT|STRING)|( '[' value+={ID ","} ']')
;
TestParamLabel:
label = STRING
;
Block:
Intro|Test|Sequence|Randomize
;
Experiment:
'experiment' '{'
blocks=Block*
'}'
;
Sequence:
'sequence' '{'
blocks=Block*
'}'
;
Randomize:
'randomize' '{'
blocks=Block*
'}'
;
Test:
'test' type=[TestDef] practice?="practice"
;
Intro:
/====*/
content=/([^=][^=]?[^=]?)*/
/====*/
;
// Special rule for comments
Comment:
/#.*$/
;
#######################################################################
# Name: textx.py
# Purpose: Demonstration of textX meta-language.
# Author: Igor R. Dejanovic <igor DOT dejanovic AT gmail DOT com>
# Copyright: (c) 2014 Igor R. Dejanovic <igor DOT dejanovic AT gmail DOT com>
# License: MIT License
#######################################################################
from arpeggio.textx import get_parser
def main(debug=False):
# Load textX description of the language
with open('pyflies.tx', 'r') as f:
language_def = f.read()
# Create parser for the new lanuage
parser = get_parser(language_def, debug=debug)
# Parse pyflies example
with open('experiment.pf') as f:
pyflies_input = f.read()
parse_tree = parser.parse(pyflies_input)
result = parser.getASG()
if __name__ == "__main__":
# In debug mode dot (graphviz) files for parser model
# and parse tree will be created for visualization.
# Checkout current folder for .dot files.
main(debug=True)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment