branch: elpa/raku-mode
commit ce3ef00b826f7613ef07450b8c15bd0a3a5fe722
Author: Hinrik Örn Sigurðsson <[email protected]>
Commit: Hinrik Örn Sigurðsson <[email protected]>
Syntax propertize <quoted words>
This is more or less a direct port of the regexes used in vim-perl.
Works decently, but can be made more efficient by doing only doing one
pair of looking-back/looking-at calls.
---
perl6-font-lock.el | 25 ++++++++++++++++++++++++-
test/perl6-mode-test.el | 8 ++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/perl6-font-lock.el b/perl6-font-lock.el
index 251ad203e9..a2452c0f5b 100644
--- a/perl6-font-lock.el
+++ b/perl6-font-lock.el
@@ -227,6 +227,27 @@ LENGTH is the length of the brackets (e.g. 2 for a
<<foo>>)."
(put-text-property (- comment-end 1) comment-end
'syntax-table (string-to-syntax "!"))))))))
+(defun perl6-syntax-propertize-angle ()
+ "Add syntax properties to angle-bracketed quotes (<foo bar>)."
+ (unless (or (looking-at "[-=]")
+ (looking-back "[+~=!]<" 2))
+ (when (or (or (not (looking-at "[\s\n]"))
+ (not (looking-back "[\s\n]<" 1)))
+ (looking-at "<\s+>")
+ (looking-back "=\s+<")
+ (looking-back "\(\s*<")
+ (or (looking-at "\s*$") (looking-back "^\s*<"))
+ (looking-back (perl6-rx (symbol (or "enum" "for" "any" "all"
"none"))
+ (0+ space) (opt "\)") (0+ space) "<")))
+ (let ((quote-beg (- (point) 1)))
+ (put-text-property quote-beg (1+ quote-beg)
+ 'syntax-table (string-to-syntax "|"))
+ (search-forward ">")
+ (let ((quote-end (- (point) 1)))
+ (put-text-property quote-beg quote-end 'syntax-multiline t)
+ (put-text-property quote-end (1+ quote-end)
+ 'syntax-table (string-to-syntax "|")))))))
+
(defun perl6-syntax-propertize (start end)
"Add context-specific syntax properties to code.
@@ -251,7 +272,9 @@ Takes arguments START and END which delimit the region to
propertize."
((rx (group "<") "<" (0+ (not-char ">")) (opt (and ">" (group ">"))))
(0 (ignore (put-text-property (match-beginning 0) (match-end 0)
'syntax-multiline t)))
(1 "|")
- (2 "|")))
+ (2 "|"))
+ ((rx "<")
+ (0 (ignore (perl6-syntax-propertize-angle)))))
start end)))
(defun perl6-font-lock-syntactic-face (state)
diff --git a/test/perl6-mode-test.el b/test/perl6-mode-test.el
index 484eebf7cc..a665d3a8e1 100644
--- a/test/perl6-mode-test.el
+++ b/test/perl6-mode-test.el
@@ -58,6 +58,14 @@ POS."
(should (eq (perl6-test-syntax-at 10) 'symbol))
(should (eq (perl6-test-syntax-at 11)
'symbol))))
+(ert-deftest perl6-syntax-propertize/angles ()
+ :tags '(syntax-table syntax-properties)
+ (perl6-test-with-temp-buffer "my @foo = <bar>; for @foo <-> $bar {}"
+ (should (eq (perl6-test-syntax-at 11)
'generic-string))
+ (should (eq (perl6-test-syntax-at 15)
'generic-string))
+ (should (eq (perl6-test-syntax-at 27)
'punctuation))
+ (should (eq (perl6-test-syntax-at 29)
'punctuation))))
+
(ert-deftest perl6-syntax-propertize/dq-words ()
:tags '(syntax-table syntax-properties)
(perl6-test-with-temp-buffer "foo «bar» bla <<baz>> quux"