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
fadc2ad3
Commit
fadc2ad3
authored
Oct 29, 2009
by
Jesse Beder
Browse files
Implemented adjacent key:value pairs when the key is JSON-like
parent
a5607f82
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
3 deletions
+31
-3
src/exp.h
src/exp.h
+2
-1
src/scanner.cpp
src/scanner.cpp
+13
-2
src/scanner.h
src/scanner.h
+3
-0
src/scantoken.cpp
src/scantoken.cpp
+13
-0
No files found.
src/exp.h
View file @
fadc2ad3
...
@@ -43,7 +43,8 @@ namespace YAML
...
@@ -43,7 +43,8 @@ namespace YAML
const
RegEx
Key
=
RegEx
(
'?'
),
const
RegEx
Key
=
RegEx
(
'?'
),
KeyInFlow
=
RegEx
(
'?'
)
+
BlankOrBreak
;
KeyInFlow
=
RegEx
(
'?'
)
+
BlankOrBreak
;
const
RegEx
Value
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
()),
const
RegEx
Value
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
()),
ValueInFlow
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
(
",}"
,
REGEX_OR
));
ValueInFlow
=
RegEx
(
':'
)
+
(
BlankOrBreak
||
RegEx
(
",}"
,
REGEX_OR
)),
ValueInJSONFlow
=
RegEx
(
':'
);
const
RegEx
Comment
=
RegEx
(
'#'
);
const
RegEx
Comment
=
RegEx
(
'#'
);
const
RegEx
AnchorEnd
=
RegEx
(
"?:,]}%@`"
,
REGEX_OR
)
||
BlankOrBreak
;
const
RegEx
AnchorEnd
=
RegEx
(
"?:,]}%@`"
,
REGEX_OR
)
||
BlankOrBreak
;
const
RegEx
URI
=
Word
||
RegEx
(
"#;/?:@&=+$,_.!~*'()[]"
,
REGEX_OR
)
||
(
RegEx
(
'%'
)
+
Hex
+
Hex
);
const
RegEx
URI
=
Word
||
RegEx
(
"#;/?:@&=+$,_.!~*'()[]"
,
REGEX_OR
)
||
(
RegEx
(
'%'
)
+
Hex
+
Hex
);
...
...
src/scanner.cpp
View file @
fadc2ad3
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
namespace
YAML
namespace
YAML
{
{
Scanner
::
Scanner
(
std
::
istream
&
in
)
Scanner
::
Scanner
(
std
::
istream
&
in
)
:
INPUT
(
in
),
m_startedStream
(
false
),
m_endedStream
(
false
),
m_simpleKeyAllowed
(
false
)
:
INPUT
(
in
),
m_startedStream
(
false
),
m_endedStream
(
false
),
m_simpleKeyAllowed
(
false
)
,
m_canBeJSONFlow
(
false
)
{
{
}
}
...
@@ -142,7 +142,7 @@ namespace YAML
...
@@ -142,7 +142,7 @@ namespace YAML
if
((
InBlockContext
()
?
Exp
::
Key
:
Exp
::
KeyInFlow
).
Matches
(
INPUT
))
if
((
InBlockContext
()
?
Exp
::
Key
:
Exp
::
KeyInFlow
).
Matches
(
INPUT
))
return
ScanKey
();
return
ScanKey
();
if
(
(
InBlockContext
()
?
Exp
::
Value
:
Exp
::
ValueInFlow
).
Matches
(
INPUT
))
if
(
GetValueRegex
(
).
Matches
(
INPUT
))
return
ScanValue
();
return
ScanValue
();
// alias/anchor
// alias/anchor
...
@@ -226,6 +226,16 @@ namespace YAML
...
@@ -226,6 +226,16 @@ namespace YAML
return
false
;
return
false
;
}
}
// GetValueRegex
// . Get the appropriate regex to check if it's a value token
const
RegEx
&
Scanner
::
GetValueRegex
()
const
{
if
(
InBlockContext
())
return
Exp
::
Value
;
return
m_canBeJSONFlow
?
Exp
::
ValueInJSONFlow
:
Exp
::
ValueInFlow
;
}
// StartStream
// StartStream
// . Set the initial conditions for starting a stream.
// . Set the initial conditions for starting a stream.
void
Scanner
::
StartStream
()
void
Scanner
::
StartStream
()
...
@@ -410,3 +420,4 @@ namespace YAML
...
@@ -410,3 +420,4 @@ namespace YAML
m_anchors
.
clear
();
m_anchors
.
clear
();
}
}
}
}
src/scanner.h
View file @
fadc2ad3
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
namespace
YAML
namespace
YAML
{
{
class
Node
;
class
Node
;
class
RegEx
;
class
Scanner
class
Scanner
{
{
...
@@ -78,6 +79,7 @@ namespace YAML
...
@@ -78,6 +79,7 @@ namespace YAML
void
ThrowParserException
(
const
std
::
string
&
msg
)
const
;
void
ThrowParserException
(
const
std
::
string
&
msg
)
const
;
bool
IsWhitespaceToBeEaten
(
char
ch
);
bool
IsWhitespaceToBeEaten
(
char
ch
);
const
RegEx
&
GetValueRegex
()
const
;
struct
SimpleKey
{
struct
SimpleKey
{
SimpleKey
(
const
Mark
&
mark_
,
int
flowLevel_
);
SimpleKey
(
const
Mark
&
mark_
,
int
flowLevel_
);
...
@@ -120,6 +122,7 @@ namespace YAML
...
@@ -120,6 +122,7 @@ namespace YAML
// state info
// state info
bool
m_startedStream
,
m_endedStream
;
bool
m_startedStream
,
m_endedStream
;
bool
m_simpleKeyAllowed
;
bool
m_simpleKeyAllowed
;
bool
m_canBeJSONFlow
;
std
::
stack
<
SimpleKey
>
m_simpleKeys
;
std
::
stack
<
SimpleKey
>
m_simpleKeys
;
std
::
stack
<
IndentMarker
*>
m_indents
;
std
::
stack
<
IndentMarker
*>
m_indents
;
std
::
vector
<
IndentMarker
*>
m_indentRefs
;
// for "garbage collection"
std
::
vector
<
IndentMarker
*>
m_indentRefs
;
// for "garbage collection"
...
...
src/scantoken.cpp
View file @
fadc2ad3
...
@@ -24,6 +24,7 @@ namespace YAML
...
@@ -24,6 +24,7 @@ namespace YAML
PopAllSimpleKeys
();
PopAllSimpleKeys
();
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
m_canBeJSONFlow
=
false
;
// store pos and eat indicator
// store pos and eat indicator
Token
token
(
Token
::
DIRECTIVE
,
INPUT
.
mark
());
Token
token
(
Token
::
DIRECTIVE
,
INPUT
.
mark
());
...
@@ -60,6 +61,7 @@ namespace YAML
...
@@ -60,6 +61,7 @@ namespace YAML
PopAllIndents
();
PopAllIndents
();
PopAllSimpleKeys
();
PopAllSimpleKeys
();
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
m_canBeJSONFlow
=
false
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
@@ -73,6 +75,7 @@ namespace YAML
...
@@ -73,6 +75,7 @@ namespace YAML
PopAllIndents
();
PopAllIndents
();
PopAllSimpleKeys
();
PopAllSimpleKeys
();
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
m_canBeJSONFlow
=
false
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
@@ -86,6 +89,7 @@ namespace YAML
...
@@ -86,6 +89,7 @@ namespace YAML
// flows can be simple keys
// flows can be simple keys
InsertPotentialSimpleKey
();
InsertPotentialSimpleKey
();
m_simpleKeyAllowed
=
true
;
m_simpleKeyAllowed
=
true
;
m_canBeJSONFlow
=
false
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
@@ -111,6 +115,7 @@ namespace YAML
...
@@ -111,6 +115,7 @@ namespace YAML
}
}
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
m_canBeJSONFlow
=
true
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
@@ -138,6 +143,7 @@ namespace YAML
...
@@ -138,6 +143,7 @@ namespace YAML
}
}
m_simpleKeyAllowed
=
true
;
m_simpleKeyAllowed
=
true
;
m_canBeJSONFlow
=
false
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
@@ -158,6 +164,7 @@ namespace YAML
...
@@ -158,6 +164,7 @@ namespace YAML
PushIndentTo
(
INPUT
.
column
(),
IndentMarker
::
SEQ
);
PushIndentTo
(
INPUT
.
column
(),
IndentMarker
::
SEQ
);
m_simpleKeyAllowed
=
true
;
m_simpleKeyAllowed
=
true
;
m_canBeJSONFlow
=
false
;
// eat
// eat
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
@@ -190,6 +197,7 @@ namespace YAML
...
@@ -190,6 +197,7 @@ namespace YAML
{
{
// and check that simple key
// and check that simple key
bool
isSimpleKey
=
VerifySimpleKey
();
bool
isSimpleKey
=
VerifySimpleKey
();
m_canBeJSONFlow
=
false
;
if
(
isSimpleKey
)
{
if
(
isSimpleKey
)
{
// can't follow a simple key with another simple key (dunno why, though - it seems fine)
// can't follow a simple key with another simple key (dunno why, though - it seems fine)
...
@@ -222,6 +230,7 @@ namespace YAML
...
@@ -222,6 +230,7 @@ namespace YAML
// insert a potential simple key
// insert a potential simple key
InsertPotentialSimpleKey
();
InsertPotentialSimpleKey
();
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
m_canBeJSONFlow
=
false
;
// eat the indicator
// eat the indicator
Mark
mark
=
INPUT
.
mark
();
Mark
mark
=
INPUT
.
mark
();
...
@@ -252,6 +261,7 @@ namespace YAML
...
@@ -252,6 +261,7 @@ namespace YAML
// insert a potential simple key
// insert a potential simple key
InsertPotentialSimpleKey
();
InsertPotentialSimpleKey
();
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
m_canBeJSONFlow
=
false
;
Token
token
(
Token
::
TAG
,
INPUT
.
mark
());
Token
token
(
Token
::
TAG
,
INPUT
.
mark
());
...
@@ -305,6 +315,7 @@ namespace YAML
...
@@ -305,6 +315,7 @@ namespace YAML
// can have a simple key only if we ended the scalar by starting a new line
// can have a simple key only if we ended the scalar by starting a new line
m_simpleKeyAllowed
=
params
.
leadingSpaces
;
m_simpleKeyAllowed
=
params
.
leadingSpaces
;
m_canBeJSONFlow
=
false
;
// finally, check and see if we ended on an illegal character
// finally, check and see if we ended on an illegal character
//if(Exp::IllegalCharInScalar.Matches(INPUT))
//if(Exp::IllegalCharInScalar.Matches(INPUT))
...
@@ -347,6 +358,7 @@ namespace YAML
...
@@ -347,6 +358,7 @@ namespace YAML
// and scan
// and scan
scalar
=
ScanScalar
(
INPUT
,
params
);
scalar
=
ScanScalar
(
INPUT
,
params
);
m_simpleKeyAllowed
=
false
;
m_simpleKeyAllowed
=
false
;
m_canBeJSONFlow
=
true
;
Token
token
(
Token
::
SCALAR
,
mark
);
Token
token
(
Token
::
SCALAR
,
mark
);
token
.
value
=
scalar
;
token
.
value
=
scalar
;
...
@@ -413,6 +425,7 @@ namespace YAML
...
@@ -413,6 +425,7 @@ namespace YAML
// simple keys always ok after block scalars (since we're gonna start a new line anyways)
// simple keys always ok after block scalars (since we're gonna start a new line anyways)
m_simpleKeyAllowed
=
true
;
m_simpleKeyAllowed
=
true
;
m_canBeJSONFlow
=
false
;
Token
token
(
Token
::
SCALAR
,
mark
);
Token
token
(
Token
::
SCALAR
,
mark
);
token
.
value
=
scalar
;
token
.
value
=
scalar
;
...
...
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