--- factorcss/Tokeniser.x 2005/01/08 00:02:19 70 +++ factorcss/Tokeniser.x 2005/02/27 13:53:48 73 @@ -2,7 +2,7 @@ -- This file is part of FactorCSS -- Licensed under the MIT License, -- http://www.opensource.org/licenses/mit-license --- Copyright 2004 James Bursa +-- Copyright 2005 James Bursa -- -- Tokeniser for CSS 2.1 @@ -25,7 +25,7 @@ @string2 = \'([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\"|$nonascii|@escape|\.)*\' @ident = @nmstart@nmchar* @name = @nmchar+ -@num = [\-\053]?[0-9]+|[0-9]*"."[0-9]+ +@num = [\-\053]?([0-9]+|[0-9]*"."[0-9]+) @string = @string1|@string2 @url = ([\!\#\x24\x25&\x2a-\x7e]|$nonascii|@escape)* $s = [\ \t\r\n\f] @@ -63,8 +63,8 @@ "!"@w"important" { \p s -> (IMPORTANT_SYM, p) } -@num em { \p s -> (EMS (read ('0':(take (length s - 2) s))), p) } -@num ex { \p s -> (EXS (read ('0':(take (length s - 2) s))), p) } +@num em { \p s -> (EMS (readz (take (length s - 2) s) p), p) } +@num ex { \p s -> (EXS (readz (take (length s - 2) s) p), p) } @num px { \p s -> (LENGTH s, p) } @num cm { \p s -> (LENGTH s, p) } @num mm { \p s -> (LENGTH s, p) } @@ -79,12 +79,12 @@ @num Hz { \p s -> (FREQ s, p) } @num kHz { \p s -> (FREQ s, p) } @num @ident { \p s -> (DIMEN s, p) } -@num "%" { \p s -> (PERCENTAGE (read ('0':(take (length s - 1) s))), p) } -@num { \p s -> (NUMBER (read ('0':s)), p) } +@num "%" { \p s -> (PERCENTAGE (readz (take (length s - 1) s) p), p) } +@num { \p s -> (NUMBER (readz s p), p) } "url("@w@string@w")" { \p s -> (URI s, p) } "url("@w@url@w")" { \p s -> (URI s, p) } -@ident"\050" { \p s -> (FUNCTION s, p) } +@ident"(" { \p s -> (FUNCTION s, p) } ";" { \p s -> (SEMI, p) } ":" { \p s -> (COLON, p) } @@ -142,4 +142,14 @@ RPAREN | DELIM Char deriving (Eq, Show) + +readz :: Read a => String -> AlexPosn -> a +readz s (AlexPn _ l c) = + if (null xs) || not (null (snd (head xs))) + then error ("Parse error at " ++ "line " ++ show l ++ + ", column " ++ show c ++ + " (when parsing \"" ++ s ++ "\")") + else fst (head xs) + where xs = reads s + }