Skip to content

Commit

Permalink
RakuAST: change semantics of 2ast methods a bit
Browse files Browse the repository at this point in the history
Previously, the match object was supposed to contain an .ast value
(a RakuAST::Name object).  If this is not present, now it will
create a RakuAST::Name object for it using the stringification of
the match object.
  • Loading branch information
lizmat committed Oct 24, 2023
1 parent 57ea28d commit e008984
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
10 changes: 5 additions & 5 deletions src/Raku/Actions.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {

method term:sym<identifier>($/) {
self.attach: $/, Nodify('Call', 'Name').new:
name => Nodify('Name').from-identifier(~$<identifier>),
name => $<identifier>.core2ast,
args => $<args>.ast
}

Expand Down Expand Up @@ -2252,8 +2252,8 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
# TODO: <variable> being defined means we should throw an NYI
# Need to support anonymous enums
my $name := $<longname>
?? $<longname>.ast
!! Nodify('Name').from-identifier('');
?? $<longname>.ast
!! Nodify('Name').from-identifier('');
my $base-type := $*OFTYPE ?? $*OFTYPE.ast !! Nodify("Type");
my $decl := Nodify('Type', 'Enum').new(
:name($name),
Expand Down Expand Up @@ -2752,8 +2752,8 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {

method typename($/) {
my $base-name := $<longname>
?? $<longname>.ast
!! Nodify('Name').from-identifier('::?' ~ $<identifier>);
?? $<longname>.ast
!! Nodify('Name').from-identifier('::?' ~ $<identifier>);
for $<colonpair> {
$base-name.add-colonpair($_.ast);
}
Expand Down
21 changes: 13 additions & 8 deletions src/Raku/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -939,16 +939,21 @@ grammar Raku::Grammar is HLL::Grammar does Raku::Common {
token use-use { use }
# Convert the invocant, a match that is expected to have a RakuAST::Name
# object as its ".ast", to a RakuAST::Name object with the name of the
# the core functionality if there is an original name known. Otherwise
# it should just return the ".ast" of the invocant.
method core2ast() { self.ast }
# object as its ".ast" (or to have no ".ast" at all), to a RakuAST::Name
# object with the name of the core functionality if there is an original
# name known. Otherwise it should just return the ".ast" of the invocant.
method core2ast() {
self.ast // self.actions.r('Name').from-identifier(~self)
}
# Convert the invocant, a match that is expected to have a RakuAST::Name
# object as its ".ast", to a RakuAST::Name object with the name of the
# the trait_mod:<is> name if there is an original name known for it.
# Otherwise it should just return the ".ast" of the invocant.
method trait-is2ast() { self.ast }
# object as its ".ast" (or to have no ".ast" at all), to a RakuAST::Name
# object with the name of the trait_mod:<is> name if there is an
# original name known. Otherwise it should just return the ".ast" ofi
# the invocant.
method trait-is2ast() {
self.ast // self.actions.r('Name').from-identifier(~self)
}
# Convert the given postcircumfix adverb if there is an original name
# for it. Otherwise it should just return the adverb unchanged.
Expand Down

0 comments on commit e008984

Please sign in to comment.