Skip to content

Commit

Permalink
update Pattern api, name elided lifetimes, bump version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Demonstrandum committed Nov 21, 2024
1 parent 9a5ca5c commit 85fe33d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ description = "Symbolic Expressions As Markup."
keywords = ["markup", "lisp", "macro", "symbolic-expression", "sexp"]
license-file = "LICENSE"
homepage = "https://git.knutsen.co/seam"
version = "0.2.5"
version = "0.2.6"
authors = ["Demonstrandum <samuel@knutsen.co>"]
edition = "2021"

Expand Down
13 changes: 12 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@ use parse::{expander, parser, lexer};

use std::{fs, io, path::Path};

pub const VERSION: (u8, u8, u8) = (0, 2, 4);
const fn parse_u8(s: &str) -> u8 {
match u8::from_str_radix(s, 10) {
Ok(n) => n,
Err(_) => panic!("is not a base 10 integer"),
}
}

pub const VERSION: (u8, u8, u8) = (
parse_u8(env!("CARGO_PKG_VERSION_MAJOR")),
parse_u8(env!("CARGO_PKG_VERSION_MINOR")),
parse_u8(env!("CARGO_PKG_VERSION_PATCH")),
);

pub fn tree_builder<'a, P: AsRef<Path>>(source_path: Option<P>, string: String)
-> expander::Expander<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'a> Lexer {
}

/// Check if source-code at current possition starts with a pattern.
fn starts_with<P>(&'a self, pat: P) -> bool where P: Pattern<'a> {
fn starts_with<P>(&self, pat: P) -> bool where P: Pattern {
self.source[self.byte_offset.get()..].starts_with(pat)
}

Expand Down
12 changes: 6 additions & 6 deletions src/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<'a> Parser {
}

/// Parse whole source code, finishing off the lexer.
pub fn parse(&'a self) -> Result<ParseTree, Box<dyn Error + 'a>> {
pub fn parse(&'a self) -> Result<ParseTree<'a>, Box<dyn Error + 'a>> {
let mut root: Vec<ParseNode> = Vec::new();
while !self.lexer.eof() {
let expr = self.parse_expr()?;
Expand All @@ -157,7 +157,7 @@ impl<'a> Parser {
}

/// Produce a parse node from the current position in the lexer.
pub fn parse_expr(&'a self) -> Result<ParseNode, Box<dyn Error + 'a>> {
pub fn parse_expr(&'a self) -> Result<ParseNode<'a>, Box<dyn Error + 'a>> {
let token = self.lexer.peek()?;
match token.kind {
Kind::LParen => self.parse_list(),
Expand All @@ -173,7 +173,7 @@ impl<'a> Parser {
}

/// Parse keyword-attribute pair.
fn parse_keyword(&'a self) -> Result<ParseNode, Box<dyn Error + 'a>> {
fn parse_keyword(&'a self) -> Result<ParseNode<'a>, Box<dyn Error + 'a>> {
// Consume :keyword token.
let token = self.lexer.consume()?;
assert_eq!(token.kind, Kind::Keyword);
Expand Down Expand Up @@ -276,7 +276,7 @@ pub trait SearchTree<'a> {
fn search_node(&'a self, kind: SearchType,
value: &str,
case_insensitive: bool,
level: usize) -> Option<&ParseNode<'a>>;
level: usize) -> Option<&'a ParseNode<'a>>;
}

#[derive(Clone, Copy, PartialEq)]
Expand All @@ -295,7 +295,7 @@ impl SearchType {

impl<'a> SearchTree<'a> for ParseNode<'a> {
fn search_node(&'a self, kind: SearchType, value: &str,
insensitive: bool, level: usize) -> Option<&ParseNode<'a>> {
insensitive: bool, level: usize) -> Option<&'a ParseNode<'a>> {
if level == 0 {
return None;
}
Expand Down Expand Up @@ -352,7 +352,7 @@ impl<'a> SearchTree<'a> for ParseNode<'a> {

impl<'a> SearchTree<'a> for ParseTree<'a> {
fn search_node(&'a self, kind: SearchType, value: &str,
insensitive: bool, level: usize) -> Option<&ParseNode<'a>> {
insensitive: bool, level: usize) -> Option<&'a ParseNode<'a>> {
if level == 0 {
return None;
}
Expand Down

0 comments on commit 85fe33d

Please sign in to comment.