]> gitweb.factorcode.org Git - factor.git/commitdiff
Forbid tabs in source code
authorSamuel Tardieu <sam@rfc1149.net>
Tue, 16 Jun 2009 18:47:56 +0000 (20:47 +0200)
committerSamuel Tardieu <sam@rfc1149.net>
Tue, 16 Jun 2009 18:49:28 +0000 (20:49 +0200)
core/lexer/lexer-docs.factor
core/lexer/lexer.factor

index 31f5a3f72e64ae97f6c1abe75d2416bf2d27e806..fcfd0806d4a44a41a380d8fc586966f14d084d02 100644 (file)
@@ -29,7 +29,7 @@ HELP: <lexer-error>
 
 HELP: skip
 { $values { "i" "a starting index" } { "seq" sequence } { "?" "a boolean" } { "n" integer } }
-{ $description "Skips to the first space character (if " { $snippet "boolean" } " is " { $link f } ") or the first non-space character (otherwise)." } ;
+{ $description "Skips to the first space character (if " { $snippet "boolean" } " is " { $link f } ") or the first non-space character (otherwise). Tabulations used as separators instead of spaces will be flagged as an error." } ;
 
 HELP: change-lexer-column
 { $values { "lexer" lexer } { "quot" { $quotation "( col line -- newcol )" } } }
index 60157033d7b6746e9dd55b0a7bc15cb6d072a09a..99e6f05c6c6df186cb947b43a2d297ebe1c139ad 100644 (file)
@@ -22,9 +22,17 @@ TUPLE: lexer text line line-text line-length column ;
 : <lexer> ( text -- lexer )
     lexer new-lexer ;
 
+ERROR: unexpected want got ;
+
+PREDICATE: unexpected-tab < unexpected
+    got>> CHAR: \t = ;
+
+: forbid-tab ( c -- c )
+    [ CHAR: \t eq? [ "[space]" "[tab]" unexpected ] when ] keep ;
+
 : skip ( i seq ? -- n )
     over length
-    [ [ swap CHAR: \s eq? xor ] curry find-from drop ] dip or ;
+    [ [ swap forbid-tab CHAR: \s eq? xor ] curry find-from drop ] dip or ;
 
 : change-lexer-column ( lexer quot -- )
     [ [ column>> ] [ line-text>> ] bi ] prepose keep
@@ -65,8 +73,6 @@ M: lexer skip-word ( lexer -- )
 
 : scan ( -- str/f ) lexer get parse-token ;
 
-ERROR: unexpected want got ;
-
 PREDICATE: unexpected-eof < unexpected
     got>> not ;