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
9 \ locstate: 0 = looking for | or -- or }}
15 \ revised 2 June 2000 - { | a -- } now works correctly
22 : ?-- ( c-addr u -- c-addr u flag )
23 2dup s" --" compare 0= ;
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= ;
29 \ examine name - if it's a 2local (starts with "2:"),
30 \ nibble the prefix (the "2:") off the name and push true.
31 \ Otherwise push false
32 \ Problem if the local is named "2:" - we fall off the end...
33 : ?2loc ( c-addr u -- c-addr u flag )
34 over dup c@ [char] 2 =
35 swap 1+ c@ [char] : = and
37 2 - swap char+ char+ swap \ dcs/jws: nibble the '2:'
44 : ?delim ( c-addr u -- state | c-addr u 0 )
45 ?| if 2drop 1 exit endif
46 ?-- if 2drop 2 exit endif
47 ?} if 2drop 3 exit endif
56 0 dup locals| locstate |
58 \ stack locals until we hit a delimiter
60 parse-word \ ( nLocals c-addr u )
61 ?delim dup to locstate
63 rot 1+ \ ( c-addr u ... c-addr u nLocals )
66 \ now unstack the locals
68 ?2loc if (2local) else (local) endif
71 \ zero locals until -- or }
75 ?delim dup to locstate
78 postpone zero postpone zero (2local)
91 ?delim dup to locstate
97 locstate 3 <> abort" syntax error in { } local line"
98 ; immediate compile-only