From 8c2f53f95032820a20e3ac5173a88871ec4861d8 Mon Sep 17 00:00:00 2001 From: John Breaux Date: Wed, 23 Aug 2023 00:15:47 -0500 Subject: [PATCH] parser.rs: Give priority to instruction parsing --- src/parser.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index de352e9..34cadae 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -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), - EndOfFile, // Expected end of file + 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 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,