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
043bbddc
Commit
043bbddc
authored
Nov 18, 2008
by
Jesse Beder
Browse files
Added line/column data for nodes so they can give better invalid scalar exceptions.
parent
9969ff51
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
19 deletions
+56
-19
include/exceptions.h
include/exceptions.h
+45
-17
include/node.h
include/node.h
+7
-2
src/node.cpp
src/node.cpp
+4
-0
No files found.
include/exceptions.h
View file @
043bbddc
...
...
@@ -5,23 +5,6 @@
namespace
YAML
{
class
Exception
:
public
std
::
exception
{};
class
ParserException
:
public
Exception
{
public:
ParserException
(
int
line_
,
int
column_
,
const
std
::
string
&
msg_
)
:
line
(
line_
),
column
(
column_
),
msg
(
msg_
)
{}
virtual
~
ParserException
()
throw
()
{}
int
line
,
column
;
std
::
string
msg
;
};
class
RepresentationException
:
public
Exception
{};
// representation exceptions
class
InvalidScalar
:
public
RepresentationException
{};
class
BadDereference
:
public
RepresentationException
{};
// error messages
namespace
ErrorMsg
{
...
...
@@ -55,5 +38,50 @@ namespace YAML
const
std
::
string
CHAR_IN_ANCHOR
=
"illegal character found while scanning anchor"
;
const
std
::
string
ZERO_INDENT_IN_BLOCK
=
"cannot set zero indentation for a block scalar"
;
const
std
::
string
CHAR_IN_BLOCK
=
"unexpected character in block scalar"
;
const
std
::
string
INVALID_SCALAR
=
"invalid scalar"
;
const
std
::
string
KEY_NOT_FOUND
=
"key not found"
;
const
std
::
string
BAD_DEREFERENCE
=
"bad dereference"
;
}
class
Exception
:
public
std
::
exception
{
public:
Exception
(
int
line_
,
int
column_
,
const
std
::
string
&
msg_
)
:
line
(
line_
),
column
(
column_
),
msg
(
msg_
)
{}
virtual
~
Exception
()
throw
()
{}
int
line
,
column
;
std
::
string
msg
;
};
class
ParserException
:
public
Exception
{
public:
ParserException
(
int
line_
,
int
column_
,
const
std
::
string
&
msg_
)
:
Exception
(
line_
,
column_
,
msg_
)
{}
};
class
RepresentationException
:
public
Exception
{
public:
RepresentationException
(
int
line_
,
int
column_
,
const
std
::
string
&
msg_
)
:
Exception
(
line_
,
column_
,
msg_
)
{}
};
// representation exceptions
class
InvalidScalar
:
public
RepresentationException
{
public:
InvalidScalar
(
int
line_
,
int
column_
)
:
RepresentationException
(
line_
,
column_
,
ErrorMsg
::
INVALID_SCALAR
)
{}
};
class
KeyNotFound
:
public
RepresentationException
{
public:
KeyNotFound
(
int
line_
,
int
column_
)
:
RepresentationException
(
line_
,
column_
,
ErrorMsg
::
KEY_NOT_FOUND
)
{}
};
class
BadDereference
:
public
RepresentationException
{
public:
BadDereference
()
:
RepresentationException
(
-
1
,
-
1
,
ErrorMsg
::
BAD_DEREFERENCE
)
{}
};
}
include/node.h
View file @
043bbddc
...
...
@@ -27,6 +27,10 @@ namespace YAML
CONTENT_TYPE
GetType
()
const
;
// file location of start of this node
int
GetLine
()
const
{
return
m_line
;
}
int
GetColumn
()
const
{
return
m_column
;
}
// accessors
Iterator
begin
()
const
;
Iterator
end
()
const
;
...
...
@@ -81,6 +85,7 @@ namespace YAML
void
ParseAlias
(
Scanner
*
pScanner
,
const
ParserState
&
state
);
private:
int
m_line
,
m_column
;
std
::
string
m_anchor
,
m_tag
;
Content
*
m_pContent
;
bool
m_alias
;
...
...
@@ -97,7 +102,7 @@ namespace YAML
inline
void
operator
>>
(
const
Node
&
node
,
T
&
value
)
{
if
(
!
Read
(
node
,
value
))
throw
InvalidScalar
();
throw
InvalidScalar
(
node
.
m_line
,
node
.
m_column
);
}
template
<
typename
T
>
...
...
@@ -114,7 +119,7 @@ namespace YAML
}
}
throw
BadDereference
(
);
throw
KeyNotFound
(
m_line
,
m_column
);
}
template
<
typename
T
>
...
...
src/node.cpp
View file @
043bbddc
...
...
@@ -37,6 +37,10 @@ namespace YAML
{
Clear
();
// save location
m_line
=
pScanner
->
peek
().
line
;
m_column
=
pScanner
->
peek
().
column
;
ParseHeader
(
pScanner
,
state
);
// is this an alias? if so, it can have no content
...
...
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