Commit bae6be74 authored by Pietro Abate's avatar Pietro Abate
Browse files

[r2003-12-08 17:07:50 by cmiachon] la projection / dans le parser de cduce, et la projection sur un

atrribut /@ et sur les descendants// dans l extension du parser pour
CQL. le // est ordonne.

Original author: cmiachon
Date: 2003-12-08 17:07:50+00:00
parent dd97aa8e
......@@ -252,6 +252,15 @@ EXTEND
|
[ e1 = expr; op = ["*"]; e2 = expr -> exp loc (Op (op,[e1;e2]))
| e1 = expr; "&&"; e2 = expr -> exp loc (logical_and e1 e2)
| e = expr; op = "/"; p = pat ->
let tag = mk loc (Internal (Types.atom (Atoms.any))) in
let att = mk loc (Internal Types.Record.any) in
let any = mk loc (Internal (Types.any)) in
let re = Star(Alt(SeqCapture(id_dummy,Elem p), Elem any)) in
let ct = mk loc (Regexp (re,any)) in
let p = mk loc (XmlT (tag, multi_prod loc [att;ct])) in
let b = (p, Var (Id.value id_dummy)) in
exp loc (Transform (e,[b]))
]
|
[ e = expr; "."; l = [IDENT | keyword ] ->
......
......@@ -73,7 +73,7 @@ let rec token = lexer
| '-'? ['0'-'9']+ ->
return lexbuf ("INT", L.utf8_lexeme lexbuf)
| [ "<>=.,:;+-*/@&{}[]()|?`!" ]
| "->" | "::" | ";;" | "--" | ":=" | "\\" | "++"
| "->" | "::" | ";;" | "--" | "//" | "/@" | ":=" | "\\" | "++"
| "{|" | "|}" | "<=" | ">=" | "<<" | ">>" | "||" | "&&"
| ["?+*"] "?" | "#" ->
return lexbuf ("", L.utf8_lexeme lexbuf)
......
......@@ -43,34 +43,25 @@ EXTEND
if !Query.nooptim
then Query.select(loc,fin,l)
else Query.selectOpt(loc,fin,l,condi)
]
| [
e = expr; "/" ;
t = [a = pat ->
let tag = mk loc (Internal (Types.atom (Atoms.any))) in
let att = mk loc (Internal Types.Record.any) in
let any = mk loc (Internal (Types.any)) in
let re = Star(Alt(SeqCapture(id_dummy,Elem a), Elem any)) in
let ct = mk loc (Regexp (re,any)) in
let p = mk loc (XmlT (tag, multi_prod loc [att;ct])) in
(p, Var (Id.value id_dummy))
| "@"; a = [IDENT|keyword]-> (* projection sur 1 attribut *)
|
e = expr; "/@";
a = [IDENT|keyword]-> (* projection sur 1 attribut *)
let tag = mk loc (Internal(Types.atom Atoms.any)) in
let any = mk loc (Internal(Types.any)) in
let att = mk loc (Record(true,[(label a,mk loc (PatVar(U.mk "$$$")))]))in
let ct= mk loc (Regexp(Elem any , any)) in
let p = mk loc(XmlT (tag,multi_prod loc[att;ct])) in
(p, Pair(Var (Id.value id_dummy),cst_nil))
] -> exp loc (Transform (e,[t]))
| e = expr; "/" ; "/" ; p = pat -> (* projections sur tous les descendants *)
let t =(p, Pair(Var (Id.value id_dummy),cst_nil))
in exp loc (Transform (e,[t]))
| e = expr; "//" ; p = pat -> (* projections sur tous les descendants *)
let assign=
exp loc ( Apply (Dot (Var(U.mk"$stack"), U.mk"set"),
(Pair (Var(U.mk"$$$"),(Apply(Dot(Var(U.mk"$stack"),U.mk"get"),cst_nil))))))
(Op("@",
[(Apply(Dot(Var(U.mk"$stack"),U.mk"get"),cst_nil));Pair(Var(U.mk"$$$"),cst_nil)]))))
in let branche=Pair(Var (Id.value id_dummy),cst_nil)
in let branches= exp loc (Match(assign,[pat_nil,branche]))
in let xt=exp loc (Xtrans (e,[(mk loc(And(mk loc(PatVar(U.mk "$$$")),p))),branches]))
in let rf=exp loc(Ref(cst_nil,mk loc (Regexp
in let rf=exp loc(Ref(cst_nil,mk loc (Regexp
(Star(Elem(p)),pat_nil))))
in exp loc(Match(rf,[mk loc(PatVar(U.mk"$stack")),
exp loc(Match(xt,
......@@ -87,7 +78,6 @@ EXTEND
NB: order is inversed
*)
]
];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment