1 #include "Literal.hpp"
  2 #include <soulng/util/Unicode.hpp>
  3 #include <sngcpp/lexer/CppLexer.hpp>
  4 #include <sngcpp/lexer/CppTokens.hpp>
  5 
  6 // this file has been automatically generated from 'D:/work/soulng-project/sngcpp/parser/Literal.parser' using soulng parser generator spg version 3.0.0
  7 
  8 using namespace soulng::unicode;
  9 using namespace CppTokens;
 10 
 11 soulng::parser::Match LiteralParser::Literal(CppLexer& lexer)
 12 {
 13     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
 14 
 15 
 16 
 17 
 18 
 19 
 20 
 21     #endif // SOULNG_PARSER_DEBUG_SUPPORT
 22     soulng::parser::Match match(false);
 23     int64_t pos = lexer.GetPos();
 24     soulng::lexer::Span span = lexer.GetSpan();
 25     switch (*lexer)
 26     {
 27         case FLOATLIT:
 28         {
 29             ++lexer;
 30             {
 31                 soulng::lexer::Token token = lexer.GetToken(pos);
 32                 double value = 0.0;
 33                 sngcpp::ast::Suffix suffix = sngcpp::ast::Suffix::none;
 34                 sngcpp::cppparser::ParseFloatingLiteral(lexer.FileName()tokenvaluesuffix);
 35                 {
 36                     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
 37 
 38                     #endif // SOULNG_PARSER_DEBUG_SUPPORT
 39                     return soulng::parser::Match(truenew sngcpp::ast::FloatingLiteralNode(spanvaluesuffixtoken.match.ToString()));
 40                 }
 41             }
 42             break;
 43         }
 44         case INTLIT:
 45         {
 46             ++lexer;
 47             {
 48                 soulng::lexer::Token token = lexer.GetToken(pos);
 49                 uint64_t value = 0;
 50                 sngcpp::ast::Base base = sngcpp::ast::Base::decimal;
 51                 sngcpp::ast::Suffix suffix = sngcpp::ast::Suffix::none;
 52                 sngcpp::cppparser::ParseIntegerLiteral(lexer.FileName()tokenvaluebasesuffix);
 53                 {
 54                     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
 55 
 56                     #endif // SOULNG_PARSER_DEBUG_SUPPORT
 57                     return soulng::parser::Match(truenew sngcpp::ast::IntegerLiteralNode(spanvaluesuffixbasetoken.match.ToString()));
 58                 }
 59             }
 60             break;
 61         }
 62         case CHARLIT:
 63         {
 64             ++lexer;
 65             {
 66                 soulng::lexer::Token token = lexer.GetToken(pos);
 67                 char32_t value = '\0';
 68                 char32_t prefix = '\0';
 69                 sngcpp::cppparser::ParseCharacterLiteral(lexer.FileName()tokenvalueprefix);
 70                 {
 71                     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
 72 
 73                     #endif // SOULNG_PARSER_DEBUG_SUPPORT
 74                     return soulng::parser::Match(truenew sngcpp::ast::CharacterLiteralNode(spanprefixvaluetoken.match.ToString()));
 75                 }
 76             }
 77             break;
 78         }
 79         case STRINGLIT:
 80         {
 81             ++lexer;
 82             {
 83                 soulng::lexer::Token token = lexer.GetToken(pos);
 84                 std::u32string value;
 85                 std::u32string encodingPrefix;
 86                 sngcpp::cppparser::ParseStringLiteral(lexer.FileName()tokenencodingPrefixvalue);
 87                 {
 88                     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
 89 
 90                     #endif // SOULNG_PARSER_DEBUG_SUPPORT
 91                     return soulng::parser::Match(truenew sngcpp::ast::StringLiteralNode(spanencodingPrefixvaluetoken.match.ToString()));
 92                 }
 93             }
 94             break;
 95         }
 96         case TRUE:
 97         {
 98             ++lexer;
 99             {
100                 soulng::lexer::Token token = lexer.GetToken(pos);
101                 {
102                     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
103 
104                     #endif // SOULNG_PARSER_DEBUG_SUPPORT
105                     return soulng::parser::Match(truenew sngcpp::ast::BooleanLiteralNode(spantruetoken.match.ToString()));
106                 }
107             }
108             break;
109         }
110         case FALSE:
111         {
112             ++lexer;
113             {
114                 soulng::lexer::Token token = lexer.GetToken(pos);
115                 {
116                     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
117 
118                     #endif // SOULNG_PARSER_DEBUG_SUPPORT
119                     return soulng::parser::Match(truenew sngcpp::ast::BooleanLiteralNode(spanfalsetoken.match.ToString()));
120                 }
121             }
122             break;
123         }
124         case NULLPTR:
125         {
126             ++lexer;
127             {
128                 soulng::lexer::Token token = lexer.GetToken(pos);
129                 {
130                     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
131 
132                     #endif // SOULNG_PARSER_DEBUG_SUPPORT
133                     return soulng::parser::Match(truenew sngcpp::ast::NullPtrLiteralNode(spantoken.match.ToString()));
134                 }
135             }
136             break;
137         }
138     }
139     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
140 
141 
142 
143 
144 
145     #endif // SOULNG_PARSER_DEBUG_SUPPORT
146     if (!match.hit)
147     {
148         match.value = nullptr;
149     }
150     return match;
151 }
152 
153 soulng::parser::Match LiteralParser::StringLiteral(CppLexer& lexer)
154 {
155     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
156 
157 
158 
159 
160 
161 
162 
163     #endif // SOULNG_PARSER_DEBUG_SUPPORT
164     soulng::parser::Match match(false);
165     soulng::parser::Match* parentMatch0 = &match;
166     {
167         int64_t pos = lexer.GetPos();
168         soulng::lexer::Span span = lexer.GetSpan();
169         soulng::parser::Match match(false);
170         if (*lexer == STRINGLIT)
171         {
172             ++lexer;
173             match.hit = true;
174         }
175         if (match.hit)
176         {
177             soulng::lexer::Token token = lexer.GetToken(pos);
178             std::u32string value;
179             std::u32string encodingPrefix;
180             sngcpp::cppparser::ParseStringLiteral(lexer.FileName()tokenencodingPrefixvalue);
181             {
182                 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
183 
184                 #endif // SOULNG_PARSER_DEBUG_SUPPORT
185                 return soulng::parser::Match(truenew sngcpp::ast::StringLiteralNode(spanencodingPrefixvaluetoken.match.ToString()));
186             }
187         }
188         *parentMatch0 = match;
189     }
190     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
191 
192 
193 
194 
195 
196     #endif // SOULNG_PARSER_DEBUG_SUPPORT
197     if (!match.hit)
198     {
199         match.value = nullptr;
200     }
201     return match;
202 }
203 
204 soulng::parser::Match LiteralParser::IntegerLiteral(CppLexer& lexer)
205 {
206     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
207 
208 
209 
210 
211 
212 
213 
214     #endif // SOULNG_PARSER_DEBUG_SUPPORT
215     soulng::parser::Match match(false);
216     soulng::parser::Match* parentMatch0 = &match;
217     {
218         int64_t pos = lexer.GetPos();
219         soulng::lexer::Span span = lexer.GetSpan();
220         soulng::parser::Match match(false);
221         if (*lexer == INTLIT)
222         {
223             ++lexer;
224             match.hit = true;
225         }
226         if (match.hit)
227         {
228             soulng::lexer::Token token = lexer.GetToken(pos);
229             uint64_t value = 0;
230             sngcpp::ast::Base base = sngcpp::ast::Base::decimal;
231             sngcpp::ast::Suffix suffix = sngcpp::ast::Suffix::none;
232             sngcpp::cppparser::ParseIntegerLiteral(lexer.FileName()tokenvaluebasesuffix);
233             {
234                 #ifdef SOULNG_PARSER_DEBUG_SUPPORT
235 
236                 #endif // SOULNG_PARSER_DEBUG_SUPPORT
237                 return soulng::parser::Match(truenew sngcpp::ast::IntegerLiteralNode(spanvaluesuffixbasetoken.match.ToString()));
238             }
239         }
240         *parentMatch0 = match;
241     }
242     #ifdef SOULNG_PARSER_DEBUG_SUPPORT
243 
244 
245 
246 
247 
248     #endif // SOULNG_PARSER_DEBUG_SUPPORT
249     if (!match.hit)
250     {
251         match.value = nullptr;
252     }
253     return match;
254 }