Skip to content

Commit 2cf27f2

Browse files
committed
Expand macros earlier so they include constants
This also simplifies macro expansion significantly, having it operate in-place.
1 parent ff5d068 commit 2cf27f2

36 files changed

+624
-753
lines changed

crates/rune-modules/README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ See each module for documentation:
5454
* [fs]
5555
* [process]
5656
* [signal]
57+
* [rand]
5758

5859
### Features
5960

@@ -62,9 +63,10 @@ See each module for documentation:
6263
* `json` for the [json module][json]
6364
* `toml` for the [toml module][toml]
6465
* `time` for the [time module][time]
65-
* `fs` for the [fs module]][fs]
66-
* `process` for the [process module]][process]
67-
* `signal` for the [process module]][signal]
66+
* `fs` for the [fs module][fs]
67+
* `process` for the [process module][process]
68+
* `signal` for the [signal module][signal]
69+
* `rand` for the [rand module][rand]
6870

6971
[http]: https://docs.rs/rune-modules/0/rune_modules/http/
7072
[json]: https://docs.rs/rune-modules/0/rune_modules/json/
@@ -73,3 +75,4 @@ See each module for documentation:
7375
[fs]: https://docs.rs/rune-modules/0/rune_modules/fs/
7476
[process]: https://docs.rs/rune-modules/0/rune_modules/process/
7577
[signal]: https://docs.rs/rune-modules/0/rune_modules/signal/
78+
[rand]: https://docs.rs/rune-modules/0/rune_modules/rand/

crates/rune/src/ast/block.rs

+4-50
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::ast;
2-
use crate::{OptionSpanned as _, Parse, ParseError, ParseErrorKind, Parser, Spanned, ToTokens};
2+
use crate::{Parse, ParseError, Parser, Spanned, ToTokens};
33

44
/// A block of expressions.
55
#[derive(Debug, Clone, PartialEq, Eq, ToTokens, Spanned)]
@@ -13,15 +13,15 @@ pub struct Block {
1313
}
1414

1515
impl Block {
16-
/// Test if the block expression doesn't produce a value.
16+
/// Test if the block produces nothing.
1717
pub fn produces_nothing(&self) -> bool {
1818
let mut it = self.statements.iter();
1919

2020
while let Some(stmt) = it.next_back() {
2121
match stmt {
22+
ast::Stmt::Item(..) => (),
2223
ast::Stmt::Expr(..) => return false,
2324
ast::Stmt::Semi(..) => return true,
24-
_ => (),
2525
}
2626
}
2727

@@ -63,55 +63,9 @@ impl Parse for Block {
6363
let mut statements = Vec::new();
6464

6565
let open = parser.parse()?;
66-
let mut must_be_last = None;
6766

6867
while !parser.peek::<ast::CloseBrace>()? {
69-
let attributes = parser.parse()?;
70-
let visibility = parser.parse()?;
71-
72-
if ast::Item::peek_as_stmt(parser)? {
73-
let decl: ast::Item = ast::Item::parse_with_meta(parser, attributes, visibility)?;
74-
75-
if let Some(span) = must_be_last {
76-
return Err(ParseError::new(
77-
span,
78-
ParseErrorKind::ExpectedBlockSemiColon {
79-
followed_span: decl.span(),
80-
},
81-
));
82-
}
83-
84-
statements.push(ast::Stmt::Item(decl));
85-
continue;
86-
}
87-
88-
if let Some(span) = visibility.option_span() {
89-
return Err(ParseError::new(
90-
span,
91-
ParseErrorKind::UnsupportedExprVisibility,
92-
));
93-
}
94-
95-
let expr: ast::Expr = ast::Expr::parse_primary_with_attributes(parser, attributes)?;
96-
97-
if let Some(span) = must_be_last {
98-
return Err(ParseError::new(
99-
span,
100-
ParseErrorKind::ExpectedBlockSemiColon {
101-
followed_span: expr.span(),
102-
},
103-
));
104-
}
105-
106-
if parser.peek::<ast::SemiColon>()? {
107-
statements.push(ast::Stmt::Semi(expr, parser.parse()?));
108-
} else {
109-
if expr.needs_semi() {
110-
must_be_last = Some(expr.span());
111-
}
112-
113-
statements.push(ast::Stmt::Expr(expr));
114-
}
68+
statements.push(parser.parse()?);
11569
}
11670

11771
let close = parser.parse()?;

0 commit comments

Comments
 (0)