summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2018-05-01 20:07:12 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2018-05-02 19:55:21 +0100
commit901bd7c839b6a726d75c0e03290a00d7eda6cbfe (patch)
treeb04885d3baf933fc8f9107b6b307ba1f074916b1
parentLexical cast is overkill, we're already pattern matched (diff)
downloadlibjsonpp-901bd7c839b6a726d75c0e03290a00d7eda6cbfe.tar.bz2
libjsonpp-901bd7c839b6a726d75c0e03290a00d7eda6cbfe.tar.xz
libjsonpp-901bd7c839b6a726d75c0e03290a00d7eda6cbfe.zip
Remove pointless VALUE state...
The default state (INITIAL) suffices cos that *is* essentially value.
-rw-r--r--libjsonpp/json.ll33
-rw-r--r--libjsonpp/jsonFlexLexer.cpp10
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
%%
-<ARRAY_ITEM,VALUE>{true} {
+<ARRAY_ITEM,INITIAL>{true} {
PushBoolean(true);
yy_pop_state();
}
-<ARRAY_ITEM,VALUE>{false} {
+<ARRAY_ITEM,INITIAL>{false} {
PushBoolean(false);
yy_pop_state();
}
-<ARRAY_ITEM,VALUE>{number} {
+<ARRAY_ITEM,INITIAL>{number} {
PushNumber(std::strtod(YYText(), NULL));
yy_pop_state();
}
-<ARRAY_ITEM,VALUE>{null} {
+<ARRAY_ITEM,INITIAL>{null} {
PushNull();
yy_pop_state();
}
-<ARRAY_ITEM,VALUE,OBJECT_ITEM>{beginstr} {
+<ARRAY_ITEM,INITIAL,OBJECT_ITEM>{beginstr} {
yy_push_state(STRING);
}
-<ARRAY_ITEM,VALUE>{beginobj} {
+<ARRAY_ITEM,INITIAL>{beginobj} {
BeginObject();
BEGIN(OBJECT_ITEM);
}
-<ARRAY_ITEM,VALUE>{beginarray} {
+<ARRAY_ITEM,INITIAL>{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>{colon} {
BEGIN(OBJECT_NEXT);
- yy_push_state(VALUE);
+ yy_push_state(INITIAL);
}
<OBJECT_NEXT>{separator} {
@@ -115,7 +114,7 @@ escape "\\"
}
<ARRAY_NEXT>{separator} {
- yy_push_state(VALUE);
+ yy_push_state(INITIAL);
}
<STRING>{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>(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 <glibmm/convert.h>
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>(value)).get();
+ });
+ }
+
ValuePtr
jsonFlexLexer::getValue() const
{