let regexp ident_letter = [ 'a' - 'z' 'A' - 'Z' ]
+ (* must be in sync with "is_ligature_char" below *)
let regexp ligature_char = [ "'`~!?@*()[]<>-+=|:;.,/\"" ]
let regexp ligature = ligature_char ligature_char+
+let is_ligature_char =
+ (* must be in sync with "regexp ligature_char" above *)
+ let chars = "'`~!?@*()[]<>-+=|:;.,/\"" in
+ (fun char ->
+ (try
+ ignore (String.index chars char);
+ true
+ with Not_found -> false))
+
let regexp ident_decoration = '\'' | '?' | '`'
let regexp ident_cont = ident_letter | xml_digit | '_'
let regexp ident = ident_letter ident_cont* ident_decoration*
let acc = acc ^ Ulexing.utf8_lexeme lexbuf in
comment_token acc depth lexbuf
+let lookup_ligatures lexeme = List.rev (Hashtbl.find_all ligatures lexeme)
+
(** @param k continuation to be invoked when no ligature has been found *)
let rec ligatures_token k =
lexer
| ligature ->
let lexeme = Ulexing.utf8_lexeme lexbuf in
- (match Hashtbl.find_all ligatures lexeme with
+ (match lookup_ligatures lexeme with
| [] -> (* ligature not found, rollback and try default lexer *)
Ulexing.rollback lexbuf;
k lexbuf
- | ligs -> (* ligatures found, use the default one *)
- let default_lig = List.hd (List.rev ligs) in
+ | default_lig :: _ -> (* ligatures found, use the default one *)
return_symbol lexbuf default_lig)
| eof -> return_eoi lexbuf
| _ -> (* not a ligature, rollback and try default lexer *)