Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser failing for array of TypeName #123

Open
olivleno opened this issue May 24, 2024 · 6 comments
Open

Parser failing for array of TypeName #123

olivleno opened this issue May 24, 2024 · 6 comments
Assignees

Comments

@olivleno
Copy link

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
Copy link
Author

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 AnHeuermann self-assigned this May 27, 2024
@AnHeuermann
Copy link
Member

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?

@AnHeuermann AnHeuermann changed the title OMJulia.API.getClassNames ERROR with recursive=true Lexer failing to tokenize very long strings. May 27, 2024
@olivleno
Copy link
Author

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
Copy link
Contributor

@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
Copy link
Member

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\"".

@AnHeuermann AnHeuermann changed the title Lexer failing to tokenize very long strings. Parser failing for array of TypeName May 28, 2024
@olivleno
Copy link
Author

@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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants