Make function body a list of AtRule rather than token
This commit is contained in:
parent
cdd0ccca16
commit
ddb5b6f32a
@ -1,6 +1,7 @@
|
|||||||
use std::iter::Peekable;
|
use std::iter::Peekable;
|
||||||
use std::vec::IntoIter;
|
use std::vec::IntoIter;
|
||||||
|
|
||||||
|
use crate::atrule::AtRule;
|
||||||
use crate::common::{Pos, Scope, Symbol};
|
use crate::common::{Pos, Scope, Symbol};
|
||||||
use crate::args::{eat_func_args, FuncArgs};
|
use crate::args::{eat_func_args, FuncArgs};
|
||||||
use crate::utils::devour_whitespace;
|
use crate::utils::devour_whitespace;
|
||||||
@ -10,12 +11,12 @@ use crate::{Token, TokenKind};
|
|||||||
pub(crate) struct Function {
|
pub(crate) struct Function {
|
||||||
scope: Scope,
|
scope: Scope,
|
||||||
args: FuncArgs,
|
args: FuncArgs,
|
||||||
body: Peekable<IntoIter<Token>>,
|
body: Peekable<IntoIter<AtRule>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
impl Function {
|
impl Function {
|
||||||
pub fn new(scope: Scope, args: FuncArgs, body: Vec<Token>) -> Self {
|
pub fn new(scope: Scope, args: FuncArgs, body: Vec<AtRule>) -> Self {
|
||||||
let body = body.into_iter().peekable();
|
let body = body.into_iter().peekable();
|
||||||
Function { scope, args, body }
|
Function { scope, args, body }
|
||||||
}
|
}
|
||||||
@ -47,18 +48,16 @@ impl Function {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut nesting = 1;
|
let mut nesting = 1;
|
||||||
let mut body = Vec::new();
|
let mut body: Vec<AtRule> = Vec::new();
|
||||||
|
|
||||||
while nesting > 0 {
|
while nesting > 0 {
|
||||||
if let Some(tok) = toks.next() {
|
if let Some(tok) = toks.next() {
|
||||||
match &tok.kind {
|
match &tok.kind {
|
||||||
TokenKind::Symbol(Symbol::OpenCurlyBrace)
|
TokenKind::AtRule(rule) => body.push(AtRule::from_tokens(&rule, tok.pos, toks, scope)),
|
||||||
// interpolation token eats the opening brace but not the closing
|
|
||||||
| TokenKind::Interpolation => nesting += 1,
|
|
||||||
TokenKind::Symbol(Symbol::CloseCurlyBrace) => nesting -= 1,
|
TokenKind::Symbol(Symbol::CloseCurlyBrace) => nesting -= 1,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
body.push(tok)
|
|
||||||
} else {
|
} else {
|
||||||
return Err((pos, String::from("unexpected EOF")));
|
return Err((pos, String::from("unexpected EOF")));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user