Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
a224c781
Commit
a224c781
authored
Jun 27, 2008
by
Jesse Beder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small plain scalar scanning fixes.
parent
8fca02fb
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
49 deletions
+84
-49
document.cpp
+1
-4
scanner.cpp
+13
-6
scanner.h
+2
-1
scantoken.cpp
+26
-10
test.yaml
+8
-2
token.h
+34
-26
No files found.
document.cpp
View file @
a224c781
...
...
@@ -34,10 +34,7 @@ namespace YAML
std
::
ifstream
fin
(
fileName
.
c_str
());
Scanner
scanner
(
fin
);
try
{
scanner
.
Scan
();
}
catch
(
const
Exception
&
e
)
{
}
scanner
.
Scan
();
getchar
();
// if(!scanner)
// return;
...
...
scanner.cpp
View file @
a224c781
...
...
@@ -37,6 +37,16 @@ namespace YAML
return
ch
;
}
// GetChar
// . Extracts 'n' characters from the stream and updates our position
std
::
string
Scanner
::
GetChar
(
int
n
)
{
std
::
string
ret
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
ret
+=
GetChar
();
return
ret
;
}
// Eat
// . Eats 'n' characters and updates our position.
void
Scanner
::
Eat
(
int
n
)
...
...
@@ -199,11 +209,8 @@ namespace YAML
if
(
INPUT
.
peek
()
==
Keys
::
FoldedScalar
&&
m_flowLevel
==
0
)
return
;
if
(
INPUT
.
peek
()
==
'\''
)
return
;
if
(
INPUT
.
peek
()
==
'\"'
)
return
;
if
(
INPUT
.
peek
()
==
'\''
||
INPUT
.
peek
()
==
'\"'
)
return
ScanAndEnqueue
(
new
QuotedScalarToken
);
// plain scalars
if
(
IsPlainScalar
())
...
...
@@ -290,7 +297,7 @@ namespace YAML
while
(
!
m_tokens
.
empty
())
{
Token
*
pToken
=
m_tokens
.
front
();
m_tokens
.
pop
();
std
::
cout
<<
typeid
(
*
pToken
).
name
()
<<
std
::
endl
;
std
::
cout
<<
typeid
(
*
pToken
).
name
()
<<
": "
<<
*
pToken
<<
std
::
endl
;
delete
pToken
;
}
}
...
...
scanner.h
View file @
a224c781
...
...
@@ -8,7 +8,7 @@
namespace
YAML
{
class
Token
;
struct
Token
;
class
Scanner
{
...
...
@@ -25,6 +25,7 @@ namespace YAML
private
:
char
GetChar
();
std
::
string
GetChar
(
int
n
);
void
Eat
(
int
n
=
1
);
void
EatLineBreak
();
...
...
scantoken.cpp
View file @
a224c781
...
...
@@ -199,6 +199,10 @@ namespace YAML
}
// PlainScalarToken
// . We scan these in passes of two steps each: First, grab all non-whitespace
// characters we can, and then grab all whitespace characters we can.
// . This has the benefit of letting us handle leading whitespace (which is chomped)
// and in-line whitespace (which is kept) separately.
template
<>
PlainScalarToken
*
Scanner
::
ScanToken
(
PlainScalarToken
*
pToken
)
{
// TODO: "save simple key"
...
...
@@ -230,20 +234,21 @@ namespace YAML
if
(
m_flowLevel
==
0
&&
Exp
::
EndScalar
.
Matches
(
INPUT
))
break
;
// join whitespace
if
(
leadingBlanks
)
{
if
(
!
leadingBreaks
.
empty
()
&&
leadingBreaks
[
0
]
==
'\n'
)
{
if
(
Exp
::
Break
.
Matches
(
leadingBreaks
)
)
{
// fold line break?
if
(
trailingBreaks
.
empty
())
scalar
+=
' '
;
else
{
else
scalar
+=
trailingBreaks
;
trailingBreaks
=
""
;
}
}
else
{
scalar
+=
leadingBreaks
+
trailingBreaks
;
leadingBreaks
=
""
;
trailingBreaks
=
""
;
}
leadingBlanks
=
false
;
leadingBreaks
=
""
;
trailingBreaks
=
""
;
}
else
if
(
!
whitespace
.
empty
())
{
scalar
+=
whitespace
;
whitespace
=
""
;
...
...
@@ -260,7 +265,8 @@ namespace YAML
// now eat blanks
while
(
INPUT
&&
Exp
::
BlankOrBreak
.
Matches
(
INPUT
))
{
if
(
Exp
::
Blank
.
Matches
(
INPUT
))
{
if
(
leadingBlanks
&&
m_column
<=
m_indents
.
top
())
// can't use tabs as indentation! only spaces!
if
(
INPUT
.
peek
()
==
'\t'
&&
leadingBlanks
&&
m_column
<=
m_indents
.
top
())
throw
IllegalTabInScalar
();
// maybe store this character
...
...
@@ -269,13 +275,17 @@ namespace YAML
else
Eat
(
1
);
}
else
{
// we know it's a line break; see how many characters to read
int
n
=
Exp
::
Break
.
Match
(
INPUT
);
std
::
string
line
=
GetChar
(
n
);
// where to store this character?
if
(
!
leadingBlanks
)
{
leadingBlanks
=
true
;
whitespace
=
""
;
leadingBreaks
+=
GetChar
()
;
leadingBreaks
+=
line
;
}
else
trailingBreaks
+=
GetChar
()
;
trailingBreaks
+=
line
;
}
}
...
...
@@ -285,10 +295,16 @@ namespace YAML
}
// now modify our token
pToken
->
SetValue
(
scalar
)
;
pToken
->
value
=
scalar
;
if
(
leadingBlanks
)
m_simpleKeyAllowed
=
true
;
return
pToken
;
}
// QuotedScalarToken
template
<>
QuotedScalarToken
*
Scanner
::
ScanToken
(
QuotedScalarToken
*
pToken
)
{
return
pToken
;
}
}
test.yaml
View file @
a224c781
---
-
milk
-
green
eggs,
and
ham!
-
eggs
# this is really important!
-
cheese and bread
-
-
cheddar cheese
-
american cheese
-
bread
...
\ No newline at end of file
token.h
View file @
a224c781
#pragma once
#include <ios>
namespace
YAML
{
class
Token
{
public
:
virtual
~
Token
()
{}
};
class
StreamStartToken
:
public
Token
{};
class
StreamEndToken
:
public
Token
{};
class
DocumentStartToken
:
public
Token
{};
class
DocumentEndToken
:
public
Token
{};
class
BlockSeqStartToken
:
public
Token
{};
class
BlockMapStartToken
:
public
Token
{};
class
BlockEndToken
:
public
Token
{};
class
BlockEntryToken
:
public
Token
{};
class
FlowSeqStartToken
:
public
Token
{};
class
FlowMapStartToken
:
public
Token
{};
class
FlowSeqEndToken
:
public
Token
{};
class
FlowMapEndToken
:
public
Token
{};
class
FlowEntryToken
:
public
Token
{};
class
KeyToken
:
public
Token
{};
class
ValueToken
:
public
Token
{};
class
PlainScalarToken
:
public
Token
{
public
:
void
SetValue
(
const
std
::
string
&
value
)
{
m_value
=
value
;
}
protected
:
std
::
string
m_value
;
struct
Token
{
virtual
~
Token
()
{}
virtual
void
Write
(
std
::
ostream
&
out
)
const
{}
friend
std
::
ostream
&
operator
<<
(
std
::
ostream
&
out
,
const
Token
&
token
)
{
token
.
Write
(
out
);
return
out
;
}
};
struct
StreamStartToken
:
public
Token
{};
struct
StreamEndToken
:
public
Token
{};
struct
DocumentStartToken
:
public
Token
{};
struct
DocumentEndToken
:
public
Token
{};
struct
BlockSeqStartToken
:
public
Token
{};
struct
BlockMapStartToken
:
public
Token
{};
struct
BlockEndToken
:
public
Token
{};
struct
BlockEntryToken
:
public
Token
{};
struct
FlowSeqStartToken
:
public
Token
{};
struct
FlowMapStartToken
:
public
Token
{};
struct
FlowSeqEndToken
:
public
Token
{};
struct
FlowMapEndToken
:
public
Token
{};
struct
FlowEntryToken
:
public
Token
{};
struct
KeyToken
:
public
Token
{};
struct
ValueToken
:
public
Token
{};
struct
ScalarToken
:
public
Token
{
std
::
string
value
;
virtual
void
Write
(
std
::
ostream
&
out
)
const
{
out
<<
value
;
}
};
struct
PlainScalarToken
:
public
ScalarToken
{};
struct
QuotedScalarToken
:
public
ScalarToken
{};
}
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