-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds support for the [Factor](https://factorcode.org) language.
- Loading branch information
Showing
17 changed files
with
1,170 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
|
||
<array> <=> 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
and not with map filter | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
[ "kernel-builtin", "and" ], | ||
[ "kernel-builtin", "not" ], | ||
[ "combinators", "with" ], | ||
[ "combinators", "map" ], | ||
[ "combinators", "filter" ] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
some builtins |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", ["\" */\""] ] | ||
] | ||
|
||
---------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Oops, something went wrong.