Skip to content

Commit

Permalink
Derive SerDe for bnf objects, json is nice to use for parse results (#74
Browse files Browse the repository at this point in the history
)

* Derive SerDe for bnf objects, json is nice to use for parse results

* cargo fmt
  • Loading branch information
shnewto authored Dec 30, 2020
1 parent c5efaed commit 6b9463b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,12 @@ version = "0.8.0"
[dependencies.nom]
version = "^6.0.1"

[dependencies.serde]
version = "1.0.118"
features = ["derive"]

[dependencies.serde_json]
version = "1.0.61"

[dev-dependencies.quickcheck]
version = "0.9.2"
3 changes: 2 additions & 1 deletion src/expression.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use error::Error;
use parsers;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::slice;
use std::str::FromStr;
use term::Term;

/// An Expression is comprised of any number of Terms
#[derive(Clone, Debug, Default, Eq, Hash, PartialEq)]
#[derive(Deserialize, Serialize, Clone, Debug, Default, Eq, Hash, PartialEq)]
pub struct Expression {
terms: Vec<Term>,
}
Expand Down
3 changes: 2 additions & 1 deletion src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ use expression::Expression;
use parsers;
use production::Production;
use rand::{rngs::StdRng, seq::SliceRandom, thread_rng, Rng, SeedableRng};
use serde::{Deserialize, Serialize};
use stacker;
use std::fmt;
use std::slice;
use std::str;
use term::Term;

/// A Grammar is comprised of any number of Productions
#[derive(Clone, Default, Debug, Eq, Hash, PartialEq)]
#[derive(Deserialize, Serialize, Clone, Default, Debug, Eq, Hash, PartialEq)]
pub struct Grammar {
productions: Vec<Production>,
}
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@

extern crate nom;
extern crate rand;
extern crate serde;
extern crate serde_json;
extern crate stacker;
mod error;
mod expression;
Expand Down
3 changes: 2 additions & 1 deletion src/production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
use error::Error;
use expression::Expression;
use parsers;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::slice;
use std::str::FromStr;
use term::Term;

/// A Production is comprised of any number of Expressions
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Deserialize, Serialize, Clone, Debug, Eq, Hash, PartialEq)]
pub struct Production {
pub lhs: Term,
rhs: Vec<Expression>,
Expand Down
3 changes: 2 additions & 1 deletion src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

use error::Error;
use parsers;
use serde::{Deserialize, Serialize};
use std::fmt;
use std::str::FromStr;

/// A Term can represent a Terminal or Nonterminal node
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
#[derive(Deserialize, Serialize, Clone, Debug, Eq, Hash, PartialEq)]
pub enum Term {
Terminal(String),
Nonterminal(String),
Expand Down

0 comments on commit 6b9463b

Please sign in to comment.