Merge pull request #406 from schungx/master
Fix hanging when parsing unterminated statements block.
This commit is contained in:
commit
f7d523e983
@ -4,11 +4,27 @@ Testing Scripts
|
||||
Testing scripts written in Rhai.
|
||||
|
||||
|
||||
Install `rhai-run` Tool
|
||||
-----------------------
|
||||
|
||||
Use the following command to install the `rhai-run` tool:
|
||||
|
||||
```sh
|
||||
cargo install --path . --bin rhai-run
|
||||
```
|
||||
|
||||
|
||||
How to Run
|
||||
----------
|
||||
|
||||
Run scripts using the `rhai-run` tool:
|
||||
|
||||
```sh
|
||||
rhai-run ./scripts/test_script_to_run.rhai
|
||||
```
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
cargo run --bin rhai-run ./scripts/test_script_to_run.rhai
|
||||
```
|
||||
|
@ -10,9 +10,10 @@ fn new_mat(x, y) {
|
||||
matrix
|
||||
}
|
||||
|
||||
fn mat_gen(n) {
|
||||
let m = new_mat(n, n);
|
||||
fn mat_gen() {
|
||||
const n = global::SIZE;
|
||||
const tmp = 1.0 / n / n;
|
||||
let m = new_mat(n, n);
|
||||
|
||||
for i in range(0, n) {
|
||||
for j in range(0, n) {
|
||||
@ -39,9 +40,7 @@ fn mat_mul(a, b) {
|
||||
c[i][j] = 0.0;
|
||||
|
||||
for z in range(0, a[i].len) {
|
||||
let x = a[i][z];
|
||||
let y = b2[j][z];
|
||||
c[i][j] += x * y;
|
||||
c[i][j] += a[i][z] * b2[j][z];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -51,8 +50,8 @@ fn mat_mul(a, b) {
|
||||
|
||||
const now = timestamp();
|
||||
|
||||
const a = mat_gen(SIZE);
|
||||
const b = mat_gen(SIZE);
|
||||
const a = mat_gen();
|
||||
const b = mat_gen();
|
||||
const c = mat_mul(a, b);
|
||||
|
||||
/*
|
||||
|
@ -2417,7 +2417,23 @@ fn parse_block(
|
||||
#[cfg(not(feature = "no_module"))]
|
||||
let prev_mods_len = state.modules.len();
|
||||
|
||||
while !match_token(input, Token::RightBrace).0 {
|
||||
loop {
|
||||
// Terminated?
|
||||
match input.peek().unwrap() {
|
||||
(Token::RightBrace, _) => {
|
||||
eat_token(input, Token::RightBrace);
|
||||
break;
|
||||
}
|
||||
(Token::EOF, pos) => {
|
||||
return Err(PERR::MissingToken(
|
||||
Token::RightBrace.into(),
|
||||
"to terminate this block".into(),
|
||||
)
|
||||
.into_err(*pos));
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
// Parse statements inside the block
|
||||
settings.is_global = false;
|
||||
|
||||
@ -2443,11 +2459,13 @@ fn parse_block(
|
||||
eat_token(input, Token::SemiColon);
|
||||
}
|
||||
// { ... { stmt } ;
|
||||
(Token::SemiColon, _) if !need_semicolon => (),
|
||||
(Token::SemiColon, _) if !need_semicolon => {
|
||||
eat_token(input, Token::SemiColon);
|
||||
}
|
||||
// { ... { stmt } ???
|
||||
(_, _) if !need_semicolon => (),
|
||||
// { ... stmt <error>
|
||||
(Token::LexError(err), pos) => return Err(err.clone().into_err(*pos)),
|
||||
(Token::LexError(err), err_pos) => return Err(err.clone().into_err(*err_pos)),
|
||||
// { ... stmt ???
|
||||
(_, pos) => {
|
||||
// Semicolons are not optional between statements
|
||||
|
Loading…
Reference in New Issue
Block a user