Skip to content

Commit

Permalink
After tabs no further indentation elements allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Dec 25, 2021
1 parent 9081f88 commit dc43247
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/YAML/PP/Lexer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ sub context { return $_[0]->{context} }
sub set_context { $_[0]->{context} = $_[1] }
sub flowcontext { return $_[0]->{flowcontext} }
sub set_flowcontext { $_[0]->{flowcontext} = $_[1] }
sub block { return $_[0]->{block} }
sub set_block { $_[0]->{block} = $_[1] }

my $RE_WS = '[\t ]';
my $RE_LB = '[\r\n]';
Expand Down Expand Up @@ -141,6 +143,7 @@ sub fetch_next_line {
$self->set_next_line(undef);
return;
}
$self->set_block(1);
$self->inc_line;
$line =~ m/\A( *)([^\r\n]*)([\r\n]|\z)/ or die "Unexpected";
$next_line = [ $1, $2, $3 ];
Expand Down Expand Up @@ -278,7 +281,15 @@ sub _fetch_next_tokens {
}
elsif ($COLON_DASH_QUESTION{ $first }) {
my $token_name = $TOKEN_NAMES{ $first };
if ($$yaml =~ s/\A\Q$first\E(?:($RE_WS+)|\z)//) {
if ($$yaml =~ s/\A\Q$first\E($RE_WS+|\z)//) {
if (not $self->flowcontext and not $self->block) {
$self->push_tokens(\@tokens);
$self->exception("Tabs can not be used for indentation");
}
my $after = $1;
if ($after =~ tr/\t//) {
$self->set_block(0);
}
my $token_name = $TOKEN_NAMES{ $first };
push @tokens, ( $token_name => $first, $self->line );
if (not defined $1) {
Expand Down
2 changes: 2 additions & 0 deletions t/11.parse-invalid.t
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ my %skip_events = (
'4H7K' => 1,
BS4K => 1,
EB22 => 1,
i037 => 1,
i038 => 1,
);


Expand Down
1 change: 1 addition & 0 deletions t/invalid/i037/===
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tabs in various contexts
1 change: 1 addition & 0 deletions t/invalid/i037/in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- -
2 changes: 2 additions & 0 deletions t/invalid/i037/test.event
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
+STR
+DOC
1 change: 1 addition & 0 deletions t/invalid/i038/===
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tabs in various contexts
1 change: 1 addition & 0 deletions t/invalid/i038/in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- -
2 changes: 2 additions & 0 deletions t/invalid/i038/test.event
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
+STR
+DOC
1 change: 1 addition & 0 deletions t/valid/v032/===
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Tabs in various contexts
1 change: 1 addition & 0 deletions t/valid/v032/in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- -1
1 change: 1 addition & 0 deletions t/valid/v032/out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- -1
7 changes: 7 additions & 0 deletions t/valid/v032/test.event
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
+STR
+DOC
+SEQ
=VAL :-1
-SEQ
-DOC
-STR

0 comments on commit dc43247

Please sign in to comment.