branch: elpa/typst-ts-mode commit adeb7bc795f060cc3ba6ed11978aa6e1c3cffa38 Author: Ziqi Yang <mr.ziqiy...@gmail.com> Commit: Ziqi Yang <mr.ziqiy...@gmail.com>
feat: add operator for code --- .gitignore | 1 - basic-syntax.typ | 24 ++++++++++++++++ highlight.compare.scm | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++ typst-ts-mode.el | 51 ++++++++++++++++++++++++--------- 4 files changed, 141 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index e1f2ee5410..c531d9867f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1 @@ *.elc -highlight.compare.scm \ No newline at end of file diff --git a/basic-syntax.typ b/basic-syntax.typ index 8d8bddbbf8..b80a0102a8 100644 --- a/basic-syntax.typ +++ b/basic-syntax.typ @@ -1,3 +1,5 @@ +// This file only serves for testing highlight, and it is not a syntax completion test. + // comment -? $ -> $ // shorthand @@ -18,3 +20,25 @@ sudo rm -rf * ``` <label> // label @reference // reference + +#(4.2) // number +#"El Psy Kongaroo" // string +#[El Psy Kongraoo] // content +#true #false // boolean +#sym.bar.h // builtin +#set text(a: 0) // call & builtin +#none // none +#auto // auto +#(a + b) // ident + +#(0 in "0" not in a) // in +#(a and b or not c) // and, or, not +#(2 + - 1) #(2 - -1) // sign +#(1 + 1) // add +#(1 - 1) // sub +#(1 * 1) // mul +#(1 / 1) // div +#if 2 > 1 [] // cmp +#import "a": * // wildcard + +#let a = b diff --git a/highlight.compare.scm b/highlight.compare.scm new file mode 100644 index 0000000000..01b636c86e --- /dev/null +++ b/highlight.compare.scm @@ -0,0 +1,79 @@ +(call + item: (ident) @function) +(call + item: (field field: (ident) @function.method)) +(tagged field: (ident) @tag) +(field field: (ident) @tag) +(comment) @comment + +; CONTROL +(let "let" @keyword.storage.type) +(branch ["if" "else"] @keyword.control.conditional) +(while "while" @keyword.control.repeat) +(for ["for" "in"] @keyword.control.repeat) +(import "import" @keyword.control.import) +(as "as" @keyword.operator) +(include "include" @keyword.control.import) +(show "show" @keyword.control) +(set "set" @keyword.control) +(return "return" @keyword.control) +(flow ["break" "continue"] @keyword.control) + +; OPERATOR +(in ["in" "not"] @keyword.operator) ;; DONE code +(and "and" @keyword.operator) ;; DONE code +(or "or" @keyword.operator) ;; DONE code +(not "not" @keyword.operator) ;; DONE code +(sign ["+" "-"] @operator) ;; DONE code +(add "+" @operator) ;; DONE code +(sub "-" @operator) ;; DONE code +(mul "*" @operator) ;; DONE code +(div "/" @operator) ;; DONE code +(cmp ["==" "<=" ">=" "!=" "<" ">"] @operator) ;; DONE code +(fraction "/" @operator) ;; TODO math +(fac "!" @operator) ;; TODO math +(attach ["^" "_"] @operator) ;; TODO math +(wildcard) @operator ;; DONE code + +; VALUE +(raw_blck "```" @operator) @markup.raw.block ;; DONE markup +(raw_span "`" @operator) @markup.raw.block ;; DONE markup +(raw_blck lang: (ident) @tag) ;; DONE markup +(label) @tag ;; DONE markup +(ref) @tag ;; DONE markup +(number) @constant.numeric ;; DONE code +(string) @string ;; DONE code +(content ["[" "]"] @operator) ;; DONE code +(bool) @constant.builtin.boolean ;; DONE code +(builtin) @constant.builtin code ;; DONE code +(none) @constant.builtin code ;; DONE code +(auto) @constant.builtin ;; DONE code +(ident) @variable ;; DONE code +(call + item: (builtin) @function.builtin) + +; MARKUP +(item "item" @operator) ;; DONE markup +(term ["item" ":"] @operator) ;; DONE markup +(heading) @markup.heading ;; DONE markup +(url) @tag ;; DONE markup +(emph "_" @operator) @markup.italic ;; DONE markup +(strong "*" @operator) @markup.bold ;; DONE markup +(item) @markup.list ;; DONE markup +(term) @markup.list ;; DONE markup +(symbol) @constant.character ;; TODO math +(shorthand) @constant.builtin ;; DONE common +(quote) @markup.quote ;; DONE markup +(align) @operator ;; TODO math +(letter) @constant.character ;; TODO math +(linebreak) @constant.builtin ;; DONE markup + +(math "$" @operator) +"#" @operator +"end" @operator + +(escape) @constant.character.escape +["(" ")" "{" "}"] @ponctuation.bracket +["," ";" ".." ":" "sep"] @ponctuation.delimiter +"assign" @ponctuation +(field "." @ponctuation) diff --git a/typst-ts-mode.el b/typst-ts-mode.el index 07e9085424..ffe720cf94 100644 --- a/typst-ts-mode.el +++ b/typst-ts-mode.el @@ -66,6 +66,8 @@ :set-after typst-ts-markup-header-same-height :group 'typst-ts-faces) +;; Markup Faces ================================================================= + (defface typst-ts-markup-header-face '((t :weight bold)) "The basic face for Typst ts markup headers.") @@ -167,58 +169,57 @@ (defface typst-ts-markup-raw-indicator-face '((t :inherit shadow)) "Face for rawblock and rawspan indicator." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-raw-blob-face '((t :inherit variable-pitch)) "Face for rawblock and rawspan blob." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-rawblock-face '((t :inherit normal)) "Face for rawblock." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-rawblock-indicator-face '((t :inherit typst-ts-markup-raw-indicator-face)) "Face for rawblock indicator." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-rawblock-blob-face '((t :inherit typst-ts-markup-raw-blob-face)) "Face for rawblock blob." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-rawspan-face '((t :inherit normal)) "Face for rawspan." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-rawspan-indicator-face '((t :inherit typst-ts-markup-raw-indicator-face)) "Face for rawspan indicator." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-rawspan-lang-face '((t :inherit variable-pitch)) "Face for rawspan ident." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-rawspan-blob-face '((t :inherit typst-ts-markup-raw-blob-face)) "Face for rawspan blob." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-label-face '((t :inherit homoglyph)) "Face for label." - :group 'typst-ts-face) + :group 'typst-ts-faces) (defface typst-ts-markup-reference-face '((t :inherit homoglyph)) "Face for reference." - :group 'typst-ts-face) - + :group 'typst-ts-faces) (defvar typst-ts-mode-font-lock-rules '(;; Typst font locking @@ -255,6 +256,30 @@ "```" @typst-ts-markup-rawblock-indicator-face) (label) @typst-ts-markup-label-face ;; TODO more precise highlight (upstream) (ref) @typst-ts-markup-reference-face) + + :language typst + :feature code + ((number) @font-lock-number-face + (string) @font-lock-string-face + (content ["[" "]"] @font-lock-punctuation-face) + (bool) @font-lock-constant-face + (builtin) @font-lock-builtin-face + (none) @font-lock-constant-face + (auto) @font-lock-constant-face + (ident) @font-lock-variable-use-face + + ;; operator + (in ["in" "not"] @font-lock-keyword-face) + (and "and" @font-lock-keyword-face) + (or "or" @font-lock-keyword-face) + (not "not" @font-lock-keyword-face) + (sign ["+" "-"] @font-lock-operator-face) + (add "+" @font-lock-operator-face) + (sub "-" @font-lock-operator-face) + (mul "*" @font-lock-operator-face) + (div "/" @font-lock-operator-face) + (cmp ["==" "<=" ">=" "!=" "<" ">"] @font-lock-operator-face) + (wildcard) @font-lock-operator-face) )) (defun typst-ts-mode-comment-setup() @@ -294,7 +319,7 @@ (apply #'treesit-font-lock-rules typst-ts-mode-font-lock-rules)) (setq-local treesit-font-lock-feature-list ;; TODO - '((comment common markup) + '((comment common markup code) ;; (markup code) ;; (builtin) ;; (operator ponctuation)