Added support for Factor (#2203)

This adds support for the [Factor](https://factorcode.org) language.
This commit is contained in:
Cat Stevens 2020-02-16 13:49:33 -05:00 committed by GitHub
parent b24f7348df
commit f941102ef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 1170 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -313,6 +313,10 @@
"require": "clike",
"owner": "simonreynolds7"
},
"factor": {
"title": "Factor",
"owner": "catb0t"
},
"firestore-security-rules": {
"title": "Firestore security rules",
"require": "clike",

403
components/prism-factor.js Normal file
View File

@ -0,0 +1,403 @@
(function (Prism) {
var comment_inside = {
'function': /\b(?:TODOS?|FIX(?:MES?)?|NOTES?|BUGS?|XX+|HACKS?|WARN(?:ING)?|\?{2,}|!{2,})\b/
};
var string_inside = {
'number': /\\[^\s']|%\w/
};
var factor = {
'comment': [
{
// ! single-line exclamation point comments with whitespace after/around the !
pattern: /(^|\s)(?:! .*|!$)/,
lookbehind: true,
inside: comment_inside
},
/* from basis/multiline: */
{
// /* comment */, /* comment*/
pattern: /(^|\s)\/\*\s[\s\S]*?\*\/(?=\s|$)/,
lookbehind: true,
greedy: true,
inside: comment_inside
},
{
// ![[ comment ]] , ![===[ comment]===]
pattern: /(^|\s)!\[(={0,6})\[\s[\s\S]*?\]\2\](?=\s|$)/,
lookbehind: true,
greedy: true,
inside: comment_inside
}
],
'number': [
{
// basic base 10 integers 9, -9
pattern: /(^|\s)[+-]?\d+(?=\s|$)/,
lookbehind: true
},
{
// base prefix integers 0b010 0o70 0xad 0d10 0XAD -0xa9
pattern: /(^|\s)[+-]?0(?:b[01]+|o[0-7]+|d\d+|x[\dA-F]+)(?=\s|$)/i,
lookbehind: true
},
{
// fractional ratios 1/5 -1/5 and the literal float approximations 1/5. -1/5.
pattern: /(^|\s)[+-]?\d+\/\d+\.?(?=\s|$)/,
lookbehind: true
},
{
// positive mixed numbers 23+1/5 +23+1/5
pattern: /(^|\s)\+?\d+\+\d+\/\d+(?=\s|$)/,
lookbehind: true
},
{
// negative mixed numbers -23-1/5
pattern: /(^|\s)-\d+-\d+\/\d+(?=\s|$)/,
lookbehind: true
},
{
// basic decimal floats -0.01 0. .0 .1 -.1 -1. -12.13 +12.13
// and scientific notation with base 10 exponents 3e4 3e-4 .3e-4
pattern: /(^|\s)[+-]?(?:\d*\.\d+|\d+\.\d*|\d+)(?:e[+-]?\d+)?(?=\s|$)/i,
lookbehind: true
},
{
// NAN literal syntax NAN: 80000deadbeef, NAN: a
pattern: /(^|\s)NAN:\s+[\da-fA-F]+(?=\s|$)/,
lookbehind: true
},
{
/*
base prefix floats 0x1.0p3 (8.0) 0b1.010p2 (5.0) 0x1.p1 0b1.11111111p11111...
"The normalized hex form ±0x1.MMMMMMMMMMMMM[pP]±EEEE allows any floating-point number to be specified precisely.
The values of MMMMMMMMMMMMM and EEEE map directly to the mantissa and exponent fields of the binary IEEE 754 representation."
<https://docs.factorcode.org/content/article-syntax-floats.html>
*/
pattern: /(^|\s)[+-]?0(?:b1\.[01]*|o1\.[0-7]*|d1\.\d*|x1\.[\dA-F]*)p\d+(?=\s|$)/i,
lookbehind: true
}
],
// R/ regexp?\/\\/
'regexp': {
pattern: /(^|\s)R\/\s+(?:\\\S|[^\\/])*\/(?:[idmsr]*|[idmsr]+-[idmsr]+)(?=\s|$)/,
lookbehind: true,
alias: 'number',
inside: {
'variable': /\\\S/,
'keyword': /[+?*\[\]^$(){}.|]/,
'operator': {
pattern: /(\/)[idmsr]+(?:-[idmsr]+)?/,
lookbehind: true
}
}
},
'boolean': {
pattern: /(^|\s)[tf](?=\s|$)/,
lookbehind: true
},
// SBUF" asd", URL" ://...", P" /etc/"
'custom-string': {
pattern: /(^|\s)[A-Z0-9\-]+"\s(?:\\\S|[^"\\])*"/,
lookbehind: true,
greedy: true,
alias: 'string',
inside: {
'number': /\\\S|%\w|\//
}
},
'multiline-string': [
{
// STRING: name \n content \n ; -> CONSTANT: name "content" (symbol)
pattern: /(^|\s)STRING:\s+\S+(?:\n|\r\n).*(?:\n|\r\n)\s*;(?=\s|$)/,
lookbehind: true,
greedy: true,
alias: 'string',
inside: {
'number': string_inside.number,
// trailing semicolon on its own line
'semicolon-or-setlocal': {
pattern: /((?:\n|\r\n)\s*);(?=\s|$)/,
lookbehind: true,
alias: 'function'
}
}
},
{
// HEREDOC: marker \n content \n marker ; -> "content" (immediate)
pattern: /(^|\s)HEREDOC:\s+\S+(?:\n|\r\n).*(?:\n|\r\n)\s*\S+(?=\s|$)/,
lookbehind: true,
greedy: true,
alias: 'string',
inside: string_inside
},
{
// [[ string ]], [==[ string]==]
pattern: /(^|\s)\[(={0,6})\[\s[\s\S]*?\]\2\](?=\s|$)/,
lookbehind: true,
greedy: true,
alias: 'string',
inside: string_inside
}
],
'special-using': {
pattern: /(^|\s)USING:(?:\s\S+)*(?=\s+;(?:\s|$))/,
lookbehind: true,
alias: 'function',
inside: {
// this is essentially a regex for vocab names, which i don't want to specify
// but the USING: gets picked up as a vocab name
'string': {
pattern: /(\s)[^:\s]+/,
lookbehind: true
}
}
},
/* this description of stack effect literal syntax is not complete and not as specific as theoretically possible
trying to do better is more work and regex-computation-time than it's worth though.
- we'd like to have the "delimiter" parts of the stack effect [ (, --, and ) ] be a different (less-important or comment-like) colour to the stack effect contents
- we'd like if nested stack effects were treated as such rather than just appearing flat (with `inside`)
- we'd like if the following variable name conventions were recognised specifically:
special row variables = ..a b..
type and stack effect annotations end with a colon = ( quot: ( a: ( -- ) -- b ) -- x ), ( x: number -- )
word throws unconditional error = *
any other word-like variable name = a ? q' etc
https://docs.factorcode.org/content/article-effects.html
these are pretty complicated to highlight properly without a real parser, and therefore out of scope
the old pattern, which may be later useful, was: (^|\s)(?:call|execute|eval)?\((?:\s+[^"\r\n\t ]\S*)*?\s+--(?:\s+[^"\n\t ]\S*)*?\s+\)(?=\s|$)
*/
// current solution is not great
'stack-effect-delimiter': [
{
// opening parenthesis
pattern: /(^|\s)(?:call|execute|eval)?\((?=\s)/,
lookbehind: true,
alias: 'operator'
},
{
// middle --
pattern: /(\s)--(?=\s)/,
lookbehind: true,
alias: 'operator'
},
{
// closing parenthesis
pattern: /(\s)\)(?=\s|$)/,
lookbehind: true,
alias: 'operator'
}
],
'combinators': {
pattern: null,
lookbehind: true,
alias: 'keyword'
},
'kernel-builtin': {
pattern: null,
lookbehind: true,
alias: 'variable'
},
'sequences-builtin': {
pattern: null,
lookbehind: true,
alias: 'variable'
},
'math-builtin': {
pattern: null,
lookbehind: true,
alias: 'variable'
},
'constructor-word': {
// <array> but not <=>
pattern: /(^|\s)<(?!=+>|-+>)\S+>(?=\s|$)/,
lookbehind: true,
alias: 'keyword'
},
'other-builtin-syntax': {
pattern: null,
lookbehind: true,
alias: 'operator'
},
/*
full list of supported word naming conventions: (the convention appears outside of the [brackets])
set-[x]
change-[x]
with-[x]
new-[x]
>[string]
[base]>
[string]>[number]
+[symbol]+
[boolean-word]?
?[of]
[slot-reader]>>
>>[slot-setter]
[slot-writer]<<
([implementation-detail])
[mutater]!
[variant]*
[prettyprint].
$[help-markup]
<constructors>, SYNTAX:, etc are supported by their own patterns.
`with` and `new` from `kernel` are their own builtins.
see <https://docs.factorcode.org/content/article-conventions.html>
*/
'conventionally-named-word': {
pattern: /(^|\s)(?!")(?:(?:set|change|with|new)-\S+|\$\S+|>[^>\s]+|[^:>\s]+>|[^>\s]+>[^>\s]+|\+[^+\s]+\+|[^?\s]+\?|\?[^?\s]+|[^>\s]+>>|>>[^>\s]+|[^<\s]+<<|\([^()\s]+\)|[^!\s]+!|[^*\s]\S*\*|[^.\s]\S*\.)(?=\s|$)/,
lookbehind: true,
alias: 'keyword'
},
'colon-syntax': {
pattern: /(^|\s)(?:[A-Z0-9\-]+#?)?:{1,2}\s+(?:;\S+|(?!;)\S+)(?=\s|$)/,
lookbehind: true,
greedy: true,
alias: 'function'
},
'semicolon-or-setlocal': {
pattern: /(\s)(?:;|:>)(?=\s|$)/,
lookbehind: true,
alias: 'function'
},
// do not highlight leading } or trailing X{ at the begin/end of the file as it's invalid syntax
'curly-brace-literal-delimiter': [
{
// opening
pattern: /(^|\s)[a-z]*\{(?=\s)/i,
lookbehind: true,
alias: 'operator'
},
{
// closing
pattern: /(\s)\}(?=\s|$)/,
lookbehind: true,
alias: 'operator'
},
],
// do not highlight leading ] or trailing [ at the begin/end of the file as it's invalid syntax
'quotation-delimiter': [
{
// opening
pattern: /(^|\s)\[(?=\s)/,
lookbehind: true,
alias: 'operator'
},
{
// closing
pattern: /(\s)\](?=\s|$)/,
lookbehind: true,
alias: 'operator'
},
],
'normal-word': {
pattern: /(^|\s)[^"\s]\S*(?=\s|$)/,
lookbehind: true
},
/*
basic first-class string "a"
with escaped double-quote "a\""
escaped backslash "\\"
and general escapes since Factor has so many "\N"
syntax that works in the reference implementation that isn't fully
supported because it's an implementation detail:
"string 1""string 2" -> 2 strings (works anyway)
"string"5 -> string, 5
"string"[ ] -> string, quotation
{ "a"} -> array<string>
the rest of those examples all properly recognise the string, but not
the other object (number, quotation, etc)
this is fine for a regex-only implementation.
*/
'string': {
pattern: /"(?:\\\S|[^"\\])*"/,
greedy: true,
inside: string_inside
}
};
var escape = function (str) {
return (str+'').replace(/([.?*+\^$\[\]\\(){}|\-])/g, '\\$1');
};
var arrToWordsRegExp = function (arr) {
return new RegExp(
'(^|\\s)(?:' + arr.map(escape).join('|') + ')(?=\\s|$)'
);
};
var builtins = {
'kernel-builtin': [
'or', '2nipd', '4drop', 'tuck', 'wrapper', 'nip', 'wrapper?', 'callstack>array', 'die', 'dupd', 'callstack', 'callstack?', '3dup', 'hashcode', 'pick', '4nip', 'build', '>boolean', 'nipd', 'clone', '5nip', 'eq?', '?', '=', 'swapd', '2over', 'clear', '2dup', 'get-retainstack', 'not', 'tuple?', 'dup', '3nipd', 'call', '-rotd', 'object', 'drop', 'assert=', 'assert?', '-rot', 'execute', 'boa', 'get-callstack', 'curried?', '3drop', 'pickd', 'overd', 'over', 'roll', '3nip', 'swap', 'and', '2nip', 'rotd', 'throw', '(clone)', 'hashcode*', 'spin', 'reach', '4dup', 'equal?', 'get-datastack', 'assert', '2drop', '<wrapper>', 'boolean?', 'identity-hashcode', 'identity-tuple?', 'null', 'composed?', 'new', '5drop', 'rot', '-roll', 'xor', 'identity-tuple', 'boolean'
],
'other-builtin-syntax': [
// syntax
'=======', 'recursive', 'flushable', '>>', '<<<<<<', 'M\\', 'B', 'PRIVATE>', '\\', '======', 'final', 'inline', 'delimiter', 'deprecated', '<PRIVATE', '>>>>>>', '<<<<<<<', 'parse-complex', 'malformed-complex', 'read-only', '>>>>>>>', 'call-next-method', '<<', 'foldable',
// literals
'$', '$[', '${'
],
'sequences-builtin': [
'member-eq?', 'mismatch', 'append', 'assert-sequence=', 'longer', 'repetition', 'clone-like', '3sequence', 'assert-sequence?', 'last-index-from', 'reversed', 'index-from', 'cut*', 'pad-tail', 'join-as', 'remove-eq!', 'concat-as', 'but-last', 'snip', 'nths', 'nth', 'sequence', 'longest', 'slice?', '<slice>', 'remove-nth', 'tail-slice', 'empty?', 'tail*', 'member?', 'virtual-sequence?', 'set-length', 'drop-prefix', 'iota', 'unclip', 'bounds-error?', 'unclip-last-slice', 'non-negative-integer-expected', 'non-negative-integer-expected?', 'midpoint@', 'longer?', '?set-nth', '?first', 'rest-slice', 'prepend-as', 'prepend', 'fourth', 'sift', 'subseq-start', 'new-sequence', '?last', 'like', 'first4', '1sequence', 'reverse', 'slice', 'virtual@', 'repetition?', 'set-last', 'index', '4sequence', 'max-length', 'set-second', 'immutable-sequence', 'first2', 'first3', 'supremum', 'unclip-slice', 'suffix!', 'insert-nth', 'tail', '3append', 'short', 'suffix', 'concat', 'flip', 'immutable?', 'reverse!', '2sequence', 'sum', 'delete-all', 'indices', 'snip-slice', '<iota>', 'check-slice', 'sequence?', 'head', 'append-as', 'halves', 'sequence=', 'collapse-slice', '?second', 'slice-error?', 'product', 'bounds-check?', 'bounds-check', 'immutable', 'virtual-exemplar', 'harvest', 'remove', 'pad-head', 'last', 'set-fourth', 'cartesian-product', 'remove-eq', 'shorten', 'shorter', 'reversed?', 'shorter?', 'shortest', 'head-slice', 'pop*', 'tail-slice*', 'but-last-slice', 'iota?', 'append!', 'cut-slice', 'new-resizable', 'head-slice*', 'sequence-hashcode', 'pop', 'set-nth', '?nth', 'second', 'join', 'immutable-sequence?', '<reversed>', '3append-as', 'virtual-sequence', 'subseq?', 'remove-nth!', 'length', 'last-index', 'lengthen', 'assert-sequence', 'copy', 'move', 'third', 'first', 'tail?', 'set-first', 'prefix', 'bounds-error', '<repetition>', 'exchange', 'surround', 'cut', 'min-length', 'set-third', 'push-all', 'head?', 'subseq-start-from', 'delete-slice', 'rest', 'sum-lengths', 'head*', 'infimum', 'remove!', 'glue', 'slice-error', 'subseq', 'push', 'replace-slice', 'subseq-as', 'unclip-last'
],
'math-builtin': [
'number=', 'next-power-of-2', '?1+', 'fp-special?', 'imaginary-part', 'float>bits', 'number?', 'fp-infinity?', 'bignum?', 'fp-snan?', 'denominator', 'gcd', '*', '+', 'fp-bitwise=', '-', 'u>=', '/', '>=', 'bitand', 'power-of-2?', 'log2-expects-positive', 'neg?', '<', 'log2', '>', 'integer?', 'number', 'bits>double', '2/', 'zero?', 'bits>float', 'float?', 'shift', 'ratio?', 'rect>', 'even?', 'ratio', 'fp-sign', 'bitnot', '>fixnum', 'complex?', '/i', 'integer>fixnum', '/f', 'sgn', '>bignum', 'next-float', 'u<', 'u>', 'mod', 'recip', 'rational', '>float', '2^', 'integer', 'fixnum?', 'neg', 'fixnum', 'sq', 'bignum', '>rect', 'bit?', 'fp-qnan?', 'simple-gcd', 'complex', '<fp-nan>', 'real', '>fraction', 'double>bits', 'bitor', 'rem', 'fp-nan-payload', 'real-part', 'log2-expects-positive?', 'prev-float', 'align', 'unordered?', 'float', 'fp-nan?', 'abs', 'bitxor', 'integer>fixnum-strict', 'u<=', 'odd?', '<=', '/mod', '>integer', 'real?', 'rational?', 'numerator'
]
// that's all for now
};
Object.keys(builtins).forEach(function (k) {
factor[k].pattern = arrToWordsRegExp( builtins[k] );
});
var combinators = [
// kernel
'2bi', 'while', '2tri', 'bi*', '4dip', 'both?', 'same?', 'tri@', 'curry', 'prepose', '3bi', '?if', 'tri*', '2keep', '3keep', 'curried', '2keepd', 'when', '2bi*', '2tri*', '4keep', 'bi@', 'keepdd', 'do', 'unless*', 'tri-curry', 'if*', 'loop', 'bi-curry*', 'when*', '2bi@', '2tri@', 'with', '2with', 'either?', 'bi', 'until', '3dip', '3curry', 'tri-curry*', 'tri-curry@', 'bi-curry', 'keepd', 'compose', '2dip', 'if', '3tri', 'unless', 'tuple', 'keep', '2curry', 'tri', 'most', 'while*', 'dip', 'composed', 'bi-curry@',
// sequences
'find-last-from', 'trim-head-slice', 'map-as', 'each-from', 'none?', 'trim-tail', 'partition', 'if-empty', 'accumulate*', 'reject!', 'find-from', 'accumulate-as', 'collector-for-as', 'reject', 'map', 'map-sum', 'accumulate!', '2each-from', 'follow', 'supremum-by', 'map!', 'unless-empty', 'collector', 'padding', 'reduce-index', 'replicate-as', 'infimum-by', 'trim-tail-slice', 'count', 'find-index', 'filter', 'accumulate*!', 'reject-as', 'map-integers', 'map-find', 'reduce', 'selector', 'interleave', '2map', 'filter-as', 'binary-reduce', 'map-index-as', 'find', 'produce', 'filter!', 'replicate', 'cartesian-map', 'cartesian-each', 'find-index-from', 'map-find-last', '3map-as', '3map', 'find-last', 'selector-as', '2map-as', '2map-reduce', 'accumulate', 'each', 'each-index', 'accumulate*-as', 'when-empty', 'all?', 'collector-as', 'push-either', 'new-like', 'collector-for', '2selector', 'push-if', '2all?', 'map-reduce', '3each', 'any?', 'trim-slice', '2reduce', 'change-nth', 'produce-as', '2each', 'trim', 'trim-head', 'cartesian-find', 'map-index',
// math
'if-zero', 'each-integer', 'unless-zero', '(find-integer)', 'when-zero', 'find-last-integer', '(all-integers?)', 'times', '(each-integer)', 'find-integer', 'all-integers?',
// math.combinators
'unless-negative', 'if-positive', 'when-positive', 'when-negative', 'unless-positive', 'if-negative',
// combinators
'case', '2cleave', 'cond>quot', 'case>quot', '3cleave', 'wrong-values', 'to-fixed-point', 'alist>quot', 'cond', 'cleave', 'call-effect', 'recursive-hashcode', 'spread', 'deep-spread>quot',
// combinators.short-circuit
'2||', '0||', 'n||', '0&&', '2&&', '3||', '1||', '1&&', 'n&&', '3&&',
// combinators.smart
'smart-unless*', 'keep-inputs', 'reduce-outputs', 'smart-when*', 'cleave>array', 'smart-with', 'smart-apply', 'smart-if', 'inputs/outputs', 'output>sequence-n', 'map-outputs', 'map-reduce-outputs', 'dropping', 'output>array', 'smart-map-reduce', 'smart-2map-reduce', 'output>array-n', 'nullary', 'input<sequence', 'append-outputs', 'drop-inputs', 'inputs', 'smart-2reduce', 'drop-outputs', 'smart-reduce', 'preserving', 'smart-when', 'outputs', 'append-outputs-as', 'smart-unless', 'smart-if*', 'sum-outputs', 'input<sequence-unsafe', 'output>sequence',
// tafn
];
factor.combinators.pattern = arrToWordsRegExp(combinators);
Prism.languages.factor = factor;
})(Prism);

1
components/prism-factor.min.js vendored Normal file

File diff suppressed because one or more lines are too long

128
examples/prism-factor.html Normal file
View File

@ -0,0 +1,128 @@
<h2>Comments</h2>
<pre><code>! FIXME: a comment
USE: multiline
![[ comment ]]
/* comment */</code></pre>
<h2>Strings</h2>
<pre><code>"a string" "\"" "\x8" "%s"
SBUF" asbdef"
USE: multiline
STRING: name
content
;
HEREDOC: marker
text
marker
[==[
str
ing
]==]
</code></pre>
<h2>Numbers</h2>
<pre><code>5 1/5 +9 -9 +1/5 -1/5 -1/5. 23+1/5 -23-1/5 23-1/5 ! NOTE: last one = word
+12.13 0.01 0e0 3E4 3e-4 3E-4 030 0xd 0o30 0b1100
-12.13 -0 -0.01 -0e0 -3E4 -3E-4 -030 -0xd -0o30 -0b1100
348756424956392657834385437598743583648756332457
-348756424956392657834385437598743583648756332457
NAN: a
NAN: 80000deadbeef
0b1.010p2 0x1.0p3 0x1.p1 0b1.111111p1111 ...</code></pre>
<h2>Sequences</h2>
<pre><code>{ 1 2 3 4 }
{ a b c d e t f }
{ "a" "b" "c" }
{ { a b } { c d } }
H{ { a b } { c d } }
H{ { "a" "b" } { "c" "d" } }
V{ 1 2 3 4 }
V{ "1" "2" "3" "4" }
BV{ 1 2 3 4 }</code></pre>
<h2>Regular Expressions</h2>
<pre><code>USE: regexp
R/ abcde?.*+\?\.\*\+\/\\\/idmsr-idmsr/idmsr-idmsr</code>
</pre>
<h2>Colon parsing words</h2>
<pre><code>: a ( -- ) ;
:: ; ! ; is not a word name
:: ;a ! ;a is a word name
USING: a b c ;
USE: a
IN: a.b
CHAR: a
GENERIC#: x 1 ( x: integer quot: ( x -- y ) -- )</code></pre>
<h2>Special words (builtins, conventions)</h2>
<pre><code>and not with map filter
new last-index + - neg
&lt;array&gt; <=> SYNTAX: x $[ xyz ]
set-x change-x with-variable ?of if* (gensym) hex. $description reader>> >>setter writer<<
string>number >hex base> mutater!
</code></pre>
<h2>Full example</h2>
<pre><code>USING: accessors arrays assocs combinators
combinators.short-circuit effects io kernel sequences
sequences.deep splitting strings vocabs words ;
IN: prism
: make-prism-syntax ( syntax-vocab -- seq )
vocab-words [
dup name>> ">>" = [ drop t ] [
{
[ "delimiter" word-prop ]
[ name>> last { CHAR: : CHAR: { CHAR: [ CHAR: ( CHAR: ) CHAR: ? CHAR: " } member? ]
[ name>> { "t" "f" } member? ]
} 1|| not
] if
] filter ;
: combinator? ( word -- ? )
[ "declared-effect" word-prop in>> flatten
[
[ effect? ] [ { "quots" "quot" } member? ] bi or
] any?
] [
"help" word-prop ?first flatten [ dup word? [ name>> ] when "quot" swap subseq? ] any?
] bi or ;
: classify ( vocab-spec -- seq )
vocab-words [
dup {
{ [ dup combinator? ] [ drop "combinator" ] }
{ [ dup "macro" word-prop ] [ drop "macro" ] }
[ drop "ordinary" ]
} cond 2array
] map ;
: print-strings ( strs -- )
[ name>> "'" dup surround ] map ", " join print ; recursive ! WARN: not recursive
: combinators. ( vocab-spec -- )
classify [ nip "combinator" = ] assoc-filter keys print-strings ; flushable
: ordinaries. ( vocab-spec -- )
classify [ nip "ordinary" = ] assoc-filter keys print-strings ; foldable
: macros. ( vocab-spec -- )
classify [ nip "macro" = ] assoc-filter keys print-strings ; inline</code></pre>

View File

@ -0,0 +1,15 @@
and not with map filter
----------------------------------------------------
[
[ "kernel-builtin", "and" ],
[ "kernel-builtin", "not" ],
[ "combinators", "with" ],
[ "combinators", "map" ],
[ "combinators", "filter" ]
]
----------------------------------------------------
some builtins

View File

@ -0,0 +1,47 @@
: a ( -- ) ;
:: ; ! ; is not a word name
:: ;a ! ;a is a word name
USING: a b c ;
USE: a
IN: a.b
CHAR: a
#: a
GENERIC#: a
----------------------------------------------------
[
[ "colon-syntax", ": a" ],
[ "stack-effect-delimiter", "(" ],
[ "stack-effect-delimiter", "--" ],
[ "stack-effect-delimiter", ")" ],
[ "semicolon-or-setlocal", ";" ],
[ "normal-word", "::" ],
[ "semicolon-or-setlocal", ";" ],
[ "comment", [ "! ; is not a word name" ] ],
[ "colon-syntax", ":: ;a" ],
[ "comment", [ "! ;a is a word name" ] ],
[ "special-using",
[ "USING: ",
[ "string", "a" ],
[ "string", "b" ],
[ "string", "c" ]
]
],
[ "semicolon-or-setlocal", ";" ],
[ "colon-syntax", "USE: a" ],
[ "colon-syntax", "IN: a.b" ],
[ "colon-syntax", "CHAR: a" ],
[ "normal-word", "#:" ],
[ "normal-word", "a" ],
[ "colon-syntax", "GENERIC#: a" ]
]
----------------------------------------------------
colon-ended parsing words

View File

@ -0,0 +1,74 @@
a! ! word
!a ! word
! comment
! bad
! fine
! "also a comment"
! : ( -- ) ;
! ! leading comment-like token
! whitespace before
words blah ! comment after code on a line
![[ comment ]]
"![[ string ]]"
![[ "comment" ]]
![[ comment]]
![==[ comment ]==]
![==[ comment]==]
![=[word ]=]
![=======[ words ]=======]
/* com
ment */
/* com
ment*/
/*word */
/* "comment" */
"/* "strings" */"
----------------------------------------------------
[
[ "conventionally-named-word", "a!"],
[ "comment", [ "! word" ] ],
[ "normal-word", "!a"],
[ "comment", [ "! word" ] ],
[ "comment", [ "! comment" ] ],
[ "normal-word", "!" ], [ "normal-word", "bad" ],
[ "comment", [ "! \tfine" ] ],
[ "comment", [ "! \"also a comment\"" ] ],
[ "comment", [ "! : ( -- ) ;" ] ],
[ "comment", [ "! ! leading comment-like token" ] ],
[ "comment", [ "! whitespace before" ] ],
[ "normal-word", "words" ],
[ "normal-word", "blah" ],
[ "comment", [ "! comment after code on a line" ] ],
[ "comment", [ "![[ comment ]]" ] ],
[ "string", [ "\"![[ string ]]\"" ] ],
[ "comment", [ "![[ \"comment\" ]]" ] ],
[ "comment", [ "![[ comment]]" ] ],
[ "comment", [ "![==[ comment ]==]" ] ],
[ "comment", [ "![==[ comment]==]" ] ],
[ "normal-word", "![=[word" ],
[ "normal-word", "]=]" ],
[ "normal-word", "![=======[" ],
[ "normal-word", "words" ],
[ "normal-word", "]=======]" ],
[ "comment", [ "/* com\r\nment */" ] ],
[ "comment", [ "/* com\r\nment*/" ] ],
[ "normal-word", "/*word" ],
[ "normal-word", "*/" ],
[ "comment", ["/* \"comment\" */"] ],
[ "string", ["\"/* \""] ],
"strings",
[ "string", ["\" */\""] ]
]
----------------------------------------------------

View File

@ -0,0 +1,18 @@
<array> <byte-array> <string>
<=> <-->
----------------------------------------------------
[
[ "constructor-word", "<array>" ],
[ "constructor-word", "<byte-array>" ],
[ "constructor-word", "<string>" ],
[ "conventionally-named-word", "<=>" ],
[ "conventionally-named-word", "<-->" ]
]
----------------------------------------------------
ctors

View File

@ -0,0 +1,56 @@
commas, primes'
set-x
change-x
with-x
new-x
>string
base>
string>number
+symbol+
que?
?of
?of*
reader>>
>>setter
writer<<
(detail)
mutater!
variant*
prettyprint.
$help
"no
----------------------------------------------------
[
[ "normal-word", "commas," ],
[ "normal-word", "primes'" ],
[ "conventionally-named-word", "set-x" ],
[ "conventionally-named-word", "change-x" ],
[ "conventionally-named-word", "with-x" ],
[ "conventionally-named-word", "new-x" ],
[ "conventionally-named-word", ">string" ],
[ "conventionally-named-word", "base>" ],
[ "conventionally-named-word", "string>number" ],
[ "conventionally-named-word", "+symbol+" ],
[ "conventionally-named-word", "que?" ],
[ "conventionally-named-word", "?of" ],
[ "conventionally-named-word", "?of*" ],
[ "conventionally-named-word", "reader>>" ],
[ "conventionally-named-word", ">>setter" ],
[ "conventionally-named-word", "writer<<" ],
[ "conventionally-named-word", "(detail)" ],
[ "conventionally-named-word", "mutater!" ],
[ "conventionally-named-word", "variant*" ],
[ "conventionally-named-word", "prettyprint." ],
[ "conventionally-named-word", "$help" ],
"\r\n\r\n\"no"
]
----------------------------------------------------
"Normal" words are not builtin well-known ones like "not", "and", "<=>", though they may be in the standard library or user-defined.
They may start with any character except `"` (double-quote), but may contain or end with double-quotes or any other non-whitespace character.
Conventionally named words follow the conventions outlined in prism-factor.js.

View File

@ -0,0 +1,49 @@
5 1/5 +9 -9 +1/5 -1/5 23+1/5 -23-1/5 23-1/5 ! last one = word
0.01 0e0 3E4 3e-4 3E-4 030 0xd 0o30 0b1100
-0 -0.01 -0e0 -3E4 -3E-4 -030 -0xd -0o30 -0b1100
348756424956392657834385437598743583648756332457
-348756424956392657834385437598743583648756332457
NAN: 80000deadbeef
---------------------------------------------------
[
[ "number", "5" ],
[ "number", "1/5" ],
[ "number", "+9" ],
[ "number", "-9" ],
[ "number", "+1/5" ],
[ "number", "-1/5" ],
[ "number", "23+1/5" ],
[ "number", "-23-1/5" ],
[ "normal-word", "23-1/5" ],
[ "comment", [ "! last one = word" ] ],
[ "number", "0.01" ],
[ "number", "0e0" ],
[ "number", "3E4" ],
[ "number", "3e-4" ],
[ "number", "3E-4" ],
[ "number", "030" ],
[ "number", "0xd" ],
[ "number", "0o30" ],
[ "number", "0b1100" ],
[ "number", "-0" ],
[ "number", "-0.01" ],
[ "number", "-0e0" ],
[ "number", "-3E4" ],
[ "number", "-3E-4" ],
[ "number", "-030" ],
[ "number", "-0xd" ],
[ "number", "-0o30" ],
[ "number", "-0b1100" ],
[ "number", "348756424956392657834385437598743583648756332457" ],
[ "number", "-348756424956392657834385437598743583648756332457" ],
[ "number", "NAN: 80000deadbeef" ]
]
---------------------------------------------------
numbers

View File

@ -0,0 +1,29 @@
<PRIVATE
:>
PRIVATE>
$[ some code ]
<< some code >>
\ M\
--------------------------------------------------
[
[ "other-builtin-syntax", "<PRIVATE" ],
[ "semicolon-or-setlocal", ":>" ],
[ "other-builtin-syntax", "PRIVATE>" ],
[ "other-builtin-syntax", "$[" ],
[ "normal-word", "some" ],
[ "normal-word", "code" ],
[ "quotation-delimiter", "]" ],
[ "other-builtin-syntax", "<<" ],
[ "normal-word", "some" ],
[ "normal-word", "code" ],
[ "other-builtin-syntax", ">>" ],
[ "other-builtin-syntax", "\\" ],
[ "other-builtin-syntax", "M\\" ]
]
--------------------------------------------------
various builtin parsing words from the syntax and kernel vocabs

View File

@ -0,0 +1,19 @@
] [ x y z and ] [
----------------------------------------------------
[
["normal-word", "]"],
["quotation-delimiter", "["],
["normal-word", "x" ],
["normal-word", "y"],
["normal-word", "z"],
["kernel-builtin", "and"],
["quotation-delimiter", "]"],
["normal-word", "["]
]
----------------------------------------------------
quotation syntax
] at the beginning, and [ at the end of the file should not be highlighted as delimiters

View File

@ -0,0 +1,27 @@
R/ abcde/i-r
R/
abcde?.+\?\*\+/
R/ \\/
R/ \//idmsr
R/ \/idmsr/
-----------------------------
[
[ "regexp", [ "R/ abcde/", [ "operator", "i-r" ] ] ],
[ "regexp", [
"R/\r\nabcde",
[ "keyword", "?" ],
[ "keyword", "." ],
[ "keyword", "+" ],
[ "variable", "\\?" ],
[ "variable", "\\*" ],
[ "variable", "\\+" ],
"/"
] ],
[ "regexp", [ "R/ ", [ "variable", "\\\\"], "/"] ],
[ "regexp", [ "R/ ", [ "variable", "\\/" ], "/", [ "operator", "idmsr" ] ] ],
[ "regexp", [ "R/ ", [ "variable", "\\/" ], "idmsr/" ] ]
]
-----------------------------

View File

@ -0,0 +1,98 @@
}
{ 1 2 3 4 }
{ a b c d e f }
{ "a" "b" "c" }
{ { a b } { c d } }
H{ { a b } { c d } }
H{ { "a" "b" } { "c" "d" } }
V{ 1 2 3 4 }
V{ "1" "2" "3" "4" }
BV{ 1 2 3 4 }
{
----------------------------------------------------
[
["normal-word", "}"],
["curly-brace-literal-delimiter", "{"],
["number", "1"],
["number", "2"],
["number", "3"],
["number", "4"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "{"],
["normal-word", "a"],
["normal-word", "b"],
["normal-word", "c"],
["normal-word", "d"],
["normal-word", "e"],
["boolean", "f"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "{"],
["string", ["\"a\""] ],
["string", ["\"b\""] ],
["string", ["\"c\""] ],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "{"],
["curly-brace-literal-delimiter", "{"],
["normal-word", "a"],
["normal-word", "b"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "{"],
["normal-word", "c"],
["normal-word", "d"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "H{"],
["curly-brace-literal-delimiter", "{"],
["normal-word", "a"],
["normal-word", "b"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "{"],
["normal-word", "c"],
["normal-word", "d"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "H{"],
["curly-brace-literal-delimiter", "{"],
["string", ["\"a\""]],
["string", ["\"b\""]],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "{"],
["string", ["\"c\""]],
["string", ["\"d\""]],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "V{"],
["number", "1"],
["number", "2"],
["number", "3"],
["number", "4"],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "V{"],
["string", ["\"1\""]],
["string", ["\"2\""]],
["string", ["\"3\""]],
["string", ["\"4\""]],
["curly-brace-literal-delimiter", "}"],
["curly-brace-literal-delimiter", "BV{"],
["number", "1"],
["number", "2"],
["number", "3"],
["number", "4"],
["curly-brace-literal-delimiter", "}"],
["normal-word", "{"]
]
----------------------------------------------------
} / { at the front / EOF are not delimiters

View File

@ -0,0 +1,74 @@
( -- )
( a b -- c )
( a: integer b: string -- c: word )
( x y quot: ( ..a -- ..a ) -- ..a )
call( -- )
call( x -- y )
execute( x -- y )
eval( x -- y )
----------------------------------------------------
[
[ "stack-effect-delimiter", "(" ],
[ "stack-effect-delimiter", "--" ],
[ "stack-effect-delimiter", ")" ],
[ "stack-effect-delimiter", "(" ],
[ "normal-word", "a" ],
[ "normal-word", "b" ],
[ "stack-effect-delimiter", "--" ],
[ "normal-word", "c" ],
[ "stack-effect-delimiter", ")" ],
[ "stack-effect-delimiter", "(" ],
[ "normal-word", "a:" ],
[ "math-builtin", "integer" ],
[ "normal-word", "b:" ],
[ "normal-word", "string" ],
[ "stack-effect-delimiter", "--" ],
[ "normal-word", "c:" ],
[ "normal-word", "word" ],
[ "stack-effect-delimiter", ")" ],
[ "stack-effect-delimiter", "(" ],
[ "normal-word", "x" ],
[ "normal-word", "y" ],
[ "normal-word", "quot:" ],
[ "stack-effect-delimiter", "(" ],
[ "normal-word", "..a" ],
[ "stack-effect-delimiter", "--" ],
[ "normal-word", "..a" ],
[ "stack-effect-delimiter", ")" ],
[ "stack-effect-delimiter", "--" ],
[ "normal-word", "..a" ],
[ "stack-effect-delimiter", ")" ],
[ "stack-effect-delimiter", "call(" ],
[ "stack-effect-delimiter", "--" ],
[ "stack-effect-delimiter", ")" ],
[ "stack-effect-delimiter", "call(" ],
[ "normal-word", "x" ],
[ "stack-effect-delimiter", "--" ],
[ "normal-word", "y" ],
[ "stack-effect-delimiter", ")" ],
[ "stack-effect-delimiter", "execute(" ],
[ "normal-word", "x" ],
[ "stack-effect-delimiter", "--" ],
[ "normal-word", "y" ],
[ "stack-effect-delimiter", ")" ],
[ "stack-effect-delimiter", "eval(" ],
[ "normal-word", "x" ],
[ "stack-effect-delimiter", "--" ],
[ "normal-word", "y" ],
[ "stack-effect-delimiter", ")" ]
]
----------------------------------------------------
stack effect syntax

View File

@ -0,0 +1,127 @@
"s" word"word" ! word: word"word"
"adjacent""strings"
" ! str not comment" ! comment
"!"
" ! "
"! "
"\""
"'"
"\n"
"\\"
"str"5
"str"[ ]
"str"{ }
{ "a"}
"5"
"1/5"
"+5"
"-5"
HEREDOC: marker
text \n
marker
STRING: name
text \n
;
[[ string ]]
[[ string]]
[==[ string ]==]
[==[ string]==]
[[word ]]
URL" " URL""
SBUF" " SBUF""
P" " P""
P" as\\""
----------------------------------------------------------
[
[ "string", ["\"s\""] ],
[ "normal-word", "word\"word\"" ],
[ "comment", ["! word: word\"word\""] ],
[ "string", ["\"adjacent\""] ],
[ "string", ["\"strings\""] ],
[ "string", ["\" ! str not comment\""] ],
[ "comment", ["! comment"] ],
[ "string", ["\"!\""] ],
[ "string", ["\" ! \""] ],
[ "string", ["\"! \""] ],
[ "string", [
"\"",
[ "number", "\\\"" ],
"\""
] ],
[ "string", ["\"'\""] ],
[ "string", [
"\"",
["number", "\\n"],
"\""
] ],
[ "string", ["\"", ["number", "\\\\"], "\""] ],
[ "string", ["\"str\""] ],
"5\r\n",
["string", ["\"str\""] ],
"[ ",
[ "quotation-delimiter", "]" ],
[ "string", ["\"str\""] ],
"{ ",
[ "curly-brace-literal-delimiter", "}" ],
[ "curly-brace-literal-delimiter", "{" ],
[ "string", ["\"a\""] ],
"}\r\n",
[ "string", ["\"5\""] ],
[ "string", ["\"1/5\""] ],
[ "string", ["\"+5\""] ],
[ "string", ["\"-5\""] ],
[ "multiline-string", [
"HEREDOC: marker\r\ntext ",
[ "number", "\\n" ],
"\r\nmarker"
] ],
[ "multiline-string", [
"STRING: name\r\ntext ",
[ "number", "\\n" ],
[ "semicolon-or-setlocal", ";" ]
] ],
[ "multiline-string", [ "[[ string ]]" ] ],
[ "multiline-string", [ "[[ string]]" ] ],
[ "multiline-string", [ "[==[ string ]==]" ] ],
[ "multiline-string", [ "[==[ string]==]" ] ],
[ "normal-word", "[[word" ],
[ "normal-word", "]]" ],
[ "custom-string", ["URL\" \""] ],
[ "normal-word", "URL\"\"" ],
[ "custom-string", ["SBUF\" \""] ],
[ "normal-word", "SBUF\"\"" ],
[ "custom-string", ["P\" \""] ],
[ "normal-word", "P\"\"" ],
[ "custom-string", [
"P\" as",
[ "number", "\\\\" ],
"\""
] ],
"\""
]
----------------------------------------------------------
string kinds