Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add github workflow. #7

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Build
run: cargo build --verbose
- name: Run tests
run: cargo test --verbose
- name: rustfmt
run: cargo fmt --all --check
4 changes: 2 additions & 2 deletions src/ast/converting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ use crate::{ast::nodes::*, parser::lexer::SourcePosition};
/// how to proceed.
pub trait AstConverting {
/// Pushes the source position of the current node onto a stack.
fn push_source_position(&mut self, start: &SourcePosition, end: &SourcePosition) -> ();
fn push_source_position(&mut self, start: &SourcePosition, end: &SourcePosition);

/// Pops the source position of the current node from the stack.
fn pop_source_position(&mut self) -> ();
fn pop_source_position(&mut self);

/// Converts a `NodeByteStr` node.
fn emit_byte_str(
Expand Down
74 changes: 25 additions & 49 deletions src/ast/nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct WithMetaData<T> {
impl<T: fmt::Display> fmt::Display for WithMetaData<T> {
/// Formats the WithMetaData instance into a string
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.node.to_string())
write!(f, "{}", self.node)
}
}

Expand All @@ -32,18 +32,13 @@ pub enum NodeByteStr {
Type(WithMetaData<String>),
}

impl NodeByteStr {
/// Converts the NodeByteStr to a string
pub fn to_string(&self) -> String {
match self {
NodeByteStr::Constant(s) => s.node.clone(),
NodeByteStr::Type(t) => t.node.clone(),
}
}
}
impl fmt::Display for NodeByteStr {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
let str = match self {
NodeByteStr::Constant(s) => s.node.clone(),
NodeByteStr::Type(t) => t.node.clone(),
};
write!(f, "{}", str)
}
}

Expand All @@ -61,23 +56,16 @@ pub enum NodeTypeNameIdentifier {
TypeOrEnumLikeIdentifier(WithMetaData<String>),
}

impl NodeTypeNameIdentifier {
/// Converts the NodeTypeNameIdentifier to a string
pub fn to_string(&self) -> String {
match self {
NodeTypeNameIdentifier::ByteStringType(byte_str) => {
format!("{}", byte_str.to_string())
}
NodeTypeNameIdentifier::EventType => format!("Event"),
impl fmt::Display for NodeTypeNameIdentifier {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let str = match self {
NodeTypeNameIdentifier::ByteStringType(byte_str) => byte_str.to_string(),
NodeTypeNameIdentifier::EventType => "Event".to_string(),
NodeTypeNameIdentifier::TypeOrEnumLikeIdentifier(custom_type) => {
format!("{}", custom_type.clone())
}
}
}
}
impl fmt::Display for NodeTypeNameIdentifier {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
};
write!(f, "{}", str)
}
}

Expand Down Expand Up @@ -121,10 +109,9 @@ pub enum NodeMetaIdentifier {
ByteString,
}

impl NodeMetaIdentifier {
/// Converts the NodeMetaIdentifier to a string
pub fn to_string(&self) -> String {
match self {
impl fmt::Display for NodeMetaIdentifier {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let str = match self {
NodeMetaIdentifier::MetaName(name) => {
format!("{}", name)
}
Expand All @@ -134,14 +121,9 @@ impl NodeMetaIdentifier {
NodeMetaIdentifier::MetaNameInHexspace(hexspace, name) => {
format!("{}.{}", hexspace, name)
}
NodeMetaIdentifier::ByteString => format!("ByStr"),
}
}
}

impl fmt::Display for NodeMetaIdentifier {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
NodeMetaIdentifier::ByteString => "ByStr".to_string(),
};
write!(f, "{}", str)
}
}

Expand All @@ -159,22 +141,16 @@ pub enum NodeVariableIdentifier {
VariableInNamespace(WithMetaData<NodeTypeNameIdentifier>, WithMetaData<String>),
}

impl NodeVariableIdentifier {
/// Converts the NodeVariableIdentifier to a string
pub fn to_string(&self) -> String {
match self {
impl fmt::Display for NodeVariableIdentifier {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let str = match self {
NodeVariableIdentifier::VariableName(name) => format!("{}", name),
NodeVariableIdentifier::SpecialIdentifier(id) => format!("{}", id),
NodeVariableIdentifier::VariableInNamespace(namespace, var_name) => {
format!("{}.{}", namespace.to_string(), var_name)
format!("{}.{}", namespace, var_name)
}
}
}
}

impl fmt::Display for NodeVariableIdentifier {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
};
write!(f, "{}", str)
}
}

Expand Down
Loading