ascii table

This commit is contained in:
Mylloon 2023-10-24 16:25:29 +02:00
parent 24860a540f
commit 0fcd634f81
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -21,7 +21,7 @@
(* Fonction qui convertie une chaîne de caractère ascii en vrai caractère. (* Fonction qui convertie une chaîne de caractère ascii en vrai caractère.
* Notamment les escapes : "\n" ou "\000" *) * Notamment les escapes : "\n" ou "\000" *)
let recup_char data lexbuf = let recup_char data =
match data with match data with
| "\\n" -> Some '\n' | "\\n" -> Some '\n'
| "\\b" -> Some '\b' | "\\b" -> Some '\b'
@ -54,7 +54,7 @@ let octa = "0o" ['0'-'7']+
(* Définition d'un atom (* Définition d'un atom
* aka un string qui représente un char, par exemple "\065" = 'A' *) * aka un string qui représente un char, par exemple "\065" = 'A' *)
let ascii_table = ['\000'-'\255'] let ascii_table = "\\" ['0'-'2'] ['0'-'9'] ['0'-'9'] (* TODO: on déborde de 255 à 299 :( *)
let ascii_hex = "\\0x" hex_dig hex_dig let ascii_hex = "\\0x" hex_dig hex_dig
let printable = ['\032'-'\038' '\040'-'\127'] let printable = ['\032'-'\038' '\040'-'\127']
let escapes = "\\n" | "\\b" | "\\r" | "\\t" | "\\'" | "\\\"" | "\\\\" let escapes = "\\n" | "\\b" | "\\r" | "\\t" | "\\'" | "\\\"" | "\\\\"
@ -73,13 +73,14 @@ let type_variable = '`' ident
(* Littéraux entiers *) (* Littéraux entiers *)
let int ='-'? digit+ let int ='-'? digit+
| hexa | hexa
| bina | bina
| octa | octa
(* Littéraux caractères *) (* Littéraux caractères *)
let letter = (digit | ['A'-'Z'] | ['a'-'z']) let letter = (digit | ['A'-'Z'] | ['a'-'z'])
(* tmp *)
let ascii_trop_grand = '\\' ['3'-'9']['0'-'9'](['0'-'9'])+ let ascii_trop_grand = '\\' ['3'-'9']['0'-'9'](['0'-'9'])+
rule token = parse rule token = parse
@ -157,7 +158,7 @@ rule token = parse
(* Characters *) (* Characters *)
| "'" (letter as c) "'" { CHAR c } | "'" (letter as c) "'" { CHAR c }
| "'" (atom as a) "'" { match recup_char a lexbuf with | "'" (atom as a) "'" { match recup_char a with
| Some c -> CHAR c | Some c -> CHAR c
| None -> error lexbuf None "" } | None -> error lexbuf None "" }