Skip to content

Commit

Permalink
feat: lex macro invocations
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddiaa0 committed Oct 28, 2022
1 parent 6419682 commit 1281c08
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ enum Token {
/// Represents a Jump Label
JumpLabel(String),

MacroInvocation {
name: String,
args: Vec<String>,
},

Macro {
name: String,
takes: u32,
Expand Down Expand Up @@ -109,8 +114,23 @@ fn lex_macro_body() -> impl Parser<char, Vec<Token>, Error = Simple<char>> {
let newline = lex_newline_and_comments();
let opcode = lex_opcode_or_jump_label();
let hex_literal = lex_hex_number();
let macro_invocation = lex_macro_invocation();

macro_invocation
.or(opcode)
.or(hex_literal)
.or(newline.clone())
.repeated()
}

fn lex_macro_invocation() -> impl Parser<char, Token, Error = Simple<char>> {
let ident = text::ident();

opcode.or(hex_literal).or(newline.clone()).repeated()
ident
.then_ignore(just('('))
// TODO: args delimited by comma
.then_ignore(just(')'))
.map(|name| Token::MacroInvocation { name, args: vec![] })
}

fn lex_hex_number() -> impl Parser<char, Token, Error = Simple<char>> {
Expand Down
2 changes: 2 additions & 0 deletions test2.huff
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
#define macro test = takes(1) returns(0) {
add sub // here
sponge
some()
sponge
}

#define macro test = takes(1) returns(1) {
add sub // here
sponge
HERE()
sponge
}

0 comments on commit 1281c08

Please sign in to comment.