Module parser

Source
Expand description

Parsing of the alpm-pkgbuild-bridge script output, which prints package metadata contained in PKGBUILD files.

This module handles the parsing of output generated by the alpm-pkgbuild-bridge script, which is shipped as a separate package. At this step, we do not yet ensure the correctness of the parsed data, instead we only parse the data structure of the output and bring it into an easy to handle struct. You can think of it as an equivalent of serde’s intermediate Value.

The output of the script has a well-known structure and provides some guarantees that we’ll use to keep the parsers simple.

Overall format specification:

  1. Variables are declared one-line per variable.

  2. All variables declaration lines begin with VAR

  3. All variable values are surrounded by double quotes ". If a value contains double quotes, those double quotes are escaped with a backslash: \".

  4. If a variable is an array, the array’s values are represented as space separated items on the same line. Each value is surrounded by double quotes.

  5. Variables cannot be declared twice.

  6. pkgbase variable declarations look as follows:

    VAR GLOBAL [ARRAY|STRING] $KEY $VALUES
    Examples:
    VAR GLOBAL STRING pkgrel "6"
    VAR GLOBAL ARRAY license "GPL-2.0-or-later" "CCPL"
  7. package function variable declarations look as follows:

    VAR FUNCTION $PACKAGE_NAME [ARRAY|STRING] $KEY $VALUES
    Examples:
    VAR FUNCTION package STRING pkgdesc "My normal package"
    VAR FUNCTION package_my-split-package STRING pkgdesc "My special split package"
    VAR FUNCTION package_my-split-package ARRAY depends "cargo" "glibc"
  8. Package overrides that clear a value/array simply don’t have any string values.

    Example:

    VAR FUNCTION package_my-split-package ARRAY depends
  9. Split-/Package functions are declared as: FUNCTION $PACKAGE_NAME

    Example:

    FUNCTION package_my-split-package

    Note that single-package PKGBUILD files don’t necessarily need to have the package_$NAME format, but rather may just have a single package function.

Structure guarantees:

  • There are no empty lines.
  • Global variables (those that apply to all packages defined in a PKGBUILD) are declared first.
  • Variables that are declared in package functions of the PKGBUILD are always returned after the global variables and are grouped by package.
  • The declarations of package function names are always returned at the end (after all package function variables are returned).

Structs§

BridgeOutput
Represents the raw parsed, but not yet typed output of the alpm-pkgbuild-bridge script.
Keyword
A keyword (with an optional Architecture suffix) of a variable found in the output of the alpm-pkgbuild-bridge script.
RawPackageName
A raw, unchecked package name.

Enums§

ClearableValue
Represents a potentially cleared or overridden value.
Value
A single value or a list of values declared in the output of the alpm-pkgbuild-bridge script.
VariableType 🔒
A type of variable found in the output of the alpm-pkgbuild-bridge script.