From 7ab22a6ef219203e81c267e10b35a0225b3a0365 Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Wed, 6 Feb 2019 13:39:33 +0100 Subject: [PATCH 1/3] Force word boundary after alphanumeric prefix op Closes #408. --- lib/_007/Parser/Syntax.pm6 | 2 +- t/features/custom-ops.t | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/_007/Parser/Syntax.pm6 b/lib/_007/Parser/Syntax.pm6 index c3689f39..c1dd306a 100644 --- a/lib/_007/Parser/Syntax.pm6 +++ b/lib/_007/Parser/Syntax.pm6 @@ -155,7 +155,7 @@ grammar _007::Parser::Syntax { method prefix { my @ops = $*parser.opscope.ops.keys; - if /@ops/(self) -> $cur { + if /@ops [ | ]/(self) -> $cur { return $cur."!reduce"("prefix"); } return //(self); diff --git a/t/features/custom-ops.t b/t/features/custom-ops.t index abde8c0e..2d5c4bf4 100644 --- a/t/features/custom-ops.t +++ b/t/features/custom-ops.t @@ -727,4 +727,26 @@ use _007::Test; "with same-precedence right-associative prefix/postfix ops, the postfix evaluates first (no matter the order declared) (#372)"; } +{ + my $program = q:to/./; + func prefix:(n) { + "oops" + } + say(H50); + . + + parse-error $program, X::Undeclared, "prefixes that end in an alphanumeric must also end in a word boundary (#408) (I)"; +} + +{ + my $program = q:to/./; + func prefix:
(n) { + "oops" + } + say(H50); + . + + parse-error $program, X::Undeclared, "prefixes that end in an alphanumeric must also end in a word boundary (#408) (II)"; +} + done-testing; From 5f8c1cbe557cd99ebb100f81e155e10a96bf3a4a Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Wed, 6 Feb 2019 14:30:29 +0100 Subject: [PATCH 2/3] Force word boundary after alphanumeric infix op --- lib/_007/Parser/Syntax.pm6 | 2 +- t/features/custom-ops.t | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/_007/Parser/Syntax.pm6 b/lib/_007/Parser/Syntax.pm6 index c1dd306a..cced5e5e 100644 --- a/lib/_007/Parser/Syntax.pm6 +++ b/lib/_007/Parser/Syntax.pm6 @@ -305,7 +305,7 @@ grammar _007::Parser::Syntax { method infix { my @ops = $*parser.opscope.ops.keys; - if /@ops/(self) -> $cur { + if /@ops [ | ]/(self) -> $cur { return $cur."!reduce"("infix"); } return //(self); diff --git a/t/features/custom-ops.t b/t/features/custom-ops.t index 2d5c4bf4..2da5e481 100644 --- a/t/features/custom-ops.t +++ b/t/features/custom-ops.t @@ -749,4 +749,26 @@ use _007::Test; parse-error $program, X::Undeclared, "prefixes that end in an alphanumeric must also end in a word boundary (#408) (II)"; } +{ + my $program = q:to/./; + func infix:(x, y) { + "oops" + } + say(2 H40); + . + + parse-error $program, X::AdHoc, "infixes that end in an alphanumeric must also end in a word boundary (I)"; +} + +{ + my $program = q:to/./; + func infix:

(x, y) { + "oops" + } + say(2 H40); + . + + parse-error $program, X::AdHoc, "infixes that end in an alphanumeric must also end in a word boundary (II)"; +} + done-testing; From 53ac1aec7f83ba4853a717d881b27a7a0f3456f0 Mon Sep 17 00:00:00 2001 From: Carl Masak Date: Wed, 6 Feb 2019 14:43:49 +0100 Subject: [PATCH 3/3] Force word boundary after alphanumeric postfix op --- lib/_007/Parser/Syntax.pm6 | 2 +- t/features/custom-ops.t | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/_007/Parser/Syntax.pm6 b/lib/_007/Parser/Syntax.pm6 index cced5e5e..6668cac2 100644 --- a/lib/_007/Parser/Syntax.pm6 +++ b/lib/_007/Parser/Syntax.pm6 @@ -332,7 +332,7 @@ grammar _007::Parser::Syntax { } my @ops = $*parser.opscope.ops.keys; - if /@ops/(self) -> $cur { + if /@ops [ | ]/(self) -> $cur { return $cur."!reduce"("postfix"); } return //(self); diff --git a/t/features/custom-ops.t b/t/features/custom-ops.t index 2da5e481..9a230633 100644 --- a/t/features/custom-ops.t +++ b/t/features/custom-ops.t @@ -771,4 +771,13 @@ use _007::Test; parse-error $program, X::AdHoc, "infixes that end in an alphanumeric must also end in a word boundary (II)"; } +{ + my $program = q:to/./; + func postfix:

(n) { "oops" } + say(2 PP) + . + + parse-error $program, X::AdHoc, "postfixes that end in an alphanumeric must also end in a word boundary"; +} + done-testing;