|
34 | 34 | table) |
35 | 35 | "Elixir mode syntax table.") |
36 | 36 |
|
37 | | -(defmacro elixir-smie-debug (message &rest format-args) |
38 | | - `(progn |
39 | | - (when elixir-smie-verbose-p |
40 | | - (message (format ,message ,@format-args))) |
41 | | - nil)) |
42 | | - |
43 | | -(defconst elixir-smie-block-intro-keywords |
44 | | - '(do else catch after rescue -> OP) |
45 | | - "Keywords in which newlines cause confusion for the parser.") |
46 | | - |
47 | | -(defvar elixir-smie--operator-regexp |
48 | | - (regexp-opt '("<<<" ">>>" "^^^" "~~~" "&&&" "|||" "===" "!==" "==" "!=" "<=" |
49 | | - ">=" "<" ">" "&&" "||" "<>" "++" "--" "//" |
50 | | - "/>" "=~" "|>" "->"))) |
51 | | - |
52 | | -(defun elixir-smie--at-dot-call () |
53 | | - (and (eq ?w (char-syntax (following-char))) |
54 | | - (eq (char-before) ?.) |
55 | | - (not (eq (char-before (1- (point))) ?.)))) |
56 | | - |
57 | | -(defun elixir-smie--implicit-semi-p () |
58 | | - (not (or (memq (char-before) '(?\{ ?\[)) |
59 | | - (looking-back elixir-smie--operator-regexp (- (point) 3) t)))) |
60 | | - |
61 | | -(defun elixir-smie-forward-token () |
62 | | - (cond |
63 | | - ((and (looking-at "\n") (elixir-smie--implicit-semi-p)) |
64 | | - (if (eolp) (forward-char 1) (forward-comment 1)) |
65 | | - ";") |
66 | | - ((looking-at elixir-smie--operator-regexp) |
67 | | - (goto-char (match-end 0)) |
68 | | - "OP") |
69 | | - (t (smie-default-forward-token)))) |
70 | | - |
71 | | -(defun elixir-smie-backward-token () |
72 | | - (let ((pos (point))) |
73 | | - (forward-comment (- (point))) |
74 | | - (cond |
75 | | - ((and (> pos (line-end-position)) |
76 | | - (elixir-smie--implicit-semi-p)) |
77 | | - ";") |
78 | | - ((looking-back elixir-smie--operator-regexp (- (point) 3) t) |
79 | | - (goto-char (match-beginning 0)) |
80 | | - "OP") |
81 | | - (t (smie-default-backward-token))))) |
82 | | - |
83 | 37 | (defconst elixir-smie-grammar |
84 | 38 | (smie-prec2->grammar |
85 | 39 | (smie-merge-prec2s |
|
121 | 75 | (left "+" "-" "<<<" ">>>" "^^^" "~~~" "&&&" "|||") |
122 | 76 | (left "*" "/")))))) |
123 | 77 |
|
| 78 | +(defvar elixir-smie--operator-regexp |
| 79 | + (regexp-opt '("<<<" ">>>" "^^^" "~~~" "&&&" "|||" "===" "!==" "==" "!=" "<=" |
| 80 | + ">=" "<" ">" "&&" "||" "<>" "++" "--" "//" |
| 81 | + "/>" "=~" "|>" "->"))) |
| 82 | + |
124 | 83 | (defvar elixir-smie-indent-basic 2) |
125 | 84 |
|
| 85 | +(defmacro elixir-smie-debug (message &rest format-args) |
| 86 | + `(progn |
| 87 | + (when elixir-smie-verbose-p |
| 88 | + (message (format ,message ,@format-args))) |
| 89 | + nil)) |
| 90 | + |
| 91 | +(defun elixir-smie--at-dot-call () |
| 92 | + (and (eq ?w (char-syntax (following-char))) |
| 93 | + (eq (char-before) ?.) |
| 94 | + (not (eq (char-before (1- (point))) ?.)))) |
| 95 | + |
| 96 | +(defun elixir-smie--implicit-semi-p () |
| 97 | + (not (or (memq (char-before) '(?\{ ?\[)) |
| 98 | + (looking-back elixir-smie--operator-regexp (- (point) 3) t)))) |
| 99 | + |
| 100 | +(defun elixir-smie-forward-token () |
| 101 | + (cond |
| 102 | + ((and (looking-at "\n") (elixir-smie--implicit-semi-p)) |
| 103 | + (if (eolp) (forward-char 1) (forward-comment 1)) |
| 104 | + ";") |
| 105 | + ((looking-at elixir-smie--operator-regexp) |
| 106 | + (goto-char (match-end 0)) |
| 107 | + "OP") |
| 108 | + (t (smie-default-forward-token)))) |
| 109 | + |
| 110 | +(defun elixir-smie-backward-token () |
| 111 | + (let ((pos (point))) |
| 112 | + (forward-comment (- (point))) |
| 113 | + (cond |
| 114 | + ((and (> pos (line-end-position)) |
| 115 | + (elixir-smie--implicit-semi-p)) |
| 116 | + ";") |
| 117 | + ((looking-back elixir-smie--operator-regexp (- (point) 3) t) |
| 118 | + (goto-char (match-beginning 0)) |
| 119 | + "OP") |
| 120 | + (t (smie-default-backward-token))))) |
| 121 | + |
126 | 122 | (defun verbose-elixir-smie-rules (kind token) |
127 | 123 | (let ((value (elixir-smie-rules kind token))) |
128 | 124 | (elixir-smie-debug "%s '%s'; sibling-p:%s parent:%s prev-is-OP:%s hanging:%s == %s" kind token |
|
0 commit comments