-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a proc macro to derive AstNode
- Loading branch information
Showing
21 changed files
with
590 additions
and
237 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
// macro hack | ||
extern crate self as shin_asm; | ||
|
||
pub mod ast; | ||
pub mod parser; | ||
pub mod syntax; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,8 @@ syntax_kind! { | |
LABEL, | ||
INSTRUCTION, | ||
|
||
INSTRUCTIONS_BLOCK, | ||
|
||
INSTR_ARG_LIST, | ||
CALL_ARG_LIST, | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
#![allow(non_snake_case)] | ||
|
||
use crate::syntax::{ | ||
ast::{self, support, AstChildren, AstNode}, | ||
Check warning on line 4 in shin-asm/src/syntax/ast/nodes.rs GitHub Actions / build
|
||
SyntaxKind::{self, *}, | ||
SyntaxNode, SyntaxToken, T, | ||
}; | ||
use shin_derive::AstNode; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, AstNode)] | ||
#[ast(kind = SOURCE_FILE)] | ||
pub struct SourceFile { | ||
pub(crate) syntax: SyntaxNode, | ||
} | ||
|
||
impl AstNode for SourceFile { | ||
fn can_cast(kind: SyntaxKind) -> bool | ||
where | ||
Self: Sized, | ||
{ | ||
kind == SOURCE_FILE | ||
} | ||
|
||
fn cast(syntax: SyntaxNode) -> Option<Self> | ||
where | ||
Self: Sized, | ||
{ | ||
if Self::can_cast(syntax.kind()) { | ||
Some(Self { syntax }) | ||
} else { | ||
None | ||
} | ||
} | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, AstNode)] | ||
pub enum Item { | ||
// NOTE: this is not what we want to do with enums... | ||
// we should support a enum of AstNodes, not of raw syntax nodes | ||
#[ast(kind = INSTRUCTIONS_BLOCK)] | ||
InstructionsBlock(SyntaxNode), | ||
// FunctionDefinition(), | ||
// SubroutineDefinition(), | ||
} | ||
|
||
fn syntax(&self) -> &SyntaxNode { | ||
&self.syntax | ||
} | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, AstNode)] | ||
#[ast(kind = INSTRUCTIONS_BLOCK)] | ||
pub struct InstructionsBlock { | ||
pub(crate) syntax: SyntaxNode, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
SOURCE_FILE | ||
LABEL | ||
IDENT "LABEL" | ||
COLON ":" | ||
INSTRUCTIONS_BLOCK | ||
LABEL | ||
IDENT "LABEL" | ||
COLON ":" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
SOURCE_FILE | ||
LABEL | ||
IDENT "LABEL" | ||
COLON ":" | ||
NEWLINE "\n" | ||
INSTRUCTIONS_BLOCK | ||
LABEL | ||
IDENT "LABEL" | ||
COLON ":" | ||
NEWLINE "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,26 @@ | ||
SOURCE_FILE | ||
LABEL | ||
IDENT "LABEL1" | ||
COLON ":" | ||
WHITESPACE " " | ||
LABEL | ||
IDENT "LABEL2" | ||
COLON ":" | ||
NEWLINE "\n" | ||
INSTRUCTIONS_BLOCK | ||
LABEL | ||
IDENT "LABEL1" | ||
COLON ":" | ||
WHITESPACE " " | ||
LABEL | ||
IDENT "LABEL2" | ||
COLON ":" | ||
NEWLINE "\n" | ||
NEWLINE "\n" | ||
LABEL | ||
IDENT "LABEL3" | ||
COLON ":" | ||
NEWLINE "\n" | ||
LABEL | ||
IDENT "LABEL4" | ||
COLON ":" | ||
NEWLINE "\n" | ||
INSTRUCTIONS_BLOCK | ||
LABEL | ||
IDENT "LABEL3" | ||
COLON ":" | ||
NEWLINE "\n" | ||
LABEL | ||
IDENT "LABEL4" | ||
COLON ":" | ||
NEWLINE "\n" | ||
NEWLINE "\n" | ||
LABEL | ||
IDENT "LABEL5" | ||
COLON ":" | ||
NEWLINE "\n" | ||
INSTRUCTIONS_BLOCK | ||
LABEL | ||
IDENT "LABEL5" | ||
COLON ":" | ||
NEWLINE "\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
SOURCE_FILE | ||
INSTRUCTION | ||
IDENT "EXIT" | ||
WHITESPACE " " | ||
INSTR_ARG_LIST | ||
LITERAL | ||
INT_NUMBER "0" | ||
COMMA "," | ||
INSTRUCTIONS_BLOCK | ||
INSTRUCTION | ||
IDENT "EXIT" | ||
WHITESPACE " " | ||
LITERAL | ||
INT_NUMBER "0" | ||
INSTR_ARG_LIST | ||
LITERAL | ||
INT_NUMBER "0" | ||
COMMA "," | ||
WHITESPACE " " | ||
LITERAL | ||
INT_NUMBER "0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
SOURCE_FILE | ||
LABEL | ||
IDENT "LABEL" | ||
COLON ":" | ||
NEWLINE "\n" | ||
WHITESPACE " " | ||
INSTRUCTION | ||
IDENT "EXIT" | ||
WHITESPACE " " | ||
INSTR_ARG_LIST | ||
LITERAL | ||
INT_NUMBER "0" | ||
COMMA "," | ||
INSTRUCTIONS_BLOCK | ||
LABEL | ||
IDENT "LABEL" | ||
COLON ":" | ||
NEWLINE "\n" | ||
WHITESPACE " " | ||
INSTRUCTION | ||
IDENT "EXIT" | ||
WHITESPACE " " | ||
LITERAL | ||
INT_NUMBER "0" | ||
INSTR_ARG_LIST | ||
LITERAL | ||
INT_NUMBER "0" | ||
COMMA "," | ||
WHITESPACE " " | ||
LITERAL | ||
INT_NUMBER "0" |
25 changes: 13 additions & 12 deletions
25
shin-asm/test_data/parser/ok/0005_labeled_exit_one_line.sast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
SOURCE_FILE | ||
LABEL | ||
IDENT "LABEL" | ||
COLON ":" | ||
INSTRUCTION | ||
IDENT "EXIT" | ||
WHITESPACE " " | ||
INSTR_ARG_LIST | ||
LITERAL | ||
INT_NUMBER "0" | ||
COMMA "," | ||
INSTRUCTIONS_BLOCK | ||
LABEL | ||
IDENT "LABEL" | ||
COLON ":" | ||
INSTRUCTION | ||
IDENT "EXIT" | ||
WHITESPACE " " | ||
LITERAL | ||
INT_NUMBER "0" | ||
INSTR_ARG_LIST | ||
LITERAL | ||
INT_NUMBER "0" | ||
COMMA "," | ||
WHITESPACE " " | ||
LITERAL | ||
INT_NUMBER "0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
SOURCE_FILE | ||
INSTRUCTION | ||
IDENT "exp" | ||
WHITESPACE " " | ||
INSTR_ARG_LIST | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$v1" | ||
COMMA "," | ||
WHITESPACE "\\\n " | ||
BIN_EXPR | ||
INSTRUCTIONS_BLOCK | ||
INSTRUCTION | ||
IDENT "exp" | ||
WHITESPACE " " | ||
INSTR_ARG_LIST | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$v1" | ||
COMMA "," | ||
WHITESPACE "\\\n " | ||
BIN_EXPR | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$x" | ||
BIN_EXPR | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$x" | ||
WHITESPACE " " | ||
DOT_STAR ".*" | ||
WHITESPACE " " | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$x" | ||
WHITESPACE " " | ||
DOT_STAR ".*" | ||
WHITESPACE " " | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$x" | ||
WHITESPACE " " | ||
PLUS "+" | ||
WHITESPACE " \\\n " | ||
BIN_EXPR | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$y" | ||
WHITESPACE " " | ||
DOT_STAR ".*" | ||
WHITESPACE " " | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$y" | ||
PLUS "+" | ||
WHITESPACE " \\\n " | ||
BIN_EXPR | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$y" | ||
WHITESPACE " " | ||
DOT_STAR ".*" | ||
WHITESPACE " " | ||
REGISTER_REF_EXPR | ||
REGISTER_IDENT "$y" |
Oops, something went wrong.