[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/phps-mode 9ac21f1 120/405: More work on inline and alte
From: |
Stefan Monnier |
Subject: |
[elpa] externals/phps-mode 9ac21f1 120/405: More work on inline and alternative control structures |
Date: |
Sat, 13 Jul 2019 09:59:56 -0400 (EDT) |
branch: externals/phps-mode
commit 9ac21f1d50e2983bc26444851e8f0aba387b970e
Author: Christian Johansson <address@hidden>
Commit: Christian Johansson <address@hidden>
More work on inline and alternative control structures
---
phps-mode-functions.el | 81 +++++++++++++++++++++++++++++++++++----------
phps-mode-test-functions.el | 4 +--
2 files changed, 65 insertions(+), 20 deletions(-)
diff --git a/phps-mode-functions.el b/phps-mode-functions.el
index 5dcdc95..a443b10 100644
--- a/phps-mode-functions.el
+++ b/phps-mode-functions.el
@@ -225,7 +225,9 @@
(line-in-doc-comment nil)
(found-line-tokens nil)
(after-special-control-structure nil)
- (round-brace-level 0))
+ (round-brace-level 0)
+ (expecting-semi-colon nil)
+ (first-token-on-line nil))
(catch 'stop-iteration
(dolist (item phps-mode-lexer-tokens)
(let ((token (car item))
@@ -247,10 +249,10 @@
;; When end of token is equal or less to beginning of current
line
(when (<= token-end line-beginning)
- ;; Change start token number
- (when (null start-token-number)
- (setq start-token-number -1))
- (setq start-token-number (+ start-token-number 1))
+ ;; Increment start token number
+ (if (null start-token-number)
+ (setq start-token-number 0)
+ (setq start-token-number (+ start-token-number 1)))
(pcase token
('T_OPEN_TAG (setq start-in-scripting t))
@@ -272,7 +274,15 @@
(equal token 'T_ENDFOR)
(equal token 'T_ENDFOREACH)
(equal token 'T_ENDSWITCH))
- (setq start-alternative-control-structure-level (-
start-alternative-control-structure-level 1))))
+ (setq start-alternative-control-structure-level (-
start-alternative-control-structure-level 1)))
+
+ ;; Reduce inline control structure level when we encounter a
semi-colon after it's opening
+ (when (and expecting-semi-colon
+ (string= token ";"))
+ (setq start-inline-control-structure-level (-
start-inline-control-structure-level 1))
+ (setq expecting-semi-colon nil))
+
+ )
;; Are we at the final line and inside a doc-comment that ends
after it?
(when (and (< token-start line-beginning)
@@ -282,9 +292,12 @@
;; When start of token is equal or less to end of curent line
(when (<= token-start line-end)
- (when (null end-token-number)
- (setq end-token-number -1))
- (setq end-token-number (+ end-token-number 1))
+
+ ;; Increment end token number
+ (if (null end-token-number)
+ (setq end-token-number 0)
+ (setq end-token-number (+ end-token-number 1)))
+
(pcase token
('T_OPEN_TAG (setq end-in-scripting t))
('T_OPEN_TAG_WITH_ECHO (setq end-in-scripting t))
@@ -305,7 +318,21 @@
(equal token 'T_ENDFOR)
(equal token 'T_ENDFOREACH)
(equal token 'T_ENDSWITCH))
- (setq end-alternative-control-structure-level (-
end-alternative-control-structure-level 1))))
+ (setq end-alternative-control-structure-level (-
end-alternative-control-structure-level 1)))
+
+ ;; Reduce inline control structure level when we encounter a
semi-colon after it's opening
+ (when (and expecting-semi-colon
+ (string= token ";"))
+ (setq end-inline-control-structure-level (-
end-inline-control-structure-level 1))
+ (setq expecting-semi-colon nil))
+
+ )
+
+ ;; Do we encounter first token on line?
+ (when (and (not first-token-on-line)
+ (>= token-start line-beginning)
+ (<= token-start line-end))
+ (setq first-token-on-line end-token-number))
;; Keep track of general round brace level
(when (string= token "(")
@@ -313,22 +340,40 @@
(when (string= token ")")
(setq round-brace-level (- round-brace-level 1)))
- ;; Are we after a special control structure
- ;; and does round bracket level match initial round bracket
level
- ;; and is token not a round bracket
+ ;; Are we after a special control structure
+ ;; and does the round bracket level match initial round bracket
level
+ ;; and is token not a round bracket
(when (and after-special-control-structure
(= after-special-control-structure round-brace-level)
(not (string= token ")"))
(not (string= token "(")))
+
+ ;; Is token not a curly bracket - because that is a ordinary
control structure syntax
(when (not (string= token "{"))
(message "After special control structure %s in buffer: %s
tokens: %s token-start: %s" token (buffer-substring-no-properties (point-min)
(point-max)) phps-mode-lexer-tokens token-start)
(if (string= token ":")
(progn
- (setq start-alternative-control-structure-level (+
start-alternative-control-structure-level 1))
- (message "Was colon"))
- (progn
- (setq start-inline-control-structure-level (+
start-inline-control-structure-level 1))
- (message "Was not colon"))))
+ (message "Was colon")
+
+ ;; Is token at or before line beginning?
+ (when (<= token-end line-beginning)
+ (setq start-alternative-control-structure-level (+
start-alternative-control-structure-level 1)))
+
+ ;; Is token at or before line end?
+ (when (<= token-start line-end)
+ (setq end-alternative-control-structure-level (+
end-alternative-control-structure-level 1)))
+
+ )
+
+ (when (or (<= token-end line-beginning)
+ (= first-token-on-line end-token-number))
+ (setq start-inline-control-structure-level (+
start-inline-control-structure-level 1)))
+
+ (when (<= token-start line-end)
+ (setq end-inline-control-structure-level (+
end-inline-control-structure-level 1)))
+
+ (setq expecting-semi-colon t)
+ (message "Was not colon")))
(setq after-special-control-structure nil))
diff --git a/phps-mode-test-functions.el b/phps-mode-test-functions.el
index ec25aaa..453462e 100644
--- a/phps-mode-test-functions.el
+++ b/phps-mode-test-functions.el
@@ -343,12 +343,12 @@
(phps-mode-test-with-buffer
"<?php\nif ($myCondition)\n echo 'was here';\necho 'was here 2';\n"
(goto-char 60)
- (should (equal (list (list t 0 0 0 0 0 4 nil) (list t 0 0 0 0 0 8 nil))
(phps-mode-functions-get-point-data))))
+ (should (equal (list (list t 0 0 0 0 0 4 nil) (list t 0 0 0 0 0 7 nil))
(phps-mode-functions-get-point-data))))
(phps-mode-test-with-buffer
"<?php\nif ($myCondition) echo 'was here'; echo 'was here 2';\n"
(goto-char 32)
- (should (equal (list (list t 0 0 0 1 0 4 nil) (list t 0 0 0 0 0 8 nil))
(phps-mode-functions-get-point-data))))
+ (should (equal (list (list t 0 0 0 0 0 4 nil) (list t 0 0 0 0 0 8 nil))
(phps-mode-functions-get-point-data))))
(phps-mode-test-with-buffer
"<?php\nif ($myCondition) echo 'was here'; echo 'was here 2';\n"
- [elpa] externals/phps-mode 2c9746b 101/405: Added switch case unit test for lexer, (continued)
- [elpa] externals/phps-mode 2c9746b 101/405: Added switch case unit test for lexer, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 47ad456 103/405: Fixed syntax table for white-spaces, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode cd1fdee 106/405: *** empty log message ***, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode efa297a 108/405: More work on renaming, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 529042e 109/405: More work on renaming, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7688cd7 111/405: Got incremental lexer working after renaming again, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9c4a3ba 117/405: More work on alternative control structures, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 3272991 110/405: Merge branch 'master' of https://github.com/cjohansson/emacs-phps-mode, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7c6ee3e 107/405: More work on renaming, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 46a8256 116/405: Starting implementation of tracking alternative control structure level, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 9ac21f1 120/405: More work on inline and alternative control structures,
Stefan Monnier <=
- [elpa] externals/phps-mode 41ef691 112/405: Fixed lint warning of unused variables, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 12c22ee 119/405: More work on alternative and inline meta information, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7e2e902 126/405: Fixed a unit test, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 80da137 114/405: Preparations for adding alternative and inline syntax, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode baab77a 121/405: Unit tests for inline control structures working, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode f0dc652 143/405: More work on new indentation function, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode 7dca537 105/405: Started work on renaming files, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e11a1fc 123/405: Fine-tuning of logic collecting data about inline and alternative control structures, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode e206605 115/405: Adding failing unit tests for inline and alternative syntax, Stefan Monnier, 2019/07/13
- [elpa] externals/phps-mode c6aa633 118/405: More work on keeping track of alternative control structures, Stefan Monnier, 2019/07/13