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

🐞 Fractions without leading zero do not parse correctly #160

Merged
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
6 changes: 3 additions & 3 deletions src/modules/expression/literal/number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ impl SyntaxModule<ParserMetadata> for Number {
if let Ok(sym) = token(meta, "-") {
self.value.push_str(&sym);
}
if let Ok(value) = number(meta, vec![]) {
if let Ok(value) = integer(meta, vec![]) {
self.value.push_str(&value);
}
if let Ok(sym) = token(meta, ".") {
self.value.push_str(&sym);
self.value.push_str(&number(meta, vec![])?);
self.value.push_str(&integer(meta, vec![])?);
}
if self.value.is_empty() {
return Err(Failure::Quiet(PositionInfo::from_metadata(meta)))
Expand All @@ -44,4 +44,4 @@ impl TranslateModule for Number {
fn translate(&self, _meta: &mut TranslateMetadata) -> String {
self.value.to_string()
}
}
}
10 changes: 10 additions & 0 deletions src/tests/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ fn very_complex_arithmetic() {
test_amber!(code, "24");
}

#[test]
fn fractions_with_no_leading_zero() {
let code = "
let a = .2
let b = .1
echo a + b
";
test_amber!(code, ".3");
}

#[test]
fn parenthesis() {
let code = "
Expand Down