X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fcic_notation%2FcicNotationLexer.ml;h=01ef6142c8de0c45603a341129804e98074ee78d;hb=ba2dfe6409e95bf9e558dc0d4be382b068671409;hp=26dc5aacae4b9e8f83ec1f9863d1b700e13fdd6f;hpb=7aa0e7901b71a660c6d6f55d96a38a3a9d1d3c7d;p=helm.git diff --git a/helm/ocaml/cic_notation/cicNotationLexer.ml b/helm/ocaml/cic_notation/cicNotationLexer.ml index 26dc5aaca..01ef6142c 100644 --- a/helm/ocaml/cic_notation/cicNotationLexer.ml +++ b/helm/ocaml/cic_notation/cicNotationLexer.ml @@ -62,6 +62,14 @@ let level1_layouts = "sqrt"; "root" ] +let level1_keywords = + [ "hbox"; "hvbox"; "hovbox"; "vbox"; + "break"; + "list0"; "list1"; "sep"; + "opt"; + "term"; "ident"; "number" + ] @ level1_layouts + let level2_meta_keywords = [ "if"; "then"; "else"; "fold"; "left"; "right"; "rec"; @@ -70,13 +78,19 @@ let level2_meta_keywords = "anonymous"; "ident"; "number"; "term"; "fresh" ] -let level1_keywords = - [ "hbox"; "hvbox"; "hovbox"; "vbox"; - "break"; - "list0"; "list1"; "sep"; - "opt"; - "term"; "ident"; "number" - ] + (* (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" ] + +let add_level2_ast_keyword k = + prerr_endline ("Adding keyword " ^ k); + Hashtbl.add level2_ast_keywords k () +let remove_level2_ast_keyword k = Hashtbl.remove level2_ast_keywords k let regexp uri = ("cic:/" | "theory:/") (* schema *) @@ -173,26 +187,38 @@ let rec level2_meta_token = lexer return lexbuf ("IDENT", s) end | "@{" -> read_unparsed_group "UNPARSED_AST" lexbuf - | ast_ident -> return lexbuf ("UNPARSED_AST", remove_left_quote (Ulexing.utf8_lexeme lexbuf)) - | ast_csymbol -> return lexbuf ("UNPARSED_AST", remove_left_quote (Ulexing.utf8_lexeme lexbuf)) + | ast_ident -> + return lexbuf ("UNPARSED_AST", + remove_left_quote (Ulexing.utf8_lexeme lexbuf)) + | ast_csymbol -> + return lexbuf ("UNPARSED_AST", + remove_left_quote (Ulexing.utf8_lexeme lexbuf)) | eof -> return lexbuf ("EOI", "") 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) - | ident -> return lexbuf ("IDENT", Ulexing.utf8_lexeme lexbuf) + | ident -> + let lexeme = Ulexing.utf8_lexeme lexbuf in + if Hashtbl.mem level2_ast_keywords lexeme then + return lexbuf ("", lexeme) + 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)) + | qstring -> + return lexbuf ("QSTRING", remove_quotes (Ulexing.utf8_lexeme lexbuf)) | csymbol -> return lexbuf ("CSYMBOL", Ulexing.utf8_lexeme lexbuf) | "${" -> read_unparsed_group "UNPARSED_META" lexbuf | "@{" -> read_unparsed_group "UNPARSED_AST" lexbuf | '(' -> return lexbuf ("LPAREN", "") | ')' -> return lexbuf ("RPAREN", "") - | meta_ident -> return lexbuf ("UNPARSED_META", remove_left_quote (Ulexing.utf8_lexeme lexbuf)) + | meta_ident -> + 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) | eof -> return lexbuf ("EOI", "") @@ -209,7 +235,8 @@ let rec level1_pattern_token = lexer return lexbuf ("IDENT", s) end | tex_token -> return lexbuf (expand_macro lexbuf) - | qkeyword -> return lexbuf ("QKEYWORD", remove_quotes (Ulexing.utf8_lexeme lexbuf)) + | qkeyword -> + return lexbuf ("QKEYWORD", remove_quotes (Ulexing.utf8_lexeme lexbuf)) | '(' -> return lexbuf ("LPAREN", "") | ')' -> return lexbuf ("RPAREN", "") | eof -> return lexbuf ("EOI", "")