Skip to content

Commit

Permalink
[61_7] Goldfish: syntax based on R7RS
Browse files Browse the repository at this point in the history
  • Loading branch information
da-liii authored Jul 25, 2024
1 parent 545d9ee commit 943ad93
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 6 deletions.
8 changes: 3 additions & 5 deletions TeXmacs/plugins/goldfish/packages/code/goldfish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
</src-license>
</src-title>>

<use-module|(data r7rs)>
<use-module|(data goldfish)>

<use-module|(code goldfish-edit)>

<assign|goldfish-prompt-color|dark green>

<assign|goldfish-input|<\macro|prompt|body>
<\with|generic-prompt-color|<value|goldfish-prompt-color>|generic-input-color|<value|scheme-input-color>>
<generic-input|<arg|prompt>|<with|prog-language|r7rs|<arg|body>>>
<generic-input|<arg|prompt>|<arg|body>>
</with>
</macro>>

\;

<assign|goldfish-result|<\macro|body>
<with|ornament-border|0ln|ornament-hpadding|0spc|padding-above|0fn|padding-below|0fn|ornament-color|pastel
green|<\ornamented>
Expand All @@ -43,4 +41,4 @@
</body>

<initial|<\collection>
</collection>>
</collection>>
100 changes: 100 additions & 0 deletions TeXmacs/plugins/goldfish/progs/code/goldfish-lang.scm
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/gpl-3.0.html>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(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))
44 changes: 44 additions & 0 deletions TeXmacs/plugins/goldfish/progs/data/goldfish.scm
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/gpl-3.0.html>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(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))

2 changes: 1 addition & 1 deletion TeXmacs/plugins/r7rs/progs/code/r7rs-keyword.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
5 changes: 5 additions & 0 deletions TeXmacs/plugins/r7rs/progs/code/srfi-keyword.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 943ad93

Please sign in to comment.