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
23 : ?-- ( c-addr u -- c-addr u flag )
24 2dup s" --" compare 0= ;
25 : ?} ( c-addr u -- c-addr u flag )
26 2dup s" }" compare 0= ;
27 : ?| ( c-addr u -- c-addr u flag )
28 2dup s" |" compare 0= ;
30 \ examine name - if it's a 2local (starts with "2:"),
31 \ nibble the prefix (the "2:") off the name and push true.
32 \ Otherwise push false
33 \ Problem if the local is named "2:" - we fall off the end...
34 : ?2loc ( c-addr u -- c-addr u flag )
35 over dup c@ [char] 2 =
36 swap 1+ c@ [char] : = and
38 2 - swap char+ char+ swap \ dcs/jws: nibble the '2:'
45 : ?delim ( c-addr u -- state | c-addr u 0 )
46 ?| if 2drop 1 exit endif
47 ?-- if 2drop 2 exit endif
48 ?} if 2drop 3 exit endif
57 0 dup locals| locstate |
59 \ stack locals until we hit a delimiter
61 parse-word \ ( nLocals c-addr u )
62 ?delim dup to locstate
64 rot 1+ \ ( c-addr u ... c-addr u nLocals )
67 \ now unstack the locals
69 ?2loc if (2local) else (local) endif
72 \ zero locals until -- or }
76 ?delim dup to locstate
79 postpone zero postpone zero (2local)
89 \ (explicitly allow | and -- in the comment)
93 ?delim dup to locstate
95 locstate 0= if 2drop endif
99 locstate 3 <> abort" syntax error in { } local line"
100 ; immediate compile-only