Skip to content

Commit

Permalink
some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 13, 2024
1 parent 0e8f668 commit 61b5021
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 37 deletions.
12 changes: 1 addition & 11 deletions v0.5/fastn-section/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ mod warning;
mod wiggin;

pub use error::Error;
pub use fastn_section::parser::header_value::header_value;
pub use fastn_section::parser::identifier::identifier;
pub use fastn_section::parser::kind::kind;
pub use fastn_section::parser::kinded_name::kinded_name;
pub use fastn_section::parser::module_name::module_name;
pub use fastn_section::parser::package_name::package_name;
pub use fastn_section::parser::qualified_identifier::qualified_identifier;
pub use fastn_section::parser::section::section;
pub use fastn_section::parser::section_init::section_init;
pub use fastn_section::warning::Warning;
pub use scanner::{Scannable, Scanner};

Expand Down Expand Up @@ -80,8 +71,7 @@ pub struct Section {
pub caption: Option<fastn_section::HeaderValue>,
pub headers: Vec<Header>,
pub body: Option<fastn_section::HeaderValue>,
pub children: Vec<Section>, // TODO: this must be `Spanned<Section>`
pub sub_sections: Vec<fastn_section::Spanned<Section>>,
pub children: Vec<Section>,
pub function_marker: Option<fastn_section::Span>,
pub is_commented: bool,
// if the user used `-- end: <section-name>` to end the section
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-section/src/parser/kind.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub fn kind(
scanner: &mut fastn_section::Scanner<fastn_section::Document>,
) -> Option<fastn_section::Kind> {
let qi = match fastn_section::qualified_identifier(scanner) {
let qi = match fastn_section::parser::qualified_identifier(scanner) {
Some(qi) => qi,
None => return None,
};
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-section/src/parser/kinded_name.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub fn kinded_name(
scanner: &mut fastn_section::Scanner<fastn_section::Document>,
) -> Option<fastn_section::KindedName> {
let kind = fastn_section::kind(scanner);
let kind = fastn_section::parser::kind(scanner);
scanner.skip_spaces();

let name = match fastn_section::identifier(scanner) {
let name = match fastn_section::parser::identifier(scanner) {
Some(v) => v,
None => {
return kind.and_then(Into::into);
Expand Down
32 changes: 21 additions & 11 deletions v0.5/fastn-section/src/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
pub(super) mod header_value;
pub(super) mod identifier;
pub(super) mod kind;
pub(super) mod kinded_name;
pub(super) mod module_name;
pub(super) mod package_name;
pub(super) mod qualified_identifier;
pub(super) mod section;
pub(super) mod section_init;
pub(super) mod visibility;
mod header_value;
mod identifier;
mod kind;
mod kinded_name;
mod module_name;
mod package_name;
mod qualified_identifier;
mod section;
mod section_init;
mod visibility;

pub use header_value::header_value;
pub use identifier::identifier;
pub use kind::kind;
pub use kinded_name::kinded_name;
pub use module_name::module_name;
pub use package_name::package_name;
pub use qualified_identifier::qualified_identifier;
pub use section::section;
pub use section_init::section_init;

impl fastn_section::Document {
pub fn parse(source: &str) -> fastn_section::Document {
Expand All @@ -24,7 +34,7 @@ impl fastn_section::Document {
pub fn document(scanner: &mut fastn_section::Scanner<fastn_section::Document>) {
// TODO: parse module_doc, comments etc
scanner.skip_spaces();
while let Some(section) = fastn_section::section(scanner) {
while let Some(section) = fastn_section::parser::section(scanner) {
scanner.skip_spaces();
scanner.skip_new_lines();
scanner.skip_spaces();
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-section/src/parser/module_name.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub fn module_name(
scanner: &mut fastn_section::Scanner<fastn_section::Document>,
) -> Option<fastn_section::ModuleName> {
let package = fastn_section::package_name(scanner)?;
let package = fastn_section::parser::package_name(scanner)?;
if !scanner.take('/') {
return Some(fastn_section::ModuleName {
name: package.alias.clone().into(),
Expand All @@ -12,7 +12,7 @@ pub fn module_name(

let mut path = {
let mut path = Vec::new();
while let Some(identifier) = fastn_section::identifier(scanner) {
while let Some(identifier) = fastn_section::parser::identifier(scanner) {
path.push(identifier);
if !scanner.take('/') {
break;
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-section/src/parser/qualified_identifier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub fn qualified_identifier(
scanner: &mut fastn_section::Scanner<fastn_section::Document>,
) -> Option<fastn_section::QualifiedIdentifier> {
let module = match fastn_section::module_name(scanner) {
let module = match fastn_section::parser::module_name(scanner) {
Some(module) => match scanner.peek() {
Some('#') => {
scanner.pop();
Expand All @@ -19,7 +19,7 @@ pub fn qualified_identifier(

let terms = {
let mut terms = Vec::new();
while let Some(identifier) = fastn_section::identifier(scanner) {
while let Some(identifier) = fastn_section::parser::identifier(scanner) {
terms.push(identifier);
if !scanner.take('.') {
break;
Expand Down
7 changes: 3 additions & 4 deletions v0.5/fastn-section/src/parser/section.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
pub fn section(
scanner: &mut fastn_section::Scanner<fastn_section::Document>,
) -> Option<fastn_section::Section> {
let section_init = fastn_section::section_init(scanner)?;
let section_init = fastn_section::parser::section_init(scanner)?;

scanner.skip_spaces();
let caption = fastn_section::header_value(scanner);
let caption = fastn_section::parser::header_value(scanner);

// TODO: implement headers, body, children, sub-sections
// TODO: implement headers, body
Some(fastn_section::Section {
init: section_init,
caption,
headers: vec![],
body: None,
children: vec![],
sub_sections: vec![],
function_marker: None,
is_commented: false,
has_end: false,
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-section/src/parser/section_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn section_init(
scanner.skip_spaces();
let dashdash = scanner.token("--")?;
scanner.skip_spaces();
let name = fastn_section::kinded_name(scanner)?;
let name = fastn_section::parser::kinded_name(scanner)?;
scanner.skip_spaces();
let colon = scanner.token(":")?;
Some(fastn_section::SectionInit {
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-unresolved/src/parser/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub(super) fn import(

// ensure there are no extra headers, children or body
fastn_unresolved::utils::assert_no_body(&section, document);
fastn_unresolved::utils::assert_no_sub_sections(&section, document);
fastn_unresolved::utils::assert_no_children(&section, document);
fastn_unresolved::utils::assert_no_extra_headers(
source,
&section,
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-unresolved/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ pub(crate) fn assert_no_body(
true
}

pub(crate) fn assert_no_sub_sections(
pub(crate) fn assert_no_children(
section: &fastn_section::Section,
document: &mut fastn_unresolved::Document,
) -> bool {
if !section.sub_sections.is_empty() {
if !section.children.is_empty() {
document.errors.push(
section
.init
Expand Down

0 comments on commit 61b5021

Please sign in to comment.