From 901bd7c839b6a726d75c0e03290a00d7eda6cbfe Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 1 May 2018 20:07:12 +0100 Subject: Remove pointless VALUE state... The default state (INITIAL) suffices cos that *is* essentially value. --- libjsonpp/json.ll | 33 ++++++++++----------------------- libjsonpp/jsonFlexLexer.cpp | 10 ++++++++++ 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/libjsonpp/json.ll b/libjsonpp/json.ll index 8fce090..2fd8317 100644 --- a/libjsonpp/json.ll +++ b/libjsonpp/json.ll @@ -32,42 +32,41 @@ escape "\\" %x ARRAY_NEXT %x COLON %x TEXT -%x VALUE %x STRING %x ESCAPE %% -{true} { +{true} { PushBoolean(true); yy_pop_state(); } -{false} { +{false} { PushBoolean(false); yy_pop_state(); } -{number} { +{number} { PushNumber(std::strtod(YYText(), NULL)); yy_pop_state(); } -{null} { +{null} { PushNull(); yy_pop_state(); } -{beginstr} { +{beginstr} { yy_push_state(STRING); } -{beginobj} { +{beginobj} { BeginObject(); BEGIN(OBJECT_ITEM); } -{beginarray} { +{beginarray} { BeginArray(); BEGIN(ARRAY_NEXT); yy_push_state(ARRAY_ITEM); @@ -77,7 +76,7 @@ escape "\\" yy_pop_state(); switch (YY_START) { case ARRAY_ITEM: - case VALUE: + case INITIAL: PushText(encodeBuf()); yy_pop_state(); break; @@ -107,7 +106,7 @@ escape "\\" {colon} { BEGIN(OBJECT_NEXT); - yy_push_state(VALUE); + yy_push_state(INITIAL); } {separator} { @@ -115,7 +114,7 @@ escape "\\" } {separator} { - yy_push_state(VALUE); + yy_push_state(INITIAL); } {escape} { @@ -147,15 +146,3 @@ escape "\\" throw ParseError(YYText(), yylineno, YY_START); } -%% - -json::jsonFlexLexer::jsonFlexLexer(std::istream & in, const std::string & enc) : - yyFlexLexer(&in, NULL), - encoding(enc) -{ - yy_push_state(VALUE); - acceptValues.push([this](const auto & value) { - return values.emplace(std::make_shared(value)).get(); - }); -} - diff --git a/libjsonpp/jsonFlexLexer.cpp b/libjsonpp/jsonFlexLexer.cpp index b761eb1..f8900b0 100644 --- a/libjsonpp/jsonFlexLexer.cpp +++ b/libjsonpp/jsonFlexLexer.cpp @@ -3,6 +3,16 @@ #include namespace json { + jsonFlexLexer::jsonFlexLexer(std::istream & in, const std::string & enc) : + yyFlexLexer(&in, NULL), + encoding(enc) + { + yy_push_state(0); + acceptValues.push([this](const auto & value) { + return values.emplace(std::make_shared(value)).get(); + }); + } + ValuePtr jsonFlexLexer::getValue() const { -- cgit v1.2.3