equal
deleted
inserted
replaced
63 val strip_blanks: string -> string |
63 val strip_blanks: string -> string |
64 val bump_init: string -> string |
64 val bump_init: string -> string |
65 val bump_string: string -> string |
65 val bump_string: string -> string |
66 val length: symbol list -> int |
66 val length: symbol list -> int |
67 val xsymbolsN: string |
67 val xsymbolsN: string |
|
68 val output: string -> output * int |
68 end; |
69 end; |
69 |
70 |
70 structure Symbol: SYMBOL = |
71 structure Symbol: SYMBOL = |
71 struct |
72 struct |
72 |
73 |
173 |
174 |
174 fun raw_chr c = |
175 fun raw_chr c = |
175 ord space <= ord c andalso ord c <= ord "~" andalso c <> "." andalso c <> ">" |
176 ord space <= ord c andalso ord c <= ord "~" andalso c <> "." andalso c <> ">" |
176 orelse ord c >= 128; |
177 orelse ord c >= 128; |
177 |
178 |
178 fun encode_raw str = |
179 fun encode_raw "" = "" |
179 let |
180 | encode_raw str = |
180 val raw0 = enclose "\\<^raw:" ">"; |
181 let |
181 val raw1 = raw0 o implode; |
182 val raw0 = enclose "\\<^raw:" ">"; |
182 val raw2 = enclose "\\<^raw" ">" o string_of_int o ord; |
183 val raw1 = raw0 o implode; |
183 |
184 val raw2 = enclose "\\<^raw" ">" o string_of_int o ord; |
184 fun encode cs = enc (Library.take_prefix raw_chr cs) |
185 |
185 and enc ([], []) = [] |
186 fun encode cs = enc (Library.take_prefix raw_chr cs) |
186 | enc (cs, []) = [raw1 cs] |
187 and enc ([], []) = [] |
187 | enc ([], d :: ds) = raw2 d :: encode ds |
188 | enc (cs, []) = [raw1 cs] |
188 | enc (cs, d :: ds) = raw1 cs :: raw2 d :: encode ds; |
189 | enc ([], d :: ds) = raw2 d :: encode ds |
189 in |
190 | enc (cs, d :: ds) = raw1 cs :: raw2 d :: encode ds; |
190 if exists_string (not o raw_chr) str then implode (encode (explode str)) |
191 in |
191 else raw0 str |
192 if exists_string (not o raw_chr) str then implode (encode (explode str)) |
192 end; |
193 else raw0 str |
|
194 end; |
193 |
195 |
194 |
196 |
195 (* diagnostics *) |
197 (* diagnostics *) |
196 |
198 |
197 fun beginning n cs = |
199 fun beginning n cs = |
517 val ss' = if symbolic_end ss then "'" :: ss else bump ss; |
519 val ss' = if symbolic_end ss then "'" :: ss else bump ss; |
518 in implode (rev ss' @ qs) end; |
520 in implode (rev ss' @ qs) end; |
519 |
521 |
520 |
522 |
521 |
523 |
522 (** xsymbols **) |
524 (** symbol output **) |
523 |
525 |
524 val xsymbolsN = "xsymbols"; |
526 (* length *) |
525 |
527 |
526 fun sym_len s = |
528 fun sym_len s = |
527 if not (is_printable s) then (0: int) |
529 if not (is_printable s) then (0: int) |
528 else if String.isPrefix "\\<long" s then 2 |
530 else if String.isPrefix "\\<long" s then 2 |
529 else if String.isPrefix "\\<Long" s then 2 |
531 else if String.isPrefix "\\<Long" s then 2 |
530 else if s = "\\<spacespace>" then 2 |
532 else if s = "\\<spacespace>" then 2 |
531 else 1; |
533 else 1; |
532 |
534 |
533 fun sym_length ss = fold (fn s => fn n => sym_len s + n) ss 0; |
535 fun sym_length ss = fold (fn s => fn n => sym_len s + n) ss 0; |
534 |
536 |
|
537 |
|
538 (* print mode *) |
|
539 |
|
540 val xsymbolsN = "xsymbols"; |
|
541 |
|
542 fun output s = (s, sym_length (sym_explode s)); |
|
543 |
|
544 |
535 (*final declarations of this structure!*) |
545 (*final declarations of this structure!*) |
|
546 val explode = sym_explode; |
536 val length = sym_length; |
547 val length = sym_length; |
537 val explode = sym_explode; |
|
538 |
548 |
539 end; |
549 end; |