diff --git a/lib/YAML/PP/Lexer.pm b/lib/YAML/PP/Lexer.pm index 459c53de..b63beb59 100644 --- a/lib/YAML/PP/Lexer.pm +++ b/lib/YAML/PP/Lexer.pm @@ -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]'; @@ -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 ]; @@ -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) { diff --git a/t/11.parse-invalid.t b/t/11.parse-invalid.t index 960a8c55..1ca889a2 100644 --- a/t/11.parse-invalid.t +++ b/t/11.parse-invalid.t @@ -43,6 +43,8 @@ my %skip_events = ( '4H7K' => 1, BS4K => 1, EB22 => 1, + i037 => 1, + i038 => 1, ); diff --git a/t/invalid/i037/=== b/t/invalid/i037/=== new file mode 100644 index 00000000..cb38fbdc --- /dev/null +++ b/t/invalid/i037/=== @@ -0,0 +1 @@ +Tabs in various contexts diff --git a/t/invalid/i037/in.yaml b/t/invalid/i037/in.yaml new file mode 100644 index 00000000..0806e5a9 --- /dev/null +++ b/t/invalid/i037/in.yaml @@ -0,0 +1 @@ +- - diff --git a/t/invalid/i037/test.event b/t/invalid/i037/test.event new file mode 100644 index 00000000..b8e31a8b --- /dev/null +++ b/t/invalid/i037/test.event @@ -0,0 +1,2 @@ ++STR ++DOC diff --git a/t/invalid/i038/=== b/t/invalid/i038/=== new file mode 100644 index 00000000..cb38fbdc --- /dev/null +++ b/t/invalid/i038/=== @@ -0,0 +1 @@ +Tabs in various contexts diff --git a/t/invalid/i038/in.yaml b/t/invalid/i038/in.yaml new file mode 100644 index 00000000..ec674043 --- /dev/null +++ b/t/invalid/i038/in.yaml @@ -0,0 +1 @@ +- - diff --git a/t/invalid/i038/test.event b/t/invalid/i038/test.event new file mode 100644 index 00000000..b8e31a8b --- /dev/null +++ b/t/invalid/i038/test.event @@ -0,0 +1,2 @@ ++STR ++DOC diff --git a/t/valid/v032/=== b/t/valid/v032/=== new file mode 100644 index 00000000..cb38fbdc --- /dev/null +++ b/t/valid/v032/=== @@ -0,0 +1 @@ +Tabs in various contexts diff --git a/t/valid/v032/in.yaml b/t/valid/v032/in.yaml new file mode 100644 index 00000000..763ef1b7 --- /dev/null +++ b/t/valid/v032/in.yaml @@ -0,0 +1 @@ +- -1 diff --git a/t/valid/v032/out.yaml b/t/valid/v032/out.yaml new file mode 100644 index 00000000..9572567a --- /dev/null +++ b/t/valid/v032/out.yaml @@ -0,0 +1 @@ +- -1 diff --git a/t/valid/v032/test.event b/t/valid/v032/test.event new file mode 100644 index 00000000..8d71c76c --- /dev/null +++ b/t/valid/v032/test.event @@ -0,0 +1,7 @@ ++STR ++DOC ++SEQ +=VAL :-1 +-SEQ +-DOC +-STR