Skip to content

Commit

Permalink
Fix: strip " and ' from the lisp variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
Atreyagaurav committed Jan 6, 2024
1 parent f255106 commit c6191e7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "string-template-plus"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
authors = ["Gaurav Atreya"]
description = "Render string template with more options"
Expand Down
2 changes: 1 addition & 1 deletion PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Maintainer: Gaurav Atreya <allmanpride@gmail.com>
pkgname=string-template-plus
pkgver=0.4.1
pkgver=0.4.2
pkgrel=1
pkgdesc="String Template with extra functionalities"
arch=('x86_64')
Expand Down
12 changes: 6 additions & 6 deletions src/bin/stp-visualize.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::env;
use std::error::Error;
use std::{collections::HashSet, env};
use string_template_plus::{Render, Template};

fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -14,11 +14,11 @@ fn main() -> Result<(), Box<dyn Error>> {
let templ = Template::parse_template(&contents)?;
templ.print();
println!();
println!("--------");
let vars: HashSet<&str> = templ.parts().iter().flat_map(|p| p.variables()).collect();
println!("Variables: {:?}", vars);
println!("--------");
println!("{:?}", templ.parts());
// println!("--------");
// let vars: HashSet<&str> = templ.parts().iter().flat_map(|p| p.variables()).collect();
// println!("Variables: {:?}", vars);
// println!("--------");
// println!("{:#?}", templ.parts());
}
Ok(())
}
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,8 +370,17 @@ impl TemplatePart {
let variables = part
.match_indices("(st+")
.filter_map(|(loc, _)| {
let end = Self::find_end(')', &part, loc).ok()? - 1;
part[loc..end].find(' ').map(|s| (s + 1 + loc, end))
let end = Self::find_end(')', &part, loc + 1).ok()?;
part[loc..end].find(' ').map(|s| {
let p = &part[(s + 1 + loc)..end];
if p.starts_with('"') {
(s + 2 + loc, end - 1)
} else if p.starts_with('\'') {
(s + 2 + loc, end)
} else {
(s + 1 + loc, end)
}
})
})
.collect();
Self::Lisp(part, fstr, variables)
Expand Down
2 changes: 1 addition & 1 deletion templates/test5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
see $(some-command --flag "and the value" {problem}) =(+ 1 2 (st+num hithere)) {otherhi?=(1+ pi):f(4)}
see $(some-command --flag "and the value" {problem}) =(+ 1 2 (st+num 'hithere) (st+num "otherhi")) {otherhi?=(1+ pi):f(4)}

0 comments on commit c6191e7

Please sign in to comment.