parser.rs: Give priority to instruction parsing
This commit is contained in:
parent
b5fd49b0b4
commit
8c2f53f950
@ -47,27 +47,26 @@ pub(crate) mod line {
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum Line {
|
||||
Empty,
|
||||
Label(Label), // TODO: Label resolution
|
||||
Insn(Instruction),
|
||||
Directive(Directive),
|
||||
Comment(Comment),
|
||||
Directive(Directive),
|
||||
Label(Label), // TODO: Label resolution
|
||||
EndOfFile, // Expected end of file
|
||||
}
|
||||
|
||||
impl Parsable for Line {
|
||||
fn parse<'text, T>(p: &Parser, stream: &mut T) -> Result<Self, Error>
|
||||
where T: TokenStream<'text> {
|
||||
if let Ok(token) = stream.peek_expect_any_of([Type::Comment, Type::Directive, Type::Insn, Type::Identifier])
|
||||
if let Ok(token) = stream.peek_expect_any_of([Type::Insn, Type::Comment, Type::Directive, Type::Identifier])
|
||||
{
|
||||
return Ok(match token.variant() {
|
||||
Type::Insn => Self::Insn(Instruction::parse(p, stream)?),
|
||||
Type::Comment => Self::Comment(Comment::parse(p, stream)?),
|
||||
Type::Directive => Self::Directive(Directive::parse(p, stream)?),
|
||||
Type::Identifier => Self::Label(Label::parse(p, stream)?),
|
||||
Type::Insn => Self::Insn(Instruction::parse(p, stream)?),
|
||||
_ => unreachable!(),
|
||||
});
|
||||
}
|
||||
// TODO: preserve comments
|
||||
let token = stream.expect_any_of([Type::EndOfFile])?;
|
||||
Ok(match token.variant() {
|
||||
Type::EndOfFile => Self::EndOfFile,
|
||||
|
Loading…
Reference in New Issue
Block a user