Skip to content

Commit e63f744

Browse files
authored
Merge pull request #777 from interscript/feat/qualified-aliases
feat: qualified alias refs through ISC
2 parents a72845e + 96e711b commit e63f744

5 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎lib/interscript/isc/generator.rb‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def item(i)
126126
when Interscript::Node::Item::Any
127127
any(i)
128128
when Interscript::Node::Item::Alias
129-
identifier(i.name)
129+
i.map ? "#{i.map}.#{identifier(i.name)}" : identifier(i.name)
130130
when Interscript::Node::Item::CaptureGroup
131131
"capture(#{item(i.data)})"
132132
when Interscript::Node::Item::CaptureRef

‎lib/interscript/isc/grammar/concerns/items.rb‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ module Items
101101
end
102102

103103
rule(:alias_reference) do
104-
(keyword.absent? >> identifier >> str("{").absent?).as(:alias)
104+
(keyword.absent? >> identifier >>
105+
(str(".") >> identifier.as(:qualified_name)).maybe >>
106+
str("{").absent?).as(:alias)
105107
end
106108

107109
# ref(N) — reference to Nth capture group. Only valid in `to` position.

‎lib/interscript/isc/items.rb‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,11 @@ def inspect
6262
end
6363

6464
class AliasRef
65-
attr_reader :name
65+
attr_reader :name, :map
6666

67-
def initialize(name)
67+
def initialize(name, map: nil)
6868
@name = name
69+
@map = map
6970
end
7071

7172
def inspect

‎lib/interscript/isc/node_adapter.rb‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def convert_item(item)
160160
when Items::Primitive
161161
convert_primitive(item)
162162
when Items::AliasRef
163-
Interscript::Node::Item::Alias.new(item.name.to_sym)
163+
convert_alias_ref(item)
164164
when Items::Capture
165165
Interscript::Node::Item::CaptureRef.new(item.index)
166166
when Items::Function
@@ -190,6 +190,10 @@ def convert_primitive(item)
190190
Interscript::Node::Item::Alias.new(item.name.to_sym)
191191
end
192192

193+
def convert_alias_ref(item)
194+
Interscript::Node::Item::Alias.new(item.name.to_sym, map: item.map&.to_sym)
195+
end
196+
193197
def convert_concat(concat)
194198
parts = concat.parts.map { |p| convert_item(p) }
195199
return parts.first if parts.size == 1

‎lib/interscript/isc/transform.rb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ class Transform < Parslet::Transform
5151
rule(none: simple(:_)) { Items::None.new }
5252
rule(primitive: simple(:p)) { Items::Primitive.new(p.to_s) }
5353
rule(function: simple(:f)) { Items::Function.new(f.to_s) }
54+
rule(alias: {identifier: simple(:n), qualified_name: simple(:q)}) {
55+
Items::AliasRef.new(q.to_s, map: n.to_s)
56+
}
5457
rule(alias: simple(:n)) { Items::AliasRef.new(n.to_s) }
5558
rule(ref: subtree(:h)) { Items::Capture.new(h[:digit].to_s.to_i) }
5659
rule(capture_inner: subtree(:inner)) { Items::CaptureGroup.new(Interscript::Isc::Transform.materialize_item(inner)) }

0 commit comments

Comments
 (0)