Skip to content

Commit 04e98a0

Browse files
committed
[WIP] Support braceless namespaces
When the wisent grammar encounters a braceless namespace statement, it emits a simple namespace tag with a `:braceless` attribute set, and leaves the next tags at the same levels while they should be members of the namespace. This commit adds a post-processing step to the toplevel parsing that moves all tags after a braceless namespace in its `:members` property.
1 parent deb9885 commit 04e98a0

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

semantic-php.el

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,44 @@ emitting separate symbols for classes, interfaces and traits."
150150
(semantic-tag-type-members tag)))
151151
(t nil)))
152152

153+
(defun semantic-php--push-tag-with-braceless (tag-table tag)
154+
"Handle braceless namespaces by growing TAG-TABLE with TAG.
155+
156+
If the last tag of TAG-TABLE is a braceless namespace, insert
157+
TAG as a member of it. Otherwise, just put TAG at the
158+
end of TAG-TABLE."
159+
(let ((last-tag (car (last tag-table)))
160+
members)
161+
(if (and last-tag (semantic-tag-get-attribute last-tag :braceless))
162+
(progn
163+
(setq members (semantic-tag-type-members last-tag))
164+
(push tag members)
165+
(semantic-tag-put-attribute last-tag :members members)
166+
tag-table)
167+
(push tag tag-table))))
168+
169+
(defun semantic-php-expand-braceless-tags (tag-table)
170+
"Include all tags following a braceless type in its members.
171+
172+
TAG-TABLE is the list of tags on which looking for braceless tags
173+
and merging the next siblings.
174+
175+
It returns a new tag list."
176+
(let ((expanded-tag-table '()))
177+
(dolist (tag tag-table)
178+
(setq expanded-tag-table (semantic-php--push-tag-with-braceless expanded-tag-table tag)))
179+
expanded-tag-table))
180+
181+
(define-mode-local-override semantic-parse-region
182+
php-mode (start end &optional nonterminal depth returnonerror)
183+
"Overrides `semantic-parse-region' to apply some post-processing to the result.
184+
185+
When this is a full reparse, merge braceless statements."
186+
(let ((raw-result (semantic-parse-region-default start end nonterminal depth returnonerror)))
187+
(if (and (= start (point-min)) (= end (point-max)))
188+
(semantic-php-expand-braceless-tags raw-result)
189+
raw-result)))
190+
153191
(define-mode-local-override semantic-get-local-variables
154192
php-mode (&optional point)
155193
"Get local values from the context of point.

0 commit comments

Comments
 (0)