0 constant number-type
1 constant boolean-type
+2 constant character-type
: istype? ( obj -- obj b )
over = ;
variable parse-idx
variable dummy-parse-idx
+: inc-parse-idx
+ 1 parse-idx +! ;
+
+: dec-parse-idx
+ 1 parse-idx -! ;
+
: store-parse-idx
parse-idx @ dummy-parse-idx ! ;
begin
whitespace?
while
- 1 parse-idx +!
+ inc-parse-idx
repeat
;
then
store-parse-idx
- 1 parse-idx +!
+ inc-parse-idx
begin digit? while
- 1 parse-idx +!
+ inc-parse-idx
repeat
delim? charavailable? false = or if
: boolean? ( -- bool )
nextchar [char] # <> if false exit then
- 1 parse-idx +!
+ store-parse-idx
+ inc-parse-idx
nextchar [char] t <>
nextchar [char] f <>
- and if 1 parse-idx -! false exit then
+ and if restore-parse-idx false exit then
- 1 parse-idx -!
+ restore-parse-idx
true
;
+: character? ( -- bool )
+ nextchar [char] # <> if false exit then
+
+ store-parse-idx
+ inc-parse-idx
+
+ nextchar [char] \ <> if restore-parse-idx false exit then
+
+ inc-parse-idx
+
+ charavailable? false = if restore-parse-idx false exit then
+
+ restore-parse-idx true
+;
+
: readnum ( -- num-atom )
minus? dup if
- 1 parse-idx +!
+ inc-parse-idx
then
0
begin digit? while
10 * nextchar [char] 0 - +
- 1 parse-idx +!
+ inc-parse-idx
repeat
swap if negate then
;
: readbool ( -- bool-atom )
- 1 parse-idx +!
+ inc-parse-idx
nextchar [char] f = if
false
\ ---- Print ----
: printnum ( numobj -- ) drop . ;
+
: printbool ( numobj -- )
drop if
." #t"
getline
eof? if
- bold fg blue ." Moriturus te saluto." reset-term
+ cr bold fg blue ." Moriturus te saluto." reset-term
exit
then
escape emit [char] 0 + emit escape-end
;
-: reset-term
- escape [char] 0 emit escape-end
-;
-
-: clear-term
- escape [char] 2 emit [char] J emit
- escape [char] 0 emit [char] ; emit [char] 0 emit [char] f emit
-;
-
-: bold
- escape [char] 1 emit escape-end
-;
-
: colour
create ,
does>
6 colour cyan
7 colour white
+: bold
+ escape [char] 1 emit escape-end
+;
+
+: reset-term
+ escape [char] 0 emit escape-end
+;
+
+: clear-term
+ escape [char] 2 emit [char] J emit
+ escape [char] 0 emit [char] ; emit [char] 0 emit [char] f emit
+;
+
\ Example usage:
\ fg red ( set fg colour to red )
\ bg green ( set bg colour to green )
\ bold ( use a bold font )
\ reset-term ( return everything to normal )
+\ clear-term ( clear terminal and return cursor to origin )