50 | _ => err ()) |
50 | _ => err ()) |
51 end; |
51 end; |
52 end; |
52 end; |
53 *} |
53 *} |
54 |
54 |
55 syntax "_STR_cartouche" :: "cartouche_position \<Rightarrow> string" ("STR _") |
55 syntax "_cartouche_string" :: "cartouche_position \<Rightarrow> string" ("_") |
56 |
56 |
57 parse_translation {* |
57 parse_translation {* |
58 [(@{syntax_const "_STR_cartouche"}, |
58 [(@{syntax_const "_cartouche_string"}, |
59 K (string_tr (Symbol_Pos.cartouche_content o Symbol_Pos.explode)))] |
59 K (string_tr (Symbol_Pos.cartouche_content o Symbol_Pos.explode)))] |
60 *} |
60 *} |
61 |
61 |
62 term "STR \<open>\<close>" |
62 term "\<open>\<close>" |
63 term "STR \<open>abc\<close>" |
63 term "\<open>abc\<close>" |
64 term "STR \<open>abc\<close> @ STR \<open>xyz\<close>" |
64 term "\<open>abc\<close> @ \<open>xyz\<close>" |
65 term "STR \<open>\<newline>\<close>" |
65 term "\<open>\<newline>\<close>" |
66 term "STR \<open>\001\010\100\<close>" |
66 term "\<open>\001\010\100\<close>" |
67 |
67 |
68 |
68 |
69 subsection {* Alternate outer and inner syntax: string literals *} |
69 subsection {* Alternate outer and inner syntax: string literals *} |
70 |
70 |
71 subsubsection {* Nested quotes *} |
71 subsubsection {* Nested quotes *} |
72 |
72 |
73 syntax "_STR_string" :: "string_position \<Rightarrow> string" ("STR _") |
73 syntax "_string_string" :: "string_position \<Rightarrow> string" ("_") |
74 |
74 |
75 parse_translation {* |
75 parse_translation {* |
76 [(@{syntax_const "_STR_string"}, K (string_tr Lexicon.explode_string))] |
76 [(@{syntax_const "_string_string"}, K (string_tr Lexicon.explode_string))] |
77 *} |
77 *} |
78 |
78 |
79 term "STR \"\"" |
79 term "\"\"" |
80 term "STR \"abc\"" |
80 term "\"abc\"" |
81 term "STR \"abc\" @ STR \"xyz\"" |
81 term "\"abc\" @ \"xyz\"" |
82 term "STR \"\<newline>\"" |
82 term "\"\<newline>\"" |
83 term "STR \"\001\010\100\"" |
83 term "\"\001\010\100\"" |
84 |
84 |
85 |
85 |
86 subsubsection {* Term cartouche and regular quotes *} |
86 subsubsection {* Term cartouche and regular quotes *} |
87 |
87 |
88 ML {* |
88 ML {* |
93 val ctxt = Toplevel.context_of state; |
93 val ctxt = Toplevel.context_of state; |
94 val t = Syntax.read_term ctxt s; |
94 val t = Syntax.read_term ctxt s; |
95 in writeln (Syntax.string_of_term ctxt t) end))) |
95 in writeln (Syntax.string_of_term ctxt t) end))) |
96 *} |
96 *} |
97 |
97 |
98 term_cartouche \<open>STR ""\<close> |
98 term_cartouche \<open>""\<close> |
99 term_cartouche \<open>STR "abc"\<close> |
99 term_cartouche \<open>"abc"\<close> |
100 term_cartouche \<open>STR "abc" @ STR "xyz"\<close> |
100 term_cartouche \<open>"abc" @ "xyz"\<close> |
101 term_cartouche \<open>STR "\<newline>"\<close> |
101 term_cartouche \<open>"\<newline>"\<close> |
102 term_cartouche \<open>STR "\001\010\100"\<close> |
102 term_cartouche \<open>"\001\010\100"\<close> |
103 |
103 |
104 |
104 |
105 subsubsection {* Further nesting: antiquotations *} |
105 subsubsection {* Further nesting: antiquotations *} |
106 |
106 |
107 setup -- "ML antiquotation" |
107 setup -- "ML antiquotation" |
123 val _ = ML_Context.eval_in (SOME context) false pos toks; |
123 val _ = ML_Context.eval_in (SOME context) false pos toks; |
124 in "" end); |
124 in "" end); |
125 *} |
125 *} |
126 |
126 |
127 ML {* |
127 ML {* |
128 @{term_cartouche \<open>STR ""\<close>}; |
128 @{term_cartouche \<open>""\<close>}; |
129 @{term_cartouche \<open>STR "abc"\<close>}; |
129 @{term_cartouche \<open>"abc"\<close>}; |
130 @{term_cartouche \<open>STR "abc" @ STR "xyz"\<close>}; |
130 @{term_cartouche \<open>"abc" @ "xyz"\<close>}; |
131 @{term_cartouche \<open>STR "\<newline>"\<close>}; |
131 @{term_cartouche \<open>"\<newline>"\<close>}; |
132 @{term_cartouche \<open>STR "\001\010\100"\<close>}; |
132 @{term_cartouche \<open>"\001\010\100"\<close>}; |
133 *} |
133 *} |
134 |
134 |
135 text {* |
135 text {* |
136 @{ML_cartouche |
136 @{ML_cartouche |
137 \<open> |
137 \<open> |
138 ( |
138 ( |
139 @{term_cartouche \<open>STR ""\<close>}; |
139 @{term_cartouche \<open>""\<close>}; |
140 @{term_cartouche \<open>STR "abc"\<close>}; |
140 @{term_cartouche \<open>"abc"\<close>}; |
141 @{term_cartouche \<open>STR "abc" @ STR "xyz"\<close>}; |
141 @{term_cartouche \<open>"abc" @ "xyz"\<close>}; |
142 @{term_cartouche \<open>STR "\<newline>"\<close>}; |
142 @{term_cartouche \<open>"\<newline>"\<close>}; |
143 @{term_cartouche \<open>STR "\001\010\100"\<close>} |
143 @{term_cartouche \<open>"\001\010\100"\<close>} |
144 ) |
144 ) |
145 \<close> |
145 \<close> |
146 } |
146 } |
147 *} |
147 *} |
148 |
148 |
158 text_cartouche |
158 text_cartouche |
159 \<open> |
159 \<open> |
160 @{ML_cartouche |
160 @{ML_cartouche |
161 \<open> |
161 \<open> |
162 ( |
162 ( |
163 @{term_cartouche \<open>STR ""\<close>}; |
163 @{term_cartouche \<open>""\<close>}; |
164 @{term_cartouche \<open>STR "abc"\<close>}; |
164 @{term_cartouche \<open>"abc"\<close>}; |
165 @{term_cartouche \<open>STR "abc" @ STR "xyz"\<close>}; |
165 @{term_cartouche \<open>"abc" @ "xyz"\<close>}; |
166 @{term_cartouche \<open>STR "\<newline>"\<close>}; |
166 @{term_cartouche \<open>"\<newline>"\<close>}; |
167 @{term_cartouche \<open>STR "\001\010\100"\<close>} |
167 @{term_cartouche \<open>"\001\010\100"\<close>} |
168 ) |
168 ) |
169 \<close> |
169 \<close> |
170 } |
170 } |
171 \<close> |
171 \<close> |
172 |
172 |