-
Notifications
You must be signed in to change notification settings - Fork 125
/
string_expr.trx
40 lines (32 loc) · 1.5 KB
/
string_expr.trx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
(*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(* importing some stuff *)
{{ open Parser_utils }}
;lbrace <- Opa_lexer.lbrace
;rbrace_nosp <- Opa_lexer.rbrace_nosp
(* parser for non constants strings like "f(3) is :{f(3)}!"
* the given example will be transformed in
* [sc_list(["f(3)",f(3),"!"])]
*)
;/** string with embedded opa **/
string_with_opa <- (=Opa_parser.deco(just_string_with_opa)):p
{{ let (l,label) = p in
(* slight optimization, but mostly it improves readability of pretty printed code *)
(computed_string l),label
}}
;just_string_with_opa <- [\"] inner_string_element*:l (=Opa_lexer.or_eof([\"])):b {{ if not b then error_string (pos_only _filename _pos_beg _pos_end) else l }}
; inner_string_element <-
/ Opa_parser.opa_in_braces_nosp:e {{ wrap_e magic_to_string e }}
/ (=Opa_parser.careful_deco(Opa_lexer.stringchar+)):p
{{ let l,label = p in string (String.concat "" l) label }}