File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -33,7 +33,9 @@ using namespace std;
3333using namespace JsonParser;
3434
3535int main() {
36- cout << Parser(Lexer(cin))->Str() << std::endl;
36+ Node json = Parser(Lexer(cin));
37+ cout << json.Str() << endl;
38+ cout << json["user_info"]["user_id"].Value() << endl;
3739 return 0;
3840}
3941```
@@ -55,7 +57,8 @@ clang++ -I <Your Include Path> ./main.cpp
5557すると、以下の結果が返されます。
5658
5759```
58- {"user_info":{"user_id":"A1234567","user_name":"Yamada Taro"}}
60+ {"user_info":{"user_id":"A1234567",""user_name"":"Yamada Taro"}}
61+ A1234567
5962```
6063
6164## ドキュメント
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ namespace JsonParser {
2222 *
2323 */
2424 class Grammar {
25- friend Node* Parser (const std::vector<std::string> &chs);
25+ friend Node Parser (const std::vector<std::string> &chs);
2626private:
2727 /* *
2828 * @brief Process <Array> in recursive descent parser.
@@ -182,9 +182,9 @@ namespace JsonParser {
182182 * @param[in] const std::vector<std::string> &chs Token array from lexical analyzer
183183 * @return JsonParser::Node* Pointer indicating the root AST node
184184 */
185- inline Node* Parser (const std::vector<std::string> &chs) {
186- Node* root = new Node (" " );
187- if (Grammar::Value (0 , chs, root) != chs.size ()) {
185+ inline Node Parser (const std::vector<std::string> &chs) {
186+ Node root (" " );
187+ if (Grammar::Value (0 , chs, & root) != chs.size ()) {
188188 throw std::runtime_error (" At Parser(): Return value of Value() is not equal to chs.size()." );
189189 }
190190 return root;
You can’t perform that action at this time.
0 commit comments