Skip to content
Newer
Older
100644 85 lines (67 sloc) 2.93 KB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 include default.trx
19
20 {{
21 open Xml
22 }}
23
24 +file : {Xml.xml * bool} <- header? content spacing eof
25 {{ let head = match __1 with Some h -> h | None -> [] in
26 let xml, ok = __2 in { xml with header = head }, ok }}
27 header <- "<?xml" spacing option* "?>" spacing {{ __3 }}
28 # factoriser
29 cdata <- "<![CDATA[" ((!"]]" .)* $_) "]]>" {{ `text __2 }}
30 extra_header <- "<!" ![\-] (![>] .)* [>] $
31
32 +content : {Xml.xml * bool} <- content_item* {{ rewrite __1 }}
33 content_item <- element / text / cdata / extra_header content_item {{ __2 }}
34
35 element <-
36 open (
37 / slash nsname {{ `stop __2 }}
38 / "!--" (!commentstop .)* "--" {{ `nothing }}
39 / nsname option* slash? {{ match __3 with Some _ -> `one (__1, __2) | _ -> `start (__1, __2) }}
40 ) close {{ __2 }}
41
42 # FIXME: UTF8 / factoriser avec url.trx et body_rewrite.trx
43 text <-
44 / space+ {{ `space }}
45 / char+ {{ `text (Tgrammar.string_of_chars __1) }}
46
47 # http://xml.silmaril.ie/authors/specials/
48 char <- [%] hexa hexa {{ char_of_int (16 * Char.hexa_value __2 + Char.hexa_value __3) }}
49 / [&] ( "gt;" {{ '>' }} / "lt;" {{ '<' }} / "amp;" {{ '&' }} / "quot;" {{ '"' }} / "apos;" {{ '\'' }}
50 / [#] int [;] {{ char_of_int __2 }} ) {{ __2 }}
51 / ![<] . {{ __2 }}
52
53 # FIXME: namespaces ns:name=value
54 name <- [a-zA-Z0-9_\-]+ spacing {{ Tgrammar.string_of_chars __1 }}
55
56 # FIXME: intégration ici des expansions optionnelles ???
57 # FIXME: il faudrait autoriser option* dans l'expansion optionnelle
58 option <-
59 / nsname (equal function {{ __2 }})? {{ __1, match __2 with Some r -> r | None -> Value "true" }}
60 / [$] name [:] lparen option rparen {{ __5 }}
61
62 # ns <- name [:]
63 nsname <- name ([:] name)? {{ __1 (* FIXME *) }}
64
65 value <- dblexpr / sglexpr / name
66 dblexpr <- dblq ("\\\"" {{ '\"' }} / !dblq .)* dblq spacing {{ Tgrammar.string_of_chars __2 }}
67 sglexpr <- quote ("\\\'" {{ '\'' }} / !quote .)* quote spacing {{ Tgrammar.string_of_chars __2 }}
68
69 funclist <- function (comma funclist {{ __2 }})?
70 {{ match __2 with
71 | None -> [__1]
72 | Some l -> __1 :: l }}
73 function <- #name lparen funclist rparen {{ Func (__1, __3)}} /
74 value {{ Value __1 }}
75
76 open <- [<] spacing
77 close <- spacing [>]
78 dblq <- [\"]
79 quote <- [\']
80
81 comment <- commentstart (!commentstop .)* commentstop $
82 commentstart <- "<!--"
83 commentstop <- "-->"
84 spacing <- (space $/ comment)* $
Something went wrong with that request. Please try again.