Implemented abool

- Tidied up code
pull/11/head
ondra05 2021-04-18 23:40:41 +02:00
parent fbd16d2bcc
commit e13db995a3
6 changed files with 97 additions and 26 deletions

70
Cargo.lock generated
View File

@ -8,6 +8,7 @@ version = "0.1.0"
dependencies = [
"clap",
"logos",
"rand",
]
[[package]]
@ -42,6 +43,12 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "2.33.3"
@ -63,6 +70,17 @@ version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
[[package]]
name = "getrandom"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "hermit-abi"
version = "0.1.18"
@ -102,6 +120,12 @@ dependencies = [
"utf8-ranges",
]
[[package]]
name = "ppv-lite86"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "proc-macro2"
version = "1.0.26"
@ -120,6 +144,46 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "rand"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
"rand_hc",
]
[[package]]
name = "rand_chacha"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7"
dependencies = [
"getrandom",
]
[[package]]
name = "rand_hc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73"
dependencies = [
"rand_core",
]
[[package]]
name = "regex-syntax"
version = "0.6.23"
@ -176,6 +240,12 @@ version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]]
name = "wasi"
version = "0.10.2+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6"
[[package]]
name = "winapi"
version = "0.3.9"

View File

@ -8,4 +8,5 @@ edition = "2018"
[dependencies]
clap="*"
logos = "0.12"
logos = "0.12"
rand = "*"

View File

@ -3,21 +3,11 @@ mod utils;
use item::Expr;
use crate::variables::Value;
use crate::{
error::{Error, ErrorKind},
tokens::Token,
};
use crate::error::{Error, ErrorKind};
use crate::tokens::Token;
use logos::Logos;
#[derive(Debug)]
pub enum ParseError {
UnexpectedToken,
LexError,
UnexpectedEOF,
}
/// Parser structure / state machine
pub struct Parser<'a> {
lexer: logos::Lexer<'a, Token>,

View File

@ -1,9 +1,8 @@
use crate::{
error::{Error, ErrorKind},
tokens::{Abool, Token},
};
use crate::error::{Error, ErrorKind};
use crate::tokens::Token;
use crate::variables::Abool;
use super::{ParseError, Parser};
use super::Parser;
pub fn abool2num(abool: Abool) -> i32 {
match abool {

View File

@ -103,10 +103,3 @@ pub enum Token {
#[error]
Error,
}
#[derive(Debug, PartialEq)]
pub enum Abool {
Never = -1,
Sometimes = 0,
Always = 1,
}

View File

@ -1,11 +1,29 @@
use rand::Rng;
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq)]
pub enum Abool {
Never = -1,
Sometimes = 0,
Always = 1,
}
impl Into<bool> for Abool {
fn into(self) -> bool {
match self {
Abool::Never => false,
Abool::Always => true,
Abool::Sometimes => rand::thread_rng().gen(),
}
}
}
#[derive(Debug, Clone)]
pub enum Value {
Str(String),
Int(i32),
Bool(bool),
//TODO(Able): Add abool and other variable types
Abool(Abool),
}
#[derive(Debug)]