Skip to content

Commit 8e1b3da

Browse files
authored
Merge pull request #20 from PANFACTORY/develop
Develop
2 parents a2c49c1 + 7770534 commit 8e1b3da

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

README.md

Lines changed: 4 additions & 1 deletion
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
```
@@ -56,6 +58,7 @@ clang++ -I <Your Include Path> ./main.cpp
5658

5759
```
5860
{"user_info":{"user_id":"A1234567","user_name":"Yamada Taro"}}
61+
A1234567
5962
```
6063

6164
## ドキュメント

src/parser.h

Lines changed: 5 additions & 5 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.
@@ -108,7 +108,7 @@ namespace JsonParser {
108108
if (chs[index_current + 1][0] != '"') {
109109
throw std::runtime_error("At Object(): '\"' is expected, however other character is set.");
110110
}
111-
child = new Node(chs[index_current + 1]);
111+
child = new Node(chs[index_current + 1].substr(1, chs[index_current + 1].size() - 2));
112112

113113
// Check exists ":" between "key" and Value.
114114
if (index_current + 2 >= chs.size()) {
@@ -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)