comparison src/urweb.lex @ 821:395a5d450cc0

Chars and more string operations
author Adam Chlipala <adamc@hcoop.net>
date Tue, 26 May 2009 12:25:06 -0400
parents af41ec2f302a
children 5154a047c6bc
comparison
equal deleted inserted replaced
820:91f465ded07e 821:395a5d450cc0
158 end 158 end
159 159
160 %% 160 %%
161 %header (functor UrwebLexFn(structure Tokens : Urweb_TOKENS)); 161 %header (functor UrwebLexFn(structure Tokens : Urweb_TOKENS));
162 %full 162 %full
163 %s COMMENT STRING XML XMLTAG; 163 %s COMMENT STRING CHAR XML XMLTAG;
164 164
165 id = [a-z_][A-Za-z0-9_']*; 165 id = [a-z_][A-Za-z0-9_']*;
166 cid = [A-Z][A-Za-z0-9_]*; 166 cid = [A-Z][A-Za-z0-9_]*;
167 ws = [\ \t\012]; 167 ws = [\ \t\012];
168 intconst = [0-9]+; 168 intconst = [0-9]+;
190 190
191 <COMMENT> "(*" => (enterComment (pos yypos); 191 <COMMENT> "(*" => (enterComment (pos yypos);
192 continue ()); 192 continue ());
193 <COMMENT> "*)" => (if exitComment () then YYBEGIN INITIAL else (); 193 <COMMENT> "*)" => (if exitComment () then YYBEGIN INITIAL else ();
194 continue ()); 194 continue ());
195
196 <INITIAL> "#\"" => (YYBEGIN CHAR; strEnder := #"\""; strStart := pos yypos; str := []; continue());
197 <CHAR> "\\\"" => (str := #"\"" :: !str; continue());
198 <CHAR> "\\'" => (str := #"'" :: !str; continue());
199 <CHAR> "\n" => (newline yypos;
200 str := #"\n" :: !str; continue());
201 <CHAR> . => (let
202 val ch = String.sub (yytext, 0)
203 in
204 if ch = !strEnder then
205 let
206 val s = String.implode (List.rev (!str))
207 in
208 YYBEGIN INITIAL;
209 if size s = 1 then
210 Tokens.CHAR (String.sub (s, 0), !strStart, pos yypos + 1)
211 else
212 (ErrorMsg.errorAt' (yypos, yypos)
213 "Character constant is zero or multiple characters";
214 continue ())
215 end
216 else
217 (str := ch :: !str;
218 continue ())
219 end);
195 220
196 <INITIAL> "\"" => (YYBEGIN STRING; strEnder := #"\""; strStart := pos yypos; str := []; continue()); 221 <INITIAL> "\"" => (YYBEGIN STRING; strEnder := #"\""; strStart := pos yypos; str := []; continue());
197 <INITIAL> "'" => (YYBEGIN STRING; strEnder := #"'"; strStart := pos yypos; str := []; continue()); 222 <INITIAL> "'" => (YYBEGIN STRING; strEnder := #"'"; strStart := pos yypos; str := []; continue());
198 <STRING> "\\\"" => (str := #"\"" :: !str; continue()); 223 <STRING> "\\\"" => (str := #"\"" :: !str; continue());
199 <STRING> "\\'" => (str := #"'" :: !str; continue()); 224 <STRING> "\\'" => (str := #"'" :: !str; continue());