validate_actions.domain_model.primitives

Primitive building blocks for creating a GHA ast.

Classes

Expression(pos, string, parts)

Represents a GitHub Actions expression like ${{ context.value }}.

Pos(line, col[, idx])

Position information for tracking locations in YAML source files.

String(string, pos[, expr])

Represents a string value with position metadata and embedded expressions.

class validate_actions.domain_model.primitives.Pos(line, col, idx=0)[source]

Bases: object

Position information for tracking locations in YAML source files.

This class provides precise position tracking for AST nodes, enabling accurate error reporting and automatic fixes. Position information includes line number, column number, and character index within the file.

Parameters:
  • line (int)

  • col (int)

  • idx (int)

line

Zero-based line number in the source file

Type:

int

col

Zero-based column number within the line

Type:

int

idx

Character index from start of file

Type:

int

Examples

Creating a position from YAML token:

pos = Pos.from_token(token)

Manual position creation:

pos = Pos(line=5, col=10, idx=125)

classmethod from_token(token)[source]

Creates a Pos instance from a PyYAML token.

Parameters:

token (Token) – PyYAML token containing position information

Returns:

Position object with line and column from the token

Return type:

Pos

class validate_actions.domain_model.primitives.Expression(pos, string, parts)[source]

Bases: object

Represents a GitHub Actions expression like ${{ context.value }}.

Expressions are parsed from strings and broken down into parts for validation. Each expression maintains position information for error reporting.

Parameters:
  • pos (Pos)

  • string (str)

  • parts (List[String])

pos

Position in the source file where this expression starts

Type:

Pos

string

Raw expression string as it appears in the YAML

Type:

str

parts

List of String objects representing parsed parts of the expression

Type:

List[String]

Examples

Expression for ${{ github.event.pull_request.number }}:
expr = Expression(

pos=Pos(5, 10), string=”github.event.pull_request.number”, parts=[String(“github”), String(“event”), String(“pull_request”), String(“number”)]

)

class validate_actions.domain_model.primitives.String(string, pos, expr=<factory>)[source]

Bases: object

Represents a string value with position metadata and embedded expressions.

This is the core string representation used throughout the AST. It preserves the original string content along with precise position information and any GitHub Actions expressions (${{ … }}) found within the string.

Parameters:
string

The string value extracted from the YAML token

Type:

str

pos

Position of the string in the source file (line and column)

Type:

Pos

expr

List of Expression objects found within this string

Type:

List[Expression]

Examples

Simple string:

s = String(“hello world”, Pos(1, 0))

String with expression:

s = String(“Hello ${{ github.actor }}”, pos, [expr])

From YAML token:

s = String.from_token(scalar_token)

classmethod from_token(token)[source]

Creates a String instance from a PyYAML ScalarToken.

Parameters:

token (ScalarToken) – ScalarToken containing string value and position information

Returns:

String object with value and position from the token

Return type:

String