Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ using namespace std;
using namespace JsonParser;

int main() {
cout << Parser(Lexer(cin))->Str() << std::endl;
Node json = Parser(Lexer(cin));
cout << json.Str() << endl;
cout << json["user_info"]["user_id"].Value() << endl;
return 0;
}
```
Expand All @@ -56,6 +58,7 @@ clang++ -I <Your Include Path> ./main.cpp

```
{"user_info":{"user_id":"A1234567","user_name":"Yamada Taro"}}
A1234567
```

## ドキュメント
Expand Down
10 changes: 5 additions & 5 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace JsonParser {
*
*/
class Grammar {
friend Node* Parser(const std::vector<std::string> &chs);
friend Node Parser(const std::vector<std::string> &chs);
private:
/**
* @brief Process <Array> in recursive descent parser.
Expand Down Expand Up @@ -108,7 +108,7 @@ namespace JsonParser {
if (chs[index_current + 1][0] != '"') {
throw std::runtime_error("At Object(): '\"' is expected, however other character is set.");
}
child = new Node(chs[index_current + 1]);
child = new Node(chs[index_current + 1].substr(1, chs[index_current + 1].size() - 2));

// Check exists ":" between "key" and Value.
if (index_current + 2 >= chs.size()) {
Expand Down Expand Up @@ -182,9 +182,9 @@ namespace JsonParser {
* @param[in] const std::vector<std::string> &chs Token array from lexical analyzer
* @return JsonParser::Node* Pointer indicating the root AST node
*/
inline Node* Parser(const std::vector<std::string> &chs) {
Node* root = new Node("");
if (Grammar::Value(0, chs, root) != chs.size()) {
inline Node Parser(const std::vector<std::string> &chs) {
Node root("");
if (Grammar::Value(0, chs, &root) != chs.size()) {
throw std::runtime_error("At Parser(): Return value of Value() is not equal to chs.size().");
}
return root;
Expand Down