Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrobeam committed May 6, 2023
0 parents commit 51c7ed8
Show file tree
Hide file tree
Showing 18 changed files with 1,330 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target
150 changes: 150 additions & 0 deletions Cargo.lock

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

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "orgparse"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bitflags = "2.1.0"
derive_more = { version = "0.99.17", features = ["from"] }
phf = {version = "0.11.1", features = ["macros"]}
15 changes: 15 additions & 0 deletions src/element/block.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

use crate::types::{Node, ParseOpts, Parseable, Result};

#[derive(Debug)]
pub struct Block<'a> {
name: &'a str,
data: Option<&'a str>,
contents: &'a str,
}

impl<'a> Parseable<'a> for Block<'a> {
fn parse(byte_arr: &'a [u8], index: usize, parse_opts: ParseOpts) -> Result<Node> {
todo!()
}
}
12 changes: 12 additions & 0 deletions src/element/comment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::types::{Node, ParseOpts, Parseable, Result};

#[derive(Debug)]
pub struct Comment<'a> {
content: &'a str,
}

impl<'a> Parseable<'a> for Comment<'a> {
fn parse(byte_arr: &'a [u8], index: usize, parse_opts: ParseOpts) -> Result<Node> {
todo!()
}
}
32 changes: 32 additions & 0 deletions src/element/heading.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use crate::types::{Node, ParseOpts, Parseable, Result};

// STARS KEYWORD PRIORITY TITLE TAGS
#[derive(Debug)]
pub struct Heading<'a> {
level: u8,
// Org-Todo type stuff
keyword: Option<&'a str>,
priority: Option<char>,
title: Option<Vec<Node<'a>>>,
}

impl<'a> Parseable<'a> for Heading<'a> {
fn parse(byte_arr: &'a [u8], index: usize, parse_opts: ParseOpts) -> Result<Node> {
todo!()
}
}

impl<'a> Heading<'a> {
fn parse_stars() {
todo!()
}
fn parse_keyword() {
todo!()
}
fn parse_priority() {
todo!()
}
fn parse_tag() {
todo!()
}
}
13 changes: 13 additions & 0 deletions src/element/keyword.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use crate::types::{Node, ParseOpts, Parseable, Result};

#[derive(Debug)]
pub struct Keyword<'a> {
key: &'a str,
val: &'a str,
}

impl<'a> Parseable<'a> for Keyword<'a> {
fn parse(byte_arr: &[u8], index: usize, parse_opts: ParseOpts) -> Result<Node> {
todo!()
}
}
11 changes: 11 additions & 0 deletions src/element/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mod block;
mod comment;
mod heading;
mod keyword;
mod paragraph;

pub use comment::Comment;
pub use heading::Heading;
pub use keyword::Keyword;
pub use block::Block;
pub use paragraph::Paragraph;
12 changes: 12 additions & 0 deletions src/element/paragraph.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
use crate::types::{Node, ParseOpts, Parseable, Result};

#[derive(Debug)]
pub struct Paragraph<'a> {
pub contents: Vec<Node<'a>>
}

impl<'a> Parseable<'a> for Paragraph<'a> {
fn parse(byte_arr: &'a [u8], index: usize, parse_opts: ParseOpts) -> Result<Node> {
todo!()
}
}
126 changes: 126 additions & 0 deletions src/inline_src.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
// use std::cell::RefCell;
// use std::rc::Rc;
// use Node::*;

// use crate::constants::*;
// use crate::types::{Match, MatchError, Node, ParseOpts, Parseable, Result};
// use crate::utils::{bytes_to_str, fn_until, word};

// #[derive(Debug)]
// pub struct InlineSrc<'a> {
// lang: &'a str,
// headers: Option<&'a str>,
// body: &'a str,
// }

// // pub fn create_node(node: Match<Node>) -> Match<Node> {
// // return Match {
// // obj: "meow",
// // start: 1,
// // end: 2
// // }
// // }


// impl<'a> Parseable<'a> for InlineSrc<'a> {
// fn parse(byte_arr: &'a [u8], index: usize, parse_opts: ParseOpts) -> Result<Node> {
// // TODO: cache this
// let src_word = word(byte_arr, index, "src_")?;

// let lang = fn_until(byte_arr, src_word.end, |chr: u8| {
// !(chr == b'[' || chr == b'{' || chr.is_ascii_whitespace())
// })?;

// match byte_arr[lang.end] {
// LBRACE => {
// let body = Self::parse_body(byte_arr, index)?;
// Ok(ParseNode::new(Match {
// obj: Node::InlineSrc(Self {
// lang: lang.obj,
// headers: None,
// body: body.obj,
// }),
// start: index,
// end: body.end,
// }))

// // Ok(ParseNode::new(Match {
// // obj: InlineSrc {
// // lang: "meow",
// // headers: None,
// // body: "cu,",
// // },
// // start: 1,
// // end: 5,
// // }))
// }
// LBRACK => {
// let header = Self::parse_header(byte_arr, lang.end)?;
// if byte_arr[header.end] != LBRACE {
// Err(MatchError)
// } else {
// let body = Self::parse_body(byte_arr, index)?;
// Ok(ParseNode::new(Match {
// obj: Node::InlineSrc(Self {
// lang: lang.obj,
// headers: Some(header.obj),
// body: body.obj,
// }),
// start: index,
// end: body.end,
// }))
// }
// }
// _ => return Err(MatchError),
// }
// }
// }

// impl<'a> InlineSrc<'a> {
// // the logic is exactly the same, except for the perimeters
// fn parse_header(byte_arr: &'a [u8], index: usize) -> Result<Match<&'a str>> {
// InlineSrc::parse_src(byte_arr, index, LBRACK, RBRACK)
// }
// fn parse_body(byte_arr: &'a [u8], index: usize) -> Result<Match<&'a str>> {
// InlineSrc::parse_src(byte_arr, index, LBRACE, RBRACE)
// }
// #[inline(always)]
// fn parse_src(
// byte_arr: &'a [u8],
// index: usize,
// lperim: u8,
// rperim: u8,
// ) -> Result<Match<&'a str>> {
// // Brackets have to be balanced
// // -1 for left bracket
// // +1 for right bracket
// let mut bracket_count: i32 = 0;

// let mut j: usize = index;

// loop {
// match byte_arr[j] {
// chr if chr == lperim => {
// bracket_count -= 1;
// }
// chr if chr == rperim => {
// bracket_count += 1;
// if bracket_count == 0 {
// let start = index;
// let end = j + 1;
// return Ok(Match {
// obj: bytes_to_str(&byte_arr[start..end]),
// start,
// end,
// });
// }
// }
// NEWLINE => {
// return Err(MatchError);
// }
// _ => {}
// }
// j += 1;
// }
// }
// }
Loading

0 comments on commit 51c7ed8

Please sign in to comment.