Skip to content

Commit

Permalink
fix lifetimes and make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdotink committed Feb 3, 2024
1 parent 452c365 commit 5ee420d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
8 changes: 1 addition & 7 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,14 @@ struct Args {
mode: Option<String>,
}

// this is stupid - but I dont want more messy
// lifetimes and its like 100 bytes once at most
fn string_to_static_str(s: String) -> &'static str {
Box::leak(s.into_boxed_str())
}

fn main() -> Result<()> {
let args = Args::parse();

let config_path = args.config.unwrap();

let config = std::fs::read_to_string(&config_path)?;

let ret = run(config.as_str(), args.mode.map(string_to_static_str));
let ret = run(config.as_str(), args.mode.as_deref());

let code = ret.code;
let diagnostics = ret.diagnostics;
Expand Down
2 changes: 1 addition & 1 deletion zap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub struct Return {
}

#[cfg(not(target_arch = "wasm32"))]
pub fn run(input: &str, mode: Option<&'static str>) -> Return {
pub fn run(input: &str, mode: Option<&str>) -> Return {
let (config, reports) = parser::parse(input, mode);

if let Some(config) = config {
Expand Down
10 changes: 5 additions & 5 deletions zap/src/parser/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{reports::Report, syntax_tree::*};

struct Converter<'src> {
config: SyntaxConfig<'src>,
mode: Option<&'static str>,
mode: Option<&'src str>,

tydecls: HashMap<&'src str, SyntaxTyDecl<'src>>,
max_unreliable_size: usize,
Expand All @@ -17,7 +17,7 @@ struct Converter<'src> {
}

impl<'src> Converter<'src> {
fn new(config: SyntaxConfig<'src>, mode: Option<&'static str>) -> Self {
fn new(config: SyntaxConfig<'src>, mode: Option<&'src str>) -> Self {
let mut tydecls = HashMap::new();
let mut ntdecls = 0;

Expand Down Expand Up @@ -263,7 +263,7 @@ impl<'src> Converter<'src> {

"queue" => {
if let SyntaxOptValueKind::Call(name, args) = &opt.kind {
let arg = if let Some(arg) = args.get(0) {
let arg = if let Some(arg) = args.first() {
if let SyntaxOptValueKind::Num(num) = arg.kind {
Self::num(&num)
} else {
Expand Down Expand Up @@ -331,7 +331,7 @@ impl<'src> Converter<'src> {

"yield" => {
if let SyntaxOptValueKind::Call(name, args) = &opt.kind {
let arg = if let Some(arg) = args.get(0) {
let arg = if let Some(arg) = args.first() {
if let SyntaxOptValueKind::Str(str) = arg.kind {
Self::str(&str)
} else {
Expand Down Expand Up @@ -804,6 +804,6 @@ impl<'src> Converter<'src> {
}
}

pub fn convert<'src>(config: SyntaxConfig<'src>, mode: Option<&'static str>) -> (Config<'src>, Vec<Report<'src>>) {
pub fn convert<'src>(config: SyntaxConfig<'src>, mode: Option<&'src str>) -> (Config<'src>, Vec<Report<'src>>) {
Converter::new(config, mode).convert()
}
2 changes: 1 addition & 1 deletion zap/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ mod syntax_tree;

lalrpop_mod!(pub grammar);

pub fn parse<'src>(input: &'src str, mode: Option<&'static str>) -> (Option<Config<'src>>, Vec<Report<'src>>) {
pub fn parse<'src>(input: &'src str, mode: Option<&'src str>) -> (Option<Config<'src>>, Vec<Report<'src>>) {
let parse_result = grammar::ConfigParser::new().parse(input);

if let Ok(syntax_config) = parse_result {
Expand Down

0 comments on commit 5ee420d

Please sign in to comment.