Skip to content

Commit

Permalink
too much indent
Browse files Browse the repository at this point in the history
  • Loading branch information
Carl Masak committed Mar 22, 2014
1 parent 08bfb4f commit a1609e6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
23 changes: 22 additions & 1 deletion lib/Text/Indented.pm
@@ -1,3 +1,24 @@
grammar Text::Indented;

regex TOP { .* }
class TooMuchIndent is Exception {}

constant TABSTOP = 4;

regex TOP {
:my @*SUITES = "root";

<line>*
}

sub indent { @*SUITES.end }

regex line {
^^ (<{ "\\x20" x TABSTOP }>*) (\h*) (\N*) $$ \n?

{
my $new_indent = $0.chars div TABSTOP;

die TooMuchIndent.new
if $new_indent > indent() + 1;
}
}
9 changes: 9 additions & 0 deletions t/parse-indent.t
Expand Up @@ -41,4 +41,13 @@ sub fails_with($input, $ex_type, $message = $ex_type.^name) {
parses_correctly($input, 'single indent');
}

{
my $input = q:to/EOF/;
Level 1
Level 3!
EOF

fails_with($input, Text::Indented::TooMuchIndent);
}

done;

0 comments on commit a1609e6

Please sign in to comment.