Skip to content

Commit

Permalink
add better err msgs for invalid open brackets for inline and leading …
Browse files Browse the repository at this point in the history
…declarator blocks
  • Loading branch information
tbrowder committed Aug 24, 2019
1 parent 71646ea commit 749831b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
56 changes: 54 additions & 2 deletions src/Perl6/Grammar.nqp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use QRegex;


use NQPP6QRegex;
use NQPP5QRegex;
use Perl6::Actions;
Expand Down Expand Up @@ -4672,13 +4673,44 @@ if $*COMPILING_CORE_SETTING {
'#' {} \N*
}
#==========================================================
# an in-line or multi-line comment (aka 'embedded comment')
#==========================================================
# examples of valid ones:
# if #`( ) 1 { say "true" } # in-line
# multiline:
# #`(
# some
# comment
# )
#==========================================================
# we panic when a non-opening bracket char follows the sym
token comment:sym<#`> {
'#`'
<.typed_panic: 'X::Syntax::Comment::Embedded'>
}
token comment:sym<#`(...)> {
'#`' <?opener> {}
[ <.quibble(self.slang_grammar('Quote'))> || <.typed_panic: 'X::Syntax::Comment::Embedded'> ]
}
#==========================
# leading declarator blocks
#==========================
# examples of valid ones:
# #| single line
# #|(
# multi-
# line
# )
#==========================
# a multi-line leading declarator block:
# we panic when a non-opening bracket char follows the sym
token comment:sym<#|(...)> {
'#|' <?opener> <attachment=.quibble(self.slang_grammar('Quote'))>
'#|' [ <?opener> || <.typed_panic('X::Syntax::Pod::DeclaratorLeading')> ]
<attachment=.quibble(self.slang_grammar('Quote'))>
{
unless $*POD_BLOCKS_SEEN{ self.from() } {
$*POD_BLOCKS_SEEN{ self.from() } := 1;
Expand All @@ -4691,6 +4723,7 @@ if $*COMPILING_CORE_SETTING {
}
}
# a single-line leading declarator block:
token comment:sym<#|> {
'#|' \h+ $<attachment>=[\N*]
{
Expand All @@ -4705,13 +4738,32 @@ if $*COMPILING_CORE_SETTING {
}
}
#===========================
# trailing declarator blocks
#===========================
# examples of valid ones:
# #= single line
# #=(
# multi-
# line
# )
#===========================
# a multi-line trailing declarator block:
# we would like to panic when a non-opening bracket char follows the sym
# TODO find a way to panic with a suitable exception class.
# I believe it may have to be done inside the:
# quibble(self.slang_grammar('Quote'))
# chunk since no variations of the following seem to work:
# [ <?opener> || <.typed_panic('X::Syntax::Pod::DeclaratorTrailing')> ]
token comment:sym<#=(...)> {
'#=' <?opener> <attachment=.quibble(self.slang_grammar('Quote'))>
{
self.attach_trailing_docs(~$<attachment><nibble>);
}
}
# a single-line trailing declarator block:
token comment:sym<#=> {
'#=' \h+ $<attachment>=[\N*]
{
Expand Down
8 changes: 8 additions & 0 deletions src/core/Exception.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -1528,6 +1528,14 @@ my class X::Syntax::Comment::Embedded does X::Syntax {
method message() { "Opening bracket required for #` comment" }
}

my class X::Syntax::Pod::DeclaratorLeading does X::Syntax {
method message() { "Opening bracket required for #| declarator block" }
}

my class X::Syntax::Pod::DeclaratorTrailing does X::Syntax {
method message() { "Opening bracket required for #= declarator block" }
}

my class X::Syntax::Pod::BeginWithoutIdentifier does X::Syntax does X::Pod {
method message() {
'=begin must be followed by an identifier; (did you mean "=begin pod"?)'
Expand Down

0 comments on commit 749831b

Please sign in to comment.