Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /ml-burg/releases/release-110.84.2/burg-lex
ViewVC logotype

Annotation of /ml-burg/releases/release-110.84.2/burg-lex

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4778 - (view) (download)

1 : monnier 249 (* burg-lex
2 :     *
3 :     * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
4 :     *
5 :     * ML-Lex specification for ML-burg.
6 :     *)
7 :    
8 :     structure T = Tokens
9 :     structure E = ErrorMsg
10 :     type pos = int
11 :     type svalue = T.svalue
12 :     type ('a,'b) token = ('a,'b) T.token
13 :     type lexresult = (svalue,pos) token
14 :    
15 :     val comLevel = ref 0
16 :     val lineNum = ref 0
17 :     val verbatimLevel = ref 0
18 :     val percentCount = ref 0
19 :     val rawLine = ref ""
20 :     val rawNoNewLine = ref false
21 :     val raw:string list ref = ref []
22 :     val reachedEop = ref false
23 :    
24 :     fun resetState() = (comLevel := 0;
25 :     lineNum := 0;
26 :     verbatimLevel := 0;
27 :     percentCount := 0;
28 :     rawLine := "";
29 :     rawNoNewLine := false;
30 :     raw := [];
31 :     reachedEop := false)
32 :    
33 :     fun inc (ri as ref i) = (ri := i+1)
34 :     fun dec (ri as ref i) = (ri := i-1)
35 :    
36 :     fun incVerbLvl() = if !verbatimLevel <> 0
37 :     then E.impossible "nested verbatim levels"
38 :     else inc verbatimLevel
39 :    
40 :     fun outputRaw (s:string) = (rawLine := !rawLine^s; rawNoNewLine := true)
41 :    
42 :     fun rawNextLine () = (raw := !rawLine^"\n":: (!raw);
43 :     rawLine := ""; rawNoNewLine := false)
44 :    
45 :     fun rawStop () = if !rawNoNewLine then rawNextLine () else ()
46 :    
47 :     fun eof() = (if !comLevel > 0 then E.complain "unclosed comment"
48 :     else if !verbatimLevel <> 0 then
49 :     E.complain "unclosed user input"
50 :     else ();
51 :     if !reachedEop
52 :     then T.K_EOF(!lineNum,!lineNum)
53 :     else (rawStop ();
54 :     T.PPERCENT(rev(!raw),!lineNum,!lineNum)
55 :     before (raw := [];
56 :     reachedEop := true)))
57 :    
58 :     %%
59 :    
60 :     %s COMMENT DUMP POSTLUDE;
61 :     %header (functor BurgLexFun(structure Tokens : Burg_TOKENS));
62 :     idchars = [A-Za-z_0-9];
63 :     id = [A-Za-z]{idchars}*;
64 :     ws = [\t\ ]*;
65 :     num = [0-9]+;
66 :     line = .*;
67 :    
68 :    
69 :    
70 :    
71 :     %%
72 :    
73 :     <INITIAL> "\n" => (inc lineNum; continue());
74 :     <INITIAL> "%{" => (incVerbLvl(); YYBEGIN DUMP; continue());
75 :     <INITIAL> "%%" => (inc percentCount;
76 :     if !percentCount = 2
77 :     then (YYBEGIN POSTLUDE; continue())
78 :     else T.PPERCENT(rev(!raw),!lineNum,!lineNum)
79 :     before raw := []);
80 :     <INITIAL> {ws} => (continue());
81 :     <INITIAL> \n => (inc lineNum; continue());
82 :     <INITIAL> "(" => (T.K_LPAREN(!lineNum,!lineNum));
83 :     <INITIAL> ")" => (T.K_RPAREN(!lineNum,!lineNum));
84 :     <INITIAL> "," => (T.K_COMMA(!lineNum,!lineNum));
85 :     <INITIAL> ":" => (T.K_COLON(!lineNum,!lineNum));
86 :     <INITIAL> ";" => (T.K_SEMICOLON(!lineNum,!lineNum));
87 :     <INITIAL> "=" => (T.K_EQUAL(!lineNum,!lineNum));
88 :     <INITIAL> "|" => (T.K_PIPE(!lineNum,!lineNum));
89 :     <INITIAL> "%term" => (T.K_TERM(!lineNum,!lineNum));
90 :     <INITIAL> "%start" => (T.K_START(!lineNum,!lineNum));
91 :     <INITIAL> "%termprefix" => (T.K_TERMPREFIX(!lineNum,!lineNum));
92 :     <INITIAL> "%ruleprefix" => (T.K_RULEPREFIX(!lineNum,!lineNum));
93 :     <INITIAL> "%sig" => (T.K_SIG(!lineNum,!lineNum));
94 :     <INITIAL> "(*" => (YYBEGIN COMMENT; comLevel:=1; continue());
95 :     <INITIAL> {num} => (T.INT(valOf(Int.fromString yytext),!lineNum,!lineNum));
96 :     <INITIAL> {id} => (T.ID(yytext,!lineNum,!lineNum));
97 :    
98 :     <COMMENT> "(*" => (inc comLevel; continue());
99 :     <COMMENT> \n => (inc lineNum; continue());
100 :     <COMMENT> "*)" => (dec comLevel;
101 :     if !comLevel=0 then YYBEGIN INITIAL else ();
102 :     continue());
103 :     <COMMENT> . => (continue());
104 :    
105 :     <DUMP> "%}" => (rawStop(); dec verbatimLevel;
106 :     YYBEGIN INITIAL; continue());
107 :     <DUMP> "\n" => (rawNextLine (); inc lineNum; continue());
108 :     <DUMP> {line} => (outputRaw yytext; continue());
109 :    
110 :    
111 :     <POSTLUDE> "\n" => (rawNextLine (); inc lineNum; continue());
112 :     <POSTLUDE> {line} => (outputRaw yytext; continue());

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0