1 ! :folding=indent:collapseFolds=1:
5 ! Copyright (C) 2004 Slava Pestov.
7 ! Redistribution and use in source and binary forms, with or without
8 ! modification, are permitted provided that the following conditions are met:
10 ! 1. Redistributions of source code must retain the above copyright notice,
11 ! this list of conditions and the following disclaimer.
13 ! 2. Redistributions in binary form must reproduce the above copyright notice,
14 ! this list of conditions and the following disclaimer in the documentation
15 ! and/or other materials provided with the distribution.
17 ! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 ! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
19 ! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20 ! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 ! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 ! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 ! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 ! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 ! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 ! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ! Parsing words. 'builtins' is a stupid vocabulary name now
29 ! that it does not contain Java words anymore!
49 : t t parsed ; parsing
50 : f f parsed ; parsing
54 : ] nreverse parsed ; parsing
56 : | ( syntax: | cdr ] )
57 #! See the word 'parsed'. We push a special sentinel, and
58 #! 'parsed' acts accordingly.
63 : } nreverse list>vector parsed ; parsing
65 ! Do not execute parsing word
66 : POSTPONE: ( -- ) scan parse-word parsed ; parsing
69 : CREATE scan "in" get create ;
72 #! Begin a word definition. Word name follows.
76 #! End a word definition.
79 [ compound, ] [ define ] ifte ; parsing
82 : DEFER: CREATE drop ; parsing
83 : USE: scan "use" cons@ ; parsing
84 : IN: scan dup "use" cons@ "in" set ; parsing
87 : unicode-escape ( -- esc )
94 : ascii-escape ( ch -- esc )
96 [ CHAR: e | CHAR: \e ]
97 [ CHAR: n | CHAR: \n ]
98 [ CHAR: r | CHAR: \r ]
99 [ CHAR: t | CHAR: \t ]
100 [ CHAR: s | CHAR: \s ]
101 [ CHAR: \s | CHAR: \s ]
102 [ CHAR: 0 | CHAR: \0 ]
103 [ CHAR: \\ | CHAR: \\ ]
104 [ CHAR: \" | CHAR: \" ]
107 : escape ( ch -- esc )
116 : parse-escape ( -- )
117 next-ch escape dup [ drop "Bad escape" throw ] unless ;
119 : parse-ch ( ch -- ch )
120 dup CHAR: \\ = [ drop parse-escape ] when ;
122 : parse-string ( -- )
123 next-ch dup CHAR: " = [
126 parse-ch % parse-string
130 #! Note the ugly hack to carry the new value of 'pos' from
131 #! the <% %> scope up to the original scope.
132 <% parse-string "pos" get %> swap "pos" set parsed ; parsing
135 : CHAR: ( -- ) skip-blank next-ch parse-ch parsed ; parsing
138 : ( ")" until drop ; parsing
139 : ! until-eol drop ; parsing
140 : #! until-eol drop ; parsing
142 ! Reading numbers in other bases
145 #! Read a number in a specific base.
146 "base" get >r "base" set scan number, r> "base" set ;
148 : HEX: 16 BASE: ; parsing
149 : DEC: 10 BASE: ; parsing
150 : OCT: 8 BASE: ; parsing
151 : BIN: 2 BASE: ; parsing