Skip to content

Commit

Permalink
Add documentation to specification regions file
Browse files Browse the repository at this point in the history
  • Loading branch information
srhickma committed Dec 23, 2019
1 parent 53dba80 commit 6070132
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/core/spec/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ pub enum RegionType {
}

lazy_static! {
/// The list of required regions in a specification.
static ref REQUIRED_REGIONS: Vec<RegionType> = vec![RegionType::CDFA, RegionType::Grammar];
}

/// Recursively traverses the specification regions under `regions_node`, calling `handler` with
/// the `SpecSymbol::Region` node and type of each region.
///
/// Returns an error if a required specification region is missing, or if `handler` returns an
/// error for any traversed region.
pub fn traverse(
regions_node: &Tree<SpecSymbol>,
handler: &mut dyn FnMut(&Tree<SpecSymbol>, &RegionType) -> Result<(), spec::GenError>,
Expand All @@ -38,6 +44,11 @@ pub fn traverse(
Ok(())
}

/// Recursively traverses the specification regions under `regions_node`, calling `handler` with
/// the `SpecSymbol::Region` node and type of each region, and storing the types of visited regions
/// in the `region_types` accumulator.
///
/// Returns an error if `handler` returns an error for any traversed region.
fn traverse_regions_node(
regions_node: &Tree<SpecSymbol>,
handler: &mut dyn FnMut(&Tree<SpecSymbol>, &RegionType) -> Result<(), spec::GenError>,
Expand All @@ -50,6 +61,11 @@ fn traverse_regions_node(
traverse_region_node(regions_node.children.last().unwrap(), handler, region_types)
}

/// Traverses a single specification region represented by `region_node`, calling `handler` with
/// the associated `SpecSymbol::Region` node and type of the region, and storing the type in the
/// `region_types` accumulator.
///
/// Returns an error if `handler` returns an error for the traversed region.
fn traverse_region_node(
region_node: &Tree<SpecSymbol>,
handler: &mut dyn FnMut(&Tree<SpecSymbol>, &RegionType) -> Result<(), spec::GenError>,
Expand All @@ -64,6 +80,7 @@ fn traverse_region_node(
Ok(())
}

/// Returns the region type associated with the `SpecSymbol::Regions` node `regions_node`.
fn type_from_node(region_node: &Tree<SpecSymbol>) -> RegionType {
let region_symbol = &region_node.get_child(0).lhs.kind();
match region_symbol {
Expand All @@ -76,6 +93,11 @@ fn type_from_node(region_node: &Tree<SpecSymbol>) -> RegionType {
}
}

/// Error: Represents an error encountered when traversing specification regions.
///
/// # Types
///
/// * `MissingRequired` - indicates that a required region is not present.
#[derive(Debug)]
pub enum Error {
MissingRequired(RegionType),
Expand Down

0 comments on commit 6070132

Please sign in to comment.