Skip to content

Commit

Permalink
wip: partial AST implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
themixednuts committed Jan 12, 2025
1 parent 114760c commit 69ab8b3
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 317 deletions.
53 changes: 53 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ human-repr = "1.1.0"
fancy-duration = "0.9.2"
indexmap = "2.7.0"
nom_locate = "4.2.0"
nom-supreme = "0.8.0"
nom-span = "0.1.2"
2 changes: 2 additions & 0 deletions metadata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ edition = "2021"
[dependencies]
nom = { workspace = true }
nom_locate = { workspace = true }
nom-supreme = { workspace = true }
encoding_rs = { workspace = true }
indexmap = { workspace = true }
nom-span = { workspace = true }
26 changes: 7 additions & 19 deletions metadata/src/ao.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
mod ast;

use crate::{
core::{
bom, expr_block, extends, is_abstract,
tokens::{Expr, ExprBlock, Span},
version,
},
visitor::Visitor,
use crate::core::{
bom, expr, extends, is_abstract,
tokens::{Expr, Span},
version,
};
use nom::{combinator::opt, multi::many0, sequence::Tuple, IResult};

pub fn parse_ao<'a>(input: Span<'a>) -> IResult<Span<'a>, AO<'a>> {
(
opt(bom),
version,
opt(is_abstract),
extends,
many0(expr_block),
)
(opt(bom), version, opt(is_abstract), extends, many0(expr))
.parse(input)
.map(|(input, (_, version, is_abstract, extends, blocks))| {
(
Expand All @@ -40,7 +31,7 @@ pub struct AO<'a> {
version: u32,
is_abstract: bool,
extends: Option<Span<'a>>,
children: Vec<ExprBlock<'a>>,
children: Vec<Expr<'a>>,
}

// impl AO<'_> {
Expand Down Expand Up @@ -103,7 +94,7 @@ mod tests {
let src = include_bytes!("../resources/character.aoc");
let src = read_string_from_utf16(src);

// let (input, ao) = parse_ao(Span::new(&src)).unwrap();
// let (input, ao) = parse_ao(Span::new(&src, false)).unwrap();
// dbg!(&ao);

// assert_eq!(ao.version, 2);
Expand All @@ -116,9 +107,6 @@ mod tests {
let src = include_bytes!("../resources/gravestoneamuletheld.aoc");
let src = read_string_from_utf16(src);

let (input, ao) = parse_ao(Span::new(&src)).unwrap();
dbg!(&ao);

// assert_eq!(ao.version, 2);
// assert_eq!(ao.is_abstract, false);
// assert_eq!(ao.extends, Some("Metadata/Parent"));
Expand Down
Loading

0 comments on commit 69ab8b3

Please sign in to comment.