Skip to content

Commit 3b88a72

Browse files
committed
Emit include tags and improve grammar actions
Parser should perform slightly better and make better apply the mixed-style bison/iterative parsing mechanism.
1 parent b254bbc commit 3b88a72

17 files changed

+351
-349
lines changed

semantic-php-test.el

+5-2
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,16 @@ buffer."
114114
(defmacro with-semantic-tag (tag &rest body)
115115
"Analyze given TAG and execute BODY"
116116
`(let ((tag ,tag)
117-
tag-name tag-class tag-type tag-attribs tag-props tag-overlay)
117+
tag-name tag-class tag-type tag-attribs tag-props
118+
tag-members tag-overlay tag-reparse-symbol)
118119
(setq tag-name (semantic-tag-name tag)
119120
tag-class (semantic-tag-class tag)
120121
tag-type (semantic-tag-type tag)
121122
tag-attribs (semantic-tag-attributes tag)
122123
tag-props (semantic-tag-properties tag)
123-
tag-overlay (semantic-tag-overlay tag))
124+
tag-members (semantic-tag-components tag)
125+
tag-overlay (semantic-tag-overlay tag)
126+
tag-reparse-symbol (plist-get tag-props 'reparse-symbol))
124127
,@body))
125128

126129
(require 'test/context)

semantic-php-util.el

+25-18
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,32 @@ parser can parse source files of common frameworks and libraries."
4949
(require 'semantic-php)
5050
(require 'test/php-faux-mode)
5151

52-
(dolist (file files)
53-
;; Open the file in a buffer
54-
(find-file file)
52+
(semantic-php-util-measure
53+
(dolist (file files)
54+
;; Open the file in a buffer
55+
(find-file file)
5556

56-
(message "Parsing %s" file)
57+
(message "Parsing %s" file)
5758

58-
;; Load fake php-mode
59-
(php-mode)
59+
;; Load fake php-mode
60+
(php-mode)
6061

61-
;; Enable semantic-php
62-
(semantic-php-default-setup)
63-
(semantic-lex-init)
62+
;; Enable semantic-php
63+
(semantic-php-default-setup)
64+
(semantic-lex-init)
6465

65-
;; Parse the file
66-
(setq tagcount (+ tagcount (length
67-
(wisent-parse-region (point-min) (point-max)))))
66+
;; Parse the file
67+
(setq tagcount (+ tagcount (length
68+
(wisent-parse-region (point-min) (point-max)))))
6869

69-
;; Clean up and report progress
70-
(kill-buffer)
70+
;; Clean up and report progress
71+
(kill-buffer)
7172

72-
(progress-reporter-update progress-reporter
73-
(setq progress (1+ progress))))
73+
(progress-reporter-update progress-reporter
74+
(setq progress (1+ progress))))
7475

75-
(progress-reporter-done progress-reporter)
76-
(message "Found total of %d tags" tagcount)))
76+
(progress-reporter-done progress-reporter)
77+
(message "Found total of %d tags" tagcount))))
7778

7879
(defun semantic-php-util-files-in-directory (directory)
7980
"Scan DIRECTORY recursively for source files.
@@ -95,6 +96,12 @@ Returns a list of absolute file names."
9596
;; Collect found source file
9697
(setq files (nconc files (list fullpath))))))))
9798

99+
(defmacro semantic-php-util-measure (&rest body)
100+
"Measure time while evaluating BODY."
101+
`(let ((time (current-time)))
102+
,@body
103+
(message "Total parsing time: %.04f seconds" (float-time (time-since time)))))
104+
98105
(defun semantic-php-util-compile-grammar ()
99106
"Generate the wisent parser semantic-php-wy.el."
100107
(let* ((grammar-path (concat (or (getenv "PACKAGE_PATH")

semantic-php-wy-macro.el

+23-14
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,29 @@
2626
;; TODO: create cleverer expand* macro's to accomodate cases like
2727
;; inline_use_statements, parenthesized expressions, etc.
2828

29-
(defun semantic-php-wy-macro-EXPANDFULL (symb nonterm &optional depth)
30-
"Expand call to EXPANDFULL grammar macro.
31-
Return the form to recursively parse an area.
32-
SYMB is a $I placeholder symbol that gives the bounds of the area.
33-
NONTERM is the nonterminal symbol to start with.
34-
DEPTH is the maximum parsing depth (defaults to 1)."
35-
(unless (member nonterm (semantic-grammar-start))
36-
(error "EXPANDFULL macro called with %s, but not used with %%start"
37-
nonterm))
38-
(let (($ri (wisent-grammar-region-placeholder symb)))
39-
(if $ri
40-
`(semantic-parse-region
41-
(car ,$ri) (cdr ,$ri) ',nonterm (or ,depth 1))
42-
(error "Invalid form (EXPANDFULL %s %s)" symb nonterm))))
29+
(defun semantic-php-wy-macro-INCLUDE-TAG (name system-flag &rest attributes)
30+
"Expand call to INCLUDE-TAG grammar macro.
31+
32+
Same as grammar-macros.el INCLUDE-TAG but allows NAME to be the
33+
result of the expr rule. An include tag is emitted only when NAME
34+
is a string, or NAME is list of one 'code tag with name
35+
\"scalar\" and contains the include name in the :detail
36+
attribute.
37+
38+
Return the form to create a semantic tag of class include.
39+
See the function `semantic-tag-new-include' for the meaning of
40+
arguments NAME, SYSTEM-FLAG and ATTRIBUTES."
41+
`(let (incname)
42+
(if (stringp ,name)
43+
(setq incname ,name)
44+
(when (and (equal 1 (length ,name))
45+
(semantic-tag-of-class-p (car ,name) 'scalar))
46+
(setq incname (semantic-tag-name (car ,name)))))
47+
48+
(when incname
49+
(wisent-cook-tag
50+
(wisent-raw-tag
51+
(semantic-tag-new-include (substring incname 1 -1) ,system-flag ,@attributes))))))
4352

4453
(defun semantic-php-wy-macro-EXPANDLIST (tags)
4554
"Expand a list of raw tags TAGS."

semantic-php.el

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@
131131
132132
If the name of the tag is a cons cell, assume (name . (start . end))
133133
and set bounds accordingly."
134-
;; TODO: restore expansion of use_declarations, compount class
134+
;; TODO: restore expansion of use_declarations, compound class
135135
;; properties and constant definitions, trait usages and global and
136136
;; static variables.
137137
nil)

0 commit comments

Comments
 (0)