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

Add support for XML-based input files. Refs #202. #203

Merged
merged 5 commits into from
Jan 19, 2025

Conversation

ivanperez-keera
Copy link
Member

This commit introduces a new library to parse XML files, and modifies ogma-core to use that functionality to support processing input files in XML in the standalone backend, as prescribed in the solution proposed for #202.

…a#202.

There is a need in Ogma to support XML-based input files, since this is
produced by many standard tools in the industry. Like with JSON, we want
users to be able to customize the input format via a command-line flag,
so that users can work with XML-based files whose format is previously
unknown to Ogma without having to modify the tool.

This commit introduces a new library to parse Ogma specifications from
XML files. The parsing functions are parameterized by the functions that
parse requirement sub-expressions, allowing for further customization,
The sub-expression parser may execute an IO-action, enabling the use of
external commands and/or LLMs to pre-process expressions. The
specification of the XML format is readable, which will also enable
parsing a format specification from an input file (either a known file
distributed with Ogma or a user-provided input file).
…#202.

There is a need in Ogma to support XML-based input files, since this is
produced by many standard tools in the industry. Like with JSON, we want
users to be able to customize the input format via a command-line flag,
so that users can work with XML-based files whose format is previously
unknown to Ogma without having to modify the tool.

A prior commit has introduced a library to parse Ogma specifications
from XML files.

This commit extends ogma-core to accept input files in XML, and to treat
any configuration file containing an XMLFormat specification as format
specification for an XML-based input file.
There is a need in Ogma to support XML-based input files, since this is
produced by many standard tools in the industry. Like with JSON, we want
users to be able to customize the input format via a command-line flag,
so that users can work with XML-based files whose format is previously
unknown to Ogma without having to modify the tool.

A prior commit has introduced the capability to use XML files with
ogma-core.

This commit adds four XML format specifications based on two standard
formats used in known MBSE tools.
@ivanperez-keera
Copy link
Member Author

Change Manager: One of the changelogs refers to issue #200 instead of #202.

@ivanperez-keera
Copy link
Member Author

Implementor: Fix implemented, review requested.

@ivanperez-keera
Copy link
Member Author

Change Manager: Verified that:

  • Solution is implemented:
    • The code proposed compiles and passes all tests. Details:
    • The solution proposed produces the expected result. Details:
      The following dockerfile uses the new parser, together with a custom XML format specification, to parse read properties from an input file and generate a Copilot monitor, checking that the produced monitor compiles correctly, after which it prints the message "Success":
      --- Dockerfile-verify-202
      FROM ubuntu:trusty
      
      RUN apt-get update
      
      RUN apt-get install --yes software-properties-common
      RUN add-apt-repository ppa:hvr/ghc
      RUN apt-get update
      
      RUN apt-get install --yes ghc-8.6.5 cabal-install-2.4
      RUN apt-get install --yes libz-dev
      
      ENV PATH=/opt/ghc/8.6.5/bin:/opt/cabal/2.4/bin:$PWD/.cabal-sandbox/bin:$PATH
      
      RUN cabal update
      RUN cabal v1-sandbox init
      RUN cabal v1-install alex happy --constraint='happy < 2.0'
      RUN apt-get install --yes git
      
      ADD xml-custom-format /tmp/xml-custom-format
      ADD properties.xml /tmp/properties.xml
      
      CMD git clone $REPO && \
          cd $NAME && \
          git checkout $COMMIT && \
          cd .. && \
          cabal v1-install copilot-4.2 $NAME/$PAT**/ && \
          ogma standalone --input-format /tmp/xml-custom-format --file-name /tmp/properties.xml --target-dir output && \
          cabal v1-exec -- runhaskell -XPartialTypeSignatures -Wno-partial-type-signatures output/Copilot.hs && \
          echo "Success"
      
      --- xml-custom-format
      XMLFormat
        { specInternalVars    = Nothing
        , specInternalVarId   = ("//*", Nothing)
        , specInternalVarExpr = ("//*", Nothing)
        , specInternalVarType = Nothing
        , specExternalVars    = Nothing
        , specExternalVarId   = ("//*", Nothing)
        , specExternalVarType = Nothing
        , specRequirements    = ("//Requirement", Nothing)
        , specRequirementId   = ("//Requirement/@Id/text()", Nothing)
        , specRequirementDesc = Just ("//Requirement/@Id/text()", Nothing)
        , specRequirementExpr = ("//Requirement/@Text/text()", Nothing)
        }
      
      --- properties.xml
      <?xml version="1.0" encoding="UTF-8"?>
      <Requirement name="REQ-1" Id="req1" Text="!go_too_fast" />
      
      Command (substitute variables based on new path after merge):
      $ docker run -e "REPO=https://github.com/ivanperez-keera/ogma" -e "NAME=ogma" -e "PAT=ogma" -e "COMMIT=c0af537eba86de2966172112b14fc52a1842202a" -it ogma-verify-202
      
  • Implementation is documented. Details:
    All new libraries, modules and top-level functions include documentation. Modifications to ogma-core's top-level definitions also include additional documentation.
  • Change history is clear.
  • Commit messages are clear.
  • Changelogs are updated.
  • Examples are updated. Details:
    No updates needed.
  • Required version bumps are evaluated. Details:
    Bump not required (API is backwards compatible).

@ivanperez-keera ivanperez-keera merged commit 9065cce into nasa:develop Jan 19, 2025
2 checks passed
@ivanperez-keera ivanperez-keera deleted the develop-xml branch January 19, 2025 18:57
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

Successfully merging this pull request may close these issues.

1 participant