Skip to content

Commit

Permalink
some wip refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 2, 2024
1 parent c7fd3b6 commit 9173ffc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion v0.5/fastn-lang/src/section/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub struct Section {
pub sub_sections: Vec<fastn_lang::Spanned<Section>>,
pub function_marker: Option<fastn_lang::Span>,
pub is_commented: bool,
pub has_ended: bool,
// if the user used `-- end: <section-name>` to end the section
pub has_end: bool,
}

/// example: `-- list<string> foo:`
Expand Down
24 changes: 17 additions & 7 deletions v0.5/fastn-lang/src/section/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ impl From<fastn_lang::section::Kind> for Option<fastn_lang::section::KindedName>
}

pub fn extend_span(span: &mut Option<fastn_lang::Span>, other: fastn_lang::Span) {
if let Some(s) = span {
s.extend(other);
if let Some(_s) = span {
// s.extend(other);
todo!()
} else {
*span = Some(other);
}
Expand All @@ -71,14 +72,23 @@ pub fn extend_spanned<T>(span: &mut Option<fastn_lang::Span>, other: &fastn_lang

impl fastn_lang::section::Kind {
fn span(&self) -> fastn_lang::Span {
let mut span = self.doc.clone();
extend_spanned(&mut span, &self.visibility);

span.unwrap()
todo!()
// let mut span = self.doc.clone();
// extend_spanned(&mut span, &self.visibility);
//
// span.unwrap()
}
}

impl fastn_lang::Section {}
impl fastn_lang::Section {
pub fn full_name_with_kind<'input>(&self, source: &'input str) -> &'input str {
todo!()
}

pub fn kind_name<'input>(&self, source: &'input str) -> &'input str {
todo!()
}
}

impl fastn_lang::section::Kind {
pub fn attach_doc(&mut self, doc: fastn_lang::Span) {
Expand Down
12 changes: 5 additions & 7 deletions v0.5/fastn-lang/src/section/wiggin.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
#![allow(dead_code)]

use std::fmt::Debug;

/// calls `inner_ender` for all the embedded section inside section in the
/// list and then calls `ender` for the list itself
pub fn ender(
Expand Down Expand Up @@ -134,7 +130,7 @@ enum Mark<'input> {

/// we are using a proxy trait so we can write tests against a fake type, and then implement the
/// trait for the real Section type
trait SectionProxy: Sized + Debug {
trait SectionProxy: Sized + std::fmt::Debug {
/// returns the name of the section, and if it starts or ends the section
fn mark<'input>(&'input self, source: &'input str) -> Result<Mark<'input>, fastn_lang::Error>;
fn add_children(&mut self, children: Vec<Self>);
Expand Down Expand Up @@ -193,14 +189,16 @@ impl SectionProxy for fastn_lang::Section {

fn add_children(&mut self, children: Vec<Self>) {
self.children = children;
// TODO: check this logic (even empty sections with end should have this set)
self.has_end = true;
}

fn end_section(&mut self) {
self.has_ended = true;
self.has_end = true;
}

fn has_ended(&self) -> bool {
self.has_ended
self.has_end
}

fn span(&self) -> fastn_lang::Span {
Expand Down
9 changes: 5 additions & 4 deletions v0.5/fastn-lang/src/unresolved/parser/import.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
pub fn import(
source: &str,
_source: &str,
section: fastn_lang::section::Section,
document: &mut fastn_lang::unresolved::Document,
_document: &mut fastn_lang::unresolved::Document,
) -> Option<fastn_lang::unresolved::Import> {
if let Some(kind) = section.init.name.kind {
document.errors.push(fastn_lang::Error::ImportCantHaveType);
if let Some(_kind) = section.init.name.kind {
// document.errors.push(fastn_lang::Error::ImportCantHaveType);
todo!()
}
// section.name must be exactly import.
// section.caption must be single text block, parsable as a module-name.
Expand Down

0 comments on commit 9173ffc

Please sign in to comment.