this repo has no description
at main 38 lines 1.2 kB view raw
1let refill_lexbuf s p buffer len = 2 if !p = String.length s then 0 3 else 4 let len' = 5 try String.index_from s !p '\n' - !p + 1 with _ -> String.length s - !p 6 in 7 let len'' = min len len' in 8 String.blit s !p buffer 0 len''; 9 p := !p + len''; 10 len'' 11 12let fallback_parse_toplevel s = 13 Printf.printf "fallback parser\n%!"; 14 let lexbuf = Lexing.from_string s in 15 let rec loop pos = 16 let _phr = Toplexer.fallback_expression lexbuf in 17 Printf.printf "Got phrase\n%!"; 18 let new_pos = Lexing.lexeme_end lexbuf in 19 let phr = String.sub s pos (new_pos - pos) in 20 let junk, (cont, output) = Toplexer.entry lexbuf in 21 let new_pos = Lexing.lexeme_end lexbuf in 22 if cont then (phr, junk, output) :: loop new_pos 23 else [ (phr, junk, output) ] 24 in 25 loop 0 26 27let parse_toplevel s = 28 let lexbuf = Lexing.from_string s in 29 let rec loop pos = 30 let _phr = !Toploop.parse_toplevel_phrase lexbuf in 31 let new_pos = Lexing.lexeme_end lexbuf in 32 let phr = String.sub s pos (new_pos - pos) in 33 let junk, (cont, output) = Toplexer.entry lexbuf in 34 let new_pos = Lexing.lexeme_end lexbuf in 35 if cont then (phr, junk, output) :: loop new_pos 36 else [ (phr, junk, output) ] 37 in 38 loop 0