Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 86 lines (68 sloc) 3.006 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 Base
22 open Xml
23 }}
24
25 +file : {Xml.xml * bool} <- header? content spacing eof
26 {{ let head = match __1 with Some h -> h | None -> [] in
27 let xml, ok = __2 in { xml with header = head }, ok }}
28 header <- "<?xml" spacing option* "?>" spacing {{ __3 }}
29 # factoriser
30 cdata <- "<![CDATA[" ((!"]]" .)* $_) "]]>" {{ `text __2 }}
31 extra_header <- "<!" ![\-] (![>] .)* [>] $
32
33 +content : {Xml.xml * bool} <- content_item* {{ rewrite __1 }}
34 content_item <- element / text / cdata / extra_header content_item {{ __2 }}
35
36 element <-
37 open (
38 / slash nsname {{ `stop __2 }}
39 / "!--" (!commentstop .)* "--" {{ `nothing }}
40 / nsname option* slash? {{ match __3 with Some _ -> `one (__1, __2) | _ -> `start (__1, __2) }}
41 ) close {{ __2 }}
42
43 # FIXME: UTF8 / factoriser avec url.trx et body_rewrite.trx
44 text <-
45 / space+ {{ `space }}
46 / char+ {{ `text (Tgrammar.string_of_chars __1) }}
47
48 # http://xml.silmaril.ie/authors/specials/
49 char <- [%] hexa hexa {{ char_of_int (16 * Char.hexa_value __2 + Char.hexa_value __3) }}
50 / [&] ( "gt;" {{ '>' }} / "lt;" {{ '<' }} / "amp;" {{ '&' }} / "quot;" {{ '"' }} / "apos;" {{ '\'' }}
51 / [#] int [;] {{ char_of_int __2 }} ) {{ __2 }}
52 / ![<] . {{ __2 }}
53
54 # FIXME: namespaces ns:name=value
55 name <- [a-zA-Z0-9_\-]+ spacing {{ Tgrammar.string_of_chars __1 }}
56
57 # FIXME: intégration ici des expansions optionnelles ???
58 # FIXME: il faudrait autoriser option* dans l'expansion optionnelle
59 option <-
60 / nsname (equal function {{ __2 }})? {{ __1, match __2 with Some r -> r | None -> Value "true" }}
61 / [$] name [:] lparen option rparen {{ __5 }}
62
63 # ns <- name [:]
64 nsname <- name ([:] name)? {{ __1 (* FIXME *) }}
65
66 value <- dblexpr / sglexpr / name
67 dblexpr <- dblq ("\\\"" {{ '\"' }} / !dblq .)* dblq spacing {{ Tgrammar.string_of_chars __2 }}
68 sglexpr <- quote ("\\\'" {{ '\'' }} / !quote .)* quote spacing {{ Tgrammar.string_of_chars __2 }}
69
70 funclist <- function (comma funclist {{ __2 }})?
71 {{ match __2 with
72 | None -> [__1]
73 | Some l -> __1 :: l }}
74 function <- #name lparen funclist rparen {{ Func (__1, __3)}} /
75 value {{ Value __1 }}
76
77 open <- [<] spacing
78 close <- spacing [>]
79 dblq <- [\"]
80 quote <- [\']
81
82 comment <- commentstart (!commentstop .)* commentstop $
83 commentstart <- "<!--"
84 commentstop <- "-->"
85 spacing <- (space $/ comment)* $
Something went wrong with that request. Please try again.