Project

General

Profile

Revision 53206908 src/lexer_lustre.mll

View differences:

src/lexer_lustre.mll
48 48
  "type", TYPE;
49 49
  "int", TINT;
50 50
  "bool", TBOOL;
51
  "float", TFLOAT;
51
  (* "float", TFLOAT; *)
52 52
  "real", TREAL;
53 53
  "clock", TCLOCK;
54 54
  "not", NOT;
......
89 89
let notnewline = [^ '\010' '\013']
90 90
let blank = [' ' '\009' '\012']
91 91

  
92
rule token = parse
93
| "--@" { Buffer.clear buf;
94
	  spec_singleline lexbuf }
95
| "(*@" { Buffer.clear buf; 
96
	  spec_multiline 0 lexbuf }
97
| "--!" { Buffer.clear buf; 
98
	  annot_singleline lexbuf }
99
| "(*!" { Buffer.clear buf; 
100
	  annot_multiline 0 lexbuf }
101
| "(*"
102
    { comment 0 lexbuf }
103
| "--" [^ '!' '@'] notnewline* (newline|eof)
104
    { incr_line lexbuf;
105
      token lexbuf }
106
| newline
107
    { incr_line lexbuf;
108
      token lexbuf }
109
| blank +
110
    {token lexbuf}
111
| ['0'-'9'] ['0'-'9']* '.' ['0'-'9']*
112
    {FLOAT (float_of_string (Lexing.lexeme lexbuf))}
113
| ['0'-'9']+ 
114
    {INT (int_of_string (Lexing.lexeme lexbuf)) }
115
| ['0'-'9']+ '.' ['0'-'9']+ ('E'|'e') ('+'|'-') ['0'-'9'] ['0'-'9']* as s {REAL s}
116
| "tel." {TEL}
117
| "tel;" {TEL}
118
| "#open" { OPEN }
119
| ['_' 'a'-'z'] [ '_' 'a'-'z' 'A'-'Z' '0'-'9']*
120
    {let s = Lexing.lexeme lexbuf in
121
    try
122
      Hashtbl.find keyword_table s
123
    with Not_found ->
124
      IDENT s}
125
| ['A'-'Z'] [ '_' 'a'-'z' 'A'-'Z' '0'-'9']*
126
    {let s = Lexing.lexeme lexbuf in
127
    try
128
      Hashtbl.find keyword_table s
129
    with Not_found ->
130
      UIDENT s}
131
| "->" {ARROW}
132
| "=>" {IMPL}
133
| "<=" {LTE}
134
| ">=" {GTE}
135
| "<>" {NEQ}
136
| '<' {LT}
137
| '>' {GT}
138
| "!=" {NEQ}
139
| '-' {MINUS}
140
| '+' {PLUS}
141
| '/' {DIV}
142
| '*' {MULT}
143
| '=' {EQ}
144
| '(' {LPAR}
145
| ')' {RPAR}
146
| '[' {LBRACKET}
147
| ']' {RBRACKET}
148
| '{' {LCUR}
149
| '}' {RCUR}
150
| ';' {SCOL}
151
| ':' {COL}
152
| ',' {COMMA}
153
| '=' {EQ}
154
| '/' {DIV}
155
| "&&" {AMPERAMPER}
156
| "||" {BARBAR}
157
| "::" {COLCOL}
158
| "^" {POWER}
159
| '"' {QUOTE}
160
| eof { EOF }
161
| _ { raise (Error (Location.curr lexbuf)) }
92
  rule token = parse
93
  | "--@" { Buffer.clear buf;
94
	    spec_singleline lexbuf }
95
  | "(*@" { Buffer.clear buf; 
96
	    spec_multiline 0 lexbuf }
97
  | "--!" { Buffer.clear buf; 
98
	    annot_singleline lexbuf }
99
  | "(*!" { Buffer.clear buf; 
100
	    annot_multiline 0 lexbuf }
101
  | "(*"
102
      { comment 0 lexbuf }
103
  | "--" [^ '!' '@'] notnewline* (newline|eof)
104
      { incr_line lexbuf;
105
	token lexbuf }
106
  | newline
107
      { incr_line lexbuf;
108
	token lexbuf }
109
  | blank +
110
      {token lexbuf}
111

  
112
  | ((['0'-'9']+ as l)  '.' (['0'-'9']* as r) ('E'|'e') (('+'|'-')? ['0'-'9']+ as exp)) as s
113
      {REAL (Num.num_of_string (l^r), String.length r + -1 * int_of_string exp , s)}
114
  | ((['0'-'9']+ as l) '.' (['0'-'9']* as r)) as s
115
      {REAL (Num.num_of_string (l^r), String.length r, s)}
116
  | ['0'-'9']+ 
117
      {INT (int_of_string (Lexing.lexeme lexbuf)) }
118
  | "tel." {TEL}
119
  | "tel;" {TEL}
120
  | "#open" { OPEN }
121
  | ['_' 'a'-'z'] [ '_' 'a'-'z' 'A'-'Z' '0'-'9']*
122
      {let s = Lexing.lexeme lexbuf in
123
       try
124
	 Hashtbl.find keyword_table s
125
       with Not_found ->
126
	 IDENT s}
127
  | ['A'-'Z'] [ '_' 'a'-'z' 'A'-'Z' '0'-'9']*
128
      {let s = Lexing.lexeme lexbuf in
129
       try
130
	 Hashtbl.find keyword_table s
131
       with Not_found ->
132
	 UIDENT s}
133
  | "->" {ARROW}
134
  | "=>" {IMPL}
135
  | "<=" {LTE}
136
  | ">=" {GTE}
137
  | "<>" {NEQ}
138
  | '<' {LT}
139
  | '>' {GT}
140
  | "!=" {NEQ}
141
  | '-' {MINUS}
142
  | '+' {PLUS}
143
  | '/' {DIV}
144
  | '*' {MULT}
145
  | '=' {EQ}
146
  | '(' {LPAR}
147
  | ')' {RPAR}
148
  | '[' {LBRACKET}
149
  | ']' {RBRACKET}
150
  | '{' {LCUR}
151
  | '}' {RCUR}
152
  | ';' {SCOL}
153
  | ':' {COL}
154
  | ',' {COMMA}
155
  | '=' {EQ}
156
  | '/' {DIV}
157
  | "&&" {AMPERAMPER}
158
  | "||" {BARBAR}
159
  | "::" {COLCOL}
160
  | "^" {POWER}
161
  | '"' {QUOTE}
162
  | eof { EOF }
163
  | _ { raise (Error (Location.curr lexbuf)) }
162 164

  
163 165
and comment n = parse
164
| eof
165
    { raise (Error (Location.curr lexbuf)) }
166
| "(*"
167
    { comment (n+1) lexbuf }
168
| "*)"
169
    { if n > 0 then comment (n-1) lexbuf else token lexbuf }
170
| newline
171
    { incr_line lexbuf;
172
      comment n lexbuf }
173
| _ { comment n lexbuf }
166
    | eof
167
	{ raise (Error (Location.curr lexbuf)) }
168
    | "(*"
169
	{ comment (n+1) lexbuf }
170
    | "*)"
171
	{ if n > 0 then comment (n-1) lexbuf else token lexbuf }
172
    | newline
173
	{ incr_line lexbuf;
174
	  comment n lexbuf }
175
    | _ { comment n lexbuf }
174 176

  
175 177
and annot_singleline = parse
176
  | newline { incr_line lexbuf; make_annot lexbuf (Buffer.contents buf) }
177
  | _ as c { Buffer.add_char buf c; annot_singleline lexbuf }
178
    | newline { incr_line lexbuf; make_annot lexbuf (Buffer.contents buf) }
179
    | _ as c { Buffer.add_char buf c; annot_singleline lexbuf }
178 180

  
179 181
and annot_multiline n = parse
180
  | "*)" as s { 
181
    if n > 0 then 
182
      (Buffer.add_string buf s; annot_multiline (n-1) lexbuf) 
183
    else 
184
      make_annot lexbuf (Buffer.contents buf) }
185
  | "(*" as s { Buffer.add_string buf s; annot_multiline (n+1) lexbuf }
186
  | newline as s { incr_line lexbuf; Buffer.add_string buf s; annot_multiline n lexbuf }
187
  | _ as c { Buffer.add_char buf c; annot_multiline n lexbuf }
182
    | "*)" as s { 
183
      if n > 0 then 
184
	(Buffer.add_string buf s; annot_multiline (n-1) lexbuf) 
185
      else 
186
	make_annot lexbuf (Buffer.contents buf) }
187
    | "(*" as s { Buffer.add_string buf s; annot_multiline (n+1) lexbuf }
188
    | newline as s { incr_line lexbuf; Buffer.add_string buf s; annot_multiline n lexbuf }
189
    | _ as c { Buffer.add_char buf c; annot_multiline n lexbuf }
188 190

  
189 191
and spec_singleline = parse
190
  | newline { incr_line lexbuf; make_spec lexbuf (Buffer.contents buf) }
191
  | _ as c { Buffer.add_char buf c; spec_singleline lexbuf }
192
    | newline { incr_line lexbuf; make_spec lexbuf (Buffer.contents buf) }
193
    | _ as c { Buffer.add_char buf c; spec_singleline lexbuf }
192 194

  
193 195
and spec_multiline n = parse
194
  | "*)" as s { if n > 0 then 
195
      (Buffer.add_string buf s; spec_multiline (n-1) lexbuf) 
196
    else 
197
      make_spec lexbuf (Buffer.contents buf) }
198
  | "(*" as s { Buffer.add_string buf s; spec_multiline (n+1) lexbuf }
199
  | newline as s { incr_line lexbuf; Buffer.add_string buf s; spec_multiline n lexbuf }
200
  | _ as c { Buffer.add_char buf c; spec_multiline n lexbuf }
196
    | "*)" as s { if n > 0 then 
197
	(Buffer.add_string buf s; spec_multiline (n-1) lexbuf) 
198
      else 
199
	make_spec lexbuf (Buffer.contents buf) }
200
    | "(*" as s { Buffer.add_string buf s; spec_multiline (n+1) lexbuf }
201
    | newline as s { incr_line lexbuf; Buffer.add_string buf s; spec_multiline n lexbuf }
202
    | _ as c { Buffer.add_char buf c; spec_multiline n lexbuf }
201 203

  

Also available in: Unified diff