[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 7d2863e 065/385: tests for SMIE state inv
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 7d2863e 065/385: tests for SMIE state invalidation |
Date: |
Tue, 5 Oct 2021 23:59:02 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 7d2863e587239e8f0417d59e32b161d3b7113d50
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
tests for SMIE state invalidation
---
haskell-tng-layout.el | 1 -
haskell-tng-smie.el | 42 ++++++++++++++++++-------------------
test/haskell-tng-smie-test.el | 48 +++++++++++++++++++++++++++++++++++++++++--
3 files changed, 67 insertions(+), 24 deletions(-)
diff --git a/haskell-tng-layout.el b/haskell-tng-layout.el
index 0fb8480..b92570b 100644
--- a/haskell-tng-layout.el
+++ b/haskell-tng-layout.el
@@ -41,7 +41,6 @@
"For use in `after-change-functions' to invalidate the state of
the layout engine."
(when haskell-tng-layout:cache
- (message "INVALIDATING LAYOUT CACHE")
(setq haskell-tng-layout:cache nil)))
;; TODO a visual debugging option would be great, showing virtuals as overlays
diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el
index f42afbc..0c3db4b 100644
--- a/haskell-tng-smie.el
+++ b/haskell-tng-smie.el
@@ -27,19 +27,18 @@
;; The list of virtual tokens that must be played back at point, or `t' to
;; indicate that virtual tokens have already been played back at point and
;; normal lexing may continue.
-(defvar-local haskell-tng-smie:virtuals nil)
+(defvar-local haskell-tng-smie:state nil)
;; A cons cell of the last known direction and point when forward or backward
-;; lexing was called. Used to invalidate `haskell-tng-smie:virtuals' during
+;; lexing was called. Used to invalidate `haskell-tng-smie:state' during
;; read-only navigation.
(defvar-local haskell-tng-smie:last nil)
-(defun haskell-tng-smie:virtuals-invalidation (_beg _end _pre-length)
+(defun haskell-tng-smie:state-invalidation (_beg _end _pre-length)
"For use in `after-change-functions' to invalidate the state of
the lexer."
- (when haskell-tng-smie:virtuals
- (message "INVALIDATING SMIE VIRTUALS")
- (setq haskell-tng-smie:virtuals nil)))
+ (when haskell-tng-smie:state
+ (setq haskell-tng-smie:state nil)))
;; Implementation of `smie-forward-token' for Haskell, i.e.
;;
@@ -56,25 +55,26 @@ the lexer."
(defun haskell-tng-smie:forward-token ()
(unwind-protect
(let (case-fold-search)
- (when (and haskell-tng-smie:virtuals
+ (when (and haskell-tng-smie:state
(not (equal haskell-tng-smie:last `(forward . ,(point)))))
- (message "INVALIDATING SMIE VIRTUALS DUE TO JUMP")
- (setq haskell-tng-smie:virtuals nil))
+ (setq haskell-tng-smie:state nil))
- (if (consp haskell-tng-smie:virtuals)
+ (if (consp haskell-tng-smie:state)
;; continue replaying virtual tokens
(haskell-tng-smie:replay-virtual)
(forward-comment (point-max))
+
;; TODO: performance. Only request virtuals when they make sense...
- ;; e.g. on newlines, or following a WLDO (assuming a lookback is
- ;; faster).
- (setq haskell-tng-smie:virtuals
- (and (not haskell-tng-smie:virtuals)
- (haskell-tng-layout:virtuals-at-point)))
+ ;; e.g. on newlines, or following a WLDO (assuming a comment-aware
+ ;; lookback is fast).
+ (setq haskell-tng-smie:state
+ (unless haskell-tng-smie:state
+ (haskell-tng-layout:virtuals-at-point)))
+
(cond
;; new virtual tokens
- (haskell-tng-smie:virtuals
+ (haskell-tng-smie:state
(haskell-tng-smie:replay-virtual))
;; syntax tables (supported by `smie-indent-forward-token')
@@ -103,9 +103,9 @@ the lexer."
(defun haskell-tng-smie:replay-virtual ()
";; read a virtual token from state, set 't when all done"
(unwind-protect
- (pop haskell-tng-smie:virtuals)
- (unless haskell-tng-smie:virtuals
- (setq haskell-tng-smie:virtuals 't))))
+ (pop haskell-tng-smie:state)
+ (unless haskell-tng-smie:state
+ (setq haskell-tng-smie:state 't))))
(defun haskell-tng-smie:last-match ()
(goto-char (match-end 0))
@@ -142,13 +142,13 @@ the lexer."
(add-to-list
'after-change-functions
- #'haskell-tng-smie:virtuals-invalidation)
+ #'haskell-tng-smie:state-invalidation)
(smie-setup
haskell-tng-smie:grammar
haskell-tng-smie:rules
:forward-token #'haskell-tng-smie:forward-token
- ;; TODO :backward-token #'haskell-tng-smie:backward-token
+ ;; FIXME :backward-token #'haskell-tng-smie:backward-token
))
(provide 'haskell-tng-smie)
diff --git a/test/haskell-tng-smie-test.el b/test/haskell-tng-smie-test.el
index faffc41..f23ddb4 100644
--- a/test/haskell-tng-smie-test.el
+++ b/test/haskell-tng-smie-test.el
@@ -66,9 +66,53 @@ When called interactively, shows the tokens in a buffer."
(should (have-expected-forward-lex (testdata "src/layout.hs")))
)
-;; TODO the backwards test should assert consistency with forward
+(ert-deftest haskell-tng-smie-state-invalidation-tests ()
+ (with-temp-buffer
+ (insert-file-contents (testdata "src/layout.hs"))
+ (haskell-tng-mode)
+
+ ;; three parses at this position will produce a virtual token and a real
+ ;; token, then move the point for another token.
+ (goto-char 317)
+ (should (equal (haskell-tng-smie-test:indent-forward-token) ";"))
+ (should (= 317 (point)))
+ (should (equal (haskell-tng-smie-test:indent-forward-token) "stkToLst"))
+ (should (= 325 (point)))
+ (should (equal (haskell-tng-smie-test:indent-forward-token) "_("))
+ (should (= 327 (point)))
+
+ ;; repeating the above, but with a user edit, should reset the state
+ (goto-char 317)
+ (should (equal (haskell-tng-smie-test:indent-forward-token) ";"))
+ (should (= 317 (point)))
+ (save-excursion
+ (goto-char (point-max))
+ (insert " "))
+ (should (= 317 (point)))
+ (should (equal (haskell-tng-smie-test:indent-forward-token) ";"))
+ (should (= 317 (point)))
+ (should (equal (haskell-tng-smie-test:indent-forward-token) "stkToLst"))
+ (should (= 325 (point)))
+ (should (equal (haskell-tng-smie-test:indent-forward-token) "_("))
+ (should (= 327 (point)))
-;; FIXME test for cache invalidation
+ ;; repeating again, but jumping the lexer, should reset the state
+ (goto-char 317)
+ (should (equal (haskell-tng-smie-test:indent-forward-token) ";"))
+ (should (= 317 (point)))
+ (goto-char 327)
+ (should (equal (haskell-tng-smie-test:indent-forward-token) "MkStack"))
+ (should (= 334 (point)))
+ (goto-char 317)
+ (should (equal (haskell-tng-smie-test:indent-forward-token) ";"))
+ (should (= 317 (point)))
+ (should (equal (haskell-tng-smie-test:indent-forward-token) "stkToLst"))
+ (should (= 325 (point)))
+ (should (equal (haskell-tng-smie-test:indent-forward-token) "_("))
+ (should (= 327 (point)))
+ ))
+
+;; TODO the backwards test should assert consistency with forward
;; ideas for an indentation tester
;;
https://github.com/elixir-editors/emacs-elixir/blob/master/test/test-helper.el#L52-L63
- [nongnu] elpa/haskell-tng-mode b690037 081/385: comment-* support, (continued)
- [nongnu] elpa/haskell-tng-mode b690037 081/385: comment-* support, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 502cc26 085/385: document a failure mode, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 08f924c 088/385: simplify the grammar rules, better s-exps, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 71cf945 048/385: lexer test based on Haskell2010, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4d6bbfc 050/385: feedback from Stefan, improving lexing, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 96609e4 052/385: thoughts on layout inference, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 06b357c 054/385: hacky closing braces, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 64ad4a8 057/385: refactored to centralise state, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 0ac5a2f 059/385: copyright years and move the test assertions, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a6bb27e 061/385: [ci skip] layout algorithm implemented and tested, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 7d2863e 065/385: tests for SMIE state invalidation,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode 41a29dd 066/385: backward lexer, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode c48e7a5 069/385: starting to transcribe the expression table, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1f1110a 073/385: transcribe the grammar rules, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 01789b1 075/385: y u no haskell-mode?, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b8f3e3f 079/385: back out incomplete grammar rules, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9e19b2b 080/385: double down on simpler grammar, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6e7a24f 083/385: lexer identifies conid / varid, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b12e49a 086/385: consym, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 7d6fa3d 091/385: thoughts on lexers, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6a05d12 090/385: planning for indentation, ELPA Syncer, 2021/10/06