diff options
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | syntax-highlight/wat.scm | 60 |
2 files changed, 61 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am index e059e0f..9729dbc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -47,6 +47,7 @@ SOURCES = \ syntax-highlight/javascript.scm \ syntax-highlight/lisp.scm \ syntax-highlight/scheme.scm \ + syntax-highlight/wat.scm \ syntax-highlight/xml.scm \ syntax-highlight.scm diff --git a/syntax-highlight/wat.scm b/syntax-highlight/wat.scm new file mode 100644 index 0000000..4966d05 --- /dev/null +++ b/syntax-highlight/wat.scm @@ -0,0 +1,60 @@ +;;; guile-syntax-highlight --- General-purpose syntax highlighter +;;; Copyright © 2023 David Thompson <davet@gnu.org> +;;; +;;; Guile-syntax-highlight is free software; you can redistribute it +;;; and/or modify it under the terms of the GNU Lesser General Public +;;; License as published by the Free Software Foundation; either +;;; version 3 of the License, or (at your option) any later version. +;;; +;;; Guile-syntax-highlight is distributed in the hope that it will be +;;; useful, but WITHOUT ANY WARRANTY; without even the implied +;;; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +;;; See the GNU Lesser General Public License for more details. +;;; +;;; You should have received a copy of the GNU Lesser General Public +;;; License along with guile-syntax-highlight. If not, see +;;; <http://www.gnu.org/licenses/>. + +;;; Commentary: +;; +;; Syntax highlighting for WebAssembly text format. +;; +;;; Code: + +(define-module (syntax-highlight wat) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-11) + #:use-module (srfi srfi-26) + #:use-module (syntax-highlight lexers) + #:export (%default-special-symbols + %default-special-prefixes + make-wat-lexer + lex-wat)) + +(define char-set:wat-delimiters + (char-set-union char-set:whitespace + (char-set #\( #\)))) + +(define char-set:wat-symbol + (char-set-complement char-set:wat-delimiters)) + +(define %keywords + '("i31" "i32" "i64" "f32" "f64" "eq" "string" "module" "type" "func" + "array" "struct" "mut" "ref" "extern" "null" "field" "sub" "import" + "export" "param" "result" "block" "loop" "local" "rec")) + +;; TODO: WAT has some weird commenting syntax that this doesn't +;; support, among probably other missing things. +(define lex-wat + (lex-consume + (lex-any (lex-char-set char-set:whitespace) + (lex-tag 'open (lex-string "(")) + (lex-tag 'close (lex-string ")")) + (lex-tag 'comment (lex-delimited ";" #:until "\n")) + (lex-tag 'special + (lex-filter (lambda (str) + (any (cut string=? <> str) %keywords)) + (lex-char-set char-set:wat-symbol))) + (lex-tag 'string (lex-delimited "\"")) + (lex-tag 'symbol (lex-char-set char-set:wat-symbol))))) |