OpenModelica / OMJulia.jl

Julia scripting OpenModelica interface
BSD 3-Clause "New" or "Revised" License
38 stars 13 forks source link

Parser failing for array of `TypeName` #123

Open olivleno opened 4 months ago

olivleno commented 4 months ago

OMJulia.API.getClassNames(omc;class_="Modelica") works fine.

OMJulia.API.getClassNames(omc;class_="Modelica", recursive=true) gives: ERROR: OMJulia.Parser.LexerError("Error while lexing")

olivleno commented 4 months ago

Similar also for:

example_names = sendExpression(omc,"getAllSubtypeOf(\"Modelica.Icons.Example\";parentClass=\"Modelica\")")
example_names = sendExpression(omc,"getAllSubtypeOf(\"Modelica.Icons.Example\";parentClass=\"Modelica\",qualified=true)")

giving: ERROR: OMJulia.Parser.LexerError("Error while lexing")

What I expected to get is a vector of class names containing all Example models of the MSL, but: example_names = sendExpression(omc,"getAllSubtypeOf(\"Modelica.Icons.Example\")") returns nothing

AnHeuermann commented 4 months ago

Looks like the lexer has some trouble tokenizing the super long string that contains all the MSL models:

"{[...],Modelica.Mechanics.Rotational.Sensors.RelAngleSensor,Modelica.Mechanics.Rotational.Sensors.RelSpeedSensor,Modelica.Mechanics.Rotational.Sensors.RelAccSensor,Modelica.Mechanics.Rotational.Sensors.TorqueSensor,Modelica.Mechanics.Rotational.Sensors.PowerSensor,Modelica.Mechanics.Rotational.Sensors.MultiSensor,Modelica.Mechanics.Rotational.Sources,Modelica.Mechanics.Rotational.Sources.Position,Modelica.Mechanics.Rotational.Sources.Speed,[...]}"

that is returned by omc. I guess it's simply too long. Unfortunately I have no idea how the lexer is working. It is some machine generated file, and I don't know where it is coming from. @JKRT and @adrpo do you know how the lexing is working and why it could struggle with long strings?

olivleno commented 4 months ago

I tried the recursive=true with a much smaller library and it didn't work either. Are you sure that it is purely due to the string size?

arun3688 commented 4 months ago

@olivleno I think this error is related to OMJulia parser, can you just add parsed=false and I think it should work, see below

example_names = sendExpression(omc,"getAllSubtypeOf(\"Modelica.Icons.Example\";parentClass=\"Modelica\")", parsed=false)

AnHeuermann commented 4 months ago

Okay, I got a minimal example to showcase the error:

julia> import OMJulia
julia> OMJulia.Parser.parseOM("{A.M1,B.M2}")
ERROR: OMJulia.Parser.LexerError("Error while lexing"}")

So it's not the length but that it's not a type we previously could parse. It's an array of MetaModelica typeTypeName. I would expect to get an array or strings or symbols in Julia. Symbols would be closer to the MetaModelica type, but strings are easier to handle and when an OM scripting function want's a TypeName input we pass something like "Modelica" and not "\"Modelica\"".

olivleno commented 4 months ago

@olivleno I think this error is related to OMJulia parser, can you just add parsed=false and I think it should work, see below

example_names = sendExpression(omc,"getAllSubtypeOf(\"Modelica.Icons.Example\";parentClass=\"Modelica\")", parsed=false)

No. parsed=false doesn't solve the issue. I tried the following:

example_names = sendExpression(omc,"getClassNames()")
3-element Vector{Symbol}:
 :ModelicaServices
 :Complex
 :Modelica
example_names = sendExpression(omc,"getClassNames(\"Modelica\")")

example_names = sendExpression(omc,"getClassNames(\"Modelica\")",parsed=false)
"\n"
example_names = sendExpression(omc,"getClassNames(\"Modelica\";recursive=true")
ERROR: OMJulia.Parser.LexerError("Error while lexing")
example_names = sendExpression(omc,"getClassNames(\"Modelica\";recursive=true",parsed=false)
"Error occurred building AST\nSyntax Error\n[<interactive>:1:1-1:0:writable] Error: Class getClassNames not found in scope <global scope> (looking for a function or record).\n[<interactive>:1:0-1:12:writable] Error: Parser error: Unexpected token near: getClassNames (IDENT)\n"