Skip to content

l0.MoonCats.Parser

MoonCatsParser = require "l0.MoonCats.Parser"
local MoonCatsParser = require("l0.MoonCats.Parser")

MoonCatsParser

Parses annotated MoonScript sources into the intermediate representation consumed by the definition emitter.

Instance methods

parse

moonCatsParser\parse source, requireId, diagnostics
moonCatsParser:parse(source, requireId, diagnostics)

Parses one MoonScript module into its definition-extraction IR.

param type description
source string The module's MoonScript source text.
requireId string Require identifier of the module (e.g. "l0.DependencyControl.Timer").
diagnostics? MoonCatsDiagnostics Collection that receives findings discovered while parsing.

Returns:

  • ir MoonCatsModuleIR? — The parsed module IR, or nil when the source fails to parse.
  • err string? — Parse error message when parsing failed.

Enums

MoonCatsMemberKind

member value description
Constructor "constructor" the class's new
Method "method" a fat-arrow instance method
StaticMethodFat "staticMethodFat" a class-level function called with the class as self
StaticMethodThin "staticMethodThin" a class-level plain function
StaticData "staticData" a class-level data field
InstanceDefault "instanceDefault" an instance-level default value declared in the class body
AccessorProperty "accessorProperty" a computed property declared via Accessors.property
EnumExport "enumExport" a class-level field holding a DependencyControl Enum
Metamethod "metamethod" a Lua metamethod

MoonCatsExportKind

member value description
Class "class" the module returns a class
Table "table" the module returns a plain table
Function "function" the module returns a bare function
Unknown "unknown" the module's export could not be determined

MoonCatsSymbolKind

member value description
Require "require" a local bound to require "..."
Import "import" a name destructured or imported from a required module
Class "class" a local bound to a class statement
Enum "enum" a local bound to a DependencyControl Enum definition
Function "function" a local bound to a function literal
Table "table" a local bound to a table literal
Literal "literal" a local bound to a scalar literal
Reference "reference" a local aliasing another local
Other "other" any binding the parser does not model

MoonCatsSegmentKind

member value description
Alias "alias" an @alias declaration with its variant lines
Class "class" an annotation-only @class declaration with its @field lines
Rest "rest" the member contract part of a block (params, returns, prose)

MoonCatsValueKind

member value description
Literal "literal" a scalar literal with a reconstructible source token
Reference "reference" a bare identifier
Call "call" a call chain (constructor or function invocation)
Table "table" a table literal
Function "function" a function literal
Expression "expression" an operator expression
Other "other" anything else

Types

MoonCatsAnnotationBlock

A run of contiguous doc-comment lines.

field type description
startLine integer 1-based line of the block's first doc line.
endLine integer 1-based line of the block's last doc line.
lines string[] The doc lines, verbatim from the leading --- on.

MoonCatsSegment

A slice of an annotation block — a standalone alias/class declaration or the member contract.

field type description
kind MoonCatsSegmentKind
name? string Declared alias/class name; nil for rest segments.
lines string[] The segment's doc lines, verbatim.
line? integer Source line the segment is anchored to, for output ordering.

MoonCatsParam

One parameter of a function signature.

field type description
name string Parameter name with any @/@@ prefix stripped.
hasDefault boolean Whether the signature declares a default value.
isVararg boolean Whether this is the ... parameter.

MoonCatsValueInfo

Classification of a member's or field's value expression.

field type description
kind MoonCatsValueKind
token? string Reconstructed source token for literal values.
literalKind? string Lua type name of a literal value ("number", "string", "boolean", "nil").
refName? string Identifier name for reference values.
baseName? string Chain base identifier for call values.
params? MoonCatsParam[] Signature for function values.
arrow? string "fat" or "slim" for function values.
node? table The raw AST node for table/call/expression/other values.

MoonCatsMemberIR

A class-body member.

field type description
kind MoonCatsMemberKind
name string
line integer Source line of the member's definition.
block? string[] The member's bound annotation lines (rest segment), verbatim.
params? MoonCatsParam[] Signature for function members.
arrow? string "fat" or "slim" for function members.
hasExplicitValueReturn? boolean Whether the body contains an explicit valued return.
isPrivate boolean From a __ name prefix or an @private tag in the block.
valueInfo? MoonCatsValueInfo For data members.
enum? MoonCatsEnumIR For enum-export members.

MoonCatsEnumIR

A DependencyControl Enum definition found in the module.

field type description
name string The Enum's declared runtime name.
line integer
members {key: string, literal: string, display?: string}[] Literal-valued members in definition order; display holds a computed key's source Enum.Member expression.
computedKeyCount integer Number of members skipped for non-literal keys or values.
exportedAs? string Member/field name the Enum is exported under, when it is.

MoonCatsClassIR

A real class found in the module.

field type description
name string The moon class statement's name.
line integer
hasParent boolean
parentName? string The extends expression's identifier when it is a simple reference.
block? string[] The class's bound annotation block, verbatim (prose + @class + @field lines).
typeName string LuaCATS type name: the block's @class name when present, else the moon name.
annotatedParentName? string Parent named in the block's @class line, when present.
members MoonCatsMemberIR[] In source order.
localSymbols table<string, MoonCatsSymbol> Class-body locals.

MoonCatsAugmentationIR

A module-level dotted assignment augmenting a class or module table.

field type description
targetName string Identifier being augmented.
name string Field name assigned.
line integer
block? string[]
valueInfo MoonCatsValueInfo
params? MoonCatsParam[] Signature when the value is a function literal.
arrow? string
hasExplicitValueReturn? boolean

MoonCatsFieldIR

A field of a table-module export.

field type description
name string
line integer
block? string[]
valueInfo MoonCatsValueInfo
enum? MoonCatsEnumIR Set when the field holds an Enum, mirroring a class-static enum export.
params? MoonCatsParam[] Signature when the value is a function literal.
arrow? string
hasExplicitValueReturn? boolean

MoonCatsExportIR

What a module returns to requirers.

field type description
kind MoonCatsExportKind
name? string The exported local/class name, when the export is a named value.
class? MoonCatsClassIR For class exports.
fields? MoonCatsFieldIR[] For table exports.
params? MoonCatsParam[] For function exports.
block? string[] For function exports: the function's bound annotation lines.
hasExplicitValueReturn? boolean For function exports.

MoonCatsSymbol

A resolved module-scope or class-scope name binding.

field type description
kind MoonCatsSymbolKind
requireId? string For require/import symbols.
enum? MoonCatsEnumIR For enum symbols.
params? MoonCatsParam[] For function symbols.
arrow? string For function symbols.
hasExplicitValueReturn? boolean For function symbols.
node? table Table node for table symbols.
target? string For reference symbols.
token? string For literal symbols.
literalKind? string For literal symbols.
block? string[] Annotation lines bound to the symbol's definition.
class? MoonCatsClassIR For class symbols.

MoonCatsModuleIR

Everything the emitter needs to know about one parsed module.

field type description
requireId string
lines string[] The module's source lines.
segments MoonCatsSegment[] Standalone alias/class declarations, in source order.
classes MoonCatsClassIR[] Real classes, in source order.
classesByName table<string, MoonCatsClassIR>
enums MoonCatsEnumIR[] All Enum definitions found.
aliases table<string, boolean> Names of @alias declarations found in this module.
symbols table<string, MoonCatsSymbol> Module-scope name bindings.
export MoonCatsExportIR
augmentations MoonCatsAugmentationIR[] Module-level dotted assignments.
moduleDoc? string[] A leading doc block detached from any declaration, documenting the module itself.