Skip to content

Commit

Permalink
Merge branch 'master' into volsa/lit
Browse files Browse the repository at this point in the history
  • Loading branch information
volsa authored Jun 18, 2024
2 parents 44ef766 + 8d0e9e5 commit b248a19
Show file tree
Hide file tree
Showing 14 changed files with 404 additions and 364 deletions.
File renamed without changes.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# RuSTy

[![Rust Build](https://github.com/PLC-lang/rusty/actions/workflows/rust.yml/badge.svg)](https://github.com/PLC-lang/ruSTy/actions)
[![Linux Build](https://github.com/PLC-lang/rusty/actions/workflows/linux.yml/badge.svg)](https://github.com/PLC-lang/ruSTy/actions)
[![Windows Build](https://github.com/PLC-lang/rusty/actions/workflows/windows.yml/badge.svg)](https://github.com/PLC-lang/rusty/actions/workflows/windows.yml)
[![Documentation](https://github.com/PLC-lang/rusty/actions/workflows/doc.yml/badge.svg)](https://plc-lang.github.io/rusty)
[![codecov](https://codecov.io/gh/PLC-lang/rusty/branch/master/graph/badge.svg?token=7ZZ5XZYE9V)](https://codecov.io/gh/PLC-lang/rusty)
[![Metrics](https://github.com/PLC-lang/rusty/actions/workflows/metrics.yml/badge.svg)](https://plc-lang.github.io/metrics)

[![Lines of Code](https://tokei.rs/b1/github/PLC-lang/rusty)](https://github.com/XAMPPRocky/tokei)

[Structured text](https://en.wikipedia.org/wiki/Structured_text) compiler written in Rust
Expand Down
33 changes: 25 additions & 8 deletions compiler/plc_diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::fmt::Display;

use serde::{Deserialize, Serialize};

use crate::diagnostics::diagnostics_registry::DIAGNOSTICS;
use plc_ast::ast::AstNode;
use plc_source::{
source_location::{SourceLocation, SourceLocationFactory},
Expand Down Expand Up @@ -88,8 +89,10 @@ impl Diagnostic {
self
}

pub fn with_error_code(mut self, error_code: &'static str) -> Self {
self.error_code = error_code;
pub fn with_error_code(mut self, code: &'static str) -> Self {
debug_assert!(DIAGNOSTICS.get(code).is_some(), "Error {code} does not exist");

self.error_code = code;
self
}

Expand Down Expand Up @@ -199,12 +202,26 @@ impl Diagnostic {
.with_error_code("E006")
}

pub fn invalid_parameter_count(expected: usize, received: usize, location: SourceLocation) -> Diagnostic {
Diagnostic::new(
format!(
"Invalid parameter count. Received {received} parameters while {expected} parameters were expected.",
)).with_error_code("E032")
.with_location(location)
pub fn invalid_argument_count<T>(expected: usize, actual: usize, location: T) -> Diagnostic
where
T: Into<SourceLocation>,
{
// Let's be extra fancy here 🕺
fn message(value: usize) -> String {
match value {
1 => format!("{value} argument"),
_ => format!("{value} arguments"),
}
}

Diagnostic::new(format!(
"this POU takes {expected} but {actual} {was_or_were} supplied",
expected = message(expected),
actual = message(actual),
was_or_were = if actual == 1 { "was" } else { "were" }
))
.with_error_code("E032")
.with_location(location.into())
}

pub fn unknown_type(type_name: &str, location: SourceLocation) -> Diagnostic {
Expand Down
Loading

0 comments on commit b248a19

Please sign in to comment.