Skip to content

Commit

Permalink
Merge 827a9eb into 899f1b1
Browse files Browse the repository at this point in the history
  • Loading branch information
igordejanovic committed Oct 22, 2020
2 parents 899f1b1 + 827a9eb commit c28863a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/functional/textx_textx/test_textx_rrel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from __future__ import unicode_literals
from os.path import join, abspath, dirname
from textx import metamodel_for_language, get_children_of_type


def test_textx_rrel_multi():

textx_mm = metamodel_for_language('textx')
grammar_model = textx_mm.grammar_model_from_file(
join(abspath(dirname(__file__)), 'textx_rrel_test.tx'))

rrels = get_children_of_type('RRELExpression', grammar_model)

# Multi
assert rrels[0].multi

# Multi with parent
assert rrels[1].multi \
and rrels[1].sequence.paths[0].parts[0].__class__.__name__ == 'RRELParent'

# Dots
dots = get_children_of_type('RRELPath', rrels[3])
assert any([x.dots == '..' for x in dots])

# Brackets
brackets = get_children_of_type('RRELBrackets', rrels[4])
assert len(brackets) == 1
12 changes: 12 additions & 0 deletions tests/functional/textx_textx/textx_rrel_test.tx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* Grammar for testing textX RREL parsing
This grammar is loaded for analysis, thus references and RREL expressions
are just syntactically valid to assert that grammar_model_from_file can
properly parse RRELs.
*/

Multi: ref=[Target|ID|+m:^some_rule];
MultiParent: ref=[Target|ID|+m:parent(SomeType).some_rule];
Parent: ref=[Target|ID|parent(SomeRule).obj.ref.~extension*.methods];
Dots: ref=[Target|ID|(..)*.(pkg)*.cls];
Brackets: ref=[Target|ID|obj.ref.(~extension)*.methods];
WhiteSpace: ref=[Target|ID|obj. ref.(~extension ) *. methods];
15 changes: 14 additions & 1 deletion textx/textx.tx
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,27 @@ BuiltinRuleRef:
;

ObjRef: // TODO: add RREL
'[' name=ClassName ('|' obj_ref_rule=ID)? ']'
'[' name=ClassName ('|' obj_ref_rule=ID ('|' rrel=RRELExpression))? ']'
;

ClassName:
QualifiedIdent
;


// RREL
RRELExpression: multi?="+m:" sequence=RRELSequence;
RRELSequence: paths+=RRELPath[','];
RRELPath: (up='^' | dots=RRELDots)? parts*=RRELPathPart['.'];
RRELPathPart: RRELZeroOrMore | RRELPathElement;
RRELZeroOrMore: element=RRELPathElement '*';
RRELPathElement: RRELParent | RRELBrackets | RRELNavigation;
RRELDots: /\.+/;
RRELBrackets: '(' sequence=RRELSequence ')';
RRELNavigation: noconsume?='~' attr=ID;
RRELParent: 'parent' '(' type=ID ')';


QualifiedIdent:
/\w+(\.\w+)?/
;
Expand Down

0 comments on commit c28863a

Please sign in to comment.