xref: /freebsd/stand/ficl/softwords/jhlocal.fr (revision fa50a3552d1e759e1bb65e54cb0b7e863bcf54d5)
1\ #if FICL_WANT_LOCALS
2\ ** ficl/softwords/jhlocal.fr
3\ ** stack comment style local syntax...
4\ { a b c | cleared -- d e }
5\ variables before the "|" are initialized in reverse order
6\ from the stack. Those after the "|" are zero initialized.
7\ Anything between "--" and "}" is treated as comment
8\ Uses locals...
9\ locstate: 0 = looking for | or -- or }}
10\           1 = found |
11\           2 = found --
12\           3 = found }
13\           4 = end of line
14\
15\ revised 2 June 2000 - { | a -- } now works correctly
16\
17\ $FreeBSD$
18
19hide
20
210 constant zero
22
23
24: ?--   ( c-addr u -- c-addr u flag )
25    2dup s" --" compare 0= ;
26: ?}    ( c-addr u -- c-addr u flag )
27    2dup s" }"  compare 0= ;
28: ?|    ( c-addr u -- c-addr u flag )
29    2dup s" |"  compare 0= ;
30
31\ examine name - if it's a 2local (starts with "2:"),
32\ nibble the prefix (the "2:") off the name and push true.
33\ Otherwise push false
34\ Problem if the local is named "2:" - we fall off the end...
35: ?2loc ( c-addr u -- c-addr u flag )
36    over dup c@ [char] 2 =
37	swap 1+  c@ [char] : = and
38    if
39        2 - swap char+ char+ swap  \ dcs/jws: nibble the '2:'
40        true
41    else
42	    false
43    endif
44;
45
46: ?delim   ( c-addr u -- state | c-addr u 0 )
47    ?|  if  2drop 1 exit endif
48    ?-- if  2drop 2 exit endif
49    ?}  if  2drop 3 exit endif
50    dup 0=
51        if  2drop 4 exit endif
52    0
53;
54
55set-current
56
57: {
58    0 dup locals| locstate |
59
60    \ stack locals until we hit a delimiter
61    begin
62        parse-word      \ ( nLocals c-addr u )
63        ?delim dup to locstate
64    0= while
65        rot 1+          \ ( c-addr u ... c-addr u nLocals )
66    repeat
67
68    \ now unstack the locals
69    0 ?do
70	    ?2loc if (2local) else (local) endif
71	loop   \ ( )
72
73    \ zero locals until -- or }
74    locstate 1 = if
75        begin
76            parse-word
77            ?delim dup to locstate
78        0= while
79            ?2loc if
80                postpone zero postpone zero (2local)
81            else
82                postpone zero (local)
83            endif
84        repeat
85    endif
86
87    0 0 (local)
88
89    \ toss words until }
90    \ (explicitly allow | and -- in the comment)
91    locstate 2 = if
92        begin
93            parse-word
94            ?delim dup  to locstate
95        3 < while
96            locstate 0=  if 2drop endif
97        repeat
98    endif
99
100    locstate 3 <> abort" syntax error in { } local line"
101; immediate compile-only
102
103previous
104\ #endif
105
106