Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
LCSB-BioCore
SBML.jl
Commits
e924dcbe
Commit
e924dcbe
authored
Apr 13, 2021
by
Miroslav Kratochvil
Browse files
support parsing of a small subset of MathML
...let's see what can be done with it
parent
aefe4708
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/math.jl
View file @
e924dcbe
"""
parseMath(ast::VPtr)::Math
ast_is(ast::VPtr, what::Symbol)::Bool
Helper for quickly recognizing kinds of ASTs
"""
ast_is
(
ast
::
VPtr
,
what
::
Symbol
)
::
Bool
=
ccall
(
sbml
(
what
),
Cint
,
(
VPtr
,),
ast
)
!=
0
"""
parse_math(ast::VPtr)::Math
This attempts to parse out a decent Julia-esque ([`Math`](@ref) AST from a
pointer to `ASTNode_t`.
"""
function
parseMath
(
ast
::
VPtr
)
::
Math
@info
"got
$
ast"
MathIdent
(
"placeholder"
)
function
parse_math
(
ast
::
VPtr
)
::
Math
if
ast_is
(
ast
,
:
ASTNode_isName
)
||
ast_is
(
ast
,
:
ASTNode_isConstant
)
return
MathIdent
(
get_string
(
ast
,
:
ASTNode_getName
))
elseif
ast_is
(
ast
,
:
ASTNode_isConstantNumber
)
return
MathVal
(
ccall_sbml
(
:
ASTNode_getValue
),
Cdouble
,
(
VPtr
,),
ast
)
elseif
ast_is
(
ast
,
:
ASTNode_isFunction
)
return
MathApply
(
get_string
(
ast
,
:
ASTNode_getName
),
[
parse_math
(
ccall
(
sbml
(
:
ASTNode_getChild
),
VPtr
,
(
VPtr
,
Cuint
),
ast
,
i
-
1
))
for
i
=
1
:
ccall
(
sbml
(
:
ASTNode_getNumChildren
),
Cuint
,
(
VPtr
,),
ast
)
],
)
elseif
ast_is
(
ast
,
:
ASTNode_isOperator
)
return
MathApply
(
string
(
Char
(
ccall
(
sbml
(
:
ASTNode_getCharacter
),
Cchar
,
(
VPtr
,),
ast
))),
[
parse_math
(
ccall
(
sbml
(
:
ASTNode_getChild
),
VPtr
,
(
VPtr
,
Cuint
),
ast
,
i
-
1
))
for
i
=
1
:
ccall
(
sbml
(
:
ASTNode_getNumChildren
),
Cuint
,
(
VPtr
,),
ast
)
],
)
else
@warn
"unsupported math element at
$
ast"
return
MathIdent
(
"?unsupported?"
)
end
end
src/readsbml.jl
View file @
e924dcbe
...
...
@@ -236,7 +236,7 @@ function extractModel(mdl::VPtr)::Model
end
if ccall(sbml(:KineticLaw_isSetMath), Cint, (VPtr,), kl) != 0
math = parse
M
ath(ccall(sbml(:KineticLaw_getMath), VPtr, (VPtr,), kl))
math = parse
_m
ath(ccall(sbml(:KineticLaw_getMath), VPtr, (VPtr,), kl))
end
end
...
...
src/structs.jl
View file @
e924dcbe
...
...
@@ -79,7 +79,6 @@ Function application ("call by name", no tricks allowed) in mathematical express
"""
struct
MathApply
<:
Math
fn
::
String
attributes
::
Dict
{
String
,
String
}
args
::
Vector
{
Math
}
end
...
...
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