Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
61ae670d
Commit
61ae670d
authored
Jul 19, 2021
by
Miroslav Kratochvil
🚴
Browse files
fix parsing of relational operators
fixes #124
parent
68e0e0b5
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/math.jl
View file @
61ae670d
...
...
@@ -16,6 +16,25 @@ parse_math_children(ast::VPtr)::Vector{Math} = [
i
=
1
:
ccall
(
sbml
(
:
ASTNode_getNumChildren
),
Cuint
,
(
VPtr
,),
ast
)
]
# Mapping of AST node type value subset to relational operations. Depends on
# `ASTNodeType.h` (also see below the case with AST_NAME_TIME)
const
relational_opers
=
Dict
{
Int32
,
String
}(
308
=>
"eq"
,
309
=>
"geq"
,
310
=>
"gt"
,
311
=>
"leq"
,
312
=>
"lt"
,
313
=>
"neq"
,
)
function
relational_oper
(
t
::
Int
)
haskey
(
relational_opers
,
t
)
||
throw
(
DomainError
(
t
,
"Unknown ASTNodeType value for relational operator"
))
relational_opers
[
t
]
end
"""
parse_math(ast::VPtr)::Math
...
...
@@ -42,11 +61,16 @@ function parse_math(ast::VPtr)::Math
return
MathVal
(
ccall
(
sbml
(
:
ASTNode_getReal
),
Cdouble
,
(
VPtr
,),
ast
))
elseif
ast_is
(
ast
,
:
ASTNode_isFunction
)
return
MathApply
(
get_string
(
ast
,
:
ASTNode_getName
),
parse_math_children
(
ast
))
elseif
ast_is
(
ast
,
:
ASTNode_isOperator
)
||
ast_is
(
ast
,
:
ASTNode_isRelational
)
elseif
ast_is
(
ast
,
:
ASTNode_isOperator
)
return
MathApply
(
string
(
Char
(
ccall
(
sbml
(
:
ASTNode_getCharacter
),
Cchar
,
(
VPtr
,),
ast
))),
parse_math_children
(
ast
),
)
elseif
ast_is
(
ast
,
:
ASTNode_isRelational
)
return
MathApply
(
relational_oper
(
Int
(
ccall
(
sbml
(
:
ASTNode_getType
),
Cint
,
(
VPtr
,),
ast
))),
parse_math_children
(
ast
),
)
elseif
ast_is
(
ast
,
:
ASTNode_isLambda
)
children
=
parse_math_children
(
ast
)
if
!
isempty
(
children
)
...
...
src/symbolics.jl
View file @
61ae670d
...
...
@@ -45,6 +45,7 @@ const default_symbolics_mapping = Dict{String,Any}(
"ln"
=>
:
log
,
"log"
=>
:
sbmlLog
,
"lt"
=>
:<
,
"neq"
=>
:
(
sbmlNeq
),
"piecewise"
=>
:
(
sbmlPiecewise
),
"power"
=>
:^
,
"root"
=>
:
sbmlRoot
,
...
...
@@ -66,6 +67,7 @@ function sbmlPiecewise(args...)
end
end
sbmlNeq
(
a
,
b
)
=
!
isequal
(
a
,
b
)
sbmlLog
(
x
)
=
log
(
x
,
10
)
sbmlLog
(
base
,
x
)
=
log
(
base
,
x
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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