diff --git a/src/parser/instruction.rs b/src/parser/instruction.rs index 57e2e9b..a19bcf1 100644 --- a/src/parser/instruction.rs +++ b/src/parser/instruction.rs @@ -34,8 +34,7 @@ impl Parsable for Instruction { T: crate::TokenStream<'text>, { // parse an opcode - let insn = stream.expect(Type::Insn)?; - let opcode: Opcode = insn.parse()?; + let opcode: Opcode = Opcode::parse(p, stream)?; // resolve the opcode to a final opcode and an encoding let (opcode, encoding) = opcode.resolve(); // parse the encoding diff --git a/src/parser/instruction/opcode.rs b/src/parser/instruction/opcode.rs index 1384cc8..bd38c5f 100644 --- a/src/parser/instruction/opcode.rs +++ b/src/parser/instruction/opcode.rs @@ -124,11 +124,18 @@ impl Opcode { } } +impl Parsable for Opcode { + fn parse<'text, T>(_: &Parser, stream: &mut T) -> Result + where T: TokenStream<'text> { + stream.expect(Type::Insn)?.parse().map_err(|e: Error| e.context(stream.context())) + } +} + impl FromStr for Opcode { type Err = Error; fn from_str(s: &str) -> Result { use Opcode::*; - //TODO: Reduce allocations here + //TODO: Reduce allocations here? let s = s.to_ascii_lowercase(); Ok(match s.as_str() { "rrc" => Rrc,