{
CssConstruct param = handleAtRuleParam(tk, iter, doc, err);
if (param == null)
{
// issue error, forward, then return
err.error(new CssGrammarException(GRAMMAR_UNEXPECTED_TOKEN,
iter.last.location, iter.last.chars));
//skip to atrule closebrace, ignoring any inner blocks
int stack = 0;
while (true)
{
CssToken tok = iter.next();
if (MATCH_SEMI.apply(tok) && stack == 0)
{
return; //a non-block at rule
}
else if (MATCH_OPENBRACE.apply(tok))
{
stack++;
}
else if (MATCH_CLOSEBRACE.apply(tok))
{
if (stack == 1)
{
break;
}
stack--;
}
}
return;
}
else
{
atRule.components.add(param);
}
}
}
}
catch (NoSuchElementException nse)
{
// UAs required to close any open constructs on premature EOF
doc.startAtRule(atRule);
err.error(new CssGrammarException(GRAMMAR_PREMATURE_EOF, iter.last.location, "';' "
+ Messages.get("or") + " '{'"));
doc.endAtRule(atRule.getName().get());
throw new PrematureEOFException();
}
if (debug)
{
checkArgument(MATCH_SEMI_OPENBRACE.apply(iter.last));
checkArgument(iter.filter() == FILTER_S_CMNT);
}
// ending up here only on expected end
doc.startAtRule(atRule);
if (atRule.hasBlock)
{
try
{
if (hasRuleSet(atRule, iter))
{
while (!MATCH_CLOSEBRACE.apply(iter.next()))
{
if (iter.last.type == CssToken.Type.ATKEYWORD)
{
handleAtRule(iter.last, iter, doc, err);
}
else
{
handleRuleSet(iter.last, iter, doc, err);
}
}
}
else
{
handleDeclarationBlock(iter.next(), iter, doc, err);
}
}
catch (NoSuchElementException nse)
{
err.error(new CssGrammarException(GRAMMAR_PREMATURE_EOF, iter.last.location, "'}'"));
doc.endAtRule(atRule.name.get());
throw new PrematureEOFException();
}
}
doc.endAtRule(atRule.name.get());