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
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= ;
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
39 2 - swap char+ char+ swap \ dcs/jws: nibble the '2:'
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
58 0 dup locals| locstate |
60 \ stack locals until we hit a delimiter
62 parse-word \ ( nLocals c-addr u )
63 ?delim dup to locstate
65 rot 1+ \ ( c-addr u ... c-addr u nLocals )
68 \ now unstack the locals
70 ?2loc if (2local) else (local) endif
73 \ zero locals until -- or }
77 ?delim dup to locstate
80 postpone zero postpone zero (2local)
90 \ (explicitly allow | and -- in the comment)
94 ?delim dup to locstate
96 locstate 0= if 2drop endif
100 locstate 3 <> abort" syntax error in { } local line"
101 ; immediate compile-only