Commit bde85892 authored by Armillon Damien's avatar Armillon Damien
Browse files

fix lexer

parent 4c8b73f0
......@@ -361,23 +361,27 @@ type lexer_result =
*)
let to_lexer_result (d:dfa) (q: dfa_state) (w: char list): lexer_result =
let (_,f) = List.find (fun (state,_) -> Set.equal q state) d.dfa_final in
match f (string_of_char_list w) with
| None -> LRskip
| Some token -> LRtoken token
let result = List.find_opt (fun (state,_) -> Set.equal q state) d.dfa_final in
match result with
| None -> LRerror
| Some (_,f) -> match f (string_of_char_list w) with
| None -> LRskip
| Some token -> LRtoken token
let tokenize_one (d : dfa) (w: char list) : lexer_result * char list =
let rec recognize (q: dfa_state) (w: char list)
(current_word: char list) (last_accepted: lexer_result * char list)
: lexer_result * char list =
let last_accepted' = (to_lexer_result d q current_word, w) in
let last_accepted' = (to_lexer_result d q current_word, w) in
match w with
| [] -> last_accepted'
| lettre::r ->
match d.dfa_step q lettre with
| None -> last_accepted'
| Some q' -> let new_current_word = current_word @ [lettre] in match to_lexer_result d q' new_current_word with
| LRerror -> recognize q' r (new_current_word) last_accepted'
| lr -> recognize q' r (new_current_word) last_accepted'
in
recognize d.dfa_initial w [] (LRerror, w)
......@@ -524,6 +528,9 @@ let nfa_of_list_regexp l =
let dfa_of_list_regexp l =
let n = nfa_of_list_regexp l in
let oc = open_out "/tmp/nfa.dot" in
nfa_to_dot oc n;
close_out oc;
dfa_of_nfa n
let tokenize_list_regexp l s =
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment