Skip to content

Commit

Permalink
#update
Browse files Browse the repository at this point in the history
  • Loading branch information
yutiansut authored and yutiansut committed Jan 4, 2022
1 parent cae4598 commit e3a425a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 9 deletions.
2 changes: 2 additions & 0 deletions qapro-rs/rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
edition = "2021"
max_width = 90
15 changes: 7 additions & 8 deletions qapro-rs/src/parsers/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use std::str::FromStr;

use parse_display::{Display, FromStr};

#[cfg(feature = "table")]

use polars::prelude::CsvReader;
#[cfg(feature = "table")]

use polars::prelude::*;

use crate::parsers::value::{BPqlValue, PqlValue, TomlValue};
Expand All @@ -16,7 +16,6 @@ pub enum LangType {
Yaml,
Toml,
Xml,
#[cfg(feature = "table")]
Csv,
}

Expand Down Expand Up @@ -56,7 +55,7 @@ impl FromStr for Lang {
impl Lang {
pub fn from_as(input: &str, lnag_type: LangType) -> anyhow::Result<Self> {
match lnag_type {
#[cfg(feature = "table")]

LangType::Csv => Self::from_as_csv(input),
LangType::Json => Self::from_as_json(input),
LangType::Toml => Self::from_as_toml(input),
Expand All @@ -65,7 +64,7 @@ impl Lang {
}
}

#[cfg(feature = "table")]

pub fn from_as_csv(input: &str) -> anyhow::Result<Self> {
if let Ok(data) = csvstr_to_pqlv(input) {
Ok(Self {
Expand Down Expand Up @@ -147,7 +146,7 @@ impl Lang {

pub fn to_string(&self, compact: bool) -> anyhow::Result<String> {
let output = match (&self.to, &self.from == &self.to) {
#[cfg(feature = "table")]

(LangType::Csv, _) => {
// To pad missing values with null, serialize them to json, deserialize them with polars, and write them to csv from there.
let sss = match &self.data {
Expand Down Expand Up @@ -186,7 +185,7 @@ impl Lang {
Ok(output)
}

#[cfg(feature = "cli")]

pub fn print(&self, compact: bool) -> anyhow::Result<()> {
let output = self.to_string(compact)?;

Expand All @@ -206,7 +205,7 @@ impl Lang {
}
}

#[cfg(feature = "table")]

fn csvstr_to_pqlv(input: &str) -> anyhow::Result<PqlValue> {
let c = std::io::Cursor::new(input.to_owned());
let df = CsvReader::new(c).infer_schema(Some(100)).finish()?;
Expand Down
2 changes: 1 addition & 1 deletion qapro-rs/src/parsers/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pub mod json_value;
mod pql_value;
mod pql_vector;

#[cfg(feature = "table")]

pub mod table;
mod toml_value;

Expand Down
51 changes: 51 additions & 0 deletions qapro-rs/src/qapraser.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,59 @@
use evalexpr::*;

use serde::{Deserialize, Serialize};

/// Defines a string constant for a single keyword: `kw_def!(SELECT);`
/// expands to `pub const SELECT = "SELECT";`
macro_rules! kw_def {
($ident:ident = $string_keyword:expr) => {
pub const $ident: &'static str = $string_keyword;
};
($ident:ident) => {
kw_def!($ident = stringify!($ident));
};
}

macro_rules! define_keywords {
($(
$ident:ident $(= $string_keyword:expr)?
),*) => {
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(non_camel_case_types)]
pub enum Keyword {
NoKeyword,
$($ident),*
}

pub const ALL_KEYWORDS_INDEX: &[Keyword] = &[
$(Keyword::$ident),*
];

$(kw_def!($ident $(= $string_keyword)?);)*
pub const ALL_KEYWORDS: &[&str] = &[
$($ident),*
];
};
}


define_keywords!(
SELECT,
AVG,
ABS);
#[cfg(test)]
mod test {
use crate::qapraser;
use super::*;

#[test]
fn test_keywords(){
println!("{:#?}", qapraser::Keyword::ABS);
}




#[test]
fn test() {
let context = context_map! {
Expand Down

0 comments on commit e3a425a

Please sign in to comment.