diff options
| author | Joel Martin <github@martintribe.org> | 2014-12-18 20:33:49 -0600 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2015-01-09 16:16:50 -0600 |
| commit | b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch) | |
| tree | f4d977ed220e9a3f665cfbf4f68770a81e4c2095 /ps/reader.ps | |
| parent | aaba249304b184e12e2445ab22d66df1f39a51a5 (diff) | |
| download | mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip | |
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'ps/reader.ps')
| -rw-r--r-- | ps/reader.ps | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/ps/reader.ps b/ps/reader.ps index f1f63f6..4b268c0 100644 --- a/ps/reader.ps +++ b/ps/reader.ps @@ -52,6 +52,32 @@ end } def end } def +% read_keyword: read a single keyword from string/idx +% string idx -> read_keyword -> name string new_idx +/read_keyword { 5 dict begin + %(in read_keyword\n) print + /idx exch def + /str exch def + /start idx def + /cnt 0 def + { % loop + idx str length ge { exit } if % EOF, break loop + /ch str idx 1 getinterval def + token_delim ch search { % if token delimeter + pop pop pop exit + }{ % else not a delim + pop + /cnt cnt 1 add def + } ifelse + /idx idx 1 add def % increment idx + } loop + + str start cnt getinterval % the matched keyword string + dup 0 127 put % TODO: something like (\x029e) would be better + str idx % return: keyword string new_idx +end } def + + % read_string: read a single string from string/idx % string idx -> read_string -> new_string string new_idx /read_string { 5 dict begin @@ -94,8 +120,10 @@ end } def %ch 48 ge ch 57 le and 45 ch eq or { %if number ch 48 ge ch 57 le and { %if number str idx read_number - }{ ch 34 eq { %elseif double-quote + }{ ch 34 eq { %elseif double-quote (string) str idx read_string + }{ ch 58 eq { %elseif colon (keyword) + str idx read_keyword }{ str idx read_symbol /idx exch def pop @@ -108,7 +136,7 @@ end } def }{ %else str idx % return the original symbol/name } ifelse } ifelse } ifelse - } ifelse } ifelse + } ifelse } ifelse } ifelse }ifelse % return: atom string new_idx |
