Skip to content
Snippets Groups Projects
Commit cdb0dcbe authored by Kylian Fontaine's avatar Kylian Fontaine
Browse files

remonter les erreurs syntaxique

parent 09595eca
No related branches found
No related tags found
No related merge requests found
......@@ -16,7 +16,13 @@ let parse_file f filename =
result
with Parser.Error ->
close_in in_channel;
raise (Failure ("Invalid Syntax line " ^ string_of_int !Lexer.numero_ligne ^". Problem close to character " ^string_of_int !Lexer.numero_carac^" '" ^ Lexing.lexeme lexbuf ^"'"))
close_in in_channel;
let pos = Lexing.lexeme_start_p lexbuf in
Printf.eprintf "Error at line %d, column %d: Problem close to %s \n"
pos.Lexing.pos_lnum
(pos.Lexing.pos_cnum - pos.Lexing.pos_bol)
(Lexing.lexeme lexbuf);
exit 1
let parse_description filename =
parse_file Parser.description filename
......@@ -64,53 +64,59 @@ rule token = parse
| "Fullcompass" {FULLCOMPASS}
| "Chirality" {CHIRALITY}
| "1-Axe Orientation" {ONEAXEORIEN}
| "[" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; BRACKETOPEN}
| "]" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; BRACKETCLOSE}
| "." {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; POINT}
| ":" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; COLON}
| ";" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; SEMICOLON}
| "(" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; PARENOPEN}
| ")" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; PARENCLOSE}
| "if" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; IF}
| "then" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; THEN}
| "else" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; ELSE}
| "true" | "false" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; BOOLEAN (bool_of_string (Lexing.lexeme lexbuf))}
| "match" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; MATCH}
| "with" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; WITH}
| "|" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; PIPE}
| "end" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; END}
| "->" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; ARROW}
| "=>" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; IMPLICATION}
| "<=>" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; EQUIVALENCE}
| "let" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; LET}
| "=" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; AFFECT}
| "in" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; IN}
| ":=" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; IS}
| '+' {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; PLUS}
| '-' {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; MINUS}
| '*' {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; MULT}
| '/' {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; DIV}
| "&&" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; AND}
| "||" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; OR}
| '>' {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; SUP}
| '<' {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; INF}
| "==" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; EQUAL}
| "!=" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; DIFF}
| "!" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; NOT}
| "fun" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; FUN}
| "/*" {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; comment lexbuf}
| integer {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; INT (int_of_string (Lexing.lexeme lexbuf))}
| float {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; FLOAT (float_of_string(Lexing.lexeme lexbuf) )}
| "," {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; COMMA}
| keyword {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; KEYWORD (Lexing.lexeme lexbuf)}
| variable {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; VARIABLE (Lexing.lexeme lexbuf)}
| space {numero_carac := !numero_carac + (String.length (Lexing.lexeme lexbuf)) ; token lexbuf}
| "\n" {numero_ligne := !numero_ligne + 1; numero_carac := 1 ; token lexbuf}
| "[" { BRACKETOPEN}
| "]" { BRACKETCLOSE}
| "." { POINT}
| ":" { COLON}
| ";" { SEMICOLON}
| "(" { PARENOPEN}
| ")" { PARENCLOSE}
| "if" { IF}
| "then" { THEN}
| "else" { ELSE}
| "true" | "false" { BOOLEAN (bool_of_string (Lexing.lexeme lexbuf))}
| "match" { MATCH}
| "with" { WITH}
| "|" { PIPE}
| "end" { END}
| "->" { ARROW}
| "=>" { IMPLICATION}
| "<=>" { EQUIVALENCE}
| "let" { LET}
| "=" { AFFECT}
| "in" { IN}
| ":=" { IS}
| '+' { PLUS}
| '-' { MINUS}
| '*' { MULT}
| '/' { DIV}
| "&&" { AND}
| "||" { OR}
| '>' { SUP}
| '<' { INF}
| "==" { EQUAL}
| "!=" { DIFF}
| "!" { NOT}
| "fun" { FUN}
| "/*" { comment lexbuf}
| integer { INT (int_of_string (Lexing.lexeme lexbuf))}
| float { FLOAT (float_of_string(Lexing.lexeme lexbuf) )}
| "," { COMMA}
| keyword { KEYWORD (Lexing.lexeme lexbuf)}
| variable { VARIABLE (Lexing.lexeme lexbuf)}
| space { let pos = lexbuf.Lexing.lex_curr_p in
lexbuf.Lexing.lex_curr_p <- { pos with Lexing.pos_cnum = pos.Lexing.pos_cnum + 1; };
token lexbuf}
| "\n" { let pos = lexbuf.Lexing.lex_curr_p in
lexbuf.Lexing.lex_curr_p <- { pos with Lexing.pos_lnum = pos.Lexing.pos_lnum + 1; Lexing.pos_bol = pos.Lexing.pos_cnum; };
token lexbuf
}
| eof {EOF}
| _ {raise (Failure ("Character not allowed in source text line "^ string_of_int !numero_ligne^" character "^string_of_int !numero_carac^": '" ^
Lexing.lexeme lexbuf ^ "'"))}
and comment = parse
| "*/" {numero_carac := !numero_carac + 1 ;token lexbuf}
| "\n" {numero_ligne := !numero_ligne + 1 ;numero_carac := 1; comment lexbuf}
| _ {numero_carac := !numero_carac + 1 ;comment lexbuf}
| "*/" {token lexbuf}
| "\n" {let pos = lexbuf.Lexing.lex_curr_p in
lexbuf.Lexing.lex_curr_p <- { pos with Lexing.pos_lnum = pos.Lexing.pos_lnum + 1; Lexing.pos_bol = pos.Lexing.pos_cnum; };
comment lexbuf}
| _ {comment lexbuf}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment