From 2e88b194959b65e6bc06df5faa47781b15884eaa Mon Sep 17 00:00:00 2001 From: jekto_vatimeliju Date: Mon, 27 Jul 2020 20:31:48 +0900 Subject: [PATCH] unaryifexpr should allow indexing by IntNum --- not_found_in_spec.md | 9 +++++++++ src/parse/mod.rs | 4 ++++ src/tests/mod.rs | 4 ++++ test089.rs | 10 ++++++++++ test089.wy | 7 +++++++ 5 files changed, 34 insertions(+) create mode 100644 test089.rs create mode 100644 test089.wy diff --git a/not_found_in_spec.md b/not_found_in_spec.md index e923790..945a1cb 100644 --- a/not_found_in_spec.md +++ b/not_found_in_spec.md @@ -80,3 +80,12 @@ for_enum_statement : FOR_START_ENUM (INT_NUM|IDENTIFIER) FOR_MID_ENUM ``` Actual behavior: seems to allow `INT_NUM|IDENTIFIER|'其'` in the second argument. + +### unary_if_expression + +spec: +``` +unary_if_expression : data|(IDENTIFIER '之'('長'|STRING_LITERAL|IDENTIFIER))|'其' ; +``` + +Actual behavior: seems to allow `'長'|STRING_LITERAL|IDENTIFIER|INT_NUM`. diff --git a/src/parse/mod.rs b/src/parse/mod.rs index fb09b09..e545b84 100644 --- a/src/parse/mod.rs +++ b/src/parse/mod.rs @@ -659,6 +659,10 @@ fn parse_unary_if_expression(mut iter: &mut LexIter<'_>) -> Result Ok(UnaryIfExpr::Complex(Value::Index( + Data::Identifier(Identifier(i.to_string())), + interpret_intnum(int_num), + ))), // not found in spec.html but exists _ => Err(Error::SomethingWentWrong(here!())), } } else { diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 1c03c78..f30866a 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -390,6 +390,10 @@ fn test087() { fn test088() { test("test088") } +#[test] +fn test089() { + test("test089") +} /// note that fail000.rs currently does not compile as a valid Rust program because of: /// * `{}` on `Vec` /// * ownership diff --git a/test089.rs b/test089.rs new file mode 100644 index 0000000..83a941e --- /dev/null +++ b/test089.rs @@ -0,0 +1,10 @@ +fn main() { + let mut JIA3 = vec![]; + JIA3.push(3.0); + JIA3.push(5.0); + let YI3 = 1.0; + if YI3 < JIA3[2 - 1] { + let _ans1 = YI3; + println!("{}", _ans1); + } +} diff --git a/test089.wy b/test089.wy new file mode 100644 index 0000000..6f418f8 --- /dev/null +++ b/test089.wy @@ -0,0 +1,7 @@ +吾有一列。名之曰「甲」。充「甲」以三。充「甲」以五。 + + +有數一。名之曰「乙」。 +若「乙」小於「甲」之二者。 + 夫「乙」。書之。 +也。