]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/scheme.js
Initial commit.
[flow-web.git] / static / highlight / languages / scheme.js
1 /*! `scheme` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: Scheme
8 Description: Scheme is a programming language in the Lisp family.
9 (keywords based on http://community.schemewiki.org/?scheme-keywords)
10 Author: JP Verkamp <me@jverkamp.com>
11 Contributors: Ivan Sagalaev <maniac@softwaremaniacs.org>
12 Origin: clojure.js
13 Website: http://community.schemewiki.org/?what-is-scheme
14 Category: lisp
15 */
16
17 function scheme(hljs) {
18 const SCHEME_IDENT_RE = '[^\\(\\)\\[\\]\\{\\}",\'`;#|\\\\\\s]+';
19 const SCHEME_SIMPLE_NUMBER_RE = '(-|\\+)?\\d+([./]\\d+)?';
20 const SCHEME_COMPLEX_NUMBER_RE = SCHEME_SIMPLE_NUMBER_RE + '[+\\-]' + SCHEME_SIMPLE_NUMBER_RE + 'i';
21 const KEYWORDS = {
22 $pattern: SCHEME_IDENT_RE,
23 built_in:
24 'case-lambda call/cc class define-class exit-handler field import '
25 + 'inherit init-field interface let*-values let-values let/ec mixin '
26 + 'opt-lambda override protect provide public rename require '
27 + 'require-for-syntax syntax syntax-case syntax-error unit/sig unless '
28 + 'when with-syntax and begin call-with-current-continuation '
29 + 'call-with-input-file call-with-output-file case cond define '
30 + 'define-syntax delay do dynamic-wind else for-each if lambda let let* '
31 + 'let-syntax letrec letrec-syntax map or syntax-rules \' * + , ,@ - ... / '
32 + '; < <= = => > >= ` abs acos angle append apply asin assoc assq assv atan '
33 + 'boolean? caar cadr call-with-input-file call-with-output-file '
34 + 'call-with-values car cdddar cddddr cdr ceiling char->integer '
35 + 'char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? '
36 + 'char-downcase char-lower-case? char-numeric? char-ready? char-upcase '
37 + 'char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? '
38 + 'char? close-input-port close-output-port complex? cons cos '
39 + 'current-input-port current-output-port denominator display eof-object? '
40 + 'eq? equal? eqv? eval even? exact->inexact exact? exp expt floor '
41 + 'force gcd imag-part inexact->exact inexact? input-port? integer->char '
42 + 'integer? interaction-environment lcm length list list->string '
43 + 'list->vector list-ref list-tail list? load log magnitude make-polar '
44 + 'make-rectangular make-string make-vector max member memq memv min '
45 + 'modulo negative? newline not null-environment null? number->string '
46 + 'number? numerator odd? open-input-file open-output-file output-port? '
47 + 'pair? peek-char port? positive? procedure? quasiquote quote quotient '
48 + 'rational? rationalize read read-char real-part real? remainder reverse '
49 + 'round scheme-report-environment set! set-car! set-cdr! sin sqrt string '
50 + 'string->list string->number string->symbol string-append string-ci<=? '
51 + 'string-ci<? string-ci=? string-ci>=? string-ci>? string-copy '
52 + 'string-fill! string-length string-ref string-set! string<=? string<? '
53 + 'string=? string>=? string>? string? substring symbol->string symbol? '
54 + 'tan transcript-off transcript-on truncate values vector '
55 + 'vector->list vector-fill! vector-length vector-ref vector-set! '
56 + 'with-input-from-file with-output-to-file write write-char zero?'
57 };
58
59 const LITERAL = {
60 className: 'literal',
61 begin: '(#t|#f|#\\\\' + SCHEME_IDENT_RE + '|#\\\\.)'
62 };
63
64 const NUMBER = {
65 className: 'number',
66 variants: [
67 {
68 begin: SCHEME_SIMPLE_NUMBER_RE,
69 relevance: 0
70 },
71 {
72 begin: SCHEME_COMPLEX_NUMBER_RE,
73 relevance: 0
74 },
75 { begin: '#b[0-1]+(/[0-1]+)?' },
76 { begin: '#o[0-7]+(/[0-7]+)?' },
77 { begin: '#x[0-9a-f]+(/[0-9a-f]+)?' }
78 ]
79 };
80
81 const STRING = hljs.QUOTE_STRING_MODE;
82
83 const COMMENT_MODES = [
84 hljs.COMMENT(
85 ';',
86 '$',
87 { relevance: 0 }
88 ),
89 hljs.COMMENT('#\\|', '\\|#')
90 ];
91
92 const IDENT = {
93 begin: SCHEME_IDENT_RE,
94 relevance: 0
95 };
96
97 const QUOTED_IDENT = {
98 className: 'symbol',
99 begin: '\'' + SCHEME_IDENT_RE
100 };
101
102 const BODY = {
103 endsWithParent: true,
104 relevance: 0
105 };
106
107 const QUOTED_LIST = {
108 variants: [
109 { begin: /'/ },
110 { begin: '`' }
111 ],
112 contains: [
113 {
114 begin: '\\(',
115 end: '\\)',
116 contains: [
117 'self',
118 LITERAL,
119 STRING,
120 NUMBER,
121 IDENT,
122 QUOTED_IDENT
123 ]
124 }
125 ]
126 };
127
128 const NAME = {
129 className: 'name',
130 relevance: 0,
131 begin: SCHEME_IDENT_RE,
132 keywords: KEYWORDS
133 };
134
135 const LAMBDA = {
136 begin: /lambda/,
137 endsWithParent: true,
138 returnBegin: true,
139 contains: [
140 NAME,
141 {
142 endsParent: true,
143 variants: [
144 {
145 begin: /\(/,
146 end: /\)/
147 },
148 {
149 begin: /\[/,
150 end: /\]/
151 }
152 ],
153 contains: [ IDENT ]
154 }
155 ]
156 };
157
158 const LIST = {
159 variants: [
160 {
161 begin: '\\(',
162 end: '\\)'
163 },
164 {
165 begin: '\\[',
166 end: '\\]'
167 }
168 ],
169 contains: [
170 LAMBDA,
171 NAME,
172 BODY
173 ]
174 };
175
176 BODY.contains = [
177 LITERAL,
178 NUMBER,
179 STRING,
180 IDENT,
181 QUOTED_IDENT,
182 QUOTED_LIST,
183 LIST
184 ].concat(COMMENT_MODES);
185
186 return {
187 name: 'Scheme',
188 aliases: ['scm'],
189 illegal: /\S/,
190 contains: [
191 hljs.SHEBANG(),
192 NUMBER,
193 STRING,
194 QUOTED_IDENT,
195 QUOTED_LIST,
196 LIST
197 ].concat(COMMENT_MODES)
198 };
199 }
200
201 return scheme;
202
203 })();
204
205 hljs.registerLanguage('scheme', hljsGrammar);
206 })();