From 943ad93d32f7f5abe4902fbc662e0a44b0885e09 Mon Sep 17 00:00:00 2001 From: Darcy Shen Date: Thu, 25 Jul 2024 17:16:55 +0800 Subject: [PATCH] [61_7] Goldfish: syntax based on R7RS --- .../goldfish/packages/code/goldfish.ts | 8 +- .../goldfish/progs/code/goldfish-lang.scm | 100 ++++++++++++++++++ .../plugins/goldfish/progs/data/goldfish.scm | 44 ++++++++ .../plugins/r7rs/progs/code/r7rs-keyword.scm | 2 +- .../plugins/r7rs/progs/code/srfi-keyword.scm | 5 + 5 files changed, 153 insertions(+), 6 deletions(-) create mode 100644 TeXmacs/plugins/goldfish/progs/code/goldfish-lang.scm create mode 100644 TeXmacs/plugins/goldfish/progs/data/goldfish.scm diff --git a/TeXmacs/plugins/goldfish/packages/code/goldfish.ts b/TeXmacs/plugins/goldfish/packages/code/goldfish.ts index 2874b16b25..01243834ac 100644 --- a/TeXmacs/plugins/goldfish/packages/code/goldfish.ts +++ b/TeXmacs/plugins/goldfish/packages/code/goldfish.ts @@ -20,7 +20,7 @@ > - + @@ -28,12 +28,10 @@ <\with|generic-prompt-color||generic-input-color|> - |>> + |> > - \; - @@ -43,4 +41,4 @@ -> +> \ No newline at end of file diff --git a/TeXmacs/plugins/goldfish/progs/code/goldfish-lang.scm b/TeXmacs/plugins/goldfish/progs/code/goldfish-lang.scm new file mode 100644 index 0000000000..11c6a85c7e --- /dev/null +++ b/TeXmacs/plugins/goldfish/progs/code/goldfish-lang.scm @@ -0,0 +1,100 @@ + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; MODULE : goldfish-lang.scm +;; DESCRIPTION : the Goldfish Scheme Language +;; COPYRIGHT : (C) 2024 Darcy Shen +;; +;; This software falls under the GNU general public license version 3 or later. +;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE +;; in the root directory or . +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(texmacs-module (code goldfish-lang) + (:use (prog default-lang) + (code r7rs-keyword) + (code srfi-keyword))) + +(tm-define (parser-feature lan key) + (:require (and (== lan "goldfish") (== key "keyword"))) + `(,(string->symbol key) + (extra_chars "?" "+" "-" "." "!" "*" ">" "=" "<" "#") + (constant + ,@(r7rs-keywords-constant) + "pi" "*stdin*" "*stdout*" "*stderr*" + "*load-hook*" "*autoload-hook*" "*error-hook*" "*read-error-hook*" + "*rootlet-redefinition-hook*" "*unbound-variable-hook*" + "*missing-close-paren-hook*") + (declare_type + ,@(r7rs-keywords-define) + "defined?" "define-macro" "define-constant" "autoload" "require" "provide" "define*" "lambda*") + (keyword + ,@(r7rs-keywords-others) ,@(srfi-1-keywords) ,@(srfi-8-keywords) ,@(srfi-13-keywords) ,@(srfi-60-keywords) ,@(srfi-78-keywords) + + ; S7 built-ins + "*load-path*" "*goldfish*" "*features*" "*libraries*" + "*cload-directory*" "*#readers*" + + "help" "bignum" "append" "procedure-source" + + ; MISC + "integer-decode-float" "random" "nan" "nan-payload" "format" "object->string" "immutable!" "immutable?" "make-hash-table" "hash-table" "hash-table?" "hash-table-ref" "hash-table-set!" "hash-table-entries" "hash-code") + (keyword_error + "syntax-error" "wrong-type-arg" "immutable-error" "out-of-range" "division-by-zero" + "unbound-variable" "read-error" "format-error" "missing-method" "out-of-memory" + "bad-result" "no-catch" "wrong-number-of-args" "io-error" "bignum-error") + (keyword_conditional ,@(r7rs-keywords-branch)) + (keyword_control ,@(r7rs-keywords-exception)))) + +(tm-define (parser-feature lan key) + (:require (and (== lan "goldfish") (== key "operator"))) + `(,(string->symbol key) + (operator "and" "or" "not" "=" "+" "-" "*" "/" "=>" "->") + (operator_special "@" "," "'" "`") + (operator_openclose "{" "[" "(" ")" "]" "}"))) + +(define (goldfish-number-suffix) + `(suffix + (imaginary "i"))) + +(tm-define (parser-feature lan key) + (:require (and (== lan "goldfish") (== key "number"))) + `(,(string->symbol key) + (bool_features "prefix_#") + (separator "_") + ,(goldfish-number-suffix))) + +(tm-define (parser-feature lan key) + (:require (and (== lan "goldfish") (== key "string"))) + `(,(string->symbol key) + (bool_features + "hex_with_8_bits" "hex_with_16_bits" + "hex_with_32_bits" "octal_upto_3_digits") + (escape_sequences "\\" "\"" "a" "b" "f" "n" "r" "t" "v") + (pairs "\""))) + +; See: https://goldfish.org/doc/v6.1.0/Single-Line-Comments.html +(tm-define (parser-feature lan key) + (:require (and (== lan "goldfish") (== key "comment"))) + `(,(string->symbol key) + (inline ";"))) + +(define (notify-goldfish-syntax var val) + (syntax-read-preferences "goldfish")) + +(define-preferences + ("syntax:goldfish:none" "red" notify-goldfish-syntax) + ("syntax:goldfish:comment" "brown" notify-goldfish-syntax) + ("syntax:goldfish:declare_type" "#309090" notify-goldfish-syntax) + ("syntax:goldfish:keyword_conditional" "#309090" notify-goldfish-syntax) + ("syntax:goldfish:keyword_control" "#309090" notify-goldfish-syntax) + ("syntax:goldfish:keyword" "#204080" notify-goldfish-syntax) + ("syntax:goldfish:keyword_error" "dark red" notify-goldfish-syntax) + ("syntax:goldfish:constant_number" "#4040c0" notify-goldfish-syntax) + ("syntax:goldfish:constant_string" "dark grey" notify-goldfish-syntax) + ("syntax:goldfish:constant_char" "#333333" notify-goldfish-syntax) + ("syntax:goldfish:operator_special" "dark magenta" notify-goldfish-syntax) + ("syntax:goldfish:operator_openclose" "dark" notify-goldfish-syntax) + ("syntax:goldfish:variable_identifier" "#204080" notify-goldfish-syntax) + ("syntax:goldfish:declare_category" "#d030d0" notify-goldfish-syntax)) diff --git a/TeXmacs/plugins/goldfish/progs/data/goldfish.scm b/TeXmacs/plugins/goldfish/progs/data/goldfish.scm new file mode 100644 index 0000000000..67b6e657b6 --- /dev/null +++ b/TeXmacs/plugins/goldfish/progs/data/goldfish.scm @@ -0,0 +1,44 @@ + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; MODULE : goldfish.scm +;; DESCRIPTION : prog format for goldfish +;; COPYRIGHT : (C) 2022 Darcy Shen, Joris van der Hoeven +;; +;; This software falls under the GNU general public license version 3 or later. +;; It comes WITHOUT ANY WARRANTY WHATSOEVER. For details, see the file LICENSE +;; in the root directory or . +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(texmacs-module (data goldfish)) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; goldfish source files +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(define-format goldfish + (:name "R7RS source code") + (:suffix "scm" ".sld" ".ss")) + +(define (texmacs->goldfish x . opts) + (texmacs->verbatim x (acons "texmacs->verbatim:encoding" "SourceCode" '()))) + +(define (goldfish->texmacs x . opts) + (code->texmacs x)) + +(define (goldfish-snippet->texmacs x . opts) + (code-snippet->texmacs x)) + +(converter texmacs-tree goldfish-document + (:function texmacs->goldfish)) + +(converter goldfish-document texmacs-tree + (:function goldfish->texmacs)) + +(converter texmacs-tree goldfish-snippet + (:function texmacs->goldfish)) + +(converter goldfish-snippet texmacs-tree + (:function goldfish-snippet->texmacs)) + diff --git a/TeXmacs/plugins/r7rs/progs/code/r7rs-keyword.scm b/TeXmacs/plugins/r7rs/progs/code/r7rs-keyword.scm index be913be940..31ef24511d 100644 --- a/TeXmacs/plugins/r7rs/progs/code/r7rs-keyword.scm +++ b/TeXmacs/plugins/r7rs/progs/code/r7rs-keyword.scm @@ -71,7 +71,7 @@ (list "if" "cond" "else" "case" "when")) (tm-define (r7rs-keywords-define) - (list "define" "define-record-type" "define-syntax" "define-values" "set!" "lambda" "let" "let*" "apply" "eval" "environment" "load" "values" "begin")) + (list "define" "define-record-type" "define-syntax" "define-values" "set!" "lambda" "let" "let*" "apply" "eval" "environment" "load" "values" "begin" "import" "export" "define-library")) (tm-define (r7rs-keywords-exception) (list "error" "guard" "with-exception-handler")) diff --git a/TeXmacs/plugins/r7rs/progs/code/srfi-keyword.scm b/TeXmacs/plugins/r7rs/progs/code/srfi-keyword.scm index 6e007e58d0..a4e3a9612f 100644 --- a/TeXmacs/plugins/r7rs/progs/code/srfi-keyword.scm +++ b/TeXmacs/plugins/r7rs/progs/code/srfi-keyword.scm @@ -75,6 +75,11 @@ ; SRFI-13: Filtering & Deleting "string-filter" "string-delete")) +(tm-define (srfi-60-keywords) + (list + "logand" "logior" "logxor" "lognot" "logand" + "logbit?" "ash")) + (tm-define (srfi-70-keywords) (list "srfi-70" ; Numbers