Skip to content

Commit

Permalink
Update to latest bitflags release, 2018 edition Rust (#2)
Browse files Browse the repository at this point in the history
* Update to 2018 edition Rust

* Update to the latest stable release of bitflags
  • Loading branch information
dralley authored and Robbepop committed Jul 16, 2019
1 parent a94d809 commit fc12ab4
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 29 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.2.0"
authors = ["Robbepop"]
license = "MIT/Apache-2.0"
readme = "README.md"
edition = "2018"
repository = "https://github.com/robbepop/dimacs-parser"
documentation = "https://docs.rs/dimacs"
keywords = ["parser", "dimacs", "sat", "lexer", "format"]
Expand All @@ -12,7 +13,7 @@ which is useful for participating in the DIMACS SAT solver competitions."""
categories = ["parsing", "parser-implementations", "text-processing"]

[dependencies]
bitflags = "0.8.2"
bitflags = "1.1.0"

[badges]
travis-ci = { repository = "Robbepop/dimacs-parser" }
Expand Down
8 changes: 4 additions & 4 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,12 @@ impl Instance {

bitflags! {
/// Possible extensions for `.sat` file SAT instances.
pub flags Extensions: u32 {
pub struct Extensions: u32 {
/// If no extensions are being used.
const NONE = 0b00000000,
const NONE = 0b00000000;
/// If the XOR-Extension is being used to allow for `xor(..)` formulas.
const XOR = 0b00000001,
const XOR = 0b00000001;
/// If the EQ-Extension is being used to allow for `=(..)` formulas.
const EQ = 0b00000010
const EQ = 0b00000010;
}
}
10 changes: 5 additions & 5 deletions src/lexer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ::errors::*;
use crate::errors::*;

use ::errors::ErrorKind::*;
use crate::errors::ErrorKind::*;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Token {
Expand Down Expand Up @@ -232,10 +232,10 @@ impl<I> Lexer<I>
self.update_nloc();
Some(
match self.peek {
'A'...'Z' |
'a'...'z' => self.scan_keyword(),
'A'..='Z' |
'a'..='z' => self.scan_keyword(),

'1'...'9' => self.scan_nat(),
'1'..='9' => self.scan_nat(),

'0' => self.bump_tok(Zero),
'(' => self.bump_tok(Open),
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod errors;
mod lexer;
mod parser;

pub use items::{
pub use crate::items::{
Clause,
Extensions,
Lit,
Expand All @@ -39,10 +39,10 @@ pub use items::{
FormulaBox,
FormulaList
};
pub use errors::{
pub use crate::errors::{
Loc,
ParseError,
ErrorKind,
Result
};
pub use parser::parse_dimacs;
pub use crate::parser::parse_dimacs;
32 changes: 16 additions & 16 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! The parser facility for parsing `.cnf` and `.sat` files as specified in the
//! The parser facility for parsing `.cnf` and `.sat` files as specified in the
//! [DIMACS format specification](http://www.domagoj-babic.com/uploads/ResearchProjects/Spear/dimacs-cnf.pdf).
//!
//!
//! The DIMACS format was specified for the DIMACS SAT solver competitions as input file format.
//! Many other DIMACS file formats exist for other competitions, however, this crate currently only
//! supports the formats that are relevant for SAT solvers.
//!
//!
//! In `.cnf` the entire SAT formula is encoded as a conjunction of disjunctions and so mainly stores
//! a list of clauses consisting of literals.
//!
//!
//! The `.sat` format is slightly more difficult as the formula can be of a different shape and thus
//! a `.sat` file internally looks similar to a Lisp file.

use lexer::*;
use errors::*;
use items::*;
use crate::lexer::*;
use crate::errors::*;
use crate::items::*;

#[derive(Debug, Clone)]
struct Parser<I>
Expand Down Expand Up @@ -135,18 +135,18 @@ impl<I> Parser<I>
while !self.is_at_eof() {
clauses.push(self.parse_clause()?);
}
Ok(clauses)
Ok(clauses)
}

fn parse_sat_extensions<'a>(&'a mut self) -> Result<Extensions> {
use self::TokenKind::{Ident};
use self::Ident::{Sat, Sate, Satx, Satex};
use self::ErrorKind::*;
match self.peek?.kind {
Ident(Sat) => { self.consume()?; Ok(NONE) },
Ident(Sate) => { self.consume()?; Ok(EQ) },
Ident(Satx) => { self.consume()?; Ok(XOR) },
Ident(Satex) => { self.consume()?; Ok(EQ | XOR) },
Ident(Sat) => { self.consume()?; Ok(Extensions::NONE) },
Ident(Sate) => { self.consume()?; Ok(Extensions::EQ) },
Ident(Satx) => { self.consume()?; Ok(Extensions::XOR) },
Ident(Satex) => { self.consume()?; Ok(Extensions::EQ | Extensions::XOR) },
_ => self.err(InvalidSatExtension)
}
}
Expand All @@ -158,8 +158,8 @@ impl<I> Parser<I>
}

fn parse_formula(&mut self) -> Result<Formula> {
use lexer::TokenKind::*;
use lexer::Ident::*;
use crate::lexer::TokenKind::*;
use crate::lexer::Ident::*;
let tok = self.peek?;
match tok.kind {
Nat(val) => { self.consume()?; Ok(Formula::lit(Lit::from_i64(val as i64))) },
Expand Down Expand Up @@ -247,7 +247,7 @@ impl<I> Parser<I>

/// Parses a the given string as `.cnf` or `.sat` file as specified in
/// [DIMACS format specification](http://www.domagoj-babic.com/uploads/ResearchProjects/Spear/dimacs-cnf.pdf).
///
///
/// Returns an appropriate SAT instance if no errors occured while parsing.
pub fn parse_dimacs(input: &str) -> Result<Instance> {
Parser::from(input.chars()).parse_dimacs()
Expand Down Expand Up @@ -306,7 +306,7 @@ mod tests {
+(4)
+(2 3)))";
let parsed = parse_dimacs(sample).expect("valid .sat");
let expected = Instance::sat(42, NONE,
let expected = Instance::sat(42, Extensions::NONE,
Formula::paren(
Formula::and(vec![
Formula::or(vec![
Expand Down

0 comments on commit fc12ab4

Please sign in to comment.