Create a Universal Analyzer language package

Add analysis support for a language that no CAST analyzer covers by describing it to the Universal Analyzer in a language package
Updated

Overview

The Universal Analyzer is a CAST analyzer that can analyze any text-based language once it is told what the language looks like. You describe the language in a language package: a set of XML files that defines the objects of the language, how to find them in the source code and how they link to each other. You then deliver the package as a custom extension.

Use a language package for a language that is not supported by a CAST analyzer or by an official extension. Check CAST Extend external link first: a User Community or CAST Labs extension may already cover the language.

How it works

Creating a language package is a three-step process:

  1. Define the language and its objects in the metamodel.
  2. Define how to recognize these objects in the source code in the language pattern. This step is not needed for languages imported with the Universal Importer.
  3. Validate the package, then deliver it in a custom extension.

Package contents

A language package is a folder named after the language. In the files below, xxx stands for the name of the language:

File Required Description
xxxMetaModel.xml Yes The object types and categories of the language, their properties and the links they can have. See Define the metamodel.
xxxLanguagePattern.xml Yes The regular expressions that recognize objects and links in the source code. See Define the language pattern.
Res\ folder Yes The icons of the object types. See Icons.
xxxInformationTracking.xml No Restricts where the analyzer looks for the target of a link, to reduce incorrect links. See Restrict the link search.
xxxCastMetrics.xml No Custom metrics based on regular expressions. See Define custom metrics.
prepro\launch.bat, prepro\launch.sh No Pre-processes the source code before the analysis. See Pre-processing and external plugins.
plugin\launch.bat, plugin\launch.sh No Runs a third-party tool after the analysis to add quality rule results. See Pre-processing and external plugins.

For example, for a language named TEST:

TEST\
    TESTMetaModel.xml
    TESTLanguagePattern.xml
    TESTInformationTracking.xml
    TESTCastMetrics.xml
    Res\
        TESTProject.ICO
        TESTFunction.ICO
        TESTClass.ICO
    prepro\
        launch.bat
        launch.sh
    plugin\
        launch.bat
        launch.sh

All the XML files in the package must be saved in UTF-8, and their XML declaration must state the encoding:

<?xml version="1.0" encoding="utf-8"?>

Step 1 - Write the package

Write the metamodel and the language pattern, then add any optional files you need:

Before you start, reserve a range of IDs for the metamodel: see Reserve ID ranges. For known pitfalls, and for packages written for older CAST releases, see Special cases.

Step 2 - Validate the package

CAST Imaging Core does not include a tool that validates a language package. The UA Package Assistant (UAPackageAssistant.exe), which validated the metamodel, the language pattern and the information tracking file, was shipped only with CAST AIP Core 8.3.x and earlier on Microsoft Windows. If you have access to such an installation, you can still use it to check the XML files before you build the extension.

Otherwise, validate the package by analyzing a small set of representative source code (see Step 4), then check the analysis log for errors and the results for the objects and links you expect. Correct the package and repeat until the results are right.

Step 3 - Build the extension

Place the language package in a Configuration\Languages folder at the root of the extension folder, next to the plugin.nuspec file:

com.castsoftware.uc.mylanguage\
    plugin.nuspec
    Configuration\
        Languages\
            MYLANGUAGE\
                MYLANGUAGEMetaModel.xml
                MYLANGUAGELanguagePattern.xml
                Res\
                    ...

Then write the description file and package the extension.

Step 4 - Deploy and analyze

Deploy the .nupkg file in CAST Imaging: see Deploy custom extensions. Then add the extension to your application in the Extensions panel.

To analyze the files of your language, create an Analysis Unit for it:

  1. Deliver source code that contains files of your language. Files of a Universal Analyzer language that has no dedicated discoverer are not assigned to an Analysis Unit automatically.
  2. In the application’s analysis configuration, go to the Universal Technology section and add an Analysis Unit.
  3. Select your language in the list of Universal Analyzer languages, and select the source code folder that contains the files to analyze.
  4. Run the analysis.

See Analysis configuration.