[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
branch master updated: Same parsing of @macro line for both parsers
From: |
Patrice Dumas |
Subject: |
branch master updated: Same parsing of @macro line for both parsers |
Date: |
Sat, 22 Jul 2023 09:09:25 -0400 |
This is an automated email from the git hooks/post-receive script.
pertusus pushed a commit to branch master
in repository texinfo.
The following commit(s) were added to refs/heads/master by this push:
new c8343fd22d Same parsing of @macro line for both parsers
c8343fd22d is described below
commit c8343fd22d74ba756517201b04df88154fe6dad4
Author: Patrice Dumas <pertusus@free.fr>
AuthorDate: Sat Jul 22 15:09:14 2023 +0200
Same parsing of @macro line for both parsers
* tp/Texinfo/ParserNonXS.pm (_parse_macro_command_line),
tp/Texinfo/XS/parsetexi/macro.c (parse_macro_command_line): use
the same code to parse @macro line for both parsers to get the
same parsing and same errors message.
* tp/Makefile.tres, tp/t/60macro.t (zero_argument_comment)
(non_ascii_in_macro_name): new tests, with comment on zero arguments
@macro line and non ascii character in macro name.
---
ChangeLog | 13 +++
tp/Makefile.tres | 2 +
tp/Texinfo/ParserNonXS.pm | 32 +++---
tp/Texinfo/XS/parsetexi/macro.c | 10 +-
tp/t/60macro.t | 15 +++
tp/t/results/macro/bad_argument.pl | 4 +-
tp/t/results/macro/non_ascii_in_macro_name.pl | 142 ++++++++++++++++++++++++
tp/t/results/macro/zero_argument_comment.pl | 150 ++++++++++++++++++++++++++
8 files changed, 349 insertions(+), 19 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index c0e33e4f69..0afc65560c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2023-07-22 Patrice Dumas <pertusus@free.fr>
+
+ Same parsing of @macro line for both parsers
+
+ * tp/Texinfo/ParserNonXS.pm (_parse_macro_command_line),
+ tp/Texinfo/XS/parsetexi/macro.c (parse_macro_command_line): use
+ the same code to parse @macro line for both parsers to get the
+ same parsing and same errors message.
+
+ * tp/Makefile.tres, tp/t/60macro.t (zero_argument_comment)
+ (non_ascii_in_macro_name): new tests, with comment on zero arguments
+ @macro line and non ascii character in macro name.
+
2023-07-22 Patrice Dumas <pertusus@free.fr>
* tp/Texinfo/Common.pm (element_extra_encoding_for_perl)
diff --git a/tp/Makefile.tres b/tp/Makefile.tres
index 248df2c460..e8bf0aef4d 100644
--- a/tp/Makefile.tres
+++ b/tp/Makefile.tres
@@ -1347,6 +1347,7 @@ test_files_generated_list =
$(test_tap_files_generated_list) \
t/results/macro/macro_zero.pl \
t/results/macro/nested_macro_call.pl \
t/results/macro/no_macrobody.pl \
+ t/results/macro/non_ascii_in_macro_name.pl \
t/results/macro/paragraph_and_macro.pl \
t/results/macro/protect_comma_macro_line.pl \
t/results/macro/protect_in_body.pl \
@@ -1368,6 +1369,7 @@ test_files_generated_list =
$(test_tap_files_generated_list) \
t/results/macro/verb_with_arobase_in_macro_call.pl \
t/results/macro/verb_with_brace_in_macro_call.pl \
t/results/macro/zero_argument.pl \
+ t/results/macro/zero_argument_comment.pl \
t/results/menu/bad_beginning.pl \
t/results/menu/block_commands_in_menu_description.pl \
t/results/menu/comment_on_menu_line.pl \
diff --git a/tp/Texinfo/ParserNonXS.pm b/tp/Texinfo/ParserNonXS.pm
index 291f4f4542..a51e4eee20 100644
--- a/tp/Texinfo/ParserNonXS.pm
+++ b/tp/Texinfo/ParserNonXS.pm
@@ -1276,18 +1276,32 @@ sub _parse_macro_command_line($$$$$;$)
my $macro = { 'cmdname' => $command, 'parent' => $parent,
'info' => {'arg_line' => $line}, 'source_info' => $source_info
};
# REMACRO
- if ($line =~ /^\s+([[:alnum:]][[:alnum:]_-]*)\s*(.*)/) {
- my $macro_name = $1;
- my $args_def = $2;
- my @args;
+ my $macro_name;
+ if ($line =~ s/^\s+([[:alnum:]][[:alnum:]_-]*)//) {
+ $macro_name = $1;
+ } else {
+ $self->_line_error(sprintf(
+ __("\@%s requires a name"), $command), $source_info);
+ $macro->{'extra'} = {'invalid_syntax' => 1};
+ return $macro;
+ }
+ if ($line ne '' and $line !~ /^([{@]|\s)/) {
+ $self->_line_error(sprintf(
+ __("bad name for \@%s"), $command), $source_info);
+ $macro->{'extra'} = {'invalid_syntax' => 1};
+ } else {
print STDERR "MACRO \@$command $macro_name\n" if ($self->{'DEBUG'});
$macro->{'args'} = [
{ 'type' => 'macro_name', 'text' => $macro_name,
'parent' => $macro } ];
- if ($args_def =~ s/^\s*{\s*(.*?)\s*}\s*//) {
+ my $args_def = $line;
+ $args_def =~ s/^\s*//;
+
+ my @args;
+ if ($args_def =~ s/^{\s*(.*?)\s*}\s*//) {
@args = split(/\s*,\s*/, $1);
}
@@ -1309,14 +1323,6 @@ sub _parse_macro_command_line($$$$$;$)
$source_info);
$macro->{'extra'} = {'invalid_syntax' => 1};
}
- } elsif ($line !~ /\S/) {
- $self->_line_error(sprintf(
- __("\@%s requires a name"), $command), $source_info);
- $macro->{'extra'} = {'invalid_syntax' => 1};
- } else {
- $self->_line_error(sprintf(
- __("bad name for \@%s"), $command), $source_info);
- $macro->{'extra'} = {'invalid_syntax' => 1};
}
return $macro;
}
diff --git a/tp/Texinfo/XS/parsetexi/macro.c b/tp/Texinfo/XS/parsetexi/macro.c
index b2f24ed2e7..7dd7175bbd 100644
--- a/tp/Texinfo/XS/parsetexi/macro.c
+++ b/tp/Texinfo/XS/parsetexi/macro.c
@@ -121,15 +121,17 @@ parse_macro_command_line (enum command_id cmd, char
**line_inout,
line += strspn (line, whitespace_chars);
name = read_command_name (&line);
- if (*line && *line != '{' && !strchr (whitespace_chars, *line))
+ if (!name)
{
- line_error ("bad name for @%s", command_name (cmd));
+ line_error ("@%s requires a name", command_name (cmd));
add_extra_integer (macro, "invalid_syntax", 1);
return macro;
}
- else if (!name)
+
+ if (*line && *line != '{' && *line != '@'
+ && !strchr (whitespace_chars, *line))
{
- line_error ("@%s requires a name", command_name (cmd));
+ line_error ("bad name for @%s", command_name (cmd));
add_extra_integer (macro, "invalid_syntax", 1);
return macro;
}
diff --git a/tp/t/60macro.t b/tp/t/60macro.t
index 3297da2869..5e42fcaffb 100644
--- a/tp/t/60macro.t
+++ b/tp/t/60macro.t
@@ -14,6 +14,14 @@ in foo
@macro abar
in bar
@end macro'],
+['zero_argument_comment',
+'@macro foo {}@c foo c
+in foo
+@end macro
+
+@macro abar@comment bar comment
+in bar
+@end macro'],
['text_before_after',
'before @macro mymacro
in macro
@@ -156,6 +164,13 @@ second arg: \second\
@twoargs{one, two, three}.
'],
+['non_ascii_in_macro_name',
+'@macro parenbr'."\x{00e8}".'ve {a}
+(@`{\a\})
+@end macro
+
+@parenbr'."\x{00e8}".'ve{e}
+'],
['macro_expansion','
@macro macroone {arg1, arg2 }
result of a macro with \arg1\ and
diff --git a/tp/t/results/macro/bad_argument.pl
b/tp/t/results/macro/bad_argument.pl
index 2e6b80235a..9707b8c8e3 100644
--- a/tp/t/results/macro/bad_argument.pl
+++ b/tp/t/results/macro/bad_argument.pl
@@ -315,12 +315,12 @@ $result_errors{'bad_argument'} = [
'type' => 'error'
},
{
- 'error_line' => 'bad name for @macro
+ 'error_line' => '@macro requires a name
',
'file_name' => '',
'line_nr' => 13,
'macro' => '',
- 'text' => 'bad name for @macro',
+ 'text' => '@macro requires a name',
'type' => 'error'
}
];
diff --git a/tp/t/results/macro/non_ascii_in_macro_name.pl
b/tp/t/results/macro/non_ascii_in_macro_name.pl
new file mode 100644
index 0000000000..ae7978781d
--- /dev/null
+++ b/tp/t/results/macro/non_ascii_in_macro_name.pl
@@ -0,0 +1,142 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors
+ %result_indices %result_sectioning %result_nodes %result_menus
+ %result_floats %result_converted %result_converted_errors
+ %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'non_ascii_in_macro_name'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'cmdname' => 'macro',
+ 'contents' => [
+ {
+ 'text' => '(@`{\\a\\})
+',
+ 'type' => 'raw'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'macro'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
+ 'text' => '
+'
+ }
+ },
+ 'type' => 'line_arg'
+ }
+ ],
+ 'cmdname' => 'end',
+ 'extra' => {
+ 'text_arg' => 'macro'
+ },
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 3,
+ 'macro' => ''
+ }
+ }
+ ],
+ 'extra' => {
+ 'invalid_syntax' => 1
+ },
+ 'info' => {
+ 'arg_line' => " parenbr\x{e8}ve {a}
+"
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 1,
+ 'macro' => ''
+ }
+ },
+ {
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'contents' => [
+ {
+ 'text' => "\x{e8}vee
+"
+ }
+ ],
+ 'type' => 'paragraph'
+ }
+ ],
+ 'type' => 'before_node_section'
+ }
+ ],
+ 'type' => 'document_root'
+};
+
+$result_texis{'non_ascii_in_macro_name'} = '@macro parenbrève {a}
+(@`{\\a\\})
+@end macro
+
+èvee
+';
+
+
+$result_texts{'non_ascii_in_macro_name'} = '
+èvee
+';
+
+$result_errors{'non_ascii_in_macro_name'} = [
+ {
+ 'error_line' => 'bad name for @macro
+',
+ 'file_name' => '',
+ 'line_nr' => 1,
+ 'macro' => '',
+ 'text' => 'bad name for @macro',
+ 'type' => 'error'
+ },
+ {
+ 'error_line' => 'unknown command `parenbr\'
+',
+ 'file_name' => '',
+ 'line_nr' => 5,
+ 'macro' => '',
+ 'text' => 'unknown command `parenbr\'',
+ 'type' => 'error'
+ },
+ {
+ 'error_line' => 'misplaced {
+',
+ 'file_name' => '',
+ 'line_nr' => 5,
+ 'macro' => '',
+ 'text' => 'misplaced {',
+ 'type' => 'error'
+ },
+ {
+ 'error_line' => 'misplaced }
+',
+ 'file_name' => '',
+ 'line_nr' => 5,
+ 'macro' => '',
+ 'text' => 'misplaced }',
+ 'type' => 'error'
+ }
+];
+
+
+$result_floats{'non_ascii_in_macro_name'} = {};
+
+
+1;
diff --git a/tp/t/results/macro/zero_argument_comment.pl
b/tp/t/results/macro/zero_argument_comment.pl
new file mode 100644
index 0000000000..7880ea5395
--- /dev/null
+++ b/tp/t/results/macro/zero_argument_comment.pl
@@ -0,0 +1,150 @@
+use vars qw(%result_texis %result_texts %result_trees %result_errors
+ %result_indices %result_sectioning %result_nodes %result_menus
+ %result_floats %result_converted %result_converted_errors
+ %result_elements %result_directions_text %result_indices_sort_strings);
+
+use utf8;
+
+$result_trees{'zero_argument_comment'} = {
+ 'contents' => [
+ {
+ 'contents' => [
+ {
+ 'args' => [
+ {
+ 'text' => 'foo',
+ 'type' => 'macro_name'
+ }
+ ],
+ 'cmdname' => 'macro',
+ 'contents' => [
+ {
+ 'text' => 'in foo
+',
+ 'type' => 'raw'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'macro'
+ }
+ ],
+ 'info' => {
+ 'spaces_after_argument' => {
+ 'text' => '
+'
+ }
+ },
+ 'type' => 'line_arg'
+ }
+ ],
+ 'cmdname' => 'end',
+ 'extra' => {
+ 'text_arg' => 'macro'
+ },
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 3,
+ 'macro' => ''
+ }
+ }
+ ],
+ 'info' => {
+ 'arg_line' => ' foo {}@c foo c
+'
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 1,
+ 'macro' => ''
+ }
+ },
+ {
+ 'text' => '
+',
+ 'type' => 'empty_line'
+ },
+ {
+ 'args' => [
+ {
+ 'text' => 'abar',
+ 'type' => 'macro_name'
+ }
+ ],
+ 'cmdname' => 'macro',
+ 'contents' => [
+ {
+ 'text' => 'in bar
+',
+ 'type' => 'raw'
+ },
+ {
+ 'args' => [
+ {
+ 'contents' => [
+ {
+ 'text' => 'macro'
+ }
+ ],
+ 'type' => 'line_arg'
+ }
+ ],
+ 'cmdname' => 'end',
+ 'extra' => {
+ 'text_arg' => 'macro'
+ },
+ 'info' => {
+ 'spaces_before_argument' => {
+ 'text' => ' '
+ }
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 7,
+ 'macro' => ''
+ }
+ }
+ ],
+ 'info' => {
+ 'arg_line' => ' abar@comment bar comment
+'
+ },
+ 'source_info' => {
+ 'file_name' => '',
+ 'line_nr' => 5,
+ 'macro' => ''
+ }
+ }
+ ],
+ 'type' => 'before_node_section'
+ }
+ ],
+ 'type' => 'document_root'
+};
+
+$result_texis{'zero_argument_comment'} = '@macro foo {}@c foo c
+in foo
+@end macro
+
+@macro abar@comment bar comment
+in bar
+@end macro';
+
+
+$result_texts{'zero_argument_comment'} = '
+';
+
+$result_errors{'zero_argument_comment'} = [];
+
+
+$result_floats{'zero_argument_comment'} = {};
+
+
+1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- branch master updated: Same parsing of @macro line for both parsers,
Patrice Dumas <=
- Prev by Date:
branch master updated: * tp/Texinfo/Common.pm (element_extra_encoding_for_perl) (set_output_encodings), tp/Texinfo/Convert/Converter.pm (txt_image_text), tp/Texinfo/Convert/IXIN.pm (output_ixin), tp/Texinfo/Convert/Plaintext.pm (converter_initialize), tp/Texinfo/Translations.pm (gdt): check if encoding name is not defined, or not empty, but not that it is not '0'.
- Next by Date:
branch master updated: * tp/Texinfo/XS/parsetexi/end_line.c (isascii_alpha) (parse_line_command_args, end_line_starting_block) (end_line_misc_line), tp/Texinfo/XS/parsetexi/handle_commands.c (parse_rawline_command), tp/Texinfo/XS/parsetexi/macro.c (parse_macro_command_line), tp/Texinfo/XS/parsetexi/parser.c (isascii_alnum, read_command_name, read_flag_name): add isascii_alpha to replace isalpha and isascii_alnum to replace isalnum to make sure that the character is also ascii, both because we want to select asci [...]
- Previous by thread:
branch master updated: * tp/Texinfo/Common.pm (element_extra_encoding_for_perl) (set_output_encodings), tp/Texinfo/Convert/Converter.pm (txt_image_text), tp/Texinfo/Convert/IXIN.pm (output_ixin), tp/Texinfo/Convert/Plaintext.pm (converter_initialize), tp/Texinfo/Translations.pm (gdt): check if encoding name is not defined, or not empty, but not that it is not '0'.
- Next by thread:
branch master updated: * tp/Texinfo/XS/parsetexi/end_line.c (isascii_alpha) (parse_line_command_args, end_line_starting_block) (end_line_misc_line), tp/Texinfo/XS/parsetexi/handle_commands.c (parse_rawline_command), tp/Texinfo/XS/parsetexi/macro.c (parse_macro_command_line), tp/Texinfo/XS/parsetexi/parser.c (isascii_alnum, read_command_name, read_flag_name): add isascii_alpha to replace isalpha and isascii_alnum to replace isalnum to make sure that the character is also ascii, both because we want to select asci [...]
- Index(es):