Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A quick and dirty clone of Markup

41 views
Skip to first unread message

luser- -droog

unread,
Dec 22, 2010, 2:16:55 AM12/22/10
to
#!/home/olpc/gscmd -dNODISPLAY

9 dict begin
/scratch 128 string def % string buffer
/part { =only } def % proc executed for partial lines
/blank { = } def % proc executed for blank lines
/full { = } def % proc executed for full lines (no escapes)
/litname { % called by embed for literal /nametype tokens
(\(glyph: )=only =only (\))=only
} def
/escape (\\) def % string prefixing an embedded fragment
/embed { % proc executed for embedded tokens
XDICT LDICT
2 index xcheck not { exch } if pop %tok DICT
1 index type 2 copy known not { pop /default } if %tok DICT type
get exec
} dup 0 << %executable types
/default { exec }
>> put dup 1 << %literal types
/stringtype /part load
/nametype /litname load
/default { dup = }
>> put def
/str null def %holds remainder of line during embed

1 dict begin
/dostr {
escape search { %2
part pop token { %3
exch /str exch def embed str SELF %6
exec % recurse for remainder of line
}{ part } ifelse
}{
dup length 0 eq { blank } { full } ifelse
} ifelse
} dup
2 get
3 get
6 2 index put def % insert self into SELF

/do {
{
{
currentfile scratch readline
//dostr { pop exit } ifelse
} loop
} stopped { (Uh O! Spaghetti-O's!)= } if
}
end %discard << /dostr ... >>
def

do

A line of text.
More text. \{(embedded procedure!)=}
Literal name can trigger a glyph \/copyright
Embedded arithmetic:
\1 \2 \{add =}

And we're done.

\exit remember the alamo!
(pstack: )= pstack
str =

%output
%A line of text.
%More text. embedded procedure!
%
%Literal name can trigger a glyph (glyph: copyright)
%Embedded arithmetic:
%1
%2
%3
%
%
%And we're done.
%
%pstack:
%remember the alamo!

0 new messages