You can use helper attributes to control the environment of the generated code. These can be applied to individual methods or at the class level to affect all parsers within that class.
IncludeFiles
Include additional source files that your parser depends on. Paths are relative to the source file containing the [GenerateParser] method. Supports glob patterns:
*: matches any characters except path separator**: matches recursively?: matches single character
IncludeUsings
Add specific using directives to the generated code.
IncludeGenerators
Specify other source generators (e.g., PolySharp) that should run before the Parlot parser generation.
Class-level Application
Applying these attributes to a partial class applies them to all [GenerateParser] methods within that class. Method-level attributes are additive to class-level attributes.
// Method-level usage
[GenerateParser]
[IncludeFiles("Ast.cs", "Tokens.cs")]
[IncludeUsings("System.Collections.Generic", "MyProject.Models")]
[IncludeGenerators("PolySharp")]
public static Parser<Expression> CreateParser() => ...;
// Class-level usage
[IncludeFiles("Ast.cs")]
[IncludeUsings("MyProject.Models")]
public static partial class MyParsers
{
[GenerateParser]
public static Parser<Expression> ExprParser() => ...;
[GenerateParser]
[IncludeFiles("Extra.cs")] // Combined with class-level
public static Parser<Statement> StmtParser() => ...;
}