Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update edition #2

Merged
merged 2 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = ["Pierre Surply <pierre.surply@gmail.com>"]
readme = "README.md"
license = "MIT"
repository = "https://github.com/psurply/dwfv"
edition = "2018"

keywords = ["eda", "vcd"]
categories = [
Expand All @@ -24,11 +25,11 @@ exclude = [
travis-ci = { repository = "psurply/dwfv" }

[build-dependencies]
lalrpop = { version = "0.18", features = ["lexer"] }
lalrpop = { version = "0.19", features = ["lexer"] }

[dependencies]
gumdrop = "0.8"
lalrpop-util = "0.18"
lalrpop-util = "0.19"
lazy_static = "1"
regex = "1"
tui = "0.9"
Expand Down
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// SPDX-License-Identifier: MIT

#[macro_use]
extern crate lalrpop_util;
#[macro_use]
extern crate lazy_static;
extern crate regex;
extern crate termion;
extern crate tui as tuirs;

mod search;
pub mod signaldb;
pub mod tui;
Expand Down
3 changes: 0 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// SPDX-License-Identifier: MIT
extern crate dwfv;
extern crate gumdrop;

use dwfv::signaldb::{AsyncSignalDB, SignalDB};
use dwfv::tui::Tui;
use gumdrop::Options;
Expand Down
6 changes: 6 additions & 0 deletions src/search.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
mod expr;
pub(crate) mod types;

pub use self::types::FindingsSummary;
pub(crate) use self::types::Search;
3 changes: 2 additions & 1 deletion src/search/expr.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
use crate::signaldb::SignalValue;
use lalrpop_util::lalrpop_mod;
use std::error::Error;
use std::io;

Expand All @@ -24,7 +25,7 @@ pub enum ExprAst {
}

impl ExprAst {
pub fn from_str(expr: &str) -> Result<ExprAst, Box<dyn Error>> {
pub(crate) fn from_str(expr: &str) -> Result<ExprAst, Box<dyn Error>> {
let ast = parser::ExprParser::new().parse(expr).map_err(|err| {
io::Error::new(
io::ErrorKind::InvalidInput,
Expand Down
5 changes: 0 additions & 5 deletions src/search/mod.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/search/parser.lalrpop
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
use crate::signaldb::SignalValue;
use search::expr::{ExprAst, ValueAst};
use crate::search::expr::{ExprAst, ValueAst};
use std::str::FromStr;

grammar;
Expand Down
26 changes: 13 additions & 13 deletions src/search/search.rs → src/search/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::error::Error;
use std::io;
use std::ops::{BitAnd, BitOr};

pub struct Search {
pub(crate) struct Search {
findings: Vec<TimeDescr>,
expr: ExprAst,
current_period: Option<Timestamp>,
Expand Down Expand Up @@ -87,7 +87,7 @@ pub enum FindingsSummary {
}

impl Search {
pub fn new(expr: &str) -> Result<Search, Box<dyn Error>> {
pub(crate) fn new(expr: &str) -> Result<Search, Box<dyn Error>> {
let search = Search {
expr: ExprAst::from_str(expr)?,
findings: Vec::new(),
Expand All @@ -97,7 +97,7 @@ impl Search {
Ok(search)
}

pub fn eval_value_at(
pub(crate) fn eval_value_at(
&self,
value: &ValueAst,
signaldb: &SignalDB,
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Search {
Ok(res)
}

pub fn search_all(&mut self, signaldb: &SignalDB) -> Result<(), Box<dyn Error>> {
pub(crate) fn search_all(&mut self, signaldb: &SignalDB) -> Result<(), Box<dyn Error>> {
self.findings.clear();
self.current_period = None;
for timestamp in signaldb.get_timestamps() {
Expand All @@ -184,7 +184,7 @@ impl Search {
Ok(())
}

pub fn search_at(
pub(crate) fn search_at(
&mut self,
signaldb: &SignalDB,
timestamp: Timestamp,
Expand Down Expand Up @@ -215,11 +215,11 @@ impl Search {
Ok(())
}

pub fn finish(&mut self) {
pub(crate) fn finish(&mut self) {
self.cursor = None
}

pub fn format_findings(&self, output: &mut dyn io::Write) {
pub(crate) fn format_findings(&self, output: &mut dyn io::Write) {
for timestamp in &self.findings {
let _ = writeln!(output, "{}", timestamp);
}
Expand All @@ -240,7 +240,7 @@ impl Search {
})
}

pub fn findings_between(&self, begin: Timestamp, end: Timestamp) -> FindingsSummary {
pub(crate) fn findings_between(&self, begin: Timestamp, end: Timestamp) -> FindingsSummary {
if let Some(current_period) = self.current_period {
if begin <= current_period && current_period < end {
return FindingsSummary::RangeBegin;
Expand Down Expand Up @@ -304,7 +304,7 @@ impl Search {
}
}

pub fn get_next_finding(&self, from: Timestamp) -> Option<Timestamp> {
pub(crate) fn get_next_finding(&self, from: Timestamp) -> Option<Timestamp> {
let index = match self.search_finding(from) {
Ok(index) => index + 1,
Err(index) => index,
Expand All @@ -326,7 +326,7 @@ impl Search {
})
}

pub fn get_end_of_next_finding(&self, from: Timestamp) -> Option<Timestamp> {
pub(crate) fn get_end_of_next_finding(&self, from: Timestamp) -> Option<Timestamp> {
let index = match self.search_finding(from) {
Ok(index) => index + 1,
Err(index) => index,
Expand All @@ -337,7 +337,7 @@ impl Search {
})
}

pub fn get_previous_finding(&self, from: Timestamp) -> Option<Timestamp> {
pub(crate) fn get_previous_finding(&self, from: Timestamp) -> Option<Timestamp> {
let index = match self.search_finding(from - from.derive(1)) {
Ok(index) => index,
Err(index) => {
Expand Down Expand Up @@ -365,14 +365,14 @@ impl Search {
})
}

pub fn get_first_finding(&self) -> Option<Timestamp> {
pub(crate) fn get_first_finding(&self) -> Option<Timestamp> {
self.findings.first().map(|x| match x {
TimeDescr::Point(t) => *t,
TimeDescr::Period(t, _) => *t,
})
}

pub fn get_last_finding(&self) -> Option<Timestamp> {
pub(crate) fn get_last_finding(&self) -> Option<Timestamp> {
self.findings.last().map(|x| match x {
TimeDescr::Point(t) => *t,
TimeDescr::Period(_, t) => *t,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/signaldb/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl fmt::Display for Signal {
#[cfg(test)]
mod test {
use super::*;
use signaldb::time::Scale;
use crate::signaldb::time::Scale;

#[test]
fn add_events() {
Expand Down
4 changes: 2 additions & 2 deletions src/tui/mod.rs → src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub mod instr;
mod searchbar;
mod statusbar;
mod symbols;
mod tui;
mod types;
mod waveform;

pub use crate::tui::tui::Tui;
pub use self::types::Tui;
6 changes: 3 additions & 3 deletions src/tui/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use std::io::BufReader;
use std::path::Path;
use std::process::Command;
use std::str::FromStr;
use tuirs::backend::Backend;
use tuirs::layout::Rect;
use tuirs::terminal::Frame;
use tui::backend::Backend;
use tui::layout::Rect;
use tui::terminal::Frame;

const MAX_ID_SIZE: usize = 28;
const MAX_SCALE_VALUE: i64 = 1 << 16;
Expand Down
8 changes: 4 additions & 4 deletions src/tui/cursorbar.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
use super::symbols::arrow;
use crate::signaldb::Timestamp;
use tuirs::buffer::Buffer;
use tuirs::layout::Rect;
use tuirs::style::{Color, Style};
use tuirs::widgets::Widget;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Style};
use tui::widgets::Widget;

pub enum CursorType {
Top,
Expand Down
8 changes: 4 additions & 4 deletions src/tui/errorbar.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
use tuirs::buffer::Buffer;
use tuirs::layout::Rect;
use tuirs::style::{Color, Style};
use tuirs::widgets::Widget;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Style};
use tui::widgets::Widget;

pub struct ErrorBar {
message: String,
Expand Down
1 change: 1 addition & 0 deletions src/tui/event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// SPDX-License-Identifier: MIT
use lazy_static::lazy_static;
use regex::Regex;
use std::collections::VecDeque;
use std::io;
Expand Down
12 changes: 6 additions & 6 deletions src/tui/searchbar.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// SPDX-License-Identifier: MIT
use super::symbols::block;
use crate::search::search::FindingsSummary;
use tuirs::buffer::Buffer;
use tuirs::layout::Rect;
use tuirs::style::{Color, Style};
use tuirs::symbols::line;
use tuirs::widgets::Widget;
use crate::search::types::FindingsSummary;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Style};
use tui::symbols::line;
use tui::widgets::Widget;

pub struct SearchBar<'a> {
data: &'a [FindingsSummary],
Expand Down
8 changes: 4 additions & 4 deletions src/tui/statusbar.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT
use tuirs::buffer::Buffer;
use tuirs::layout::Rect;
use tuirs::style::{Color, Modifier, Style};
use tuirs::widgets::Widget;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Modifier, Style};
use tui::widgets::Widget;

pub struct StatusBar {
message: String,
Expand Down
4 changes: 2 additions & 2 deletions src/tui/tui.rs → src/tui/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use std::io;
use std::path::Path;
use termion::input::MouseTerminal;
use termion::raw::{IntoRawMode, RawTerminal};
use tuirs::backend::TermionBackend;
use tuirs::Terminal;
use tui::backend::TermionBackend;
use tui::Terminal;

/// Digital Waveform Viewer Text User Interface
pub struct Tui {
Expand Down
10 changes: 5 additions & 5 deletions src/tui/waveform.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// SPDX-License-Identifier: MIT
use super::symbols::block;
use tuirs::buffer::Buffer;
use tuirs::layout::Rect;
use tuirs::style::{Color, Modifier, Style};
use tuirs::symbols::line;
use tuirs::widgets::Widget;
use tui::buffer::Buffer;
use tui::layout::Rect;
use tui::style::{Color, Modifier, Style};
use tui::symbols::line;
use tui::widgets::Widget;

#[derive(Clone, PartialEq, Eq)]
pub enum WaveformElement {
Expand Down
3 changes: 3 additions & 0 deletions src/vcd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// SPDX-License-Identifier: MIT
pub(crate) mod lexer;
pub(crate) mod parser;
17 changes: 9 additions & 8 deletions src/vcd/lexer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// SPDX-License-Identifier: MIT
use crate::signaldb::{Scale, SignalValue, Timestamp};
use lazy_static::lazy_static;
use regex::Regex;
use std::collections::VecDeque;
use std::io::prelude::*;
use std::str::FromStr;

#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Keyword {
pub(crate) enum Keyword {
Comment,
Date,
DumpVars,
Expand All @@ -20,7 +21,7 @@ pub enum Keyword {
}

#[derive(Debug, Clone, PartialEq)]
pub enum Token {
pub(crate) enum Token {
Word(String),
Keyword(Keyword),
Range(u64, u64),
Expand All @@ -35,7 +36,7 @@ pub enum Token {
}

#[derive(Copy, Clone, Debug)]
pub enum Context {
pub(crate) enum Context {
Comment,
Stmt,
Id,
Expand All @@ -45,8 +46,8 @@ pub enum Context {
Timescale,
}

pub struct Lexer<I: BufRead> {
pub buf: String,
pub(crate) struct Lexer<I: BufRead> {
pub(crate) buf: String,
input: I,
tok_queue: VecDeque<Token>,
}
Expand Down Expand Up @@ -164,7 +165,7 @@ impl Token {
}

impl<I: BufRead> Lexer<I> {
pub fn new(input: I) -> Lexer<I> {
pub(crate) fn new(input: I) -> Lexer<I> {
Lexer {
input,
buf: String::new(),
Expand Down Expand Up @@ -199,12 +200,12 @@ impl<I: BufRead> Lexer<I> {
}
}

pub fn pop(&mut self, ctx: Context) -> Token {
pub(crate) fn pop(&mut self, ctx: Context) -> Token {
self.prepare_queue();
self.tok_queue.pop_front().unwrap().retokenize(ctx)
}

pub fn get_current_line(&self) -> String {
pub(crate) fn get_current_line(&self) -> String {
self.buf.to_string()
}
}
Expand Down
3 changes: 0 additions & 3 deletions src/vcd/mod.rs

This file was deleted.

Loading