4 Antiquotations within plain text. |
4 Antiquotations within plain text. |
5 *) |
5 *) |
6 |
6 |
7 signature ANTIQUOTE = |
7 signature ANTIQUOTE = |
8 sig |
8 sig |
9 datatype 'a antiquote = |
9 type antiq = Symbol_Pos.T list * {start: Position.T, stop: Position.T, range: Position.range} |
10 Text of 'a | |
10 datatype 'a antiquote = Text of 'a | Antiq of antiq |
11 Antiq of Symbol_Pos.T list * Position.range |
|
12 val is_text: 'a antiquote -> bool |
11 val is_text: 'a antiquote -> bool |
13 val reports_of: ('a -> Position.report_text list) -> |
12 val reports_of: ('a -> Position.report_text list) -> |
14 'a antiquote list -> Position.report_text list |
13 'a antiquote list -> Position.report_text list |
15 val scan_antiq: Symbol_Pos.T list -> (Symbol_Pos.T list * Position.range) * Symbol_Pos.T list |
14 val scan_antiq: Symbol_Pos.T list -> antiq * Symbol_Pos.T list |
16 val scan_antiquote: Symbol_Pos.T list -> Symbol_Pos.T list antiquote * Symbol_Pos.T list |
15 val scan_antiquote: Symbol_Pos.T list -> Symbol_Pos.T list antiquote * Symbol_Pos.T list |
17 val read: Symbol_Pos.T list * Position.T -> Symbol_Pos.T list antiquote list |
16 val read: Symbol_Pos.T list * Position.T -> Symbol_Pos.T list antiquote list |
18 end; |
17 end; |
19 |
18 |
20 structure Antiquote: ANTIQUOTE = |
19 structure Antiquote: ANTIQUOTE = |
21 struct |
20 struct |
22 |
21 |
23 (* datatype antiquote *) |
22 (* datatype antiquote *) |
24 |
23 |
25 datatype 'a antiquote = |
24 type antiq = Symbol_Pos.T list * {start: Position.T, stop: Position.T, range: Position.range}; |
26 Text of 'a | |
25 datatype 'a antiquote = Text of 'a | Antiq of antiq; |
27 Antiq of Symbol_Pos.T list * Position.range; |
|
28 |
26 |
29 fun is_text (Text _) = true |
27 fun is_text (Text _) = true |
30 | is_text _ = false; |
28 | is_text _ = false; |
31 |
29 |
32 |
30 |
33 (* reports *) |
31 (* reports *) |
34 |
32 |
|
33 fun reports_of_antiq ((_, {start, stop, range = (pos, _)}): antiq) = |
|
34 map (rpair "") [(start, Markup.antiquote), (stop, Markup.antiquote), (pos, Markup.antiquoted)]; |
|
35 |
35 fun reports_of text = |
36 fun reports_of text = |
36 maps (fn Text x => text x | Antiq (_, (pos, _)) => [((pos, Markup.antiq), "")]); |
37 maps (fn Text x => text x | Antiq antiq => reports_of_antiq antiq); |
37 |
38 |
38 |
39 |
39 (* scan *) |
40 (* scan *) |
40 |
41 |
41 open Basic_Symbol_Pos; |
42 open Basic_Symbol_Pos; |
54 Scan.one (fn (s, _) => s <> "}" andalso Symbol.is_regular s) >> single; |
55 Scan.one (fn (s, _) => s <> "}" andalso Symbol.is_regular s) >> single; |
55 |
56 |
56 in |
57 in |
57 |
58 |
58 val scan_antiq = |
59 val scan_antiq = |
59 Symbol_Pos.scan_pos -- ($$ "@" |-- $$ "{" |-- |
60 Symbol_Pos.scan_pos -- ($$ "@" |-- $$ "{" |-- Symbol_Pos.scan_pos -- |
60 Symbol_Pos.!!! (fn () => err_prefix ^ "missing closing brace") |
61 Symbol_Pos.!!! (fn () => err_prefix ^ "missing closing brace") |
61 (Scan.repeat scan_antiq_body -- ($$ "}" |-- Symbol_Pos.scan_pos))) |
62 (Scan.repeat scan_antiq_body -- Symbol_Pos.scan_pos -- ($$ "}" |-- Symbol_Pos.scan_pos))) |
62 >> (fn (pos1, (body, pos2)) => (flat body, Position.range pos1 pos2)); |
63 >> (fn (pos1, (pos2, ((body, pos3), pos4))) => |
|
64 (flat body, |
|
65 {start = Position.set_range (pos1, pos2), |
|
66 stop = Position.set_range (pos3, pos4), |
|
67 range = Position.range pos1 pos4})); |
63 |
68 |
64 val scan_antiquote = scan_antiq >> Antiq || scan_txt >> Text; |
69 val scan_antiquote = scan_antiq >> Antiq || scan_txt >> Text; |
65 |
70 |
66 end; |
71 end; |
67 |
72 |