pub struct Program {
pub settings: Option<Settings>,
pub global_variables: Vec<Variable>,
pub player_variables: Vec<Variable>,
pub subroutines: Vec<Subroutine>,
pub rules: Vec<Rule>,
/* private fields */
}Expand description
A complete Workshop program built from Workshop concepts.
Fields§
§settings: Option<Settings>§global_variables: Vec<Variable>§player_variables: Vec<Variable>§subroutines: Vec<Subroutine>§rules: Vec<Rule>Implementations§
Source§impl Program
impl Program
Sourcepub fn element_count(
&self,
catalog: &Catalog,
) -> Result<ElementCountReport, ElementCountError>
pub fn element_count( &self, catalog: &Catalog, ) -> Result<ElementCountReport, ElementCountError>
Count the canonical Workshop target represented by this program.
Source§impl Program
impl Program
pub fn new() -> Self
Sourcepub fn add_file(&mut self, file: SourceFile) -> FileId
pub fn add_file(&mut self, file: SourceFile) -> FileId
Register a source file and return its public file identity.
pub fn global_variable(&mut self, variable: Variable) -> &mut Self
pub fn player_variable(&mut self, variable: Variable) -> &mut Self
pub fn subroutine(&mut self, subroutine: Subroutine) -> &mut Self
pub fn rule(&mut self, rule: Rule) -> &mut Self
Sourcepub fn source(&self, file: FileId) -> Option<&SourceDocument>
pub fn source(&self, file: FileId) -> Option<&SourceDocument>
Return the retained source document for a parsed file.
Sourcepub fn set_rule_span(
&mut self,
rule: usize,
span: Option<Span>,
) -> Result<(), SourceMappingError>
pub fn set_rule_span( &mut self, rule: usize, span: Option<Span>, ) -> Result<(), SourceMappingError>
Attach the authored span of a public rule.
Sourcepub fn set_condition_span(
&mut self,
rule: usize,
condition: usize,
span: Option<Span>,
) -> Result<(), SourceMappingError>
pub fn set_condition_span( &mut self, rule: usize, condition: usize, span: Option<Span>, ) -> Result<(), SourceMappingError>
Attach the authored span of a public rule condition value.
Sourcepub fn set_action_span(
&mut self,
rule: usize,
action: usize,
span: Option<Span>,
) -> Result<(), SourceMappingError>
pub fn set_action_span( &mut self, rule: usize, action: usize, span: Option<Span>, ) -> Result<(), SourceMappingError>
Attach the authored span of a public action in its linear rule order.
Sourcepub fn set_action_argument_span(
&mut self,
rule: usize,
action: usize,
argument: usize,
span: Option<Span>,
) -> Result<(), SourceMappingError>
pub fn set_action_argument_span( &mut self, rule: usize, action: usize, argument: usize, span: Option<Span>, ) -> Result<(), SourceMappingError>
Attach the authored span of a direct value argument of a public action.
Sourcepub fn set_global_variable_spans(
&mut self,
variable: usize,
span: Option<Span>,
name_span: Option<Span>,
) -> Result<(), SourceMappingError>
pub fn set_global_variable_spans( &mut self, variable: usize, span: Option<Span>, name_span: Option<Span>, ) -> Result<(), SourceMappingError>
Attach the authored and identifier spans of a global variable.
Sourcepub fn set_player_variable_spans(
&mut self,
variable: usize,
span: Option<Span>,
name_span: Option<Span>,
) -> Result<(), SourceMappingError>
pub fn set_player_variable_spans( &mut self, variable: usize, span: Option<Span>, name_span: Option<Span>, ) -> Result<(), SourceMappingError>
Attach the authored and identifier spans of a player variable.
Sourcepub fn set_subroutine_spans(
&mut self,
subroutine: usize,
span: Option<Span>,
name_span: Option<Span>,
) -> Result<(), SourceMappingError>
pub fn set_subroutine_spans( &mut self, subroutine: usize, span: Option<Span>, name_span: Option<Span>, ) -> Result<(), SourceMappingError>
Attach the authored and identifier spans of a subroutine.
Sourcepub fn rule_span(&self, rule: usize) -> Option<Span>
pub fn rule_span(&self, rule: usize) -> Option<Span>
Return the authored span of a public rule, when source metadata exists.
Attached mappings record the program shape they were attached to. Every
span accessor returns None once the public rules, conditions, or
actions have been inserted or removed since the mapping was attached.
Sourcepub fn condition_span(&self, rule: usize, condition: usize) -> Option<Span>
pub fn condition_span(&self, rule: usize, condition: usize) -> Option<Span>
Return the authored span of a public rule condition value.
Sourcepub fn action_span(&self, rule: usize, action: usize) -> Option<Span>
pub fn action_span(&self, rule: usize, action: usize) -> Option<Span>
Return the authored span of a public action in its linear rule order.
Sourcepub fn action_argument_span(
&self,
rule: usize,
action: usize,
argument: usize,
) -> Option<Span>
pub fn action_argument_span( &self, rule: usize, action: usize, argument: usize, ) -> Option<Span>
Return the authored span of a direct value argument of a public action.
Sourcepub fn global_variable_name_span(&self, variable: usize) -> Option<Span>
pub fn global_variable_name_span(&self, variable: usize) -> Option<Span>
Return the authored span of the declared name of a global variable.
Source-language providers attach an explicit identifier span through
set_global_variable_spans. For raw
Workshop parses the recorded declaration span already covers exactly
the declared name and is returned as the identifier span.
Sourcepub fn player_variable_name_span(&self, variable: usize) -> Option<Span>
pub fn player_variable_name_span(&self, variable: usize) -> Option<Span>
Return the authored span of the declared name of a player variable.
See global_variable_name_span.
Sourcepub fn subroutine_name_span(&self, subroutine: usize) -> Option<Span>
pub fn subroutine_name_span(&self, subroutine: usize) -> Option<Span>
Return the authored span of the declared name of a subroutine.
See global_variable_name_span.
Sourcepub fn action_identifier_span(&self, rule: usize, action: usize) -> Option<Span>
pub fn action_identifier_span(&self, rule: usize, action: usize) -> Option<Span>
Return the span recorded for the variable or subroutine identifier a
public action names: the target of set/modify and for-variable actions,
or the callee of a Call Subroutine action.
Raw Workshop parses record the variable name for Set/Modify
variable actions, For variable loops, and Global.name/Event Player.name infix assignments, and the callee name for Call Subroutine. Indexed writes lower to ... Variable At Index calls and
record the name on their variable argument — see
action_argument_value_span.
Other action forms always return None.
Sourcepub fn rule_name_span(&self, rule: usize) -> Option<Span>
pub fn rule_name_span(&self, rule: usize) -> Option<Span>
Return the span recorded for a rule’s name inside its rule("name")
string, or None when no provenance was recorded.
Sourcepub fn rule_event_name_span(&self, rule: usize) -> Option<Span>
pub fn rule_event_name_span(&self, rule: usize) -> Option<Span>
Return the span recorded for the subroutine name a rule’s Subroutine
event binding names, or None for other event kinds and when no
provenance was recorded.
Sourcepub fn condition_value_span(
&self,
rule: usize,
condition: usize,
path: &[usize],
) -> Option<Span>
pub fn condition_value_span( &self, rule: usize, condition: usize, path: &[usize], ) -> Option<Span>
Return the authored span of a value nested inside a public rule condition.
path walks the public Value tree: each element selects a child by
position — Value::Array elements and Value::Call arguments by
index, Value::Vector components as 0/1/2 for x/y/z, and a
Value::PlayerVariable player at 0. An empty path returns the
condition value’s own span, matching condition_span.
For a variable or subroutine reference the identifier span is returned
when the parser recorded one: raw Workshop records the variable name
for Global.name, Global/Player Variable(name), Event Player.name,
bare-name, and ... At Index argument spellings. Other nodes return
the span recorded for the node itself.
Sourcepub fn action_argument_value_span(
&self,
rule: usize,
action: usize,
argument: usize,
path: &[usize],
) -> Option<Span>
pub fn action_argument_value_span( &self, rule: usize, action: usize, argument: usize, path: &[usize], ) -> Option<Span>
Return the authored span of a value nested inside a direct value argument of a public action.
argument selects the same direct argument as
action_argument_span and path walks
into it the way condition_value_span
describes; an empty path returns the argument’s own span. Like
condition_value_span, a variable or subroutine reference returns its
recorded identifier span.
Sourcepub fn edit_source(
&self,
span: Span,
replacement: impl Into<String>,
) -> Result<SourceEdit, SourceEditError>
pub fn edit_source( &self, span: Span, replacement: impl Into<String>, ) -> Result<SourceEdit, SourceEditError>
Create a checked source edit through the authored source attached to this canonical program.
Sourcepub fn validate(&self) -> Result<(), WorkshopError>
pub fn validate(&self) -> Result<(), WorkshopError>
Validate the structural invariants of the canonical program.
Sourcepub fn semantic_issues(&self, catalog: &Catalog) -> Vec<SemanticIssue>
pub fn semantic_issues(&self, catalog: &Catalog) -> Vec<SemanticIssue>
Report constructs that are structurally preserved but not fully understood by the canonical catalog.