Skip to content

Commit

Permalink
re-arranging code
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu committed Nov 3, 2024
1 parent 0237152 commit 502d760
Show file tree
Hide file tree
Showing 39 changed files with 545 additions and 424 deletions.
16 changes: 16 additions & 0 deletions v0.5/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions v0.5/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[workspace]
members = [
"fastn",
"fastn-lang",
"fastn-router",
"fastn-section",
]
exclude = []
resolver = "2"
Expand Down
13 changes: 8 additions & 5 deletions v0.5/fastn-lang/src/compiler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
pub struct Compiler {
unresolved:
std::collections::HashMap<fastn_lang::token::Identifier, fastn_lang::parse::Definition>,
resolved: std::collections::HashMap<fastn_lang::token::Identifier, fastn_lang::ast::Definition>,
unresolved: std::collections::HashMap<
fastn_section::token::Identifier,
fastn_section::parse::Definition,
>,
resolved:
std::collections::HashMap<fastn_section::token::Identifier, fastn_section::ast::Definition>,
}

enum CompilerState {
Done(Compiler),
StuckOnDocuments(Compiler, Vec<fastn_lang::Span>),
StuckOnDocuments(Compiler, Vec<fastn_section::Span>),
}

impl Compiler {
Expand All @@ -17,7 +20,7 @@ impl Compiler {
pub fn continue_after_documents(
self,
_source: &str,
_documents: std::collections::HashMap<fastn_lang::Span, &str>,
_documents: std::collections::HashMap<fastn_section::Span, &str>,
) -> CompilerState {
todo!()
}
Expand Down
12 changes: 2 additions & 10 deletions v0.5/fastn-lang/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ mod debug;
mod error;
mod parse;
mod scanner;
mod token;
mod warning;

pub use error::Error;
pub use scanner::{Scannable, Scanner};
pub use warning::Warning;
// fastn_lang::Section is used in more than one place, so it is at the top level.
pub use token::Section;
// fastn_section::Section is used in more than one place, so it is at the top level.
pub use fastn_section::Section;

/// public | private | public<package> | public<module>
///
Expand All @@ -36,13 +35,6 @@ pub enum Visibility {
Private,
}

pub type Span = std::ops::Range<usize>;
#[derive(Debug, PartialEq, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct Spanned<T> {
pub span: Span,
pub value: T,
}

#[derive(Default, Debug)]
pub struct Fuel {
#[allow(dead_code)]
Expand Down
32 changes: 16 additions & 16 deletions v0.5/fastn-lang/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,36 @@ pub use parser::parse;

#[derive(Debug, Clone, Default, serde::Serialize, serde::Deserialize)]
pub struct Document {
pub module_doc: Option<fastn_lang::Span>,
pub imports: Vec<fastn_lang::parse::Import>,
pub definitions: std::collections::HashMap<fastn_lang::token::Identifier, Definition>,
pub content: Vec<fastn_lang::Section>,
pub errors: Vec<fastn_lang::Spanned<fastn_lang::Error>>,
pub warnings: Vec<fastn_lang::Spanned<fastn_lang::Warning>>,
pub comments: Vec<fastn_lang::Span>,
pub module_doc: Option<fastn_section::Span>,
pub imports: Vec<fastn_section::parse::Import>,
pub definitions: std::collections::HashMap<fastn_section::token::Identifier, Definition>,
pub content: Vec<fastn_section::Section>,
pub errors: Vec<fastn_section::Spanned<fastn_section::Error>>,
pub warnings: Vec<fastn_section::Spanned<fastn_section::Warning>>,
pub comments: Vec<fastn_section::Span>,
pub line_starts: Vec<usize>,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub enum Definition {
Component(fastn_lang::Section),
Variable(fastn_lang::Section),
Function(fastn_lang::Section),
TypeAlias(fastn_lang::Section),
Record(fastn_lang::Section),
OrType(fastn_lang::Section),
Module(fastn_lang::Section),
Component(fastn_section::Section),
Variable(fastn_section::Section),
Function(fastn_section::Section),
TypeAlias(fastn_section::Section),
Record(fastn_section::Section),
OrType(fastn_section::Section),
Module(fastn_section::Section),
}

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct Import {
pub module: fastn_lang::token::ModuleName,
pub module: fastn_section::token::ModuleName,
pub exports: Option<Export>,
pub exposing: Option<Export>,
}

#[derive(Debug, Clone, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum Export {
All,
Things(Vec<fastn_lang::token::AliasableIdentifier>),
Things(Vec<fastn_section::token::AliasableIdentifier>),
}
6 changes: 3 additions & 3 deletions v0.5/fastn-lang/src/parse/parser/import.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pub(super) fn import(
_source: &str,
section: fastn_lang::token::Section,
_document: &mut fastn_lang::parse::Document,
section: fastn_section::token::Section,
_document: &mut fastn_section::parse::Document,
) {
if let Some(_kind) = section.init.name.kind {
// document.errors.push(fastn_lang::Error::ImportCantHaveType);
// document.errors.push(fastn_section::Error::ImportCantHaveType);
todo!()
}
// section.name must be exactly import.
Expand Down
4 changes: 2 additions & 2 deletions v0.5/fastn-lang/src/parse/parser/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod import;

pub fn parse(source: &str) -> fastn_lang::parse::Document {
pub fn parse(source: &str) -> fastn_section::parse::Document {
let (mut document, sections) =
fastn_lang::parse::Document::new(fastn_lang::token::Document::parse(source));
fastn_section::parse::Document::new(fastn_section::token::Document::parse(source));
// guess the section and call the appropriate parse method.
for section in sections.into_iter() {
let name = section.name(source).to_ascii_lowercase();
Expand Down
8 changes: 4 additions & 4 deletions v0.5/fastn-lang/src/parse/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
impl fastn_lang::parse::Document {
impl fastn_section::parse::Document {
pub fn new(
document: fastn_lang::token::Document,
) -> (fastn_lang::parse::Document, Vec<fastn_lang::Section>) {
document: fastn_section::token::Document,
) -> (fastn_section::parse::Document, Vec<fastn_section::Section>) {
(
fastn_lang::parse::Document {
fastn_section::parse::Document {
module_doc: document.module_doc,
imports: vec![],
definitions: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-lang/src/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v0.5/fastn-lang/src/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: fastn-p1/src/lib.rs
assertion_line: 182
expression: "fastn_lang::ParseOutput::parse(\"foo\", &s).debug(&s)"
expression: "fastn_section::ParseOutput::parse(\"foo\", &s).debug(&s)"
input_file: fastn-p1/t/000-tutorial.ftd
---
doc_name: foo
Expand Down
2 changes: 1 addition & 1 deletion v0.5/fastn-lang/src/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v0.5/fastn-lang/src/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v0.5/fastn-lang/src/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v0.5/fastn-lang/src/snapshots/[email protected]

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion v0.5/fastn-lang/src/snapshots/[email protected]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
source: fastn-p1/src/lib.rs
assertion_line: 182
expression: "fastn_lang::ParseOutput::parse(\"foo\", &s).debug(&s)"
expression: "fastn_section::ParseOutput::parse(\"foo\", &s).debug(&s)"
input_file: fastn-p1/t/004-simple-section.ftd
---
doc_name: foo
Expand Down
26 changes: 0 additions & 26 deletions v0.5/fastn-lang/src/token/parser/kinded_name.rs

This file was deleted.

Loading

0 comments on commit 502d760

Please sign in to comment.