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
89865cb9
Commit
89865cb9
authored
Jul 26, 2014
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use lookup table for Tokenize()
parent
01126def
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
32 deletions
+40
-32
reader.h
include/rapidjson/reader.h
+40
-32
No files found.
include/rapidjson/reader.h
View file @
89865cb9
...
@@ -829,44 +829,52 @@ private:
...
@@ -829,44 +829,52 @@ private:
};
};
// Tokens
// Tokens
enum
IterativeParsing
Token
{
enum
Token
{
IterativeParsing
LeftBracketToken
=
0
,
LeftBracketToken
=
0
,
IterativeParsing
RightBracketToken
,
RightBracketToken
,
IterativeParsing
LeftCurlyBracketToken
,
LeftCurlyBracketToken
,
IterativeParsing
RightCurlyBracketToken
,
RightCurlyBracketToken
,
IterativeParsing
CommaToken
,
CommaToken
,
IterativeParsing
ColonToken
,
ColonToken
,
IterativeParsing
StringToken
,
StringToken
,
IterativeParsing
FalseToken
,
FalseToken
,
IterativeParsing
TrueToken
,
TrueToken
,
IterativeParsing
NullToken
,
NullToken
,
IterativeParsing
NumberToken
,
NumberToken
,
cIterativeParsing
TokenCount
k
TokenCount
};
};
IterativeParsingToken
Tokenize
(
Ch
c
)
{
RAPIDJSON_FORCEINLINE
Token
Tokenize
(
Ch
c
)
{
switch
(
c
)
{
#define N NumberToken
case
'['
:
return
IterativeParsingLeftBracketToken
;
#define N16 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N
case
']'
:
return
IterativeParsingRightBracketToken
;
// Maps from ASCII to Token
case
'{'
:
return
IterativeParsingLeftCurlyBracketToken
;
static
const
unsigned
char
tokenMap
[
256
]
=
{
case
'}'
:
return
IterativeParsingRightCurlyBracketToken
;
N16
,
// 00~0F
case
','
:
return
IterativeParsingCommaToken
;
N16
,
// 10~1F
case
':'
:
return
IterativeParsingColonToken
;
N
,
N
,
StringToken
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
CommaToken
,
N
,
N
,
N
,
// 20~2F
case
'"'
:
return
IterativeParsingStringToken
;
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
ColonToken
,
N
,
N
,
N
,
N
,
N
,
// 30~3F
case
'f'
:
return
IterativeParsingFalseToken
;
N16
,
// 40~4F
case
't'
:
return
IterativeParsingTrueToken
;
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
LeftBracketToken
,
N
,
RightBracketToken
,
N
,
N
,
// 50~5F
case
'n'
:
return
IterativeParsingNullToken
;
N
,
N
,
N
,
N
,
N
,
N
,
FalseToken
,
N
,
N
,
N
,
N
,
N
,
N
,
N
,
NullToken
,
N
,
// 60~6F
default:
return
IterativeParsingNumberToken
;
N
,
N
,
N
,
N
,
TrueToken
,
N
,
N
,
N
,
N
,
N
,
N
,
LeftCurlyBracketToken
,
N
,
RightCurlyBracketToken
,
N
,
N
,
// 70~7F
}
N16
,
N16
,
N16
,
N16
,
N16
,
N16
,
N16
,
N16
// 80~FF
};
#undef N
#undef N16
if
(
sizeof
(
Ch
)
==
1
||
unsigned
(
c
)
<
256
)
return
(
Token
)
tokenMap
[(
unsigned
char
)
c
];
else
return
NumberToken
;
}
}
IterativeParsingState
Predict
(
IterativeParsingState
state
,
IterativeParsing
Token
token
)
{
IterativeParsingState
Predict
(
IterativeParsingState
state
,
Token
token
)
{
// current state x one lookahead token -> new state
// current state x one lookahead token -> new state
static
const
char
G
[
cIterativeParsingStateCount
][
cIterativeParsing
TokenCount
]
=
{
static
const
char
G
[
cIterativeParsingStateCount
][
k
TokenCount
]
=
{
// Start
// Start
{
{
IterativeParsingArrayInitialState
,
// Left bracket
IterativeParsingArrayInitialState
,
// Left bracket
...
@@ -1025,7 +1033,7 @@ private:
...
@@ -1025,7 +1033,7 @@ private:
// Make an advance in the token stream and state based on the candidate destination state which was returned by Transit().
// 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.
// May return a new state on state pop.
template
<
unsigned
parseFlags
,
typename
InputStream
,
typename
Handler
>
template
<
unsigned
parseFlags
,
typename
InputStream
,
typename
Handler
>
IterativeParsingState
Transit
(
IterativeParsingState
src
,
IterativeParsing
Token
token
,
IterativeParsingState
dst
,
InputStream
&
is
,
Handler
&
handler
)
{
IterativeParsingState
Transit
(
IterativeParsingState
src
,
Token
token
,
IterativeParsingState
dst
,
InputStream
&
is
,
Handler
&
handler
)
{
//int c = 0;
//int c = 0;
//IterativeParsingState n;
//IterativeParsingState n;
//bool hr;
//bool hr;
...
@@ -1081,7 +1089,7 @@ private:
...
@@ -1081,7 +1089,7 @@ private:
return
dst
;
return
dst
;
case
IterativeParsingKeyValueDelimiterState
:
case
IterativeParsingKeyValueDelimiterState
:
if
(
token
==
IterativeParsing
ColonToken
)
{
if
(
token
==
ColonToken
)
{
is
.
Take
();
is
.
Take
();
return
dst
;
return
dst
;
}
}
...
@@ -1207,7 +1215,7 @@ private:
...
@@ -1207,7 +1215,7 @@ private:
SkipWhitespace
(
is
);
SkipWhitespace
(
is
);
while
(
is
.
Peek
()
!=
'\0'
)
{
while
(
is
.
Peek
()
!=
'\0'
)
{
IterativeParsing
Token
t
=
Tokenize
(
is
.
Peek
());
Token
t
=
Tokenize
(
is
.
Peek
());
IterativeParsingState
n
=
Predict
(
state
,
t
);
IterativeParsingState
n
=
Predict
(
state
,
t
);
IterativeParsingState
d
=
Transit
<
parseFlags
>
(
state
,
t
,
n
,
is
,
handler
);
IterativeParsingState
d
=
Transit
<
parseFlags
>
(
state
,
t
,
n
,
is
,
handler
);
...
...
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