-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
729 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
tests/functional/test_scoping/components_model1/example_uppercase.components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package interfaces { | ||
interface B | ||
interface C | ||
} | ||
package base { | ||
interface A | ||
interface D | ||
component Start { | ||
out output1 (format A) | ||
} | ||
component Middle { | ||
in input2 (format A,interfaces.B,interfaces.C) | ||
out output2 (format interfaces.B,interfaces.C,D) | ||
} | ||
component End { | ||
in input3 (format interfaces.B,interfaces.C,D) | ||
} | ||
} | ||
|
||
package usage { | ||
instance start : base.Start | ||
instance action1 : base.Middle | ||
instance action2 : base.Middle | ||
instance action3 : base.Middle | ||
instance end : base.End | ||
|
||
connect start.OUTPUT1 to action1.INPUT2 | ||
connect action1.OUTPUT2 to action2.INPUT2 | ||
connect action2.OUTPUT2 to action3.INPUT2 | ||
connect action3.OUTPUT2 to end.INPUT3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
tests/functional/test_scoping/test_name_resolver/file1.model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import "file2.model" | ||
|
||
package p1 { | ||
component; | ||
component unnamed_1; | ||
component unnamed_4; | ||
|
||
package p2 { | ||
component unnamed_2; | ||
component unnamed_3; | ||
package p3 { | ||
component; // unnamed_0 | ||
component; // unnamed_1 | ||
component; // unnamed_2 | ||
|
||
instance i0: unnamed_0 | ||
instance i1: unnamed_1 | ||
instance i2: unnamed_2 | ||
instance i3: unnamed_3 // from p2 | ||
instance i4: unnamed_4 // from p1 | ||
instance i5: p1.unnamed_4 // from p1 | ||
instance i6: p1.unnamed_0 // from p1 | ||
instance i7: p1.unnamed_3 // from p1 (other file) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package p1 { | ||
component; | ||
component; | ||
component; | ||
component; | ||
} |
96 changes: 96 additions & 0 deletions
96
tests/functional/test_scoping/test_name_resolver/test_issue193_auto_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from __future__ import unicode_literals | ||
import textx | ||
from textx.scoping import Postponed | ||
from textx.scoping.providers import default_name_resolver | ||
from textx.scoping.tools import resolve_model_path | ||
|
||
|
||
MyLanguage = r""" | ||
Model | ||
: (locations+=Location)* | ||
(employees+=Employee)* | ||
(positions+=Position)* | ||
(projects+=Project)* | ||
; | ||
Project | ||
: 'project' name=ID | ||
('{' | ||
('use' use=[Position])* | ||
'}')? | ||
; | ||
Position | ||
: 'define' 'position' employee=[Employee|FQN] | ||
'->' location=[Location|FQN] ('as' name=ID)? | ||
; | ||
Employee | ||
: 'employee' name=ID | ||
; | ||
Location | ||
: 'location' name=ID | ||
( '{' | ||
(sub_location+=Location)+ | ||
'}')? | ||
; | ||
FQN | ||
: ID('.' ID)* | ||
; | ||
Comment: | ||
/\/\/.*$/ | ||
; | ||
""" | ||
|
||
MyCode = """ | ||
location Building | ||
{ | ||
location Entrance | ||
location Exit | ||
} | ||
employee Hans | ||
employee Juergen | ||
// Shall be referred to with the given name: "EntranceGuy" | ||
define position Hans->Building.Entrance as EntranceGuy | ||
// Shall be referred to with the autogenerated name: | ||
// <Employee>"At"<LastLocation> | ||
define position Juergen->Building.Exit | ||
project SecurityProject | ||
{ | ||
use EntranceGuy | ||
use JuergenAtExit | ||
} | ||
""" | ||
|
||
|
||
def test_issue193_auto_name(): | ||
meta_model = textx.metamodel_from_str(MyLanguage) | ||
|
||
def position_name_generator(obj): | ||
if obj is None: | ||
return None | ||
elif textx.textx_isinstance(obj, meta_model["Position"]): | ||
if obj.name is not None and len(obj.name) > 0: | ||
return obj.name | ||
location = resolve_model_path(obj, "location") | ||
employee = resolve_model_path(obj, "employee") | ||
if type(location) is Postponed or type(employee) is Postponed: | ||
return Postponed() | ||
assert location is not None and employee is not None | ||
return employee.name + "At" + location.name | ||
else: | ||
return default_name_resolver(obj) | ||
|
||
meta_model.register_scope_providers({ | ||
"*.*": textx.scoping.providers.FQN( | ||
name_resolver=position_name_generator), | ||
}) | ||
|
||
model = meta_model.model_from_str(MyCode) | ||
assert model, "Could not create model..." |
Oops, something went wrong.