Skip to content
Browse files

[enhance] compiler, database, syntax: Added syntax for path selection

  • Loading branch information...
1 parent c1a67b5 commit 7d90ca8622a54cf0fe2e2b5d0ad530ea19323a62 @BourgerieQuentin BourgerieQuentin committed Apr 11, 2012
View
2 opalang/classic_syntax/opa_parser.trx
@@ -542,7 +542,7 @@ just_expr10 <-
/ match
/ lambda
/ letin
- / Parser_path.path_kind:v {{ let (path,access_kind) = v in DBPath (path, access_kind)}}
+ / Parser_path.path_kind:v {{ let (path,access_kind, s) = v in DBPath (path, access_kind, s)}}
(* FIXME: useful? / paths_opa_expr / props_aux*)
/ Css.css_map:e {{ undecorate e }} (* useful when saying some_style = ... *)
/ Trx.ExpressionAsFunction:e {{ parser_ e }}
View
40 opalang/classic_syntax/parser_path.trx
@@ -32,6 +32,7 @@
;spacing <- Opa_lexer.spacing
;semic <- Opa_lexer.semic
;tilda <- Opa_parser.tilda
+_succeed <- (&. $/ !. $)
(* path definition, ie for [db pathdef : typ] or [db pathdef = expr] *)
;pathdef_nosp <-slash_nosp ml_identifier_nosp:i
@@ -54,17 +55,17 @@ pathdef_type <- spacing pathdef_type_nosp:v {{ v }}
(* path for reading *)
;/** database query **/
-path_kind <- querytype:qt path:p {{ p, qt }}
+path_kind <- querytype:qt path:p select:s {{ p, qt, s }}
; /** database update path **/
path_update <-
- / '@'? slash_nosp path:pa (Opa_lexer.larrow update:u {{u}} / update_simple):u
+ / '@'? slash_nosp path:pa select:s spacing (Opa_lexer.larrow update:u {{u}} / update_simple):u
{{
- DBPath (pa, QmlAst.Db.Update u)
+ DBPath (pa, QmlAst.Db.Update u, s)
}}
- / '@'? slash_nosp path:pa (Opa_lexer.larrow / Opa_lexer.assign) Opa_parser.expr:e
+ / '@'? slash_nosp path:pa select:s spacing (Opa_lexer.larrow / Opa_lexer.assign) Opa_parser.expr:e
{{
- DBPath (pa, QmlAst.Db.Update (QmlAst.Db.UExpr e))
+ DBPath (pa, QmlAst.Db.Update (QmlAst.Db.UExpr e), s)
}}
@@ -119,6 +120,35 @@ update_list <-
(* ******************************************************************)
(**
+ {7 Path selection }
+*)
+;/** Path selection **/
+select <-
+ / "." (select_fields / select_list / select_star):s {{ s }}
+ / select_nil
+
+select_field <-
+ / Opa_parser.record_long_ident:i select:e
+ {{ List.map undecorate i, e }}
+
+select_fields <-
+ / lbrace
+ (=list0(select_field, Opa_parser.record_fields_separator)):l Opa_parser.record_fields_separator?
+ rbrace
+ {{
+ QmlAst.Db.SFlds l
+ }}
+
+select_list <-
+ / lbracket Opa_parser.expr:e rbracket {{ QmlAst.Db.SSlice (e, none (label e)) }}
+ / lbracket Opa_parser.expr:e1 Opa_lexer.comma Opa_parser.expr:e2 rbracket {{ QmlAst.Db.SSlice (e1, e2) }}
+
+select_star <- "*" {{ QmlAst.Db.SStar }}
+
+select_nil <- _succeed {{ QmlAst.Db.SNil }}
+
+(* ******************************************************************)
+(**
{7 Path querying }
*)
query <-
View
2 opalang/js_syntax/opa_parser.trx
@@ -814,7 +814,7 @@ expr_noop_simple <-
/ module
/ record / block (* Becareful : Keep this order for keep single fields record *)
/ tuple_expr
- / Parser_path.path_kind:v {{ let (p, k) = v in DBPath (p, k) }}
+ / Parser_path.path_kind:v {{ let (p, k, s) = v in DBPath (p, k, s) }}
(* FIXME: useful? / paths_opa_expr / props_aux*)
/ Css.css_map:e {{ undecorate e }} (* useful when saying some_style = ... *)
/ Trx.ExpressionAsFunction:e {{ parser_ e }}

0 comments on commit 7d90ca8

Please sign in to comment.
Something went wrong with that request. Please try again.