# HG changeset patch # User Adam Chlipala # Date 1281465866 14400 # Node ID b04354e24d1ba9fb8518e097cad0cfedad39131c # Parent a9a500d22ebc6d51c06aed0fe8e796961928dc7e ML-style comments inside XML diff -r a9a500d22ebc -r b04354e24d1b src/urweb.lex --- a/src/urweb.lex Tue Jul 27 14:04:09 2010 -0400 +++ b/src/urweb.lex Tue Aug 10 14:44:26 2010 -0400 @@ -34,6 +34,8 @@ type ('a,'b) token = ('a,'b) Tokens.token type lexresult = (svalue,pos) Tokens.token +val commentOut = ref (fn () => ()) + local val commentLevel = ref 0 val commentPos = ref 0 @@ -47,7 +49,10 @@ fun exitComment () = (ignore (commentLevel := !commentLevel - 1); - !commentLevel = 0) + if !commentLevel = 0 then + !commentOut () + else + ()) fun eof () = let @@ -167,17 +172,14 @@ ws = [\ \t\012]; intconst = [0-9]+; realconst = [0-9]+\.[0-9]*; -notags = [^<{\n]+; +notags = [^<{\n(]+; oint = [0-9][0-9][0-9]; xint = x[0-9a-fA-F][0-9a-fA-F]; %% - \n => (newline yypos; - continue ()); - \n => (newline yypos; - continue ()); - \n => (newline yypos; + + \n => (newline yypos; continue ()); \n => (newline yypos; Tokens.NOTAGS (yytext, yypos, yypos + size yytext)); @@ -185,14 +187,24 @@ {ws}+ => (lex ()); "(*" => (YYBEGIN COMMENT; + commentOut := (fn () => YYBEGIN INITIAL); enterComment (pos yypos); continue ()); - "*)" => (ErrorMsg.errorAt' (pos yypos, pos yypos) "Unbalanced comments"; + "(*" => (YYBEGIN COMMENT; + commentOut := (fn () => YYBEGIN XML); + enterComment (pos yypos); + continue ()); + "(*" => (YYBEGIN COMMENT; + commentOut := (fn () => YYBEGIN XMLTAG); + enterComment (pos yypos); + continue ()); + + "*)" => (ErrorMsg.errorAt' (pos yypos, pos yypos) "Unbalanced comments"; continue ()); "(*" => (enterComment (pos yypos); continue ()); - "*)" => (if exitComment () then YYBEGIN INITIAL else (); + "*)" => (exitComment (); continue ()); "\\\"" => (str := #"\"" :: !str; continue()); diff -r a9a500d22ebc -r b04354e24d1b tests/xcomments.ur --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/xcomments.ur Tue Aug 10 14:44:26 2010 -0400 @@ -0,0 +1,8 @@ +fun foo () = Hi! + +(* fun bar () = return (* No *)Yes! *) + +fun main () = return + A (* B *) C (* D (* E *) F *) D
+ A (* B *) C D (* E *) F {foo ()} +
diff -r a9a500d22ebc -r b04354e24d1b tests/xcomments.urp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/xcomments.urp Tue Aug 10 14:44:26 2010 -0400 @@ -0,0 +1,1 @@ +xcomments diff -r a9a500d22ebc -r b04354e24d1b tests/xcomments.urs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/xcomments.urs Tue Aug 10 14:44:26 2010 -0400 @@ -0,0 +1,1 @@ +val main : unit -> transaction page