From 1b6986193d5e29c2dddeb54d0775a6db373cb47e Mon Sep 17 00:00:00 2001 From: Elizabeth Mattijsen Date: Thu, 18 Jun 2020 16:37:53 +0200 Subject: [PATCH] Remove some superfluous grammar.new's 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. --- S05-grammar/action-stubs.t | 6 +++--- S05-grammar/protoregex.t | 2 +- S12-meta/grammarhow.t | 2 +- S15-nfg/GraphemeBreakTest.t | 4 ++-- integration/99problems-41-to-50.t | 12 ++++++------ 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/S05-grammar/action-stubs.t b/S05-grammar/action-stubs.t index 532c3be53e..554564987e 100644 --- a/S05-grammar/action-stubs.t +++ b/S05-grammar/action-stubs.t @@ -89,7 +89,7 @@ is $action.calls, 'ab', '... and in the right order'; method value($/) { make 1..$/}; method TOP($/) { make 1 + $/}; } - 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'; @@ -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( @@ -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)'; diff --git a/S05-grammar/protoregex.t b/S05-grammar/protoregex.t index 29b1371f28..2354647ba9 100644 --- a/S05-grammar/protoregex.t +++ b/S05-grammar/protoregex.t @@ -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.ast, 'bazbaz', 'action method got called, make() worked'; diff --git a/S12-meta/grammarhow.t b/S12-meta/grammarhow.t index b38e176f8a..b741f464fa 100644 --- a/S12-meta/grammarhow.t +++ b/S12-meta/grammarhow.t @@ -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 diff --git a/S15-nfg/GraphemeBreakTest.t b/S15-nfg/GraphemeBreakTest.t index 0790334de3..ed48c09515 100755 --- a/S15-nfg/GraphemeBreakTest.t +++ b/S15-nfg/GraphemeBreakTest.t @@ -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 { diff --git a/integration/99problems-41-to-50.t b/integration/99problems-41-to-50.t index 97c8a12d97..611f118e80 100644 --- a/integration/99problems-41-to-50.t +++ b/integration/99problems-41-to-50.t @@ -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', @@ -237,8 +237,8 @@ plan 13; method term:sym($/) { make $.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', @@ -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',