simonjwright / libadalang2xml

Generates an XML representation of Ada source using libadalang.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Libadalang2XML is a tool to extract syntatic aspects of Ada source code into XML. It's designed to be built using Alire.

The Ada source is initially read using Libadalang. The resulting tree is then traversed, and its structure output in an XML form.

The document type definition isn't explicit; it's simply derived from the tree elements created by Libadalang. Note that Libadalang includes much more semantic information than the surface structure generated by this tool, but nevertheless there's enough there to --- for example --- create a scriptable body for a package spec.

Building on macOS

Using the standard langkit_support, libadalang crates, you must build with LIBRARY_TYPE set to relocatable:

alr build -- -XLIBRARY_TYPE=relocatable

This is because those crates try to build standalone static object libraries using features not available for Darwin's mach-o object format.

You can obtain versions of those crates adjusted to not require those features, which can therefore build the (default) static libraries, by visiting this site.

Example

As an example of the output, this code

package Demo is
   procedure Square (X : in out Integer);
end Demo;

generates

<CompilationUnit>
  <AdaNodeList/>
  <LibraryItem>
    <PrivateAbsent/>
    <PackageDecl>
      <DefiningName>
        <Id>Demo</Id>
      </DefiningName>
      <PublicPart>
        <AdaNodeList>
          <SubpDecl>
            <OverridingUnspecified/>
            <SubpSpec>
              <SubpKindProcedure>procedure</SubpKindProcedure>
              <DefiningName>
                <Id>Square</Id>
              </DefiningName>
              <Params>
                <ParamSpecList>
                  <ParamSpec>
                    <DefiningNameList>
                      <DefiningName>
                        <Id>X</Id>
                      </DefiningName>
                    </DefiningNameList>
                    <AliasedAbsent/>
                    <ModeInOut>in out</ModeInOut>
                    <SubtypeIndication>
                      <NotNullAbsent/>
                      <Id>Integer</Id>
                    </SubtypeIndication>
                  </ParamSpec>
                </ParamSpecList>
              </Params>
            </SubpSpec>
          </SubpDecl>
        </AdaNodeList>
      </PublicPart>
      <EndName>
        <Id>Demo</Id>
      </EndName>
    </PackageDecl>
  </LibraryItem>
  <PragmaNodeList/>
</CompilationUnit>

About

Generates an XML representation of Ada source using libadalang.


Languages

Language:Ada 100.0%