Skip to content

Commit 4b63239

Browse files
committed
Parserの呼び出し方を修正
1 parent 36f9d91 commit 4b63239

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ using namespace std;
3333
using namespace JsonParser;
3434
3535
int 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
## ドキュメント

src/parser.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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);
2626
private:
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;

0 commit comments

Comments
 (0)