Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
91aaa346
Commit
91aaa346
authored
Jul 08, 2014
by
thebusytypist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish the new implementation of state machine. But not been unittested.
parent
6b0df217
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
41 deletions
+117
-41
reader.h
include/rapidjson/reader.h
+117
-41
No files found.
include/rapidjson/reader.h
View file @
91aaa346
...
...
@@ -762,14 +762,16 @@ private:
// Object states
IterativeParsingObjectInitialState
,
IterativeParsingMemberState
,
IterativeParsingObjectDelimiterState
,
IterativeParsingMemberKeyState
,
IterativeParsingKeyValueDelimiterState
,
IterativeParsingMemberValueState
,
IterativeParsingMemberDelimiterState
,
IterativeParsingObjectFinishState
,
// Array states
IterativeParsingArrayInitialState
,
IterativeParsingElementState
,
IterativeParsing
Array
DelimiterState
,
IterativeParsing
Element
DelimiterState
,
IterativeParsingArrayFinishState
,
cIterativeParsingStateCount
...
...
@@ -784,9 +786,9 @@ private:
IterativeParsingRightCurlyBracketToken
,
IterativeParsingCommaToken
,
IterativeParsingColonToken
,
IterativeParsingQuotesToken
,
IterativeParsingStringToken
,
IterativeParsingFalseToken
,
IterativeParsingTrueToken
,
IterativeParsingNullToken
,
...
...
@@ -802,7 +804,8 @@ private:
case
'{'
:
return
IterativeParsingLeftCurlyBracketToken
;
case
'}'
:
return
IterativeParsingRightCurlyBracketToken
;
case
','
:
return
IterativeParsingCommaToken
;
case
'"'
:
return
IterativeParsingQuotesToken
;
case
':'
:
return
IterativeParsingColonToken
;
case
'"'
:
return
IterativeParsingStringToken
;
case
'f'
:
return
IterativeParsingFalseToken
;
case
't'
:
return
IterativeParsingTrueToken
;
case
'n'
:
return
IterativeParsingNullToken
;
...
...
@@ -815,12 +818,13 @@ private:
static
const
IterativeParsingState
G
[
cIterativeParsingStateCount
][
cIterativeParsingTokenCount
]
=
{
// Start
{
IterativeParsing
ObjectInitialState
,
// Left bracket
IterativeParsing
ArrayInitialState
,
// Left bracket
IterativeParsingErrorState
,
// Right bracket
IterativeParsing
Array
InitialState
,
// Left curly bracket
IterativeParsing
Object
InitialState
,
// Left curly bracket
IterativeParsingErrorState
,
// Right curly bracket
IterativeParsingErrorState
,
// Comma
IterativeParsingErrorState
,
// Quotes
IterativeParsingErrorState
,
// Colon
IterativeParsingErrorState
,
// String
IterativeParsingErrorState
,
// False
IterativeParsingErrorState
,
// True
IterativeParsingErrorState
,
// Null
...
...
@@ -829,12 +833,14 @@ private:
// Finish(sink state)
{
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
},
// Error(sink state)
{
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
},
// ObjectInitial
{
...
...
@@ -843,33 +849,64 @@ private:
IterativeParsingErrorState
,
// Left curly bracket
IterativeParsingObjectFinishState
,
// Right curly bracket
IterativeParsingErrorState
,
// Comma
IterativeParsingMemberState
,
// Quotes
IterativeParsingErrorState
,
// Colon
IterativeParsingMemberKeyState
,
// String
IterativeParsingErrorState
,
// False
IterativeParsingErrorState
,
// True
IterativeParsingErrorState
,
// Null
IterativeParsingErrorState
// Number
},
// Member
// MemberKey
{
IterativeParsingErrorState
,
// Left bracket
IterativeParsingErrorState
,
// Right bracket
IterativeParsingErrorState
,
// Left curly bracket
IterativeParsingErrorState
,
// Right curly bracket
IterativeParsingErrorState
,
// Comma
IterativeParsingKeyValueDelimiterState
,
// Colon
IterativeParsingErrorState
,
// String
IterativeParsingErrorState
,
// False
IterativeParsingErrorState
,
// True
IterativeParsingErrorState
,
// Null
IterativeParsingErrorState
// Number
},
// KeyValueDelimiter
{
IterativeParsingArrayInitialState
,
// Left bracket(push MemberValue state)
IterativeParsingErrorState
,
// Right bracket
IterativeParsingObjectInitialState
,
// Left curly bracket(push MemberValue state)
IterativeParsingErrorState
,
// Right curly bracket
IterativeParsingErrorState
,
// Comma
IterativeParsingErrorState
,
// Colon
IterativeParsingMemberValueState
,
// String
IterativeParsingMemberValueState
,
// False
IterativeParsingMemberValueState
,
// True
IterativeParsingMemberValueState
,
// Null
IterativeParsingMemberValueState
// Number
},
// MemberValue
{
IterativeParsingErrorState
,
// Left bracket
IterativeParsingErrorState
,
// Right bracket
IterativeParsingErrorState
,
// Left curly bracket
IterativeParsingObjectFinishState
,
// Right curly bracket
IterativeParsingObjectDelimiterState
,
// Comma
IterativeParsingErrorState
,
// Quotes
IterativeParsingMemberDelimiterState
,
// Comma
IterativeParsingErrorState
,
// Colon
IterativeParsingErrorState
,
// String
IterativeParsingErrorState
,
// False
IterativeParsingErrorState
,
// True
IterativeParsingErrorState
,
// Null
IterativeParsingErrorState
// Number
},
//
Object
Delimiter
//
Member
Delimiter
{
IterativeParsingErrorState
,
// Left bracket
IterativeParsingErrorState
,
// Right bracket
IterativeParsingErrorState
,
// Left curly bracket
IterativeParsingErrorState
,
// Right curly bracket
IterativeParsingErrorState
,
// Comma
IterativeParsingMemberState
,
// Quotes
IterativeParsingErrorState
,
// Colon
IterativeParsingMemberKeyState
,
// String
IterativeParsingErrorState
,
// False
IterativeParsingErrorState
,
// True
IterativeParsingErrorState
,
// Null
...
...
@@ -878,16 +915,18 @@ private:
// ObjectFinish(sink state)
{
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
},
// ArrayInitial
{
IterativeParsing
ElementState
,
// Left bracket
IterativeParsing
ArrayInitialState
,
// Left bracket(push Element state)
IterativeParsingArrayFinishState
,
// Right bracket
IterativeParsing
ElementState
,
// Left curly bracket
IterativeParsing
ObjectInitialState
,
// Left curly bracket(push Element state)
IterativeParsingErrorState
,
// Right curly bracket
IterativeParsingErrorState
,
// Comma
IterativeParsingElementState
,
// Quotes
IterativeParsingErrorState
,
// Colon
IterativeParsingElementState
,
// String
IterativeParsingElementState
,
// False
IterativeParsingElementState
,
// True
IterativeParsingElementState
,
// Null
...
...
@@ -899,21 +938,23 @@ private:
IterativeParsingArrayFinishState
,
// Right bracket
IterativeParsingErrorState
,
// Left curly bracket
IterativeParsingErrorState
,
// Right curly bracket
IterativeParsingArrayDelimiterState
,
// Comma
IterativeParsingErrorState
,
// Quotes
IterativeParsingElementDelimiterState
,
// Comma
IterativeParsingErrorState
,
// Colon
IterativeParsingErrorState
,
// String
IterativeParsingErrorState
,
// False
IterativeParsingErrorState
,
// True
IterativeParsingErrorState
,
// Null
IterativeParsingErrorState
// Number
},
//
Array
Delimiter
//
Element
Delimiter
{
IterativeParsing
ElementState
,
// Left bracket
IterativeParsing
ArrayInitialState
,
// Left bracket(push Element state)
IterativeParsingErrorState
,
// Right bracket
IterativeParsing
ElementState
,
// Left curly bracket
IterativeParsing
ObjectInitialState
,
// Left curly bracket(push Element state)
IterativeParsingErrorState
,
// Right curly bracket
IterativeParsingErrorState
,
// Comma
IterativeParsingElementState
,
// Quotes
IterativeParsingErrorState
,
// Colon
IterativeParsingElementState
,
// String
IterativeParsingElementState
,
// False
IterativeParsingElementState
,
// True
IterativeParsingElementState
,
// Null
...
...
@@ -922,15 +963,16 @@ private:
// ArrayFinish(sink state)
{
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
,
IterativeParsingErrorState
}
};
// End of G
return
G
[
state
][
token
];
}
//
Store or process informations during state transition
.
// May return a new state.
//
Make an advance in the token stream and state based on the candidate destination state which was returned by Transit()
.
// May return a new state
on state pop
.
template
<
unsigned
parseFlags
,
typename
InputStream
,
typename
Handler
>
IterativeParsingState
Advance
(
IterativeParsingState
src
,
IterativeParsingToken
token
,
IterativeParsingState
dst
,
InputStream
&
is
,
Handler
&
handler
)
{
int
c
=
0
;
...
...
@@ -951,25 +993,57 @@ private:
case
IterativeParsingObjectInitialState
:
case
IterativeParsingArrayInitialState
:
is
.
Take
();
// Push the state(Element or MemeberValue) if we are nested in another array or value of member.
// In this way we can get the correct state on ObjectFinish or ArrayFinish by frame pop.
n
=
src
;
if
(
src
==
IterativeParsingArrayInitialState
||
src
==
IterativeParsingElementDelimiterState
)
n
=
IterativeParsingElementState
;
else
if
(
src
==
IterativeParsingKeyValueDelimiterState
)
n
=
IterativeParsingMemberValueState
;
// Push current state.
*
stack_
.
template
Push
<
IterativeParsingState
>
(
1
)
=
src
;
*
stack_
.
template
Push
<
IterativeParsingState
>
(
1
)
=
n
;
// Initialize and push the member/element count.
*
stack_
.
template
Push
<
int
>
(
1
)
=
0
;
// Call handler
if
(
dst
==
IterativeParsingObjectInitialState
)
handler
.
StartObject
();
else
handler
.
StartArray
();
return
dst
;
case
IterativeParsingMemberState
:
return
dst
;
case
IterativeParsingMemberKeyState
:
ParseString
<
parseFlags
>
(
is
,
handler
);
if
(
HasParseError
())
return
IterativeParsingErrorState
;
else
return
dst
;
case
IterativeParsingElementState
:
if
(
token
==
IterativeParsingLeftBracketToken
||
token
==
IterativeParsingLeftCurlyBracketToken
)
{
case
IterativeParsingKeyValueDelimiterState
:
if
(
token
==
IterativeParsingColonToken
)
{
is
.
Take
();
return
dst
;
}
else
{
else
return
IterativeParsingErrorState
;
case
IterativeParsingMemberValueState
:
// Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state.
ParseValue
<
parseFlags
>
(
is
,
handler
);
if
(
HasParseError
())
{
return
IterativeParsingErrorState
;
}
return
dst
;
case
IterativeParsingElementState
:
// Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state.
ParseValue
<
parseFlags
>
(
is
,
handler
);
if
(
HasParseError
())
{
return
IterativeParsingErrorState
;
}
return
dst
;
case
IterativeParsing
Object
DelimiterState
:
case
IterativeParsing
Array
DelimiterState
:
case
IterativeParsing
Member
DelimiterState
:
case
IterativeParsing
Element
DelimiterState
:
is
.
Take
();
// Update member/element count.
*
stack_
.
template
Top
<
int
>
()
=
*
stack_
.
template
Top
<
int
>
()
+
1
;
...
...
@@ -979,7 +1053,8 @@ private:
is
.
Take
();
// Get member count.
c
=
*
stack_
.
template
Pop
<
int
>
(
1
);
if
(
src
==
IterativeParsingMemberState
)
// If the object is not empty, count the last member.
if
(
src
==
IterativeParsingMemberValueState
)
++
c
;
// Restore the state.
n
=
*
stack_
.
template
Pop
<
IterativeParsingState
>
(
1
);
...
...
@@ -994,6 +1069,7 @@ private:
is
.
Take
();
// Get element count.
c
=
*
stack_
.
template
Pop
<
int
>
(
1
);
// If the array is not empty, count the last element.
if
(
src
==
IterativeParsingElementState
)
++
c
;
// Restore the state.
...
...
@@ -1016,11 +1092,11 @@ private:
IterativeParsingState
state
=
IterativeParsingStartState
;
SkipWhitespace
(
is
);
while
(
is
.
Peek
()
!=
'\0'
&&
state
!=
IterativeParsingErrorState
)
{
while
(
is
.
Peek
()
!=
'\0'
)
{
IterativeParsingToken
t
=
GuessToken
(
is
.
Peek
());
IterativeParsingState
n
=
Transit
(
state
,
t
);
if
(
Advance
<
parseFlags
>
(
state
,
t
,
n
,
is
,
handler
)
)
if
(
(
n
=
Advance
<
parseFlags
>
(
state
,
t
,
n
,
is
,
handler
))
!=
IterativeParsingErrorState
)
state
=
n
;
else
break
;
...
...
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