Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
belr
Commits
40c048cf
Commit
40c048cf
authored
Dec 10, 2015
by
Sylvain Berfini
🐮
Browse files
Fix some values not initialized + possibility of infinite loop
parent
7f03415a
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
21 deletions
+39
-21
include/belr/belr.hh
include/belr/belr.hh
+4
-0
include/belr/grammarbuilder.hh
include/belr/grammarbuilder.hh
+4
-0
include/belr/parser-impl.cc
include/belr/parser-impl.cc
+3
-3
include/belr/parser.hh
include/belr/parser.hh
+1
-1
src/belr.cc
src/belr.cc
+3
-4
src/grammarbuilder.cc
src/grammarbuilder.cc
+24
-13
No files found.
include/belr/belr.hh
View file @
40c048cf
...
...
@@ -38,6 +38,7 @@ protected:
virtual
bool
_getTransitionMap
(
TransitionMap
*
mask
);
virtual
void
_optimize
(
int
recursionLevel
)
=
0
;
Recognizer
();
virtual
~
Recognizer
()
{
}
virtual
size_t
_feed
(
const
shared_ptr
<
ParserContextBase
>
&
ctx
,
const
string
&
input
,
size_t
pos
)
=
0
;
string
mName
;
unsigned
int
mId
;
...
...
@@ -155,6 +156,9 @@ public:
* Initialize an empty grammar, giving a name for debugging.
**/
Grammar
(
const
string
&
name
);
virtual
~
Grammar
()
{
}
/**
* Include another grammar into this grammar.
**/
...
...
include/belr/grammarbuilder.hh
View file @
40c048cf
...
...
@@ -17,6 +17,7 @@ public:
class
ABNFRule
:
public
ABNFBuilder
{
public:
ABNFRule
();
static
shared_ptr
<
ABNFRule
>
create
();
void
setName
(
const
string
&
name
);
void
setDefinedAs
(
const
string
&
defined_as
);
...
...
@@ -56,6 +57,7 @@ private:
class
ABNFElement
:
public
ABNFBuilder
{
public:
ABNFElement
();
static
shared_ptr
<
ABNFElement
>
create
();
shared_ptr
<
Recognizer
>
buildRecognizer
(
const
shared_ptr
<
Grammar
>
&
grammar
);
void
setElement
(
const
shared_ptr
<
ABNFBuilder
>
&
e
);
...
...
@@ -70,6 +72,7 @@ private:
class
ABNFGroup
:
public
ABNFBuilder
{
public:
ABNFGroup
();
static
shared_ptr
<
ABNFGroup
>
create
();
shared_ptr
<
Recognizer
>
buildRecognizer
(
const
shared_ptr
<
Grammar
>
&
grammar
);
void
setAlternation
(
const
shared_ptr
<
ABNFAlternation
>
&
a
);
...
...
@@ -95,6 +98,7 @@ private:
class
ABNFOption
:
public
ABNFBuilder
{
public:
ABNFOption
();
static
shared_ptr
<
ABNFOption
>
create
();
void
setAlternation
(
const
shared_ptr
<
ABNFAlternation
>
&
a
);
shared_ptr
<
Recognizer
>
buildRecognizer
(
const
shared_ptr
<
Grammar
>
&
grammar
);
...
...
include/belr/parser-impl.cc
View file @
40c048cf
...
...
@@ -127,7 +127,7 @@ void HandlerContext< _parserElementT >::recycle(){
//
template
<
typename
_parserElementT
>
ParserHandlerBase
<
_parserElementT
>::
ParserHandlerBase
(
const
Parser
<
_parserElementT
>
&
parser
,
const
string
&
name
)
:
mParser
(
parser
),
mRulename
(
tolower
(
name
)){
ParserHandlerBase
<
_parserElementT
>::
ParserHandlerBase
(
const
Parser
<
_parserElementT
>
&
parser
,
const
string
&
name
)
:
mParser
(
parser
),
mRulename
(
tolower
(
name
))
,
mCachedContext
(
NULL
)
{
}
template
<
typename
_parserElementT
>
...
...
@@ -181,7 +181,7 @@ _parserElementT ParserHandler<_derivedParserElementT,_parserElementT>::invoke(co
//
template
<
typename
_parserElementT
>
ParserContext
<
_parserElementT
>::
ParserContext
(
Parser
<
_parserElementT
>
&
parser
)
:
mParser
(
parser
){
ParserContext
<
_parserElementT
>::
ParserContext
(
Parser
<
_parserElementT
>
&
parser
)
:
mParser
(
parser
)
,
mRoot
(
NULL
)
{
}
template
<
typename
_parserElementT
>
...
...
@@ -294,7 +294,7 @@ void ParserContext<_parserElementT>::removeBranch(const shared_ptr<HandlerContex
//
template
<
typename
_parserElementT
>
Parser
<
_parserElementT
>::
Parser
(
const
shared_ptr
<
Grammar
>
&
grammar
)
:
mGrammar
(
grammar
){
Parser
<
_parserElementT
>::
Parser
(
const
shared_ptr
<
Grammar
>
&
grammar
)
:
mGrammar
(
grammar
)
,
mNullHandler
(
NULL
),
mNullCollector
(
NULL
)
{
if
(
!
mGrammar
->
isComplete
()){
cerr
<<
"Grammar not complete, aborting."
<<
endl
;
return
;
...
...
include/belr/parser.hh
View file @
40c048cf
...
...
@@ -140,7 +140,7 @@ private:
};
struct
ParserLocalContext
{
ParserLocalContext
(){
ParserLocalContext
()
:
mHandlerContext
(
NULL
),
mRecognizer
(
NULL
),
mAssignmentPos
(
0
)
{
}
void
set
(
const
shared_ptr
<
HandlerContextBase
>&
hc
,
const
shared_ptr
<
Recognizer
>&
rec
,
size_t
pos
){
mHandlerContext
=
hc
;
...
...
src/belr.cc
View file @
40c048cf
...
...
@@ -37,7 +37,7 @@ void TransitionMap::merge(const TransitionMap* other){
Recognizer
::
Recognizer
(){
Recognizer
::
Recognizer
()
:
mId
(
0
)
{
}
void
Recognizer
::
setName
(
const
string
&
name
){
...
...
@@ -253,9 +253,8 @@ void Sequence::_optimize(int recursionLevel){
}
Loop
::
Loop
(){
mMin
=
0
;
mMax
=-
1
;
Loop
::
Loop
()
:
mRecognizer
(
NULL
),
mMin
(
0
),
mMax
(
-
1
)
{
}
shared_ptr
<
Loop
>
Loop
::
setRecognizer
(
const
shared_ptr
<
Recognizer
>
&
element
,
int
min
,
int
max
){
...
...
src/grammarbuilder.cc
View file @
40c048cf
...
...
@@ -44,6 +44,9 @@ void ABNFNumval::parseValues(const string &val, int base){
char
*
endptr
=
NULL
;
do
{
long
lv
=
strtol
(
s
,
&
endptr
,
base
);
if
(
lv
==
0
&&
s
==
endptr
)
{
break
;
}
if
(
*
endptr
==
'.'
)
s
=
endptr
+
1
;
else
s
=
endptr
;
mValues
.
push_back
(
lv
);
...
...
@@ -67,6 +70,10 @@ shared_ptr< Recognizer > ABNFOption::buildRecognizer(const shared_ptr< Grammar >
return
Foundation
::
loop
()
->
setRecognizer
(
mAlternation
->
buildRecognizer
(
grammar
),
0
,
1
);
}
ABNFOption
::
ABNFOption
()
:
mAlternation
(
NULL
)
{
}
shared_ptr
<
ABNFOption
>
ABNFOption
::
create
(){
return
make_shared
<
ABNFOption
>
();
}
...
...
@@ -75,6 +82,10 @@ void ABNFOption::setAlternation(const shared_ptr< ABNFAlternation >& a){
mAlternation
=
a
;
}
ABNFGroup
::
ABNFGroup
()
:
mAlternation
(
NULL
)
{
}
shared_ptr
<
ABNFGroup
>
ABNFGroup
::
create
(){
return
make_shared
<
ABNFGroup
>
();
}
...
...
@@ -103,6 +114,10 @@ shared_ptr< Recognizer > ABNFElement::buildRecognizer(const shared_ptr< Grammar
return
NULL
;
}
ABNFElement
::
ABNFElement
()
:
mElement
(
NULL
)
{
}
shared_ptr
<
ABNFElement
>
ABNFElement
::
create
(){
return
make_shared
<
ABNFElement
>
();
}
...
...
@@ -126,7 +141,9 @@ void ABNFElement::setProseVal(const string& prose){
}
}
ABNFRepetition
::
ABNFRepetition
()
:
mMin
(
0
),
mMax
(
-
1
),
mCount
(
-
1
),
mElement
(
NULL
)
{
}
shared_ptr
<
ABNFRepetition
>
ABNFRepetition
::
create
(){
return
make_shared
<
ABNFRepetition
>
();
...
...
@@ -148,6 +165,9 @@ void ABNFRepetition::setRepeat(const string& r){
mRepeat
=
r
;
}
void
ABNFRepetition
::
setElement
(
const
shared_ptr
<
ABNFElement
>&
e
){
mElement
=
e
;
}
shared_ptr
<
Recognizer
>
ABNFRepetition
::
buildRecognizer
(
const
shared_ptr
<
Grammar
>&
grammar
){
if
(
mRepeat
.
empty
())
return
mElement
->
buildRecognizer
(
grammar
);
...
...
@@ -159,18 +179,6 @@ shared_ptr< Recognizer > ABNFRepetition::buildRecognizer(const shared_ptr< Gramm
}
}
ABNFRepetition
::
ABNFRepetition
(){
mMin
=
0
;
mMax
=-
1
;
mCount
=-
1
;
}
void
ABNFRepetition
::
setElement
(
const
shared_ptr
<
ABNFElement
>&
e
){
mElement
=
e
;
}
shared_ptr
<
ABNFConcatenation
>
ABNFConcatenation
::
create
(){
return
make_shared
<
ABNFConcatenation
>
();
}
...
...
@@ -218,6 +226,9 @@ shared_ptr< Recognizer > ABNFAlternation::buildRecognizerNoOptim(const shared_pt
return
sel
;
}
ABNFRule
::
ABNFRule
()
:
mAlternation
(
NULL
)
{
}
shared_ptr
<
ABNFRule
>
ABNFRule
::
create
(){
return
make_shared
<
ABNFRule
>
();
...
...
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