1
2
3
4
5
6 [hpp]#include <sngcpp/parser/ParserApi.hpp>
7 [hpp]#include <sngcpp/ast/Expression.hpp>
8 [hpp]#include <sngcpp/parser/ParsingContext.hpp>
9 [cpp]#include <sngcpp/parser/Template.hpp>
10 [cpp]#include <sngcpp/lexer/CppLexer.hpp>
11 [cpp]#include <sngcpp/lexer/CppTokens.hpp>
12
13 using namespace CppTokens;
14
15 parser api(SNGCPP_PARSER_API) IdentifierParser
16 {
17 uselexer CppLexer;
18
19 using TemplateParser.SimpleTemplateId;
20
21 Identifier : std::u32string
22 ::= ID{ soulng::lexer::Token token = lexer.GetToken(pos); return token.match.ToString(); }
23 ;
24
25 IdNode(sngcpp::cppparser::ParsingContext* ctx) : sngcpp::ast::Node*
26 ::= SimpleTemplateId(ctx):simpleTemplateId{ return simpleTemplateId; }
27 | Identifier:identifier{ return new sngcpp::ast::IdentifierNode(span, identifier); }
28 ;
29
30 NestedNameSpecifier(sngcpp::cppparser::ParsingContext* ctx, var std::unique_ptr node) : sngcpp::ast::Node*
31 ::= (IdNode(ctx):left{ node.reset(left); } COLONCOLON (IdNode(ctx):right COLONCOLON{ node.reset(new sngcpp::ast::NestedIdNode(span, node.release(), right)); })*)
32 {
33 return node.release();
34 }
35 ;
36
37 QualifiedIdNode(sngcpp::cppparser::ParsingContext* ctx, var std::unique_ptr node) : sngcpp::ast::Node*
38 ::= ((COLONCOLON NestedNameSpecifier(ctx):ns1{ node.reset(ns1); } IdNode(ctx):id1){ node.reset(new sngcpp::ast::NestedIdNode(span, new sngcpp::ast::NestedIdNode(span, nullptr, node.release()), id1)); }
39 | (NestedNameSpecifier(ctx):ns2{ node.reset(ns2); } IdNode(ctx):id2){ node.reset(new sngcpp::ast::NestedIdNode(span, node.release(), id2)); }
40 | IdNode(ctx):id3{ node.reset(id3); }
41 )
42 {
43 return node.release();
44 }
45 ;
46 }