123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181(*s: parser_php_mly_helper.ml *)openCommonopenCst_php(*****************************************************************************)(* Parse helpers functions *)(*****************************************************************************)(*s: function top_statements_to_toplevels *)letrecsquash_stmt_listxs=matchxswith|[]->[]|x::xs->letv,rest=(matchxwith|(FuncDef_|ClassDef_|ConstantDef_|TypeDef_|NamespaceDef_|NamespaceBracketDef_|NamespaceUse_)->x,xs|StmtList[st]->letstmts,rest=xs|>Common.span(function|StmtList_->true|_->false)inletstmts'=stmts|>List.map(function|StmtList[st]->st|_->raiseImpossible)inStmtList(st::stmts'),rest|StmtList_->raiseImpossible|(FinalDef_|NotParsedCorrectly_)->raiseImpossible)inv::squash_stmt_listrest(*e: function top_statements_to_toplevels *)(*****************************************************************************)(* todo? *)(*****************************************************************************)(*
and refvar_to_variable refvar =
let v =
match refvar with
| Var2 (name, scope) ->
(match name with
| DName ("this", info) ->
This (info)
| _ ->
Var(name, scope)
)
| VDollar2 (tok, exprp) -> VBrace(tok, exprp)
| VArrayAccess2(refvar, exprb) ->
let v = refvar_to_variable refvar in
VArrayAccess(v, exprb)
| VBraceAccess2(refvar, exprb) ->
let v = refvar_to_variable refvar in
VBraceAccess(v, exprb)
in
v
*)(* even if A::$v['fld'] is parsed in the grammar
* as a Qualifier(A, ArrayAccess($v, 'fld') we should really
* generate a ArrayAccess(Qualifier(A, $v), 'fld').
*
* So this function try to put the qualifier closer to the variable
* it is attached to. We must recurse when we have ArrayAccess to
* access the deaper variable. We must stop when there is an indirect
* because A::$$v should not be parsed as $(A::$v).
*)(*
and lift_qualifier_closer_to_var qu v =
let rec aux v =
match v with
| Indirect _ | VBrace _ | VBraceAccess _ ->
raise Not_found
| VArrayAccess (lval, e) ->
let lval' = aux lval in
VArrayAccess (lval', e)
| Var (name, scope) ->
(match qu with
| Left3 qu ->
(ClassVar (qu, name))
| Middle3 (tok1, tok2) ->
raise Impossible
| Right3 (refvar, tok) ->
let v = refvar_to_variable refvar in
(DynamicClassVar (v, tok, (Var (name, scope))))
)
| This _ ->
failwith "todo: what mean A::this ?"
(* v should have been build via vwithoutobj_to_variable so
* we should see only a restrict set of lvalue constructor here
*)
| _ -> raise Impossible
in
try
aux v
with Not_found ->
(match qu with
| Left3 qu ->
(VQualifier (qu, v))
| Middle3 _ ->
(* todo: static::$... ? *)
raise Parsing.Parse_error
| Right3 (refvar, tok) ->
let v2 = refvar_to_variable refvar in
(* e.g. when parse $class::$$prop *)
(DynamicClassVar (v2, tok, v))
)
*)(*****************************************************************************)(* XHP *)(*****************************************************************************)letfailwith_xhp_ambiguity_coloninfo=leterr="XHP: ambiguity on ':', please put a space after the colon in "^Parse_info.string_of_infoinfoin(*failwith err*)pr2err;raiseParsing.Parse_errorletfailwith_xhp_ambiguity_percentinfo=leterr="XHP: ambiguity on '%', please put a space after the percent in "^Parse_info.string_of_infoinfoin(*failwith err*)pr2err;raiseParsing.Parse_error(*****************************************************************************)(* Xdebug *)(*****************************************************************************)(* todo: xdebug_guard *)(*****************************************************************************)(* shortcuts *)(*****************************************************************************)(*s: AST builder *)letmk_params={p_type=None;p_attrs=None;p_ref=None;p_name=DNames;p_default=None;p_modifier=None;p_soft_type=None;p_variadic=None;}(* old: e, Ast_php.noType() *)letmk_ee=eletmk_var(s,tok)=matchswith|"this"->Thistok|_->IdVar(DName(s,tok),Cst_php.noScope())letrecvalidate_parameter_list=function|[]->()|Middle3_::params->validate_parameter_list_emptyparams|Left3param::params->ifparam.p_variadic<>Nonethenvalidate_parameter_list_emptyparamselsevalidate_parameter_listparams|Right3_::params->validate_parameter_listparamsandvalidate_parameter_list_empty=function|[]->()|Right3_::params->validate_parameter_list_emptyparams|_->raiseParsing.Parse_error(*e: AST builder *)(*e: parser_php_mly_helper.ml *)