/[james]/factorcss/Tokeniser.x
ViewVC logotype

Diff of /factorcss/Tokeniser.x

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 70 by james, Sat Jan 8 00:02:19 2005 UTC revision 73 by james, Sun Feb 27 13:53:48 2005 UTC
# Line 2  Line 2 
2  -- This file is part of FactorCSS  -- This file is part of FactorCSS
3  -- Licensed under the MIT License,  -- Licensed under the MIT License,
4  --                http://www.opensource.org/licenses/mit-license  --                http://www.opensource.org/licenses/mit-license
5  -- Copyright 2004 James Bursa <james@semichrome.net>  -- Copyright 2005 James Bursa <james@semichrome.net>
6  --  --
7    
8  -- Tokeniser for CSS 2.1  -- Tokeniser for CSS 2.1
# Line 25  $nonascii      = [\x80-\xff] Line 25  $nonascii      = [\x80-\xff]
25  @string2        = \'([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\"|$nonascii|@escape|\.)*\'  @string2        = \'([\t\ \!\#\x24\x25&\x28-\x7e]|\\@nl|\"|$nonascii|@escape|\.)*\'
26  @ident          = @nmstart@nmchar*  @ident          = @nmstart@nmchar*
27  @name           = @nmchar+  @name           = @nmchar+
28  @num            = [\-\053]?[0-9]+|[0-9]*"."[0-9]+  @num            = [\-\053]?([0-9]+|[0-9]*"."[0-9]+)
29  @string         = @string1|@string2  @string         = @string1|@string2
30  @url            = ([\!\#\x24\x25&\x2a-\x7e]|$nonascii|@escape)*  @url            = ([\!\#\x24\x25&\x2a-\x7e]|$nonascii|@escape)*
31  $s              = [\ \t\r\n\f]  $s              = [\ \t\r\n\f]
# Line 63  $s+                    { \p s -> (S, p) } Line 63  $s+                    { \p s -> (S, p) }
63    
64  "!"@w"important"        { \p s -> (IMPORTANT_SYM, p) }  "!"@w"important"        { \p s -> (IMPORTANT_SYM, p) }
65    
66  @num em                 { \p s -> (EMS (read ('0':(take (length s - 2) s))), p) }  @num em                 { \p s -> (EMS (readz (take (length s - 2) s) p), p) }
67  @num ex                 { \p s -> (EXS (read ('0':(take (length s - 2) s))), p) }  @num ex                 { \p s -> (EXS (readz (take (length s - 2) s) p), p) }
68  @num px                 { \p s -> (LENGTH s, p) }  @num px                 { \p s -> (LENGTH s, p) }
69  @num cm                 { \p s -> (LENGTH s, p) }  @num cm                 { \p s -> (LENGTH s, p) }
70  @num mm                 { \p s -> (LENGTH s, p) }  @num mm                 { \p s -> (LENGTH s, p) }
# Line 79  $s+                    { \p s -> (S, p) } Line 79  $s+                    { \p s -> (S, p) }
79  @num Hz                 { \p s -> (FREQ s, p) }  @num Hz                 { \p s -> (FREQ s, p) }
80  @num kHz                { \p s -> (FREQ s, p) }  @num kHz                { \p s -> (FREQ s, p) }
81  @num @ident             { \p s -> (DIMEN s, p) }  @num @ident             { \p s -> (DIMEN s, p) }
82  @num "%"                { \p s -> (PERCENTAGE (read ('0':(take (length s - 1) s))), p) }  @num "%"                { \p s -> (PERCENTAGE (readz (take (length s - 1) s) p), p) }
83  @num                    { \p s -> (NUMBER (read ('0':s)), p) }  @num                    { \p s -> (NUMBER (readz s p), p) }
84    
85  "url("@w@string@w")"    { \p s -> (URI s, p) }  "url("@w@string@w")"    { \p s -> (URI s, p) }
86  "url("@w@url@w")"       { \p s -> (URI s, p) }  "url("@w@url@w")"       { \p s -> (URI s, p) }
87  @ident"\050"            { \p s -> (FUNCTION s, p) }  @ident"("               { \p s -> (FUNCTION s, p) }
88    
89  ";"                     { \p s -> (SEMI, p) }  ";"                     { \p s -> (SEMI, p) }
90  ":"                     { \p s -> (COLON, p) }  ":"                     { \p s -> (COLON, p) }
# Line 142  data Token = Line 142  data Token =
142          RPAREN          |          RPAREN          |
143          DELIM Char          DELIM Char
144          deriving (Eq, Show)          deriving (Eq, Show)
145    
146    readz :: Read a => String -> AlexPosn -> a
147    readz s (AlexPn _ l c) =
148            if (null xs) || not (null (snd (head xs)))
149            then error ("Parse error at " ++ "line " ++ show l ++
150                            ", column " ++ show c ++
151                            " (when parsing \"" ++ s ++ "\")")
152            else fst (head xs)
153                    where xs = reads s
154    
155  }  }

Legend:
Removed from v.70  
changed lines
  Added in v.73

  ViewVC Help
Powered by ViewVC 1.1.26