1
2
3
4
5
6 [hpp]#include <sngcm/cmparser/ParserApi.hpp>
7 [hpp]#include <sngcm/ast/Constant.hpp>
8 [hpp]#include <sngcm/cmparser/ParsingContext.hpp>
9 [cpp]#include <sngcm/cmparser/Specifier.hpp>
10 [cpp]#include <sngcm/cmparser/TypeExpr.hpp>
11 [cpp]#include <sngcm/cmparser/Identifier.hpp>
12 [cpp]#include <sngcm/cmparser/Expression.hpp>
13 [cpp]#include <sngcm/cmlexer/CmajorLexer.hpp>
14 [cpp]#include <sngcm/cmlexer/CmajorTokens.hpp>
15
16 using namespace sngcm::ast;
17 using namespace CmajorTokens;
18
19 parser api(SNGCM_PARSER_API) ConstantParser
20 {
21 uselexer CmajorLexer;
22
23 using SpecifierParser.Specifiers;
24 using TypeExprParser.TypeExpr;
25 using ExpressionParser.Expression;
26 using IdentifierParser.Identifier;
27
28 Constant(ParsingContext* ctx, var Span s, var Span v, var std::unique_ptr e) : ConstantNode*
29 ::= Specifiers:specifiers{ s = span; } CONST TypeExpr(ctx):type! Identifier:id!{ v = span; } ASSIGN Expression(ctx):expr{ e.reset(expr); } SEMICOLON
30 {
31 e->SetFullSpan();
32 v.end = e->GetSpan().end;
33 s.end = e->GetSpan().end;
34 ConstantNode* value = new ConstantNode(s, specifiers, type, id, e.release());
35 value->SetStrValue(lexer.GetMatch(v));
36 return value;
37 }
38 ;
39
40 ruleinfo
41 {
42 (Constant, "constant")
43 }
44 }