Permalink
Browse files

too much indent

  • Loading branch information...
1 parent 08bfb4f commit a1609e603dd5062c3a93e6d5d8219c82b533d8ab @masak committed Mar 22, 2014
Showing with 31 additions and 1 deletion.
  1. +22 −1 lib/Text/Indented.pm
  2. +9 −0 t/parse-indent.t
View
@@ -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;
+ }
+}
View
@@ -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.