|
| 1 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 2 | +;; |
| 3 | +;; MODULE : fish-lang.scm |
| 4 | +;; DESCRIPTION : fish language support |
| 5 | +;; COPYRIGHT : (C) 2025 veista |
| 6 | +;; |
| 7 | +;; This software falls under the GNU general public license version 3 or later. |
| 8 | +;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE |
| 9 | +;; in the root directory or <http://www.gnu.org/licenses/gpl-3.0.html>. |
| 10 | +;; |
| 11 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 12 | + |
| 13 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 14 | +;;; |
| 15 | +;;; DESCRIPTION: |
| 16 | +;;; This module provides language support for fish within TeXmacs. It |
| 17 | +;;; defines language features such as keywords, operators, number formats, |
| 18 | +;;; string formats, and comment formats for proper syntax highlighting and |
| 19 | +;;; parsing of fish code. |
| 20 | +;;; |
| 21 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 22 | + |
| 23 | +;; 定义fish语言支持模块,使用默认语言支持模块 |
| 24 | +(texmacs-module (code fish-lang) |
| 25 | + (:use (prog default-lang))) |
| 26 | + |
| 27 | +;;------------------------------------------------------------------------------ |
| 28 | +;; 关键字定义 |
| 29 | +;; |
| 30 | + |
| 31 | +;; 定义fish语言的关键字分类 |
| 32 | +(tm-define (parser-feature lan key) |
| 33 | + (:require (and (== lan "fish") (== key "keyword"))) |
| 34 | + `(,(string->symbol key) |
| 35 | + (constant |
| 36 | + "true" "false" "null") |
| 37 | + (declare_function |
| 38 | + "define" "struct" "structure") |
| 39 | + (declare_identifier |
| 40 | + "local" "global") |
| 41 | + (keyword_conditional |
| 42 | + "if" "else if" "else" "endif" |
| 43 | + "caseof" "case" "endcase") |
| 44 | + (keyword_control |
| 45 | + "loop" "endloop" "exit loop" "continue" |
| 46 | + "section" "endsection" "exit section" |
| 47 | + "command" "endcommand" |
| 48 | + "return" "exit" "end" "lock"))) |
| 49 | + |
| 50 | +;;------------------------------------------------------------------------------ |
| 51 | +;; 操作符定义 |
| 52 | +;; |
| 53 | + |
| 54 | +;; 定义fish语言的操作符符号 |
| 55 | +(tm-define (parser-feature lan key) |
| 56 | + (:require (and (== lan "fish") (== key "operator"))) |
| 57 | + `(,(string->symbol key) |
| 58 | + (operator |
| 59 | + ;; 算术运算符 |
| 60 | + "+" "-" "*" "/" "^" |
| 61 | + ;; 关系运算符 |
| 62 | + "==" "!=" "#" "<" ">" "<=" ">=" |
| 63 | + ;; 逻辑运算符 |
| 64 | + "and" "or" "not" |
| 65 | + ;; 其他运算符 |
| 66 | + "=" "(" ")" "[" "]" "{" "}" ";" "," "." "@"))) |
| 67 | + |
| 68 | +;;------------------------------------------------------------------------------ |
| 69 | +;; 数字格式定义 |
| 70 | +;; |
| 71 | + |
| 72 | +;; 定义fish语言的数字格式,支持科学计数法 |
| 73 | +(tm-define (parser-feature lan key) |
| 74 | + (:require (and (== lan "fish") (== key "number"))) |
| 75 | + `(,(string->symbol key) |
| 76 | + (bool_features |
| 77 | + "prefix_0x" |
| 78 | + "sci_notation"))) |
| 79 | + |
| 80 | +;;------------------------------------------------------------------------------ |
| 81 | +;; 字符串格式定义 |
| 82 | +;; |
| 83 | + |
| 84 | +;; 定义fish语言的字符串格式,支持转义字符 |
| 85 | +(tm-define (parser-feature lan key) |
| 86 | + (:require (and (== lan "fish") (== key "string"))) |
| 87 | + `(,(string->symbol key) |
| 88 | + (bool_features |
| 89 | + "escape_char_after_backslash") |
| 90 | + (escape_sequences "\\" "\"" "n" "t" "b" "r" "f" "a" "v" "0") |
| 91 | + (double_escape "'"))) |
| 92 | + |
| 93 | +;;------------------------------------------------------------------------------ |
| 94 | +;; 注释格式定义 |
| 95 | +;; |
| 96 | + |
| 97 | +;; 定义fish语言的注释格式,使用 ; 作为注释 |
| 98 | +(tm-define (parser-feature lan key) |
| 99 | + (:require (and (== lan "fish") (== key "comment"))) |
| 100 | + `(,(string->symbol key) |
| 101 | + (inline ";"))) |
| 102 | + |
| 103 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 104 | +;; Preferences for syntax highlighting |
| 105 | +;; 语法高亮偏好设置 |
| 106 | +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
| 107 | + |
| 108 | +;; 通知fish语法更改的函数 |
| 109 | +(define (notify-fish-syntax var val) |
| 110 | + (syntax-read-preferences "fish")) |
| 111 | + |
| 112 | +;; 定义fish语法高亮颜色偏好设置 |
| 113 | +;; 已验证可生效 |
| 114 | +(define-preferences |
| 115 | + ("syntax:fish:none" "red" notify-fish-syntax) |
| 116 | + ("syntax:fish:comment" "brown" notify-fish-syntax) |
| 117 | + ("syntax:fish:error" "dark red" notify-fish-syntax) |
| 118 | + ("syntax:fish:constant" "#4040c0" notify-fish-syntax) |
| 119 | + ("syntax:fish:constant_number" "#3030b0" notify-fish-syntax) |
| 120 | + ("syntax:fish:constant_string" "dark grey" notify-fish-syntax) |
| 121 | + ("syntax:fish:constant_char" "#333333" notify-fish-syntax) |
| 122 | + ("syntax:fish:declare_function" "#0000c0" notify-fish-syntax) |
| 123 | + ("syntax:fish:declare_type" "#0000c0" notify-fish-syntax) |
| 124 | + ("syntax:fish:declare_module" "#0000c0" notify-fish-syntax) |
| 125 | + ("syntax:fish:operator" "#8b008b" notify-fish-syntax) |
| 126 | + ("syntax:fish:operator_openclose" "#B02020" notify-fish-syntax) |
| 127 | + ("syntax:fish:operator_field" "#888888" notify-fish-syntax) |
| 128 | + ("syntax:fish:operator_special" "orange" notify-fish-syntax) |
| 129 | + ("syntax:fish:keyword" "#309090" notify-fish-syntax) |
| 130 | + ("syntax:fish:keyword_conditional" "#309090" notify-fish-syntax) |
| 131 | + ("syntax:fish:keyword_control" "#008080ff" notify-fish-syntax)) |
0 commit comments