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,