From 73ac4b603994c0706bcaf839448e2b48f3a5961b Mon Sep 17 00:00:00 2001 From: z7zmey Date: Tue, 28 Nov 2017 01:09:44 +0200 Subject: [PATCH] parse ns types --- parser.go | 382 +++++++++++++++++++++++++++++------------------------- parser.y | 21 ++- 2 files changed, 225 insertions(+), 178 deletions(-) diff --git a/parser.go b/parser.go index f5fd6d6..9938579 100644 --- a/parser.go +++ b/parser.go @@ -362,11 +362,11 @@ const yyEofCode = 1 const yyErrCode = 2 const yyInitialStackSize = 16 -//line parser.y:335 +//line parser.y:347 const src = ` identifier %type top_statement %type namespace_name +%type namespace_name_parts +%type name %type top_statement_list %type statement %type inner_statement @@ -219,9 +221,19 @@ identifier: | semi_reserved { $$ = Node("reserved") } ; +namespace_name_parts: + T_STRING { $$ = Node("NamespaceParts").append(Node($1)) } + | namespace_name_parts T_NS_SEPARATOR T_STRING { $$ = $1.append(Node($3)) } +; + namespace_name: - T_STRING { $$ = Node("Namespace").append(Node($1)) } - | namespace_name T_NS_SEPARATOR T_STRING { $$ = $1.append(Node($3)) } + namespace_name_parts { $$ = Node("Namespace").append($1); } +; + +name: + namespace_name { $$ = Node("Name").append($1); } + | T_NS_SEPARATOR namespace_name { $$ = Node("Name").append($2).attribute("FullyQualified", "true"); } + | T_NAMESPACE T_NS_SEPARATOR namespace_name { $$ = Node("Name").append($3).attribute("Relative", "true"); } ; top_statement_list: @@ -320,7 +332,8 @@ type_expr: ; type: - T_ARRAY { $$ = Node("array type"); } + name { $$ = $1; } + | T_ARRAY { $$ = Node("array type"); } | T_CALLABLE { $$ = Node("callable type"); } ; @@ -336,7 +349,7 @@ return_type: const src = `