Re: [CEDET-devel] semantic-token creation
Brought to you by:
zappo
From: <ry...@ds...> - 2003-03-15 05:41:33
|
>>>>> "DP" == David PONCE <Dav...@wa...> writes: DP> DP> Hi Eric, DP> Following your work on providing a clean TAG API for grammars, I made DP> the attached patch to semantic (mostly the wisent part) to implement DP> the <any>-TAG macros :-) DP> DP> I updated the java grammars to use the new tag macros in place of DP> direct function calls. Effectively, the grammars now looks better DP> ;-), and more important, contain less implementation dependent code! Hi, I also replaced many (wisent-token ...) with the new macros in wisent-python.wy file. The only remaining use of (wisent-token ...) in that file are 'code' tags, e.g., (wisent-token $1 'code nil nil). In order to replace these with macros as well, I created CODE-TAG entry and added related code. The patch follows. It seemed like the right thing to do based on what David did. If this is not approprate, please ignore. #!bin/sh echo 'This patch file was create on Fri Mar 14 21:25:09 2003' echo 'PWD=/usr/local/src/cedet/semantic' echo '' patch -p0 <<EOFEOF Index: semantic-token.el =================================================================== RCS file: /cvsroot/cedet/cedet/semantic/semantic-token.el,v retrieving revision 1.6 diff -u -r1.6 semantic-token.el --- semantic-token.el 14 Mar 2003 02:28:32 -0000 1.6 +++ semantic-token.el 15 Mar 2003 05:30:38 -0000 @@ -24,7 +24,7 @@ ;;; Commentary: ;; ;; I. The core production of semantic is the list of tokens produced by the -;; different parsers. This files provides 3 APIs related to token access: +;; different parsers. This file provides 3 APIs related to token access: ;; ;; 1) Primitive Token Access ;; There is a set of common features to all tokens. These access @@ -468,6 +468,15 @@ EXTRA-SPECIFIERS is a property list of additional features of this token. Any property with a value of nil is not stored in the list." (list name 'package detail nil) + ) + +(defun semantic-tag-new-code (name detail &rest extra-specifiers) + "Create semantic token of type code. +NAME is a string representing the name of this token. +DETAIL is extra information about the tag. +EXTRA-SPECIFIERS is a property list of additional features of this token. +Any property with a value of nil is not stored in the list." + (list name 'code detail nil) ) ;; Lets test this out during this short transition. Index: wisent/wisent-grammar.el =================================================================== RCS file: /cvsroot/cedet/cedet/semantic/wisent/wisent-grammar.el,v retrieving revision 1.6 diff -u -r1.6 wisent-grammar.el --- wisent/wisent-grammar.el 14 Mar 2003 08:18:37 -0000 1.6 +++ wisent/wisent-grammar.el 15 Mar 2003 05:30:50 -0000 @@ -97,6 +97,11 @@ ARGS are the arguments passed to the expanded form." `(wisent-cook-tag ,@args)) +(defun wisent-grammar-CODE-TAG (name &rest args) + "Return expansion of built-in CODE-TAG expression. +NAME is the tag name." + `(wisent-raw-tag (semantic-tag-new-code name ,@args))) + (defconst wisent-grammar-builtins '( ;; Builtin name . Expander @@ -110,6 +115,7 @@ ( TYPE-TAG . wisent-grammar-TYPE-TAG) ( INCLUDE-TAG . wisent-grammar-INCLUDE-TAG) ( PACKAGE-TAG . wisent-grammar-PACKAGE-TAG) + ( CODE-TAG . wisent-grammar-CODE-TAG) ( EXPANDTAG . wisent-grammar-EXPANDTAG) ;; ------------ . --------------------------------- ) Index: wisent/wisent-python.el =================================================================== RCS file: /cvsroot/cedet/cedet/semantic/wisent/wisent-python.el,v retrieving revision 1.37 diff -u -r1.37 wisent-python.el --- wisent/wisent-python.el 14 Mar 2003 08:20:39 -0000 1.37 +++ wisent/wisent-python.el 15 Mar 2003 05:30:52 -0000 @@ -340,7 +340,7 @@ ;;;**************************************************************************** (defconst wisent-python-parser-tables - ;;DO NOT EDIT! Generated from wisent-python.wy - 2003-03-14 09:04+0100 + ;;DO NOT EDIT! Generated from wisent-python.wy - 2003-03-14 21:23-0800 (progn (eval-when-compile (require 'wisent-comp)) @@ -368,7 +368,8 @@ ((assert_stmt))) (print_stmt ((PRINT print_stmt_trailer) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (print_stmt_trailer ((test_list_opt) nil) @@ -391,7 +392,8 @@ (string-match "^\\(\\sw\\|\\s_\\)+$" $1)) (wisent-raw-tag (semantic-tag-new-variable $1 nil nil)) - (wisent-token $1 'code nil nil)))) + (wisent-raw-tag + (semantic-tag-new-code name))))) (expr_stmt_trailer ((augassign testlist)) ((eq_testlist_zom))) @@ -414,7 +416,8 @@ ((DIVDIVEQ))) (del_stmt ((DEL exprlist) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (exprlist ((expr_list comma_opt) nil)) @@ -425,7 +428,8 @@ nil)) (pass_stmt ((PASS) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (flow_stmt ((break_stmt)) ((continue_stmt)) @@ -434,23 +438,28 @@ ((yield_stmt))) (break_stmt ((BREAK) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (continue_stmt ((CONTINUE) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (return_stmt ((RETURN testlist_opt) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (testlist_opt (nil) ((testlist) nil)) (yield_stmt ((YIELD testlist) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (raise_stmt ((RAISE zero_one_two_or_three_tests) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (zero_one_two_or_three_tests (nil) ((test zero_one_or_two_tests) @@ -498,13 +507,15 @@ (format "%s.%s" $1 $3))) (global_stmt ((GLOBAL comma_sep_name_list) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (comma_sep_name_list ((NAME)) ((comma_sep_name_list COMMA NAME))) (exec_stmt ((EXEC expr exec_trailer) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (exec_trailer (nil) ((IN test comma_test_opt) @@ -515,7 +526,8 @@ nil)) (assert_stmt ((ASSERT test comma_test_opt) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (compound_stmt ((if_stmt)) ((while_stmt)) @@ -525,7 +537,8 @@ ((class_declaration))) (if_stmt ((IF test COLON suite elif_suite_pair_list else_suite_pair_opt) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (elif_suite_pair_list (nil) ((elif_suite_pair_list ELIF test COLON suite) @@ -554,15 +567,19 @@ ((compound_stmt))) (while_stmt ((WHILE test COLON suite else_suite_pair_opt) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (for_stmt ((FOR exprlist IN testlist COLON suite else_suite_pair_opt) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (try_stmt ((TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt) - (wisent-token $1 'code nil nil)) + (wisent-raw-tag + (semantic-tag-new-code name))) ((TRY COLON suite FINALLY COLON suite) - (wisent-token $1 'code nil nil))) + (wisent-raw-tag + (semantic-tag-new-code name)))) (except_clause_suite_pair_list ((except_clause COLON suite) nil) @@ -804,7 +821,7 @@ "Parser automaton.") (defconst wisent-python-keywords - ;;DO NOT EDIT! Generated from wisent-python.wy - 2003-03-14 09:04+0100 + ;;DO NOT EDIT! Generated from wisent-python.wy - 2003-03-14 21:23-0800 (semantic-lex-make-keyword-table '(("and" . AND) ("assert" . ASSERT) @@ -866,7 +883,7 @@ "Keywords.") (defconst wisent-python-tokens - ;;DO NOT EDIT! Generated from wisent-python.wy - 2003-03-14 09:04+0100 + ;;DO NOT EDIT! Generated from wisent-python.wy - 2003-03-14 21:23-0800 (wisent-lex-make-token-table '(("<no-type>" (DEDENT) @@ -939,7 +956,7 @@ ;;;###autoload (defun wisent-python-default-setup () "Setup buffer for parse." - ;;DO NOT EDIT! Generated from wisent-python.wy - 2003-03-14 09:04+0100 + ;;DO NOT EDIT! Generated from wisent-python.wy - 2003-03-14 21:23-0800 (progn (semantic-install-function-overrides '((parse-stream . wisent-parse-stream))) Index: wisent/wisent-python.wy =================================================================== RCS file: /cvsroot/cedet/cedet/semantic/wisent/wisent-python.wy,v retrieving revision 1.27 diff -u -r1.27 wisent-python.wy --- wisent/wisent-python.wy 14 Mar 2003 05:44:43 -0000 1.27 +++ wisent/wisent-python.wy 15 Mar 2003 05:30:53 -0000 @@ -318,7 +318,7 @@ ;; | '>>' test [ (',' test)+ [','] ] print_stmt : PRINT print_stmt_trailer - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; [ test (',' test)* [','] ] | '>>' test [ (',' test)+ [','] ] @@ -355,7 +355,7 @@ ;; If this is an assignment statement and left side is a symbol, ;; then generate a 'variable token, else return 'code token. (VARIABLE-TAG $1 nil nil) - (wisent-token $1 'code nil nil)) + (CODE-TAG $1)) ; ;; Could be EMPTY because of eq_testlist_zom. @@ -388,7 +388,7 @@ ;; del_stmt: 'del' exprlist del_stmt : DEL exprlist - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; exprlist: expr (',' expr)* [','] @@ -412,7 +412,7 @@ ;; pass_stmt: 'pass' pass_stmt : PASS - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;;;============================================================================ @@ -430,19 +430,19 @@ ;; break_stmt: 'break' break_stmt : BREAK - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; continue_stmt: 'continue' continue_stmt : CONTINUE - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; return_stmt: 'return' [testlist] return_stmt : RETURN testlist_opt - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; [testlist] @@ -455,13 +455,13 @@ ;; yield_stmt: 'yield' testlist yield_stmt : YIELD testlist - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; raise_stmt: 'raise' [test [',' test [',' test]]] raise_stmt : RAISE zero_one_two_or_three_tests - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; [test [',' test [',' test]]] @@ -553,7 +553,7 @@ ;; global_stmt: 'global' NAME (',' NAME)* global_stmt : GLOBAL comma_sep_name_list - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; NAME (',' NAME)* @@ -569,7 +569,7 @@ ;; exec_stmt: 'exec' expr ['in' test [',' test]] exec_stmt : EXEC expr exec_trailer - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; ['in' test [',' test]] @@ -593,7 +593,7 @@ ;; assert_stmt: 'assert' test [',' test] assert_stmt : ASSERT test comma_test_opt - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;;;**************************************************************************** @@ -616,7 +616,7 @@ ;; if_stmt: 'if' test ':' suite ('elif' test ':' suite)* ['else' ':' suite] if_stmt : IF test COLON suite elif_suite_pair_list else_suite_pair_opt - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; ('elif' test ':' suite)* @@ -664,7 +664,7 @@ ;; while_stmt: 'while' test ':' suite ['else' ':' suite] while_stmt : WHILE test COLON suite else_suite_pair_opt - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;;;============================================================================ @@ -674,7 +674,7 @@ ;; for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] for_stmt : FOR exprlist IN testlist COLON suite else_suite_pair_opt - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;;;============================================================================ @@ -685,9 +685,9 @@ ;; ['else' ':' suite] | 'try' ':' suite 'finally' ':' suite) try_stmt : TRY COLON suite except_clause_suite_pair_list else_suite_pair_opt - (wisent-token $1 'code nil nil) + (CODE-TAG $1) | TRY COLON suite FINALLY COLON suite - (wisent-token $1 'code nil nil) + (CODE-TAG $1) ; ;; (except_clause ':' suite)+ EOFEOF |