Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
json
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
json
Commits
850671b9
Unverified
Commit
850671b9
authored
Mar 29, 2018
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
🔨
using a vector<bool> for the parser hierarchy
parent
5f723bbe
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
42 deletions
+28
-42
parser.hpp
include/nlohmann/detail/input/parser.hpp
+14
-21
json.hpp
single_include/nlohmann/json.hpp
+14
-21
No files found.
include/nlohmann/detail/input/parser.hpp
View file @
850671b9
...
...
@@ -162,10 +162,9 @@ class parser
private
:
bool
sax_parse_internal
(
json_sax_t
*
sax
)
{
// two values for the structured values
enum
class
parse_state_t
{
array_value
,
object_value
};
// stack to remember the hieararchy of structured values we are parsing
std
::
vector
<
parse_state_t
>
states
;
// true = array; false = object
std
::
vector
<
bool
>
states
;
// value to avoid a goto (see comment where set to true)
bool
skip_to_state_evaluation
=
false
;
...
...
@@ -221,7 +220,7 @@ class parser
}
// remember we are now inside an object
states
.
push_back
(
parse_state_t
::
object_valu
e
);
states
.
push_back
(
fals
e
);
// parse values
get_token
();
...
...
@@ -249,7 +248,7 @@ class parser
}
// remember we are now inside an array
states
.
push_back
(
parse_state_t
::
array_val
ue
);
states
.
push_back
(
tr
ue
);
// parse values (no need to call get_token)
continue
;
...
...
@@ -359,9 +358,7 @@ class parser
else
{
get_token
();
switch
(
states
.
back
())
{
case
parse_state_t
:
:
array_value
:
if
(
states
.
back
())
// array
{
// comma -> next value
if
(
last_token
==
token_type
::
value_separator
)
...
...
@@ -379,11 +376,10 @@ class parser
return
false
;
}
// We are done with this array. Before we can parse
// a new value, we need to evaluate the new state
// first. By setting skip_to_state_evaluation to
// false, we are effectively jumping to the
// beginning of this switch.
// We are done with this array. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
assert
(
not
states
.
empty
());
states
.
pop_back
();
skip_to_state_evaluation
=
true
;
...
...
@@ -396,8 +392,7 @@ class parser
parse_error
::
create
(
101
,
m_lexer
.
get_position
(),
exception_message
(
token_type
::
end_array
)));
}
}
case
parse_state_t
:
:
object_value
:
else
// object
{
// comma -> next value
if
(
last_token
==
token_type
::
value_separator
)
...
...
@@ -441,11 +436,10 @@ class parser
return
false
;
}
// We are done with this object. Before we can
// parse a new value, we need to evaluate the new
// state first. By setting skip_to_state_evaluation
// to false, we are effectively jumping to the
// beginning of this switch.
// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
assert
(
not
states
.
empty
());
states
.
pop_back
();
skip_to_state_evaluation
=
true
;
...
...
@@ -461,7 +455,6 @@ class parser
}
}
}
}
/// get next token from lexer
token_type
get_token
()
...
...
single_include/nlohmann/json.hpp
View file @
850671b9
...
...
@@ -3955,10 +3955,9 @@ class parser
private
:
bool
sax_parse_internal
(
json_sax_t
*
sax
)
{
// two values for the structured values
enum
class
parse_state_t
{
array_value
,
object_value
};
// stack to remember the hieararchy of structured values we are parsing
std
::
vector
<
parse_state_t
>
states
;
// true = array; false = object
std
::
vector
<
bool
>
states
;
// value to avoid a goto (see comment where set to true)
bool
skip_to_state_evaluation
=
false
;
...
...
@@ -4014,7 +4013,7 @@ class parser
}
// remember we are now inside an object
states
.
push_back
(
parse_state_t
::
object_valu
e
);
states
.
push_back
(
fals
e
);
// parse values
get_token
();
...
...
@@ -4042,7 +4041,7 @@ class parser
}
// remember we are now inside an array
states
.
push_back
(
parse_state_t
::
array_val
ue
);
states
.
push_back
(
tr
ue
);
// parse values (no need to call get_token)
continue
;
...
...
@@ -4152,9 +4151,7 @@ class parser
else
{
get_token
();
switch
(
states
.
back
())
{
case
parse_state_t
:
:
array_value
:
if
(
states
.
back
())
// array
{
// comma -> next value
if
(
last_token
==
token_type
::
value_separator
)
...
...
@@ -4172,11 +4169,10 @@ class parser
return
false
;
}
// We are done with this array. Before we can parse
// a new value, we need to evaluate the new state
// first. By setting skip_to_state_evaluation to
// false, we are effectively jumping to the
// beginning of this switch.
// We are done with this array. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
assert
(
not
states
.
empty
());
states
.
pop_back
();
skip_to_state_evaluation
=
true
;
...
...
@@ -4189,8 +4185,7 @@ class parser
parse_error
::
create
(
101
,
m_lexer
.
get_position
(),
exception_message
(
token_type
::
end_array
)));
}
}
case
parse_state_t
:
:
object_value
:
else
// object
{
// comma -> next value
if
(
last_token
==
token_type
::
value_separator
)
...
...
@@ -4234,11 +4229,10 @@ class parser
return
false
;
}
// We are done with this object. Before we can
// parse a new value, we need to evaluate the new
// state first. By setting skip_to_state_evaluation
// to false, we are effectively jumping to the
// beginning of this switch.
// We are done with this object. Before we can parse a
// new value, we need to evaluate the new state first.
// By setting skip_to_state_evaluation to false, we
// are effectively jumping to the beginning of this if.
assert
(
not
states
.
empty
());
states
.
pop_back
();
skip_to_state_evaluation
=
true
;
...
...
@@ -4254,7 +4248,6 @@ class parser
}
}
}
}
/// get next token from lexer
token_type
get_token
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment