Skip to content

Commit

Permalink
upgrade parser; bump 0.4.33
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Sep 19, 2021
1 parent faa5e4f commit 9a9e0fe
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 69 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calcit_runner"
version = "0.4.32"
version = "0.4.33"
authors = ["jiyinyiyong <jiyinyiyong@gmail.com>"]
edition = "2018"
license = "MIT"
Expand All @@ -21,8 +21,8 @@ exclude = [

[dependencies]
chrono = "0.4.19"
cirru_edn = "0.1.5"
cirru_parser = "0.1.1"
cirru_edn = "0.1.6"
cirru_parser = "0.1.2"
clap = "2.33.3"
dirs = "3.0.1"
im = "15.0.0"
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@calcit/procs",
"version": "0.4.32",
"version": "0.4.33",
"main": "./lib/calcit.procs.js",
"devDependencies": {
"@types/node": "^16.7.10",
Expand Down
90 changes: 44 additions & 46 deletions src/bin/bundle_calcit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,59 +54,57 @@ pub fn main() -> io::Result<()> {
if let Some(ext) = entry.path().extension() {
if ext.to_str().unwrap() == "cirru" {
let content = read_to_string(entry.path())?;
let file_data = cirru_parser::parse(&content).map_err(io_err)?;
if let Cirru::List(xs) = file_data {
let mut file: HashMap<Edn, Edn> = HashMap::new();
let (ns_name, ns_code) = if let Some(Cirru::List(ns_form)) = xs.get(0) {
match (ns_form.get(0), ns_form.get(1)) {
(Some(Cirru::Leaf(x0)), Some(Cirru::Leaf(x1))) if x0.as_str() == "ns" => (x1.to_string(), ns_form),
(a, b) => return Err(io_err(format!("in valid ns starts {:?} {:?}", a, b))),
}
} else {
return Err(io_err(format!(
"first expression of file should be a ns form, got: {:?}",
xs.get(0)
)));
};
file.insert(
Edn::Keyword(String::from("ns")),
Edn::Quote(Cirru::List(ns_code.to_owned())),
);

let mut defs: HashMap<Edn, Edn> = HashMap::new();
for (idx, line) in xs.iter().enumerate() {
if idx > 0 {
if let Cirru::List(ys) = line {
match (ys.get(0), ys.get(1)) {
(Some(Cirru::Leaf(x0)), Some(Cirru::Leaf(x1))) => {
if x0 == "def"
|| x0 == "defn"
|| x0 == "defmacro"
|| x0 == "defatom"
|| x0 == "defrecord"
|| x0.starts_with("def")
{
defs.insert(Edn::Str(x1.to_owned()), Edn::Quote(line.to_owned()));
} else {
return Err(io_err(format!("invalid def op: {}", x0)));
}
}
(a, b) => {
return Err(io_err(format!("invalid def code {:?} {:?}", a, b)));
let xs = cirru_parser::parse(&content).map_err(io_err)?;

let mut file: HashMap<Edn, Edn> = HashMap::new();
let (ns_name, ns_code) = if let Some(Cirru::List(ns_form)) = xs.get(0) {
match (ns_form.get(0), ns_form.get(1)) {
(Some(Cirru::Leaf(x0)), Some(Cirru::Leaf(x1))) if x0.as_str() == "ns" => (x1.to_string(), ns_form),
(a, b) => return Err(io_err(format!("in valid ns starts {:?} {:?}", a, b))),
}
} else {
return Err(io_err(format!(
"first expression of file should be a ns form, got: {:?}",
xs.get(0)
)));
};
file.insert(
Edn::Keyword(String::from("ns")),
Edn::Quote(Cirru::List(ns_code.to_owned())),
);

let mut defs: HashMap<Edn, Edn> = HashMap::new();
for (idx, line) in xs.iter().enumerate() {
if idx > 0 {
if let Cirru::List(ys) = line {
match (ys.get(0), ys.get(1)) {
(Some(Cirru::Leaf(x0)), Some(Cirru::Leaf(x1))) => {
if x0 == "def"
|| x0 == "defn"
|| x0 == "defmacro"
|| x0 == "defatom"
|| x0 == "defrecord"
|| x0.starts_with("def")
{
defs.insert(Edn::Str(x1.to_owned()), Edn::Quote(line.to_owned()));
} else {
return Err(io_err(format!("invalid def op: {}", x0)));
}
}
} else {
return Err(io_err(format!("file line not an expr {}", line)));
(a, b) => {
return Err(io_err(format!("invalid def code {:?} {:?}", a, b)));
}
}
} else {
return Err(io_err(format!("file line not an expr {}", line)));
}
} else {
}

file.insert(Edn::Keyword(String::from("defs")), Edn::Map(defs));
files.insert(Edn::Str(ns_name.to_owned()), Edn::Map(file));
} else {
return Err(io_err(format!("file should be expressions, molformed, {}", file_data)));
}

file.insert(Edn::Keyword(String::from("defs")), Edn::Map(defs));
files.insert(Edn::Str(ns_name.to_owned()), Edn::Map(file));

if verbose {
println!("bunding {}", entry.path().display());
}
Expand Down
10 changes: 8 additions & 2 deletions src/builtins/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ use crate::primes::{Calcit, CalcitItems, CrListWrap};
use crate::program;
use crate::runner;
use crate::util::number::f64_to_usize;

use cirru_parser::Cirru;

use std::cmp::Ordering;
use std::sync::atomic;
use std::sync::atomic::AtomicUsize;
Expand Down Expand Up @@ -137,7 +140,7 @@ pub fn display_stack(_xs: &CalcitItems) -> Result<Calcit, String> {
pub fn parse_cirru(xs: &CalcitItems) -> Result<Calcit, String> {
match xs.get(0) {
Some(Calcit::Str(s)) => match cirru_parser::parse(s) {
Ok(nodes) => Ok(cirru::cirru_to_calcit(&nodes)),
Ok(nodes) => Ok(cirru::cirru_to_calcit(&Cirru::List(nodes))),
Err(e) => Err(format!("parse-cirru failed, {}", e)),
},
Some(a) => Err(format!("parse-cirru expected a string, got: {}", a)),
Expand Down Expand Up @@ -338,7 +341,10 @@ pub fn tuple_nth(xs: &CalcitItems) -> Result<Calcit, String> {
},
(Some(_), None) => Err(format!("&tuple:nth expected a tuple and an index, got: {:?}", xs)),
(None, Some(_)) => Err(format!("&tuple:nth expected a tuple and an index, got: {:?}", xs)),
(_, _) => Err(format!("&tuple:nth expected 2 argument, got: {}", CrListWrap(xs.to_owned()))),
(_, _) => Err(format!(
"&tuple:nth expected 2 argument, got: {}",
CrListWrap(xs.to_owned())
)),
}
}

Expand Down
17 changes: 6 additions & 11 deletions src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,13 @@ pub fn gen_default() -> Snapshot {
}
}

pub fn create_file_from_snippet(code: &str) -> Result<FileInSnapShot, String> {
match cirru_parser::parse(code) {
pub fn create_file_from_snippet(raw: &str) -> Result<FileInSnapShot, String> {
match cirru_parser::parse(raw) {
Ok(lines) => {
let code = match lines {
Cirru::List(line) => {
if line.len() == 1 {
line[0].to_owned()
} else {
return Err(format!("unexpected snippet: {}", code));
}
}
Cirru::Leaf(s) => return Err(format!("unexpected snippet: {}", s)),
let code = if lines.len() == 1 {
lines[0].to_owned()
} else {
return Err(format!("unexpected snippet: {}", raw));
};
let mut def_dict: HashMap<String, Cirru> = HashMap::new();
def_dict.insert(
Expand Down
2 changes: 1 addition & 1 deletion ts-src/calcit.procs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// CALCIT VERSION
export const calcit_version = "0.4.32";
export const calcit_version = "0.4.33";

import { overwriteComparator, initTernaryTreeMap } from "@calcit/ternary-tree";
import { parse } from "@cirru/parser.ts";
Expand Down

0 comments on commit 9a9e0fe

Please sign in to comment.