Colin Benner
78331c36a8
Add parse_radix
to handle near-identical cases
...
In `parse_term`, remove some code duplication by moving code common to
parsing hexadecimal, octal and binary numbers into its own
function.
2019-10-19 20:30:06 -07:00
Colin Benner
b035f08d49
Move Name
, Resolver
out of load::load
2019-10-19 20:28:00 -07:00
Colin Benner
bf46daa227
Simplify parse_term
, eliminate is_func
...
Try to parse a function, or attribute, then match the result. This
eliminates the two-step approach: check whether we have a function, then
parse as a function.
2019-10-19 20:28:00 -07:00
Colin Benner
8bcd12252a
Rename is_attr
to attr_from_name
...
A function returning an `Option` should not have a name beginning with
`is_`.
2019-10-19 20:28:00 -07:00
Colin Benner
124a41773a
Move common subexpression out of match
2019-10-19 20:28:00 -07:00
Colin Benner
a7c746f48a
Simplify match statement using try!
...
This is simpler than manually handling an error in each component of the
triple we match on. In addition, we get to drop a bunch of `Ok`s.
2019-10-19 20:28:00 -07:00
Colin Benner
f805f5d180
Represent function using an enum
...
We only support a limited set of function, so we may as well put them in an
enum instead of passing around strings. This allows us to simplify match
statements, eliminating the case of unsupported functions.
2019-10-19 20:28:00 -07:00
Colin Benner
1ce838983d
Simplify some matches
2019-10-19 20:28:00 -07:00
Colin Benner
31897c48c1
Derive Default
for NumberParts
...
No need to write this out explicitly.
2019-10-19 20:27:59 -07:00
Colin Benner
9c5818b2f2
Address more clippy carnings
2019-10-19 20:27:59 -07:00
Colin Benner
1e87d5a54f
Get content from Name
with one method
...
Get the content of whatever variant by calling `Name::name()`.
2019-10-19 20:27:59 -07:00
Colin Benner
9c74a38b4d
Simplify Resolver::lookup
...
Move duplicate code into a closure. Simplify inner using `.any()`.
Eliminate conditionals using logical operators.
2019-10-19 20:27:59 -07:00
Colin Benner
0b289c8966
Be more explicit in Num::to_rational
...
Rather than checking whether `x == ai`, we simply check whether their
difference, of which we want to take the reciprocal in the next step, is
zero.
2019-10-19 20:27:59 -07:00
Colin Benner
e68e4f6167
Use unreachable!()
instead of panic!()
...
This seems to capture the intended meaning more clearly.
2019-10-19 20:27:59 -07:00
Colin Benner
5a0189ff77
Use the dirs
crate to find the config dir
2019-10-19 20:27:59 -07:00
Colin Benner
62aec5a8a0
Handle division by zero with a macro
...
Eliminate repetitive code by using a simple macro all over
`substance.rs`.
2019-10-19 20:27:59 -07:00
Colin Benner
02f13cc7cb
Merge if statement with surrounding else block
2019-10-19 20:27:59 -07:00
Colin Benner
0e65b19e56
Simplify Context::describe_unit
...
Move duplicate code into a closure.
2019-10-19 20:27:59 -07:00
Colin Benner
612ca08306
Use is_empty
...
Check whether a collections is empty by using the `.is_empty` method
instead of comparing `.len()` to 0.
2019-10-19 20:27:59 -07:00
Colin Benner
72864485b7
Simplify Context::{lookup, canonicalize}
2019-10-19 20:27:59 -07:00
Colin Benner
8247a2415c
Fix lots of clippy warnings
2019-10-19 20:27:59 -07:00
Colin Benner
da9313f6fe
Simplify match in text_query::is_func
2019-10-19 20:25:56 -07:00
Colin Benner
b042663807
Eliminate temperature!
in eval::eval
...
Like the last, commit, replace the macro calls by putting the macro
arguments into variables and putting the macro body after that.
As we need the exact same match statement in both cases, it is
implemented as a method on `Degree`.
2019-10-19 20:25:56 -07:00
Colin Benner
249c9941af
Eliminate macro in eval::eval_outer
...
We can get rid of `temperature!` if we just put the macro arguments into
variables and put the macro body below that.
2019-10-19 20:25:56 -07:00
Colin Benner
232f35c108
Use Display
for Degree
in token::describe
2019-10-19 20:25:56 -07:00
Colin Benner
0581d8f247
Simplify temperature handling
...
Use a single enum, `Degree`, wherever a temperature scale is referenced.
That way, we can a simplify `Conversion` and `Token`, as well as some
matches.
2019-10-19 20:25:56 -07:00
Tiffany Bennett
79aebd9a17
Fix warnings
2019-10-19 20:19:03 -07:00
Tiffany Bennett
a7d76f922d
Fix warnings about AsciiExt
2019-01-15 20:28:32 -08:00
Tiffany Bennett
0755cb5f9d
Update rust-gmp
2019-01-15 20:23:37 -08:00
Colin Benner
5beb4ba987
Handle file not found gracefully
...
If the input file provided on the command line cannot be opened, reprt
an error, rather than unwrapping.
2018-11-20 07:13:13 +01:00
Colin Benner
e8dd3a0b9e
Also support -V
and --version
2018-11-20 07:13:02 +01:00
Colin Benner
94e7bd00b1
Support -
h and --help
...
Print a usage message when called with `-h` or `--help`, or when called
with the wrong number of arguments.
2018-11-20 07:11:57 +01:00
Colin Benner
4a41da18c8
Fix typo
2018-11-15 22:32:36 +01:00
Colin Benner
d54d410d15
Document what substance_from_formula
does
2018-11-15 22:32:36 +01:00
Colin Benner
f97a076f52
Test additional cases in date::attempt
2018-11-15 22:32:36 +01:00
Colin Benner
d609611454
Test parse_datepattern
2018-11-15 22:32:32 +01:00
Colin Benner
9cf86a5839
Test more cases in parse_{weekday, monthname}
2018-11-15 22:31:46 +01:00
Colin Benner
77cfd49454
Fix bug found by test_date_input
2018-11-15 22:31:46 +01:00
Colin Benner
54ffee9945
Another test for the date parser
2018-11-15 22:31:36 +01:00
Colin Benner
9ae738ad15
Properly handle comments: skip closing slash
...
When we reach the end of an inline comment, we need to call self.0.next().
Otherwise, the closing slash is treated as a separate token.
Ignore `Token::Comment` in `parse_term`, do not return an error.
Add regression test.
2018-11-15 21:51:25 +01:00
Colin Benner
7787156d88
Test parse_date on 24h and plain seconds
2018-11-15 18:55:45 +01:00
Colin Benner
cbc5c89670
Test parsing timezone names
2018-11-15 18:55:45 +01:00
Colin Benner
1f9fda92fb
Test weekday parser
2018-11-15 18:55:45 +01:00
Colin Benner
64f72fe743
Test parsing offsets
2018-11-15 18:55:45 +01:00
Colin Benner
c203481a08
More parse_date tests
2018-11-15 18:55:45 +01:00
Colin Benner
a6d044511d
More parse_date tests
2018-11-15 18:55:45 +01:00
Colin Benner
b3670b8559
Add test for a bunch of cases in parse_date
2018-11-15 18:55:45 +01:00
Colin Benner
4474c376b0
Add another test case in date.rs
2018-11-15 18:55:45 +01:00
Colin Benner
00dcdd4f52
Simplify tests in date.rs
2018-11-15 18:55:45 +01:00
Colin Benner
4437500941
Run date parser on "+123"
2018-11-15 18:55:45 +01:00