Skip to content

Commit

Permalink
Merge pull request #20 from mrLSD/feat/func-params
Browse files Browse the repository at this point in the history
Feat: Function parameters init as variables
  • Loading branch information
mrLSD authored Dec 2, 2023
2 parents eea35c6 + 6c713fa commit 177e077
Show file tree
Hide file tree
Showing 12 changed files with 339 additions and 59 deletions.
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "semantic-analyzer"
version = "0.3.1"
version = "0.3.2"
authors = ["Evgeny Ukhanov <mrlsd@ya.ru>"]
description = "Semantic analyzer library for compilers written in Rust for semantic analysis of programming languages AST"
keywords = ["compiler", "semantic-analisis", "semantic-alalyzer", "compiler-design", "semantic"]
Expand All @@ -13,5 +13,9 @@ repository = "https://github.com/mrLSD/semantic-analyzer-rs"
[lib]
doctest = false

#[lints.clippy]
#pedantic = "deny"
#nursery = "deny"

[dependencies]
nom_locate = "4.2"
11 changes: 11 additions & 0 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl GetName for ImportName<'_> {
}

impl<'a> ImportName<'a> {
#[must_use]
pub const fn new(ident: Ident<'a>) -> Self {
Self(ident)
}
Expand All @@ -47,6 +48,7 @@ pub struct ConstantName<'a>(Ident<'a>);

impl<'a> ConstantName<'a> {
/// Init `ConstantName`, especially useful for testing
#[must_use]
pub const fn new(name: Ident<'a>) -> Self {
Self(name)
}
Expand All @@ -69,6 +71,7 @@ impl GetName for ConstantName<'_> {
pub struct FunctionName<'a>(Ident<'a>);

impl<'a> FunctionName<'a> {
#[must_use]
pub const fn new(name: Ident<'a>) -> Self {
Self(name)
}
Expand All @@ -92,6 +95,7 @@ impl<'a> ToString for FunctionName<'a> {
pub struct ParameterName<'a>(Ident<'a>);

impl<'a> ParameterName<'a> {
#[must_use]
pub const fn new(name: Ident<'a>) -> Self {
Self(name)
}
Expand All @@ -112,6 +116,7 @@ impl ToString for ParameterName<'_> {
pub struct ValueName<'a>(Ident<'a>);

impl<'a> ValueName<'a> {
#[must_use]
pub const fn new(name: Ident<'a>) -> Self {
Self(name)
}
Expand All @@ -138,16 +143,19 @@ impl CodeLocation {
/// Initialize code location with:
/// - `location` - line of source code
/// - `offset` - position on the line of source code
#[must_use]
pub const fn new(location: u32, offset: usize) -> Self {
Self(location, offset)
}

/// Get location line in the source
#[must_use]
pub const fn line(&self) -> u32 {
self.0
}

/// Get location position on the line in the source
#[must_use]
pub const fn offset(&self) -> usize {
self.1
}
Expand Down Expand Up @@ -383,6 +391,7 @@ pub enum PrimitiveValue {
}

impl PrimitiveValue {
#[must_use]
pub const fn get_type(&self) -> Type<'_> {
match self {
Self::U8(_) => Type::Primitive(PrimitiveTypes::U8),
Expand Down Expand Up @@ -451,6 +460,8 @@ pub enum ExpressionOperations {
}

impl ExpressionOperations {
/// Get expression operation priority level
#[must_use]
pub const fn priority(&self) -> u8 {
match self {
Self::Plus => 5,
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![deny(clippy::pedantic, clippy::nursery)]
#![allow(clippy::module_name_repetitions)]
//! # Semantic Analyzer
//! The semantic analyzer consists of the following basic elements:
//! - AST is an abstract syntax tree that implements a predefined set of
Expand Down
Loading

0 comments on commit 177e077

Please sign in to comment.