This repository has been archived on 2025-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
corten/src/assembler/operand_parser.rs
Anthony Foxclaw 86f060e0f5 Implemented HLT instruction
- Instructions are now detected automatically based on context
- Since MIPs can't decide if it wants to be open or not, Corten will be aiming to be more of a RISC-V VM in the long term.
2020-02-09 15:16:38 -05:00

30 lines
655 B
Rust

#![allow(unused_imports)]
use nom::*;
use nom::{digit, types::CompleteStr};
use crate::assembler::Token;
named!(pub integer_operand<CompleteStr, Token>,
ws!(
do_parse!(
tag!("#") >>
reg_num: digit >>
(
Token::Number{value: reg_num.parse::<i32>().unwrap()}
)
)
)
);
#[cfg(test)]
mod reg_parser_test {
use super::*;
#[test]
fn test_opcode() {
let result = integer_operand(CompleteStr("#10"));
let (rest, value) = result.unwrap();
assert_eq!(rest, CompleteStr(""));
assert_eq!(value, Token::Number { value: 10 });
}
}