def parse
stacks = [[]]
level = 0
until (token = @lexer.next_token(stacks[level>0?level-1:0].last)).nil?
directive = token[0]
nesting = token[1]
ntop = stacks[level].last.nil? ?
directive : stacks[level].last.join(directive)
stacks[level] << directive
if nesting > 0
stacks.push []
level += 1
elsif nesting < 0
directives = stacks.pop
level -= 1
stacks[level].last.connect directives
end
end
if stacks.size > 1
raise SyntaxError.new(stacks[-2].last.pos), 'unterminated directive'
end
return stacks[0]
end