File: prism-factor.html

package info (click to toggle)
node-prismjs 1.30.0%2Bdfsg%2B~1.26.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,220 kB
  • sloc: javascript: 27,628; makefile: 9; sh: 7; awk: 4
file content (127 lines) | stat: -rw-r--r-- 2,867 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<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; &lt;=> SYNTAX: x $[ xyz ]

set-x change-x with-variable ?of if* (gensym) hex. $description reader>> >>setter writer&lt;&lt;

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>