Skip to content

Commit

Permalink
Remove some superfluous grammar.new's
Browse files Browse the repository at this point in the history
Unless your grammar actually contains non-system attributes that need
instantiating, you do *not* need to instantiate a grammar in order to
be able go parse strings with it.

Saves one unnecessary call to Match::BUILD.
  • Loading branch information
lizmat committed Jun 18, 2020
1 parent cfe16b9 commit 1b69861
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
6 changes: 3 additions & 3 deletions S05-grammar/action-stubs.t
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ is $action.calls, 'ab', '... and in the right order';
method value($/) { make 1..$/};
method TOP($/) { make 1 + $/<value>};
}
my $match = Math.parse('234', :actions(Actions.new));
my $match = Math.parse('234', :actions(Actions));
ok $match, 'can parse with action stubs that make() regexes';
is $match.ast, 235, 'got the right .ast';

Expand All @@ -110,7 +110,7 @@ is $action.calls, 'ab', '... and in the right order';
}
}

is ActionsTestGrammar.parse("ab\ncd", :actions(TestActions.new)).ast, 123,
is ActionsTestGrammar.parse("ab\ncd", :actions(TestActions)).ast, 123,
'Can call Str.subst in an action method without any trouble';
# https://github.com/Raku/old-issue-tracker/issues/2231
isa-ok ActionsTestGrammar.parse('a', :actions(
Expand All @@ -130,7 +130,7 @@ is $action.calls, 'ab', '... and in the right order';
};

my $x = Grammar::Trivial.parse: 'a',
actions => Grammar::Trivial::A.new;
actions => Grammar::Trivial::A;
ok $x, 'Trivial grammar parsed';
is $x.ast[0], 1, 'make(List) (1)';
is $x.ast[1], 2, 'make(List) (2)';
Expand Down
2 changes: 1 addition & 1 deletion S05-grammar/protoregex.t
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SomeActions {
}
}

ok ($match = Alts.subparse('argl', :actions(SomeActions.new))),
ok ($match = Alts.subparse('argl', :actions(SomeActions))),
'can parse with action methods';
is $match<alt>.ast, 'bazbaz', 'action method got called, make() worked';

Expand Down
2 changes: 1 addition & 1 deletion S12-meta/grammarhow.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class Foo::Actions {
}
}

lives-ok { Foo.new.parse('', :actions(Foo::Actions.new)) }
lives-ok { Foo.parse('', :actions(Foo::Actions)) }

# vim: expandtab shiftwidth=4
4 changes: 2 additions & 2 deletions S15-nfg/GraphemeBreakTest.t
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ sub process-line (Str:D $line, @fail, :@only!) {
return if $line.starts-with('#');
my Bool:D $fudge-b = %fudged-tests{$line-no}:exists ?? True !! False;
note 'LINE: [' ~ $line ~ ']' if $DEBUG;
my $list = GraphemeBreakTest.new.parse(
my $list = GraphemeBreakTest.parse(
$line,
actions => parser.new
actions => parser
).made;
die "line $line-no undefined parse" if $list.defined.not;
if $fudge-b {
Expand Down
12 changes: 6 additions & 6 deletions integration/99problems-41-to-50.t
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ plan 13;

}

my $parser = LogicalExpr.new;
my $actions = LogicalExpr::Actions.new;
my $parser = LogicalExpr;
my $actions = LogicalExpr::Actions;

is-deeply $parser.truth-table('table(A,B,and(A,or(A,B))).',$actions),
['true true true',
Expand Down Expand Up @@ -237,8 +237,8 @@ plan 13;
method term:sym<paren>($/) { make $<term>.ast }
}

my $parser = LogicalExpr::Infix.new;
my $actions = LogicalExpr::Infix::Actions.new;
my $parser = LogicalExpr::Infix;
my $actions = LogicalExpr::Infix::Actions;

is-deeply $parser.truth-table('table(A,B, A and (A or not B)).',$actions),
['true true true',
Expand Down Expand Up @@ -269,8 +269,8 @@ plan 13;
# fail fail fail true

# w'eve already done the heavy lifting
my $parser = LogicalExpr::Infix.new;
my $actions = LogicalExpr::Infix::Actions.new;
my $parser = LogicalExpr::Infix;
my $actions = LogicalExpr::Infix::Actions;

is-deeply $parser.truth-table('table(A,B,C, A and (B or C) equ A and B or A and C).',$actions),
['true true true true',
Expand Down

0 comments on commit 1b69861

Please sign in to comment.