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
tsoc
openmm
Commits
5f0e2f92
Commit
5f0e2f92
authored
Aug 12, 2010
by
Peter Eastman
Browse files
Made parsing exceptions more informative
parent
d8c88e74
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
8 deletions
+8
-8
libraries/lepton/src/ExpressionTreeNode.cpp
libraries/lepton/src/ExpressionTreeNode.cpp
+4
-4
libraries/lepton/src/Parser.cpp
libraries/lepton/src/Parser.cpp
+4
-4
No files found.
libraries/lepton/src/ExpressionTreeNode.cpp
View file @
5f0e2f92
...
@@ -38,25 +38,25 @@ using namespace std;
...
@@ -38,25 +38,25 @@ using namespace std;
ExpressionTreeNode
::
ExpressionTreeNode
(
Operation
*
operation
,
const
vector
<
ExpressionTreeNode
>&
children
)
:
operation
(
operation
),
children
(
children
)
{
ExpressionTreeNode
::
ExpressionTreeNode
(
Operation
*
operation
,
const
vector
<
ExpressionTreeNode
>&
children
)
:
operation
(
operation
),
children
(
children
)
{
if
(
operation
->
getNumArguments
()
!=
children
.
size
())
if
(
operation
->
getNumArguments
()
!=
children
.
size
())
throw
Exception
(
"Parse error: wrong number of arguments to function
"
);
throw
Exception
(
"Parse error: wrong number of arguments to function
: "
+
operation
->
getName
()
);
}
}
ExpressionTreeNode
::
ExpressionTreeNode
(
Operation
*
operation
,
const
ExpressionTreeNode
&
child1
,
const
ExpressionTreeNode
&
child2
)
:
operation
(
operation
)
{
ExpressionTreeNode
::
ExpressionTreeNode
(
Operation
*
operation
,
const
ExpressionTreeNode
&
child1
,
const
ExpressionTreeNode
&
child2
)
:
operation
(
operation
)
{
children
.
push_back
(
child1
);
children
.
push_back
(
child1
);
children
.
push_back
(
child2
);
children
.
push_back
(
child2
);
if
(
operation
->
getNumArguments
()
!=
children
.
size
())
if
(
operation
->
getNumArguments
()
!=
children
.
size
())
throw
Exception
(
"Parse error: wrong number of arguments to function
"
);
throw
Exception
(
"Parse error: wrong number of arguments to function
: "
+
operation
->
getName
()
);
}
}
ExpressionTreeNode
::
ExpressionTreeNode
(
Operation
*
operation
,
const
ExpressionTreeNode
&
child
)
:
operation
(
operation
)
{
ExpressionTreeNode
::
ExpressionTreeNode
(
Operation
*
operation
,
const
ExpressionTreeNode
&
child
)
:
operation
(
operation
)
{
children
.
push_back
(
child
);
children
.
push_back
(
child
);
if
(
operation
->
getNumArguments
()
!=
children
.
size
())
if
(
operation
->
getNumArguments
()
!=
children
.
size
())
throw
Exception
(
"Parse error: wrong number of arguments to function
"
);
throw
Exception
(
"Parse error: wrong number of arguments to function
: "
+
operation
->
getName
()
);
}
}
ExpressionTreeNode
::
ExpressionTreeNode
(
Operation
*
operation
)
:
operation
(
operation
)
{
ExpressionTreeNode
::
ExpressionTreeNode
(
Operation
*
operation
)
:
operation
(
operation
)
{
if
(
operation
->
getNumArguments
()
!=
children
.
size
())
if
(
operation
->
getNumArguments
()
!=
children
.
size
())
throw
Exception
(
"Parse error: wrong number of arguments to function
"
);
throw
Exception
(
"Parse error: wrong number of arguments to function
: "
+
operation
->
getName
()
);
}
}
ExpressionTreeNode
::
ExpressionTreeNode
(
const
ExpressionTreeNode
&
node
)
:
operation
(
&
node
.
getOperation
()
==
NULL
?
NULL
:
node
.
getOperation
().
clone
()),
children
(
node
.
getChildren
())
{
ExpressionTreeNode
::
ExpressionTreeNode
(
const
ExpressionTreeNode
&
node
)
:
operation
(
&
node
.
getOperation
()
==
NULL
?
NULL
:
node
.
getOperation
().
clone
()),
children
(
node
.
getChildren
())
{
...
...
libraries/lepton/src/Parser.cpp
View file @
5f0e2f92
...
@@ -177,7 +177,7 @@ ParsedExpression Parser::parse(const string& expression, const map<string, Custo
...
@@ -177,7 +177,7 @@ ParsedExpression Parser::parse(const string& expression, const map<string, Custo
int
pos
=
0
;
int
pos
=
0
;
subexpDefs
[
name
]
=
parsePrecedence
(
tokens
,
pos
,
customFunctions
,
subexpDefs
,
0
);
subexpDefs
[
name
]
=
parsePrecedence
(
tokens
,
pos
,
customFunctions
,
subexpDefs
,
0
);
if
(
pos
!=
tokens
.
size
())
if
(
pos
!=
tokens
.
size
())
throw
Exception
(
"Parse error: unexpected text at end of subexpression
"
);
throw
Exception
(
"Parse error: unexpected text at end of subexpression
: "
+
tokens
[
pos
].
getText
()
);
}
}
// Now parse the primary expression.
// Now parse the primary expression.
...
@@ -186,7 +186,7 @@ ParsedExpression Parser::parse(const string& expression, const map<string, Custo
...
@@ -186,7 +186,7 @@ ParsedExpression Parser::parse(const string& expression, const map<string, Custo
int
pos
=
0
;
int
pos
=
0
;
ExpressionTreeNode
result
=
parsePrecedence
(
tokens
,
pos
,
customFunctions
,
subexpDefs
,
0
);
ExpressionTreeNode
result
=
parsePrecedence
(
tokens
,
pos
,
customFunctions
,
subexpDefs
,
0
);
if
(
pos
!=
tokens
.
size
())
if
(
pos
!=
tokens
.
size
())
throw
Exception
(
"Parse error: unexpected text at end of expression
"
);
throw
Exception
(
"Parse error: unexpected text at end of expression
: "
+
tokens
[
pos
].
getText
()
);
return
ParsedExpression
(
result
);
return
ParsedExpression
(
result
);
}
}
...
@@ -250,7 +250,7 @@ ExpressionTreeNode Parser::parsePrecedence(const vector<ParseToken>& tokens, int
...
@@ -250,7 +250,7 @@ ExpressionTreeNode Parser::parsePrecedence(const vector<ParseToken>& tokens, int
result
=
ExpressionTreeNode
(
new
Operation
::
Negate
(),
toNegate
);
result
=
ExpressionTreeNode
(
new
Operation
::
Negate
(),
toNegate
);
}
}
else
else
throw
Exception
(
"Parse error: unexpected token
"
);
throw
Exception
(
"Parse error: unexpected token
: "
+
token
.
getText
()
);
// Now deal with the next binary operator.
// Now deal with the next binary operator.
...
@@ -332,7 +332,7 @@ Operation* Parser::getFunctionOperation(const std::string& name, const map<strin
...
@@ -332,7 +332,7 @@ Operation* Parser::getFunctionOperation(const std::string& name, const map<strin
map
<
string
,
Operation
::
Id
>::
const_iterator
iter
=
opMap
.
find
(
trimmed
);
map
<
string
,
Operation
::
Id
>::
const_iterator
iter
=
opMap
.
find
(
trimmed
);
if
(
iter
==
opMap
.
end
())
if
(
iter
==
opMap
.
end
())
throw
Exception
(
"Parse error: unknown function
"
);
throw
Exception
(
"Parse error: unknown function
: "
+
trimmed
);
switch
(
iter
->
second
)
{
switch
(
iter
->
second
)
{
case
Operation
::
SQRT
:
case
Operation
::
SQRT
:
return
new
Operation
::
Sqrt
();
return
new
Operation
::
Sqrt
();
...
...
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