Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
json
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
json
Commits
8b9f5117
Unverified
Commit
8b9f5117
authored
Apr 24, 2017
by
Niels Lohmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✨
started working on #458
a simple acceptor function
parent
cfc2e839
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
589 additions
and
0 deletions
+589
-0
src/json.hpp
src/json.hpp
+144
-0
test/src/unit-class_parser.cpp
test/src/unit-class_parser.cpp
+445
-0
No files found.
src/json.hpp
View file @
8b9f5117
...
...
@@ -12501,6 +12501,7 @@ scan_number_done:
@brief public parser interface
@param[in] strict whether to expect the last token to be EOF
@return parsed JSON value
@throw parse_error.101 in case of an unexpected token
@throw parse_error.102 if to_unicode fails or surrogate error
...
...
@@ -12524,6 +12525,30 @@ scan_number_done:
return
result
.
is_discarded
()
?
basic_json
()
:
std
::
move
(
result
);
}
/*!
@brief public accept interface
@param[in] strict whether to expect the last token to be EOF
@return whether the input is a proper JSON text
*/
bool
accept
(
const
bool
strict
=
true
)
{
// read first token
get_token
();
if
(
not
accept_internal
())
{
return
false
;
}
if
(
strict
and
last_token
!=
lexer
::
token_type
::
end_of_input
)
{
return
false
;
}
return
true
;
}
private:
/*!
@brief the actual parser
...
...
@@ -12745,6 +12770,125 @@ scan_number_done:
return
result
;
}
/*!
@brief the acutal acceptor
*/
bool
accept_internal
()
{
switch
(
last_token
)
{
case
lexer
:
:
token_type
::
begin_object
:
{
// read next token
get_token
();
// closing } -> we are done
if
(
last_token
==
lexer
::
token_type
::
end_object
)
{
get_token
();
return
true
;
}
// parse values
while
(
true
)
{
// parse key
if
(
last_token
!=
lexer
::
token_type
::
value_string
)
{
return
false
;
}
// parse separator (:)
get_token
();
if
(
last_token
!=
lexer
::
token_type
::
name_separator
)
{
return
false
;
}
// parse value
get_token
();
if
(
not
accept_internal
())
{
return
false
;
}
// comma -> next value
if
(
last_token
==
lexer
::
token_type
::
value_separator
)
{
get_token
();
continue
;
}
// closing }
if
(
last_token
!=
lexer
::
token_type
::
end_object
)
{
return
false
;
}
get_token
();
return
true
;
}
}
case
lexer
:
:
token_type
::
begin_array
:
{
// read next token
get_token
();
// closing ] -> we are done
if
(
last_token
==
lexer
::
token_type
::
end_array
)
{
get_token
();
return
true
;
}
// parse values
while
(
true
)
{
// parse value
if
(
not
accept_internal
())
{
return
false
;
}
// comma -> next value
if
(
last_token
==
lexer
::
token_type
::
value_separator
)
{
get_token
();
continue
;
}
// closing ]
if
(
last_token
!=
lexer
::
token_type
::
end_array
)
{
return
false
;
}
get_token
();
return
true
;
}
}
case
lexer
:
:
token_type
::
literal_null
:
case
lexer
:
:
token_type
::
value_string
:
case
lexer
:
:
token_type
::
literal_true
:
case
lexer
:
:
token_type
::
literal_false
:
case
lexer
:
:
token_type
::
value_unsigned
:
case
lexer
:
:
token_type
::
value_integer
:
case
lexer
:
:
token_type
::
value_float
:
{
get_token
();
return
true
;
}
default:
{
// the last token was unexpected
return
false
;
}
}
}
/// get next token from lexer
typename
lexer
::
token_type
get_token
()
{
...
...
test/src/unit-class_parser.cpp
View file @
8b9f5117
This diff is collapsed.
Click to expand it.
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