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/lexerLustreSpec.mll
15 15
  open Parser_lustre
16 16
  open Utils
17 17

  
18
  let str_buf = Buffer.create 1024
19

  
20 18
  exception Error of Location.t
19
 
20
  let str_buf = Buffer.create 1024
21 21

  
22 22
(* As advised by Caml documentation. This way a single lexer rule is
23 23
   used to handle all the possible keywords. *)
......
44 44
  "wcet", WCET;
45 45
  "int", TINT;
46 46
  "bool", TBOOL;
47
  "float", TFLOAT;
47
  (* "float", TFLOAT; *)
48 48
  "real", TREAL;
49 49
  "clock", TCLOCK;
50 50
  "not", NOT;
......
86 86
	token lexbuf }
87 87
  | blank +
88 88
      {token lexbuf}
89
  | '-'? ['0'-'9'] ['0'-'9']* '.' ['0'-'9']*
90
      {FLOAT (float_of_string (Lexing.lexeme lexbuf))}
89
  | (('-'? ['0'-'9'] ['0'-'9']* as l) '.' (['0'-'9']* as r)) as s
90
      {REAL (Num.num_of_string (l^r), String.length r, s)}
91
  | (('-'? ['0'-'9']+ as l)  '.' (['0'-'9']+ as r) ('E'|'e') (('+'|'-') ['0'-'9'] ['0'-'9']* as exp)) as s
92
      {REAL (Num.num_of_string (l^r), String.length r + -1 * int_of_string exp, s)}
91 93
  | '-'? ['0'-'9']+ 
92 94
      {INT (int_of_string (Lexing.lexeme lexbuf)) }
93
  | '-'? ['0'-'9']+ '.' ['0'-'9']+ ('E'|'e') ('+'|'-') ['0'-'9'] ['0'-'9'] as s {REAL s}
94 95
 (* | '/' (['_' 'A'-'Z' 'a'-'z'] ['A'-'Z' 'a'-'z' '_' '0'-'9']* '/')+ as s
95 96
      {IDENT s}
96 97
 *)
......
126 127
  | "^" {POWER}
127 128
  | '"' { Buffer.clear str_buf; string_parse lexbuf }
128 129
  | eof { EOF }
129
  | _ { raise (Error (Location.curr lexbuf)) }
130
  | _ { raise (Parse.Error (Location.curr lexbuf, Unexpected_eof)) }
130 131
and comment_line n = parse
131 132
| eof
132
    { raise (Error (Location.curr lexbuf)) }
133
    { raise (Parse.Error (Location.curr lexbuf, Unfinished_comment)) }
133 134
| "(*"
134 135
    { comment_line (n+1) lexbuf }
135 136
| "*)"
......
139 140
      comment_line n lexbuf }
140 141
| _ { comment_line n lexbuf }
141 142
and string_parse = parse
143
  | eof { raise (Parse.Error (Location.curr lexbuf, Unfinished_string)) }
142 144
  | "\\\"" as s { Buffer.add_string str_buf s; string_parse lexbuf}
143 145
  | '"' { STRING (Buffer.contents str_buf) }
144 146
  | _ as c  { Buffer.add_char str_buf c; string_parse lexbuf }
......
146 148
{
147 149

  
148 150
  let annot s =
149
    let lb = Lexing.from_string s in
151
    let lexbuf = Lexing.from_string s in
150 152
   try
151
     Parser_lustre.lustre_annot(* ParserLustreSpec.lustre_annot *) token lb
153
     Parser_lustre.lustre_annot(* ParserLustreSpec.lustre_annot *) token lexbuf
152 154
   with Parsing.Parse_error as _e -> (
153 155
     Format.eprintf "Lexing error at position %a:@.unexpected token %s@.@?"
154
       (fun fmt p -> Format.fprintf fmt "%s l%i c%i" p.Lexing.pos_fname p.Lexing.pos_lnum p.Lexing.pos_cnum) lb.Lexing.lex_curr_p
155
       (Lexing.lexeme lb);
156
     raise Parsing.Parse_error)
156
       (fun fmt p -> Format.fprintf fmt "%s l%i c%i" p.Lexing.pos_fname p.Lexing.pos_lnum p.Lexing.pos_cnum) lexbuf.Lexing.lex_curr_p
157
       (Lexing.lexeme lexbuf);
158
     raise (Error (Location.curr lexbuf)))
157 159
     
158 160

  
159 161
  let spec s =
160
    let lb = Lexing.from_string s in
161
    Parser_lustre.lustre_spec (*ParserLustreSpec.lustre_spec*) token lb
162

  
162
    let lexbuf = Lexing.from_string s in
163
    try
164
      Parser_lustre.lustre_spec (*ParserLustreSpec.lustre_spec*) token lexbuf
165
    with Parsing.Parse_error ->
166
      raise (Error (Location.curr lexbuf))
163 167
}

Also available in: Unified diff