Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
19673ff0
Commit
19673ff0
authored
Sep 05, 2009
by
Jesse Beder
Browse files
Moved token enums into Token scope
parent
1db573dd
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
86 additions
and
84 deletions
+86
-84
src/map.cpp
src/map.cpp
+11
-11
src/node.cpp
src/node.cpp
+8
-8
src/parser.cpp
src/parser.cpp
+3
-3
src/scanner.cpp
src/scanner.cpp
+7
-7
src/scantoken.cpp
src/scantoken.cpp
+14
-14
src/sequence.cpp
src/sequence.cpp
+8
-8
src/simplekey.cpp
src/simplekey.cpp
+7
-7
src/token.h
src/token.h
+28
-26
No files found.
src/map.cpp
View file @
19673ff0
...
...
@@ -59,8 +59,8 @@ namespace YAML
// split based on start token
switch
(
pScanner
->
peek
().
type
)
{
case
T
T_
BLOCK_MAP_START
:
ParseBlock
(
pScanner
,
state
);
break
;
case
T
T_
FLOW_MAP_START
:
ParseFlow
(
pScanner
,
state
);
break
;
case
T
oken
::
BLOCK_MAP_START
:
ParseBlock
(
pScanner
,
state
);
break
;
case
T
oken
::
FLOW_MAP_START
:
ParseFlow
(
pScanner
,
state
);
break
;
default:
break
;
}
}
...
...
@@ -75,10 +75,10 @@ namespace YAML
throw
ParserException
(
Mark
::
null
(),
ErrorMsg
::
END_OF_MAP
);
Token
token
=
pScanner
->
peek
();
if
(
token
.
type
!=
T
T_
KEY
&&
token
.
type
!=
T
T_
VALUE
&&
token
.
type
!=
T
T_
BLOCK_MAP_END
)
if
(
token
.
type
!=
T
oken
::
KEY
&&
token
.
type
!=
T
oken
::
VALUE
&&
token
.
type
!=
T
oken
::
BLOCK_MAP_END
)
throw
ParserException
(
token
.
mark
,
ErrorMsg
::
END_OF_MAP
);
if
(
token
.
type
==
T
T_
BLOCK_MAP_END
)
{
if
(
token
.
type
==
T
oken
::
BLOCK_MAP_END
)
{
pScanner
->
pop
();
break
;
}
...
...
@@ -86,13 +86,13 @@ namespace YAML
std
::
auto_ptr
<
Node
>
pKey
(
new
Node
),
pValue
(
new
Node
);
// grab key (if non-null)
if
(
token
.
type
==
T
T_
KEY
)
{
if
(
token
.
type
==
T
oken
::
KEY
)
{
pScanner
->
pop
();
pKey
->
Parse
(
pScanner
,
state
);
}
// now grab value (optional)
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
T
T_
VALUE
)
{
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
T
oken
::
VALUE
)
{
pScanner
->
pop
();
pValue
->
Parse
(
pScanner
,
state
);
}
...
...
@@ -113,13 +113,13 @@ namespace YAML
Token
&
token
=
pScanner
->
peek
();
// first check for end
if
(
token
.
type
==
T
T_
FLOW_MAP_END
)
{
if
(
token
.
type
==
T
oken
::
FLOW_MAP_END
)
{
pScanner
->
pop
();
break
;
}
// now it better be a key
if
(
token
.
type
!=
T
T_
KEY
)
if
(
token
.
type
!=
T
oken
::
KEY
)
throw
ParserException
(
token
.
mark
,
ErrorMsg
::
END_OF_MAP_FLOW
);
pScanner
->
pop
();
...
...
@@ -130,16 +130,16 @@ namespace YAML
pKey
->
Parse
(
pScanner
,
state
);
// now grab value (optional)
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
T
T_
VALUE
)
{
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
T
oken
::
VALUE
)
{
pScanner
->
pop
();
pValue
->
Parse
(
pScanner
,
state
);
}
// now eat the separator (or could be a map end, which we ignore - but if it's neither, then it's a bad node)
Token
&
nextToken
=
pScanner
->
peek
();
if
(
nextToken
.
type
==
T
T_
FLOW_ENTRY
)
if
(
nextToken
.
type
==
T
oken
::
FLOW_ENTRY
)
pScanner
->
pop
();
else
if
(
nextToken
.
type
!=
T
T_
FLOW_MAP_END
)
else
if
(
nextToken
.
type
!=
T
oken
::
FLOW_MAP_END
)
throw
ParserException
(
nextToken
.
mark
,
ErrorMsg
::
END_OF_MAP_FLOW
);
// assign the map with the actual pointers
...
...
src/node.cpp
View file @
19673ff0
...
...
@@ -88,15 +88,15 @@ namespace YAML
// now split based on what kind of node we should be
switch
(
pScanner
->
peek
().
type
)
{
case
T
T_
SCALAR
:
case
T
oken
::
SCALAR
:
m_pContent
=
new
Scalar
;
break
;
case
T
T_
FLOW_SEQ_START
:
case
T
T_
BLOCK_SEQ_START
:
case
T
oken
::
FLOW_SEQ_START
:
case
T
oken
::
BLOCK_SEQ_START
:
m_pContent
=
new
Sequence
;
break
;
case
T
T_
FLOW_MAP_START
:
case
T
T_
BLOCK_MAP_START
:
case
T
oken
::
FLOW_MAP_START
:
case
T
oken
::
BLOCK_MAP_START
:
m_pContent
=
new
Map
;
break
;
default:
...
...
@@ -124,9 +124,9 @@ namespace YAML
return
;
switch
(
pScanner
->
peek
().
type
)
{
case
T
T_
TAG
:
ParseTag
(
pScanner
,
state
);
break
;
case
T
T_
ANCHOR
:
ParseAnchor
(
pScanner
,
state
);
break
;
case
T
T_
ALIAS
:
ParseAlias
(
pScanner
,
state
);
break
;
case
T
oken
::
TAG
:
ParseTag
(
pScanner
,
state
);
break
;
case
T
oken
::
ANCHOR
:
ParseAnchor
(
pScanner
,
state
);
break
;
case
T
oken
::
ALIAS
:
ParseAlias
(
pScanner
,
state
);
break
;
default:
return
;
}
}
...
...
src/parser.cpp
View file @
19673ff0
...
...
@@ -46,14 +46,14 @@ namespace YAML
return
;
// first eat doc start (optional)
if
(
m_pScanner
->
peek
().
type
==
T
T_
DOC_START
)
if
(
m_pScanner
->
peek
().
type
==
T
oken
::
DOC_START
)
m_pScanner
->
pop
();
// now parse our root node
document
.
Parse
(
m_pScanner
,
m_state
);
// and finally eat any doc ends we see
while
(
!
m_pScanner
->
empty
()
&&
m_pScanner
->
peek
().
type
==
T
T_
DOC_END
)
while
(
!
m_pScanner
->
empty
()
&&
m_pScanner
->
peek
().
type
==
T
oken
::
DOC_END
)
m_pScanner
->
pop
();
// clear anchors from the scanner, which are no longer relevant
...
...
@@ -71,7 +71,7 @@ namespace YAML
break
;
Token
&
token
=
m_pScanner
->
peek
();
if
(
token
.
type
!=
T
T_
DIRECTIVE
)
if
(
token
.
type
!=
T
oken
::
DIRECTIVE
)
break
;
// we keep the directives from the last document if none are specified;
...
...
src/scanner.cpp
View file @
19673ff0
...
...
@@ -31,7 +31,7 @@ namespace YAML
EnsureTokensInQueue
();
if
(
!
m_tokens
.
empty
())
{
// Saved anchors shouldn't survive popping the document end marker
if
(
m_tokens
.
front
().
type
==
T
T_
DOC_END
)
{
if
(
m_tokens
.
front
().
type
==
T
oken
::
DOC_END
)
{
ClearAnchors
();
}
m_tokens
.
pop
();
...
...
@@ -60,11 +60,11 @@ namespace YAML
Token
&
token
=
m_tokens
.
front
();
// if this guy's valid, then we're done
if
(
token
.
status
==
T
S_
VALID
)
if
(
token
.
status
==
T
oken
::
VALID
)
return
;
// here's where we clean up the impossible tokens
if
(
token
.
status
==
T
S_
INVALID
)
{
if
(
token
.
status
==
T
oken
::
INVALID
)
{
m_tokens
.
pop
();
continue
;
}
...
...
@@ -263,9 +263,9 @@ namespace YAML
// now push
m_indents
.
push
(
indent
);
if
(
type
==
IndentMarker
::
SEQ
)
m_tokens
.
push
(
Token
(
T
T_
BLOCK_SEQ_START
,
INPUT
.
mark
()));
m_tokens
.
push
(
Token
(
T
oken
::
BLOCK_SEQ_START
,
INPUT
.
mark
()));
else
if
(
type
==
IndentMarker
::
MAP
)
m_tokens
.
push
(
Token
(
T
T_
BLOCK_MAP_START
,
INPUT
.
mark
()));
m_tokens
.
push
(
Token
(
T
oken
::
BLOCK_MAP_START
,
INPUT
.
mark
()));
else
assert
(
false
);
...
...
@@ -319,9 +319,9 @@ namespace YAML
IndentMarker
::
INDENT_TYPE
type
=
m_indents
.
top
().
type
;
m_indents
.
pop
();
if
(
type
==
IndentMarker
::
SEQ
)
m_tokens
.
push
(
Token
(
T
T_
BLOCK_SEQ_END
,
INPUT
.
mark
()));
m_tokens
.
push
(
Token
(
T
oken
::
BLOCK_SEQ_END
,
INPUT
.
mark
()));
else
if
(
type
==
IndentMarker
::
MAP
)
m_tokens
.
push
(
Token
(
T
T_
BLOCK_MAP_END
,
INPUT
.
mark
()));
m_tokens
.
push
(
Token
(
T
oken
::
BLOCK_MAP_END
,
INPUT
.
mark
()));
}
// GetTopIndent
...
...
src/scantoken.cpp
View file @
19673ff0
...
...
@@ -50,7 +50,7 @@ namespace YAML
params
.
push_back
(
param
);
}
Token
token
(
T
T_
DIRECTIVE
,
mark
);
Token
token
(
T
oken
::
DIRECTIVE
,
mark
);
token
.
value
=
name
;
token
.
params
=
params
;
m_tokens
.
push
(
token
);
...
...
@@ -66,7 +66,7 @@ namespace YAML
// eat
Mark
mark
=
INPUT
.
mark
();
INPUT
.
eat
(
3
);
m_tokens
.
push
(
Token
(
T
T_
DOC_START
,
mark
));
m_tokens
.
push
(
Token
(
T
oken
::
DOC_START
,
mark
));
}
// DocEnd
...
...
@@ -79,7 +79,7 @@ namespace YAML
// eat
Mark
mark
=
INPUT
.
mark
();
INPUT
.
eat
(
3
);
m_tokens
.
push
(
Token
(
T
T_
DOC_END
,
mark
));
m_tokens
.
push
(
Token
(
T
oken
::
DOC_END
,
mark
));
}
// FlowStart
...
...
@@ -93,7 +93,7 @@ namespace YAML
// eat
Mark
mark
=
INPUT
.
mark
();
char
ch
=
INPUT
.
get
();
T
OKEN_
TYPE
type
=
(
ch
==
Keys
::
FlowSeqStart
?
T
T_
FLOW_SEQ_START
:
T
T_
FLOW_MAP_START
);
T
oken
::
TYPE
type
=
(
ch
==
Keys
::
FlowSeqStart
?
T
oken
::
FLOW_SEQ_START
:
T
oken
::
FLOW_MAP_START
);
m_tokens
.
push
(
Token
(
type
,
mark
));
}
...
...
@@ -109,7 +109,7 @@ namespace YAML
// eat
Mark
mark
=
INPUT
.
mark
();
char
ch
=
INPUT
.
get
();
T
OKEN_
TYPE
type
=
(
ch
==
Keys
::
FlowSeqEnd
?
T
T_
FLOW_SEQ_END
:
T
T_
FLOW_MAP_END
);
T
oken
::
TYPE
type
=
(
ch
==
Keys
::
FlowSeqEnd
?
T
oken
::
FLOW_SEQ_END
:
T
oken
::
FLOW_MAP_END
);
m_tokens
.
push
(
Token
(
type
,
mark
));
}
...
...
@@ -121,7 +121,7 @@ namespace YAML
// eat
Mark
mark
=
INPUT
.
mark
();
INPUT
.
eat
(
1
);
m_tokens
.
push
(
Token
(
T
T_
FLOW_ENTRY
,
mark
));
m_tokens
.
push
(
Token
(
T
oken
::
FLOW_ENTRY
,
mark
));
}
// BlockEntry
...
...
@@ -141,7 +141,7 @@ namespace YAML
// eat
Mark
mark
=
INPUT
.
mark
();
INPUT
.
eat
(
1
);
m_tokens
.
push
(
Token
(
T
T_
BLOCK_ENTRY
,
mark
));
m_tokens
.
push
(
Token
(
T
oken
::
BLOCK_ENTRY
,
mark
));
}
// Key
...
...
@@ -164,7 +164,7 @@ namespace YAML
// eat
Mark
mark
=
INPUT
.
mark
();
INPUT
.
eat
(
1
);
m_tokens
.
push
(
Token
(
T
T_
KEY
,
mark
));
m_tokens
.
push
(
Token
(
T
oken
::
KEY
,
mark
));
}
// Value
...
...
@@ -199,7 +199,7 @@ namespace YAML
// eat
Mark
mark
=
INPUT
.
mark
();
INPUT
.
eat
(
1
);
m_tokens
.
push
(
Token
(
T
T_
VALUE
,
mark
));
m_tokens
.
push
(
Token
(
T
oken
::
VALUE
,
mark
));
}
// AnchorOrAlias
...
...
@@ -231,7 +231,7 @@ namespace YAML
throw
ParserException
(
INPUT
.
mark
(),
alias
?
ErrorMsg
::
CHAR_IN_ALIAS
:
ErrorMsg
::
CHAR_IN_ANCHOR
);
// and we're done
Token
token
(
alias
?
T
T_
ALIAS
:
T
T_
ANCHOR
,
mark
);
Token
token
(
alias
?
T
oken
::
ALIAS
:
T
oken
::
ANCHOR
,
mark
);
token
.
value
=
name
;
m_tokens
.
push
(
token
);
}
...
...
@@ -268,7 +268,7 @@ namespace YAML
handle
=
"!"
;
}
Token
token
(
T
T_
TAG
,
mark
);
Token
token
(
T
oken
::
TAG
,
mark
);
token
.
value
=
handle
;
token
.
params
.
push_back
(
suffix
);
m_tokens
.
push
(
token
);
...
...
@@ -305,7 +305,7 @@ namespace YAML
//if(Exp::IllegalCharInScalar.Matches(INPUT))
// throw ParserException(INPUT.mark(), ErrorMsg::CHAR_IN_SCALAR);
Token
token
(
T
T_
SCALAR
,
mark
);
Token
token
(
T
oken
::
SCALAR
,
mark
);
token
.
value
=
scalar
;
m_tokens
.
push
(
token
);
}
...
...
@@ -344,7 +344,7 @@ namespace YAML
scalar
=
ScanScalar
(
INPUT
,
params
);
m_simpleKeyAllowed
=
false
;
Token
token
(
T
T_
SCALAR
,
mark
);
Token
token
(
T
oken
::
SCALAR
,
mark
);
token
.
value
=
scalar
;
m_tokens
.
push
(
token
);
}
...
...
@@ -409,7 +409,7 @@ namespace YAML
// simple keys always ok after block scalars (since we're gonna start a new line anyways)
m_simpleKeyAllowed
=
true
;
Token
token
(
T
T_
SCALAR
,
mark
);
Token
token
(
T
oken
::
SCALAR
,
mark
);
token
.
value
=
scalar
;
m_tokens
.
push
(
token
);
}
...
...
src/sequence.cpp
View file @
19673ff0
...
...
@@ -66,8 +66,8 @@ namespace YAML
// split based on start token
switch
(
pScanner
->
peek
().
type
)
{
case
T
T_
BLOCK_SEQ_START
:
ParseBlock
(
pScanner
,
state
);
break
;
case
T
T_
FLOW_SEQ_START
:
ParseFlow
(
pScanner
,
state
);
break
;
case
T
oken
::
BLOCK_SEQ_START
:
ParseBlock
(
pScanner
,
state
);
break
;
case
T
oken
::
FLOW_SEQ_START
:
ParseFlow
(
pScanner
,
state
);
break
;
default:
break
;
}
}
...
...
@@ -82,11 +82,11 @@ namespace YAML
throw
ParserException
(
Mark
::
null
(),
ErrorMsg
::
END_OF_SEQ
);
Token
token
=
pScanner
->
peek
();
if
(
token
.
type
!=
T
T_
BLOCK_ENTRY
&&
token
.
type
!=
T
T_
BLOCK_SEQ_END
)
if
(
token
.
type
!=
T
oken
::
BLOCK_ENTRY
&&
token
.
type
!=
T
oken
::
BLOCK_SEQ_END
)
throw
ParserException
(
token
.
mark
,
ErrorMsg
::
END_OF_SEQ
);
pScanner
->
pop
();
if
(
token
.
type
==
T
T_
BLOCK_SEQ_END
)
if
(
token
.
type
==
T
oken
::
BLOCK_SEQ_END
)
break
;
Node
*
pNode
=
new
Node
;
...
...
@@ -95,7 +95,7 @@ namespace YAML
// check for null
if
(
!
pScanner
->
empty
())
{
const
Token
&
token
=
pScanner
->
peek
();
if
(
token
.
type
==
T
T_
BLOCK_ENTRY
||
token
.
type
==
T
T_
BLOCK_SEQ_END
)
if
(
token
.
type
==
T
oken
::
BLOCK_ENTRY
||
token
.
type
==
T
oken
::
BLOCK_SEQ_END
)
continue
;
}
...
...
@@ -113,7 +113,7 @@ namespace YAML
throw
ParserException
(
Mark
::
null
(),
ErrorMsg
::
END_OF_SEQ_FLOW
);
// first check for end
if
(
pScanner
->
peek
().
type
==
T
T_
FLOW_SEQ_END
)
{
if
(
pScanner
->
peek
().
type
==
T
oken
::
FLOW_SEQ_END
)
{
pScanner
->
pop
();
break
;
}
...
...
@@ -125,9 +125,9 @@ namespace YAML
// now eat the separator (or could be a sequence end, which we ignore - but if it's neither, then it's a bad node)
Token
&
token
=
pScanner
->
peek
();
if
(
token
.
type
==
T
T_
FLOW_ENTRY
)
if
(
token
.
type
==
T
oken
::
FLOW_ENTRY
)
pScanner
->
pop
();
else
if
(
token
.
type
!=
T
T_
FLOW_SEQ_END
)
else
if
(
token
.
type
!=
T
oken
::
FLOW_SEQ_END
)
throw
ParserException
(
token
.
mark
,
ErrorMsg
::
END_OF_SEQ_FLOW
);
}
}
...
...
src/simplekey.cpp
View file @
19673ff0
...
...
@@ -14,17 +14,17 @@ namespace YAML
void
Scanner
::
SimpleKey
::
Validate
()
{
if
(
pMapStart
)
pMapStart
->
status
=
T
S_
VALID
;
pMapStart
->
status
=
T
oken
::
VALID
;
if
(
pKey
)
pKey
->
status
=
T
S_
VALID
;
pKey
->
status
=
T
oken
::
VALID
;
}
void
Scanner
::
SimpleKey
::
Invalidate
()
{
if
(
pMapStart
)
pMapStart
->
status
=
T
S_
INVALID
;
pMapStart
->
status
=
T
oken
::
INVALID
;
if
(
pKey
)
pKey
->
status
=
T
S_
INVALID
;
pKey
->
status
=
T
oken
::
INVALID
;
}
// InsertSimpleKey
...
...
@@ -37,12 +37,12 @@ namespace YAML
// first add a map start, if necessary
key
.
pMapStart
=
PushIndentTo
(
INPUT
.
column
(),
IndentMarker
::
MAP
);
if
(
key
.
pMapStart
)
key
.
pMapStart
->
status
=
T
S_
UNVERIFIED
;
key
.
pMapStart
->
status
=
T
oken
::
UNVERIFIED
;
// then add the (now unverified) key
m_tokens
.
push
(
Token
(
T
T_
KEY
,
INPUT
.
mark
()));
m_tokens
.
push
(
Token
(
T
oken
::
KEY
,
INPUT
.
mark
()));
key
.
pKey
=
&
m_tokens
.
back
();
key
.
pKey
->
status
=
T
S_
UNVERIFIED
;
key
.
pKey
->
status
=
T
oken
::
UNVERIFIED
;
m_simpleKeys
.
push
(
key
);
}
...
...
src/token.h
View file @
19673ff0
...
...
@@ -11,29 +11,6 @@
namespace
YAML
{
enum
TOKEN_STATUS
{
TS_VALID
,
TS_INVALID
,
TS_UNVERIFIED
};
enum
TOKEN_TYPE
{
TT_DIRECTIVE
,
TT_DOC_START
,
TT_DOC_END
,
TT_BLOCK_SEQ_START
,
TT_BLOCK_MAP_START
,
TT_BLOCK_SEQ_END
,
TT_BLOCK_MAP_END
,
TT_BLOCK_ENTRY
,
TT_FLOW_SEQ_START
,
TT_FLOW_MAP_START
,
TT_FLOW_SEQ_END
,
TT_FLOW_MAP_END
,
TT_FLOW_ENTRY
,
TT_KEY
,
TT_VALUE
,
TT_ANCHOR
,
TT_ALIAS
,
TT_TAG
,
TT_SCALAR
};
const
std
::
string
TokenNames
[]
=
{
"DIRECTIVE"
,
"DOC_START"
,
...
...
@@ -57,7 +34,32 @@ namespace YAML
};
struct
Token
{
Token
(
TOKEN_TYPE
type_
,
const
Mark
&
mark_
)
:
status
(
TS_VALID
),
type
(
type_
),
mark
(
mark_
)
{}
// enums
enum
STATUS
{
VALID
,
INVALID
,
UNVERIFIED
};
enum
TYPE
{
DIRECTIVE
,
DOC_START
,
DOC_END
,
BLOCK_SEQ_START
,
BLOCK_MAP_START
,
BLOCK_SEQ_END
,
BLOCK_MAP_END
,
BLOCK_ENTRY
,
FLOW_SEQ_START
,
FLOW_MAP_START
,
FLOW_SEQ_END
,
FLOW_MAP_END
,
FLOW_ENTRY
,
KEY
,
VALUE
,
ANCHOR
,
ALIAS
,
TAG
,
SCALAR
};
// data
Token
(
TYPE
type_
,
const
Mark
&
mark_
)
:
status
(
VALID
),
type
(
type_
),
mark
(
mark_
)
{}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Token
&
token
)
{
out
<<
TokenNames
[
token
.
type
]
<<
std
::
string
(
": "
)
<<
token
.
value
;
...
...
@@ -66,8 +68,8 @@ namespace YAML
return
out
;
}
TOKEN_
STATUS
status
;
TOKEN_
TYPE
type
;
STATUS
status
;
TYPE
type
;
Mark
mark
;
std
::
string
value
;
std
::
vector
<
std
::
string
>
params
;
...
...
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