Skip to content
This repository
tag: v1314
Fetching contributors…

Cannot retrieve contributors at this time

file 69 lines (59 sloc) 2.486 kb
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
(*
    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/>.
*)
(**
 * Actions parser
 *)

(** importing from the lexer/main parser *)
let deco rule = (=Opa_parser.deco(rule))
;let exact_symbol rule = (=Opa_lexer.exact_symbol(rule))
;let exact_ident rule = (=Opa_lexer.exact_ident(rule))


(** the actual action parser *)
;jqs = deco just_jqs
;just_jqs <-
  / (=Opa_parser.careful_deco(("." {{ "class" }} / "#" {{ "id" }}))):kind
    ( Opa_parser.deco_ml_identifier:s {{ string2 s }}
    / Opa_parser.opa_in_braces:e {{ e }}):e
       {{
         let (k, lbl) = kind in
         let ident_name =
           (match k with
            | "class" -> Opacapi.Dom.select_class
            | "id" -> Opacapi.Dom.select_id
            | _ -> assert false) in
         let ident_expr = ((Ident ident_name), lbl) in
         let apply_expr = Parser_utils.apply ident_expr e in
         coerce_name apply_expr Opacapi.Types.dom
       }}
  / Opa_parser.opa_in_braces:e {{ coerce_name e Opacapi.Types.dom }}

;verb = deco just_verb
;just_verb <- (=exact_symbol("<-")) {{ "set" }}
            / (=exact_symbol("-<-")) {{ "prepend" }}
            / (=exact_symbol("+<-")) {{ "append" }}

;val_css_option <- Opa_parser.pos:p (Opa_lexer.rarrow val_css:v{{v}})?:v
  {{ Option.default
       (("content", `magicToXml, None),p)
       v
   }}
;val_css = deco just_val_css
;just_val_css <- (Opa_lexer.CSS / (=exact_ident("style")) $) {{ ("css", `identity, None) }}
               / (=exact_ident("value")) {{ ("value", `magicToString, None) }}
               / (=deco(Opa_lexer.ml_identifier)):p {{ ("value_p", `identity, Some [("property", string2 p)]) }}
               / Opa_parser.opa_in_braces:e {{ ("value_p", `identity, Some [("property", e)]) }}

;/** action **/
action = deco just_action
;just_action <-
  jqs:jqs
  val_css_option:val_css
  verb:verb
  Opa_parser.expr:e {{ action _filename jqs val_css verb e }}
Something went wrong with that request. Please try again.