branch: externals/javaimp commit 6af25f120e5dbc8146718d947f51675c500cab97 Author: Filipp Gunbin <fgun...@fastmail.fm> Commit: Filipp Gunbin <fgun...@fastmail.fm>
* javaimp-parse.el: Add 'array' scope --- javaimp-parse.el | 15 +++++++++++++-- javaimp-tests.el | 8 ++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/javaimp-parse.el b/javaimp-parse.el index df5df2a..8cf8e35 100644 --- a/javaimp-parse.el +++ b/javaimp-parse.el @@ -33,7 +33,7 @@ present." (cl-defstruct javaimp-scope type ; one of anonymous-class, class, interface, enum, local-class, - ; method, statement, simple-statement, unknown + ; method, statement, simple-statement, array, unknown name start open-brace) @@ -123,7 +123,8 @@ non-nil or t. Otherwise the return value is nil. If STOP-P wants to look forward, it should be prepared to see whitespace / comments, this is because backward movement skips them before invoking STOP-P. It should not move point. If -omitted, it defaults to `always'." +omitted, it defaults to `always', in this case the effect of the +function is to just skip whitespace / comments." (or stop-p (setq stop-p #'always)) (catch 'done (let (last-what last-pos) @@ -320,6 +321,16 @@ not be continued." (goto-char pos) nil)))) +(defun javaimp--parse-scope-array (state) + "Attempts to parse 'array' scope." + (save-excursion + (and (javaimp--parse-skip-back-until) + (member (char-before) '(?, ?{ ?\])) + (make-javaimp-scope :type 'array + :name "" + :start nil + :open-brace (nth 1 state))))) + (defun javaimp--parse-scope-unknown (state) "Catch-all parser which produces `unknown' scope." (make-javaimp-scope :type 'unknown diff --git a/javaimp-tests.el b/javaimp-tests.el index 80d72c4..a54d8ff 100644 --- a/javaimp-tests.el +++ b/javaimp-tests.el @@ -94,6 +94,14 @@ throws E1 {" '("static {" simple-statement "static"))) +(ert-deftest javaimp-test--parse-scope-array () + (javaimp-test--check-scope #'javaimp--parse-scope-array + '("new String[] {" + array "") + '("new Object[][] { {" + array "") + '("new int[] {{1, 2}, {" + array ""))) (ert-deftest javaimp-test--parse-arglist () (dolist (data '(("")