Skip to content

Add support for comments before class-definition #34

@AnHeuermann

Description

@AnHeuermann

Description

Base Modelica generated by OpenModelica will always include a comment at the beginning of the file to note the Base Modelica "version" used to generate it. This breaks the parser. It expects the first word to be package.

How to reproduce

Comment.mo

//! base 0.1.0
package 'Comment'
  model 'Comment'
    Real 'x';
  equation
    der('x') = 'x';
  end 'Comment';
end 'Comment';
julia> BaseModelica.parse_basemodelica("comment.mo")
ERROR: ParserCombinator.ParserException("cannot parse")
Stacktrace:
 [1] once(channel::Channel{Any})
   @ ParserCombinator ~/.julia/packages/ParserCombinator/kIa3L/src/core/parsers.jl:196
 [2] single_result
   @ ~/.julia/packages/ParserCombinator/kIa3L/src/core/parsers.jl:201 [inlined]
 [3] (::ParserCombinator.var"#single_result#36"{ParserCombinator.var"#single_result#35#37"{@Kwargs{}, UnionAll}})(source::String, matcher::ParserCombinator.Transform)
   @ ParserCombinator ~/.julia/packages/ParserCombinator/kIa3L/src/core/parsers.jl:200
 [4] parse_str(data::String)
   @ BaseModelica ~/.julia/packages/BaseModelica/qCG6a/src/parser.jl:603
 [5] parse_file
   @ ~/.julia/packages/BaseModelica/qCG6a/src/parser.jl:610 [inlined]
 [6] parse_basemodelica(filename::String)
   @ BaseModelica ~/.julia/packages/BaseModelica/qCG6a/src/BaseModelica.jl:22
 [7] top-level scope
   @ REPL[4]:1

Versions 'n Stuff

  • Julia Version 1.11.6
  • BaseModelica v1.1.0
  • OS: Ubuntu 24.04.3 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions