Skip to content

Commit

Permalink
Merge pull request #3 from rust-playground/correct-object-output
Browse files Browse the repository at this point in the history
correct JSON Object output
  • Loading branch information
Dean Karn authored Jun 8, 2022
2 parents 7368534 + eb98885 commit c2882fb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.3.1] - 2022-06-08
### Fixed
- Missing commas between items is output JSON Objects.

### Changed
- Release profile for smaller binary size.
- Updated deps to latest.
- Linter suggested updates.

## [0.3.0] - 2022-04-06
### Changed
- Lexer token return signature reducing its size from 12->8 bytes
Expand Down Expand Up @@ -39,8 +48,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Initial release.

[Unreleased]: https://github.com/rust-playground/ksql/compare/v0.3.0...HEAD
[0.2.0]: https://github.com/rust-playground/ksql/compare/v0.2.0...v0.3.0
[Unreleased]: https://github.com/rust-playground/ksql/compare/v0.3.1...HEAD
[0.3.1]: https://github.com/rust-playground/ksql/compare/v0.3.0...v0.3.1
[0.3.0]: https://github.com/rust-playground/ksql/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/rust-playground/ksql/compare/v0.1.2...v0.2.0
[0.1.2]: https://github.com/rust-playground/ksql/compare/v0.1.1...v0.1.2
[0.1.1]: https://github.com/rust-playground/ksql/compare/v0.1.0...v0.1.1
Expand Down
10 changes: 6 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "ksql"
description = "A JSON data expression lexer, parser, cli and library"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -16,11 +16,11 @@ keywords = [
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.56"
anyhow = "1.0.57"
atty = "0.2.14"
clap = { version = "3.1.8", features = ["derive"] }
clap = { version = "3.1.18", features = ["derive"] }
gjson = "0.8.1"
thiserror = "1.0.30"
thiserror = "1.0.31"

[dev-dependencies]
criterion = { version = "0.3.5", features = ["html_reports"] }
Expand All @@ -34,4 +34,6 @@ harness = false

[profile.release]
lto = true
strip = true
codegen-units = 1
panic = 'abort'
8 changes: 4 additions & 4 deletions src/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@
use thiserror::Error;

/// The lexed token.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub struct Token {
pub start: u32,
pub len: u16,
pub kind: TokenKind,
}

/// The kind of `Token`.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum TokenKind {
Identifier,
QuotedString,
Expand Down Expand Up @@ -162,7 +162,7 @@ where
pub type Result<T> = std::result::Result<T, Error>;

/// Error type for the lexer.
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
pub enum Error {
#[error("invalid identifier: {0}")]
InvalidIdentifier(String),
Expand All @@ -185,7 +185,7 @@ pub enum Error {

/// Try to lex a single token from the input stream.
fn tokenize_single_token(data: &[u8]) -> Result<(TokenKind, u16)> {
let b = match data.get(0) {
let b = match data.first() {
Some(b) => b,
None => panic!("invalid data passed"),
};
Expand Down
9 changes: 5 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::lexer::{TokenKind, Tokenizer};
use anyhow::anyhow;
use gjson::Kind;
use std::collections::BTreeMap;
use std::fmt::{Debug, Display, Formatter};
use std::fmt::{Debug, Display, Formatter, Write};
use thiserror::Error;

/// Represents the calculated Expression result.
Expand All @@ -43,16 +43,17 @@ impl Display for Value {
let mut s = String::new();
s.push('{');
for (k, v) in o.iter() {
s.push_str(&format!(r#""{}":{}"#, k, v));
let _ = write!(s, r#""{}":{},"#, k, v);
}
s = s.trim_end_matches(',').to_string();
s.push('}');
s
}),
Value::Array(a) => write!(f, "{}", {
let mut s = String::new();
s.push('[');
for v in a.iter() {
s.push_str(&format!("{},", v));
let _ = write!(s, "{},", v);
}
s = s.trim_end_matches(',').to_string();
s.push(']');
Expand Down Expand Up @@ -740,7 +741,7 @@ impl Expression for Arr {
pub type Result<T> = std::result::Result<T, Error>;

/// Error type for the expression parser.
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
pub enum Error {
#[error("unsupported type comparison: {0}")]
UnsupportedTypeComparison(String),
Expand Down

0 comments on commit c2882fb

Please sign in to comment.