X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fcic_notation%2FcicNotationLexer.ml;h=9c0efc8bb99a8b06c6b1e684637c1da562ba7c55;hb=f981a524748846acc29b76b6e616af110b4ee13d;hp=01ef6142c8de0c45603a341129804e98074ee78d;hpb=ba2dfe6409e95bf9e558dc0d4be382b068671409;p=helm.git diff --git a/helm/ocaml/cic_notation/cicNotationLexer.ml b/helm/ocaml/cic_notation/cicNotationLexer.ml index 01ef6142c..9c0efc8bb 100644 --- a/helm/ocaml/cic_notation/cicNotationLexer.ml +++ b/helm/ocaml/cic_notation/cicNotationLexer.ml @@ -29,19 +29,24 @@ exception Error of int * int * string let regexp number = xml_digit+ + (* ZACK: breaks unicode's binder followed by an ascii letter without blank *) +(* let regexp ident_letter = xml_letter *) + +let regexp ident_letter = [ 'a' - 'z' 'A' - 'Z' ] + let regexp ident_decoration = '\'' | '!' | '?' | '`' -let regexp ident_cont = xml_letter | xml_digit | '_' -let regexp ident = xml_letter ident_cont* ident_decoration* +let regexp ident_cont = ident_letter | xml_digit | '_' +let regexp ident = ident_letter ident_cont* ident_decoration* let regexp tex_token = '\\' ident let regexp delim_begin = "\\[" let regexp delim_end = "\\]" -let regexp keyword = '"' ident '"' let regexp qkeyword = "'" ident "'" let regexp implicit = '?' +let regexp placeholder = '%' let regexp meta = implicit number let regexp csymbol = '\'' ident @@ -55,6 +60,11 @@ let regexp meta_ident = "$" ident let regexp meta_anonymous = "$_" let regexp qstring = '"' [^ '"']* '"' +let regexp begincomment = "(**" xml_blank +let regexp endcomment = "*)" +let regexp comment_char = [^'*'] | '*'[^')'] +let regexp note = "(*" ([^'*'] | "**") comment_char* "*)" + let level1_layouts = [ "sub"; "sup"; "below"; "above"; @@ -81,15 +91,11 @@ let level2_meta_keywords = (* (string, unit) Hashtbl.t, to exploit multiple bindings *) let level2_ast_keywords = Hashtbl.create 23 let _ = - (* TODO ZACK: keyword list almost cut and paste from cicTextualLexer2.ml, to - * be reviewed *) List.iter (fun k -> Hashtbl.add level2_ast_keywords k ()) - [ "Prop"; "Type"; "Set"; "let"; "rec"; "corec"; "match"; "with"; "in"; - "and"; "on" ] + [ "CProp"; "Prop"; "Type"; "Set"; "let"; "rec"; "corec"; "using"; "match"; + "with"; "in"; "and"; "to"; "as"; "on"; "names" ] -let add_level2_ast_keyword k = - prerr_endline ("Adding keyword " ^ k); - Hashtbl.add level2_ast_keywords k () +let add_level2_ast_keyword k = Hashtbl.add level2_ast_keywords k () let remove_level2_ast_keyword k = Hashtbl.remove level2_ast_keywords k let regexp uri = @@ -152,8 +158,6 @@ let expand_macro lexbuf = ("SYMBOL", Utf8Macro.expand macro) with Utf8Macro.Macro_not_found _ -> "SYMBOL", Ulexing.utf8_lexeme lexbuf -let keyword lexbuf = "KEYWORD", remove_quotes (Ulexing.utf8_lexeme lexbuf) - let remove_quotes s = String.sub s 1 (String.length s - 2) let remove_left_quote s = String.sub s 1 (String.length s - 1) @@ -198,7 +202,8 @@ let rec level2_meta_token = lexer let rec level2_ast_token = lexer | xml_blank+ -> level2_ast_token lexbuf | meta -> return lexbuf ("META", Ulexing.utf8_lexeme lexbuf) - | implicit -> return lexbuf ("IMPLICIT", Ulexing.utf8_lexeme lexbuf) + | implicit -> return lexbuf ("IMPLICIT", "") + | placeholder -> return lexbuf ("PLACEHOLDER", "") | ident -> let lexeme = Ulexing.utf8_lexeme lexbuf in if Hashtbl.mem level2_ast_keywords lexeme then @@ -206,12 +211,12 @@ let rec level2_ast_token = lexer else return lexbuf ("IDENT", lexeme) | number -> return lexbuf ("NUMBER", Ulexing.utf8_lexeme lexbuf) - | keyword -> return lexbuf (keyword lexbuf) | tex_token -> return lexbuf (expand_macro lexbuf) | uri -> return lexbuf ("URI", Ulexing.utf8_lexeme lexbuf) | qstring -> return lexbuf ("QSTRING", remove_quotes (Ulexing.utf8_lexeme lexbuf)) - | csymbol -> return lexbuf ("CSYMBOL", Ulexing.utf8_lexeme lexbuf) + | csymbol -> + return lexbuf ("CSYMBOL", remove_left_quote (Ulexing.utf8_lexeme lexbuf)) | "${" -> read_unparsed_group "UNPARSED_META" lexbuf | "@{" -> read_unparsed_group "UNPARSED_AST" lexbuf | '(' -> return lexbuf ("LPAREN", "") @@ -220,8 +225,15 @@ let rec level2_ast_token = lexer return lexbuf ("UNPARSED_META", remove_left_quote (Ulexing.utf8_lexeme lexbuf)) | meta_anonymous -> return lexbuf ("UNPARSED_META", "anonymous") - | _ -> return lexbuf ("SYMBOL", Ulexing.utf8_lexeme lexbuf) + | note -> + let comment = + Ulexing.utf8_sub_lexeme lexbuf 2 (Ulexing.lexeme_length lexbuf - 4) + in + return lexbuf ("NOTE", comment) + | begincomment -> return lexbuf ("BEGINCOMMENT","") + | endcomment -> return lexbuf ("ENDCOMMENT","") | eof -> return lexbuf ("EOI", "") + | _ -> return lexbuf ("SYMBOL", Ulexing.utf8_lexeme lexbuf) let rec level1_pattern_token = lexer | xml_blank+ -> level1_pattern_token lexbuf