[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 96609e4 052/385: thoughts on layout infer
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 96609e4 052/385: thoughts on layout inference |
Date: |
Tue, 5 Oct 2021 23:59:00 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 96609e4b9a4b8572c0527dde20657434dbabd4ac
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
thoughts on layout inference
---
haskell-tng-smie.el | 41 +++++++++++++++++++++++++++++------------
test/lexer/layout.hs.lexer | 4 ++--
2 files changed, 31 insertions(+), 14 deletions(-)
diff --git a/haskell-tng-smie.el b/haskell-tng-smie.el
index 576a783..67ac14d 100644
--- a/haskell-tng-smie.el
+++ b/haskell-tng-smie.el
@@ -46,17 +46,27 @@
(case-fold-search nil)
(syntax (char-syntax (char-after))))
(cond
- ;; TODO brace inference
- ((and
- (not (eq start-line this-line))
- (<=
- (haskell-tng-smie:indentation-level (point))
- (haskell-tng-smie:indentation-level start))
- ";"))
+ ;; layout: semicolon inference
+ ((not (eq start-line this-line))
+ (let ((start-layout (haskell-tng-smie:layout-level start-line))
+ (this-layout (current-indentation)))
+ (cond
+ ((null start-layout) ""
+ (eq start-layout this-layout) ";"
+ t ""))))
;; parens
((member syntax '(?\( ?\) ?\" ?$)) nil)
+ ;; TODO brace inference ("offside" rule).
+ ;;
+ ;; Starting braces are trivial, there is a known list of keywords, so
+ ;; we just need to do a lookback when we hit a non-{ lexeme. Ending
+ ;; braces are a lot harder, as we need to calculate "do we need to
+ ;; close a brace here" every time the indentation level decreases. A
+ ;; possible solution is to calculate and cache the closing brace when
+ ;; discovering an open brace, but that just introduces more problems.
+
;; regexps
((or
;; known identifiers
@@ -68,12 +78,19 @@
(goto-char (match-end 0))
(match-string-no-properties 0)))))))
-(defun haskell-tng-smie:indentation-level (p)
- "Calculates the indentation level of the most inner part of the given
point's line."
- ;; FIXME this is a hack for now, look for `let', `do' and friends according
to
- ;; the Haskell2010 report.
+(defun haskell-tng-smie:layout-level (line)
+ "Calculates the layout indentation of the most inner part of
+the given point's line."
+ ;; FIXME should the input be the line numbers?
+ ;;
+ ;; TODO starting at the end of the line, look backwards for wldo (where,
let, do, of).
+ ;; If the wldo is the last lexeme, then the layout level is set by the next
line (return nil).
+ ;; If the wldo is followed by a non-brace lexeme, set the layout level.
+ ;;
+ ;; If there is no wldo, the layout level is set by the indentation level
+ ;; (think about this some more)
(save-excursion
- (goto-char p)
+ (goto-line line)
(current-indentation)))
;; TODO a haskell grammar
diff --git a/test/lexer/layout.hs.lexer b/test/lexer/layout.hs.lexer
index d048eb2..f76687b 100644
--- a/test/lexer/layout.hs.lexer
+++ b/test/lexer/layout.hs.lexer
@@ -64,8 +64,8 @@ where
stkToLst
Empty
=
-[
-]
+SYNTAX_[
+SYNTAX_]
;
stkToLst
SYNTAX_(
- [nongnu] elpa/haskell-tng-mode 3e53f56 055/385: cleaner lexer test output, (continued)
- [nongnu] elpa/haskell-tng-mode 3e53f56 055/385: cleaner lexer test output, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 73e2b11 063/385: the new lexer works!, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8e1a225 068/385: sexp tests, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 269be91 072/385: revert broken grammar rules, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3194e62 074/385: stefan to the rescue, ELPA Syncer, 2021/10/06
- [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 <=
- [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, 2021/10/06
- [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