Crates.io | rvs-parser |
lib.rs | rvs-parser |
version | 0.5.0 |
source | src |
created_at | 2017-12-27 17:12:00.726192 |
updated_at | 2020-11-26 19:41:44.613344 |
description | Parser for Rvs - A library for defining and evaluating random variables using a simple DSL |
homepage | |
repository | https://github.com/rfdonnelly/rvs |
max_upload_size | |
id | 44594 |
size | 38,116 |
Rvs is a C API library for defining and evaluating random variables using a simple DSL (Domain Specific Language).
// An enumeration defintion with implicit value members.
enum Command {
Read,
Write,
Erase,
}
// A variable that yields the repeating pattern: 2, 0, 1, 0
pattern = Pattern(
Command::Erase,
Command::Read,
Command::Write,
Command::Read,
);
// A variable that yields random values in the range [0, 7] inclusive
range = [0, 7];
// A variable that yields random values in the set {0, 1, 2}. Yielded values
// are added back to the set.
sample_with_replacement = r{
Command::Read,
Command::Write,
Command::Erase,
};
// A variable that yields random values in the set {0, 1, 2}. Yielded values
// are removed from the set. After all values have been yielded, the set is
// repopulated.
sample_without_replacement = {
Command::Read,
Command::Write,
Command::Erase,
};
// A variable that yields weighted random values `0` 40% of the time, `1` 50%
// of the time, and `2` 10% of the time.
weighted_sample_with_replacement = r{
40: Command::Read,
50: Command::Write,
10: Command::Erase,
};
// A variable that randomly yields values from a pool of 40 `0`s, 50 `1`s, and
// 10 `2`s. Yielded values are removed from the pool. The pool is
// re-populated after all values have been yielded.
weighted_sample_without_replacement = {
40: Command::Read,
50: Command::Write,
10: Command::Erase,
};
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Expr features
next()
prev()
done()
reset()
Display
Parse from string
C API
rvs_context_new()
rvs_context_free()
rvs_seed()
rvs_parse()
rvs_get()
rvs_next()
rvs_done()
rvs_prev()
rvs_reset()
rvs_write_definitions()
Grammar
enum Enum { Value, }
enum Enum { Value = 0, }
enum Enum { Value = 0, } a = Enum::Value
expands to a = 0
enum Enum { Value0, Value1, } a = Sample(Enum)
expands to a = Sample(0, 1)
<identifier>
<identifier>.copy
<identifier>.prev
<expr>.done
<expr>.once
Expand(<expr>)
OR Expand(<expr>, <count-expr>)
[<lower>, <upper>]
r{<weight>: <expr>, ...}
r{<expr>, ...}
{<weight>: <expr>, ...}
{<expr>, ...}
Pattern(<expr>, ...)
* [x] Select new sub-expression only when current sub-expression is doneSequence(<count>)
OR
Sequence(<offset>, <count>)
OR
Sequence(<offset>, <increment>, <count>)
::key0::path::file => '/a/b/c/path/file.rvs'
path::file
=> ['/a/b/c/path/file.rvs', '/d/e/f/path/file.rvs']import fileb
in filea
becomes $(dirname filea)/fileb.rvs
path::file
instead of 'path/file.rvs'
HashMap<String, Box<Expr>>
to HashMap<&str, Box<Expr>>
RangeInclusive
with
rand::distributions::Range::new_inclusive()
Iterator
trait