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
3405a6fe
Commit
3405a6fe
authored
Oct 29, 2009
by
Jesse Beder
Browse files
Refactored the compact map notation, which made it easy to implement explicit keys for compact maps
parent
d372729b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
8 additions
and
20 deletions
+8
-20
src/map.cpp
src/map.cpp
+6
-15
src/node.cpp
src/node.cpp
+1
-1
src/simplekey.cpp
src/simplekey.cpp
+0
-3
test/spectests.cpp
test/spectests.cpp
+1
-1
No files found.
src/map.cpp
View file @
3405a6fe
...
...
@@ -65,7 +65,7 @@ namespace YAML
switch
(
pScanner
->
peek
().
type
)
{
case
Token
::
BLOCK_MAP_START
:
ParseBlock
(
pScanner
,
state
);
break
;
case
Token
::
FLOW_MAP_START
:
ParseFlow
(
pScanner
,
state
);
break
;
case
Token
::
FLOW_MAP_COMPACT
:
ParseCompact
(
pScanner
,
state
);
break
;
case
Token
::
KEY
:
ParseCompact
(
pScanner
,
state
);
break
;
case
Token
::
VALUE
:
ParseCompactWithNoKey
(
pScanner
,
state
);
break
;
default:
break
;
}
...
...
@@ -151,23 +151,14 @@ namespace YAML
}
// ParseCompact
// . Single key: value pair in a flow sequence
// . Single
"
key: value
"
pair in a flow sequence
void
Map
::
ParseCompact
(
Scanner
*
pScanner
,
const
ParserState
&
state
)
{
// eat start token
pScanner
->
pop
();
if
(
pScanner
->
empty
())
throw
ParserException
(
Mark
::
null
(),
ErrorMsg
::
END_OF_MAP_FLOW
);
Token
&
token
=
pScanner
->
peek
();
std
::
auto_ptr
<
Node
>
pKey
(
new
Node
),
pValue
(
new
Node
);
// grab key (if non-null)
if
(
token
.
type
==
Token
::
KEY
)
{
pScanner
->
pop
();
pKey
->
Parse
(
pScanner
,
state
);
}
// grab key
pScanner
->
pop
();
pKey
->
Parse
(
pScanner
,
state
);
// now grab value (optional)
if
(
!
pScanner
->
empty
()
&&
pScanner
->
peek
().
type
==
Token
::
VALUE
)
{
...
...
@@ -180,7 +171,7 @@ namespace YAML
}
// ParseCompactWithNoKey
// . Single
key
: value pair in a flow sequence
// . Single
"
: value
"
pair in a flow sequence
void
Map
::
ParseCompactWithNoKey
(
Scanner
*
pScanner
,
const
ParserState
&
state
)
{
std
::
auto_ptr
<
Node
>
pKey
(
new
Node
),
pValue
(
new
Node
);
...
...
src/node.cpp
View file @
3405a6fe
...
...
@@ -104,7 +104,7 @@ namespace YAML
break
;
case
Token
::
FLOW_MAP_START
:
case
Token
::
BLOCK_MAP_START
:
case
Token
::
FLOW_MAP_COMPACT
:
case
Token
::
KEY
:
m_pContent
=
new
Map
;
break
;
default:
...
...
src/simplekey.cpp
View file @
3405a6fe
...
...
@@ -72,9 +72,6 @@ namespace YAML
key
.
pMapStart
=
key
.
pIndent
->
pStartToken
;
key
.
pMapStart
->
status
=
Token
::
UNVERIFIED
;
}
}
else
if
(
m_flows
.
top
()
==
FLOW_SEQ
)
{
key
.
pMapStart
=
PushToken
(
Token
::
FLOW_MAP_COMPACT
);
key
.
pMapStart
->
status
=
Token
::
UNVERIFIED
;
}
// then add the (now unverified) key
...
...
test/spectests.cpp
View file @
3405a6fe
...
...
@@ -1781,7 +1781,7 @@ namespace Test {
PARSE
(
doc
,
input
);
YAML_ASSERT
(
doc
.
size
()
==
1
);
YAML_ASSERT
(
doc
[
0
].
size
()
==
1
);
YAML_ASSERT
(
doc
[
0
][
"foo"
]
==
"ba
r
"
);
YAML_ASSERT
(
doc
[
0
][
"foo
bar
"
]
==
"ba
z
"
);
return
true
;
}
...
...
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