Project

General

Profile

« Previous | Next » 

Revision 3b2bd83d

Added by Teme Kahsai about 8 years ago

updating to onera version 30f766a:2016-12-04

View differences:

src/lexer_lustre.mll
13 13
open Parser_lustre
14 14
open Utils
15 15

  
16
exception Error of Location.t
17

  
18 16
(* As advised by Caml documentation. This way a single lexer rule is
19 17
   used to handle all the possible keywords. *)
20 18
let keyword_table =
......
48 46
  "type", TYPE;
49 47
  "int", TINT;
50 48
  "bool", TBOOL;
51
  "float", TFLOAT;
49
  (* "float", TFLOAT; *)
52 50
  "real", TREAL;
53 51
  "clock", TCLOCK;
54 52
  "not", NOT;
......
75 73
  try
76 74
    let ann = LexerLustreSpec.annot s in
77 75
    ANNOT ann
78
  with _ -> (Format.eprintf "Impossible to parse the following annotation:@.%s@.@?" s; exit 1)
76
  with LexerLustreSpec.Error loc -> raise (Parse.Error (Location.shift (Location.curr lexbuf) loc, Parse.Annot_error s))
79 77

  
80 78
let make_spec lexbuf s = 
81 79
  try
82 80
    let ns = LexerLustreSpec.spec s in
83 81
    NODESPEC ns
84
  with _ -> (Format.eprintf "Impossible to parse the following node specification:@.%s@.@?" s; exit 1)
82
  with LexerLustreSpec.Error loc -> raise (Parse.Error (Location.shift (Location.curr lexbuf) loc, Parse.Node_spec_error s))
85 83
   
86 84
}
87 85

  
......
108 106
      token lexbuf }
109 107
| blank +
110 108
    {token lexbuf}
111
| ['0'-'9'] ['0'-'9']* '.' ['0'-'9']*
112
    {FLOAT (float_of_string (Lexing.lexeme lexbuf))}
109
| ((['0'-'9']+ as l)  '.' (['0'-'9']* as r) ('E'|'e') (('+'|'-')? ['0'-'9']+ as exp)) as s
110
    {REAL (Num.num_of_string (l^r), String.length r + -1 * int_of_string exp , s)}
111
| ((['0'-'9']+ as l) '.' (['0'-'9']* as r)) as s
112
    {REAL (Num.num_of_string (l^r), String.length r, s)}
113 113
| ['0'-'9']+ 
114 114
    {INT (int_of_string (Lexing.lexeme lexbuf)) }
115
| ['0'-'9']+ '.' ['0'-'9']+ ('E'|'e') ('+'|'-') ['0'-'9'] ['0'-'9']* as s {REAL s}
116 115
| "tel." {TEL}
117 116
| "tel;" {TEL}
118 117
| "#open" { OPEN }
......
158 157
| "^" {POWER}
159 158
| '"' {QUOTE}
160 159
| eof { EOF }
161
| _ { raise (Error (Location.curr lexbuf)) }
160
| _ { raise (Parse.Error (Location.curr lexbuf, Parse.Undefined_token (Lexing.lexeme lexbuf))) }
162 161

  
163 162
and comment n = parse
164 163
| eof
165
    { raise (Error (Location.curr lexbuf)) }
164
    { raise (Parse.Error (Location.curr lexbuf, Parse.Unfinished_comment)) }
166 165
| "(*"
167 166
    { comment (n+1) lexbuf }
168 167
| "*)"
......
173 172
| _ { comment n lexbuf }
174 173

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

  
179 179
and annot_multiline n = parse
180
  | eof { raise (Parse.Error (Location.curr lexbuf, Parse.Unfinished_annot)) }
180 181
  | "*)" as s { 
181 182
    if n > 0 then 
182 183
      (Buffer.add_string buf s; annot_multiline (n-1) lexbuf) 
......
187 188
  | _ as c { Buffer.add_char buf c; annot_multiline n lexbuf }
188 189

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

  
193 195
and spec_multiline n = parse
196
  | eof { raise (Parse.Error (Location.curr lexbuf, Parse.Unfinished_node_spec)) }
194 197
  | "*)" as s { if n > 0 then 
195 198
      (Buffer.add_string buf s; spec_multiline (n-1) lexbuf) 
196 199
    else 

Also available in: Unified diff