Skip to content

Commit

Permalink
Fix span and string reference
Browse files Browse the repository at this point in the history
  • Loading branch information
oovm committed Mar 23, 2024
1 parent 761feab commit 2103d29
Show file tree
Hide file tree
Showing 37 changed files with 975 additions and 965 deletions.
2 changes: 1 addition & 1 deletion projects/valkyrie-parser/src/atomic/create_lambda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<'i> crate::DefineLambdaNode<'i> {
parameters: self.function_middle().parameters(ctx),
returns,
body: self.continuation().build(ctx),
span: self.span().clone(),
span: self.get_range32(),
})
}
}
6 changes: 2 additions & 4 deletions projects/valkyrie-parser/src/atomic/create_new.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use super::*;
use crate::utils::Ast2Hir;
use yggdrasil_rt::YggdrasilNode;

impl<'i> crate::NewStatementNode<'i> {
pub(crate) fn build(&self, ctx: &mut ProgramState) -> Result<ConstructNewNode> {
Expand All @@ -15,12 +13,12 @@ impl<'i> crate::NewStatementNode<'i> {
generics,
arguments: self.tuple_literal().as_ref().map(|s| s.tuple_terms().to_hir(ctx)).unwrap_or_default(),
body: self.new_block().as_ref().map(|s| s.build(ctx)).unwrap_or_default(),
span: self.get_range(),
span: self.get_range32(),
})
}
fn annotations(&self, ctx: &mut ProgramState) -> AnnotationNode {
let mut out = AnnotationNode::default();
for term in &self.modifier_ahead {
for term in &self.modifier_ahead() {
out.modifiers.terms.push(term.build(ctx))
}
out
Expand Down
11 changes: 3 additions & 8 deletions projects/valkyrie-parser/src/atomic/identifier.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use super::*;
use nyar_error::SourceID;
use std::sync::Arc;
use yggdrasil_rt::YggdrasilNode;

impl<'i> crate::NamepathNode<'i> {
pub(crate) fn build(&self, ctx: &mut ProgramState) -> NamePathNode {
Expand All @@ -19,11 +16,9 @@ impl<'i> crate::NamepathFreeNode<'i> {
impl<'i> crate::IdentifierNode<'i> {
pub fn build(&self, file: SourceID) -> IdentifierNode {
match self {
Self::IdentifierBare(v) => {
IdentifierNode { name: Arc::from(v.get_text().as_str()), span: file.with_range(v.get_range32().clone()) }
}
Self::IdentifierBare(v) => IdentifierNode { name: Arc::from(v.get_str()), span: file.with_range(v.get_range32()) },
Self::IdentifierRaw(v) => IdentifierNode {
name: Arc::from(v.identifier_raw_text().get_text().as_str()),
name: Arc::from(v.identifier_raw_text().get_str()),
span: file.with_range(v.get_range32().clone()),
},
}
Expand All @@ -32,7 +27,7 @@ impl<'i> crate::IdentifierNode<'i> {

impl<'i> crate::SlotNode<'i> {
pub(crate) fn build(&self, ctx: &mut ProgramState) -> Result<LambdaSlotNode> {
Ok(LambdaSlotNode { level: self.op_slot().get_range32(), item: self.item(ctx)?, span: self.get_range32() })
Ok(LambdaSlotNode { level: self.op_slot().get_str().len(), item: self.item(ctx)?, span: self.get_range32() })
}
fn item(&self, ctx: &mut ProgramState) -> Result<LambdaSlotItem> {
match &self.slot_item() {
Expand Down
11 changes: 8 additions & 3 deletions projects/valkyrie-parser/src/atomic/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
use crate::{helpers::ProgramState, utils::build_annotation_terms};
use nyar_error::{Result, SyntaxError};
use std::num::NonZeroU64;
use crate::{
helpers::ProgramState,
traits::YggdrasilNodeExtension,
utils::{build_annotation_terms, Ast2Hir},
};
use nyar_error::{Result, SourceID, SyntaxError};
use std::{num::NonZeroU64, sync::Arc};
use valkyrie_ast::*;
use yggdrasil_rt::YggdrasilNode;

mod bytes;
mod create_lambda;
Expand Down
24 changes: 12 additions & 12 deletions projects/valkyrie-parser/src/atomic/number.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use crate::SignNode;
use crate::{traits::YggdrasilNodeExtension, SignNode};
use nyar_error::NyarError;
use std::{str::FromStr, sync::Arc};
use valkyrie_ast::NullNode;
Expand Down Expand Up @@ -27,16 +27,16 @@ impl<'i> crate::DecimalNode<'i> {
pub(crate) fn build(&self, ctx: &mut ProgramState) -> Result<ExpressionKind> {
let mut n = NumberLiteralNode::new(10);
n.set_span(ctx.file.with_range(self.get_range32()));
n.set_integer(&self.lhs().text, ctx.file, self.lhs().span.start as usize)?;
n.set_integer(&self.lhs().get_str(), ctx.file, self.lhs().get_range().start)?;
if let Some(s) = &self.rhs() {
n.set_decimal(&s.text, ctx.file, s.span.start as usize)?
n.set_decimal(s.get_str(), ctx.file, s.get_range().start)?
}
if let Some(s) = &self.unit() {
n.unit = Some(s.build(ctx.file))
}
if let Some(s) = &self.shift() {
match &self.sign() {
Some(SignNode::Netative) => n.shift = -s.parse::<isize>(ctx)?,
Some(SignNode::Netative(_)) => n.shift = -s.parse::<isize>(ctx)?,
_ => n.shift = s.parse::<isize>(ctx)?,
}
}
Expand All @@ -49,16 +49,16 @@ impl<'i> crate::DecimalXNode<'i> {
pub(crate) fn build(&self, ctx: &mut ProgramState) -> Result<ExpressionKind> {
let mut n = NumberLiteralNode::new(self.base().as_base(ctx)?);
n.set_span(ctx.file.with_range(self.get_range32()));
n.set_integer(&self.lhs().text, ctx.file, self.lhs().span.start as usize)?;
n.set_integer(self.lhs().get_str(), ctx.file, self.lhs().get_range().start as usize)?;
if let Some(s) = &self.rhs() {
n.set_decimal(&s.text, ctx.file, s.span.start as usize)?
n.set_decimal(s.get_str(), ctx.file, s.get_range().start as usize)?
}
if let Some(s) = &self.unit() {
n.unit = Some(s.build(ctx.file))
}
if let Some(s) = &self.shift() {
match &self.sign() {
Some(SignNode::Netative) => n.shift = -s.parse::<isize>(ctx)?,
Some(SignNode::Netative(_)) => n.shift = -s.parse::<isize>(ctx)?,
_ => n.shift = s.parse::<isize>(ctx)?,
}
}
Expand All @@ -72,12 +72,12 @@ impl<'i> crate::IntegerNode<'i> {
// NumberLiteralNode::new(10, self.get_range32())
// }
pub(crate) fn as_identifier(&self, ctx: &mut ProgramState) -> IdentifierNode {
let text: String = self.get_text().chars().filter(|c| c.is_digit(10)).collect();
let text: String = self.get_chars().filter(|c| c.is_digit(10)).collect();
IdentifierNode { name: Arc::from(text), span: ctx.file.with_range(self.get_range32()) }
}
pub(crate) fn as_base(&self, ctx: &mut ProgramState) -> Result<u32> {
let span = ctx.file.with_range(self.get_range32());
match u32::from_str(&self.get_text()) {
match u32::from_str(self.get_str()) {
Ok(o) if o >= 2 && o <= 36 => Ok(o),
Ok(_) => Err(NyarError::syntax_error(format!("Currently only `2 ⩽ base ⩽ 36` is supported"), span)),
Err(e) => Err(NyarError::syntax_error(e.to_string(), span)),
Expand All @@ -89,7 +89,7 @@ impl<'i> crate::IntegerNode<'i> {
<T as FromStr>::Err: std::error::Error,
{
let span = ctx.file.with_range(self.get_range32());
match T::from_str(&self.text) {
match T::from_str(self.get_str()) {
Ok(o) => Ok(o),
Err(e) => Err(NyarError::syntax_error(e.to_string(), span)),
}
Expand All @@ -98,12 +98,12 @@ impl<'i> crate::IntegerNode<'i> {

impl<'i> crate::SpecialNode<'i> {
pub(crate) fn build(&self) -> ExpressionKind {
match self.get_text().as_str() {
match self.get_str() {
"false" => BooleanNode { value: false, span: self.get_range32() }.into(),
"true" => BooleanNode { value: true, span: self.get_range32() }.into(),
"∞" => NullNode { nil: true, span: self.get_range32() }.into(),
"∅" | "nil" => NullNode { nil: true, span: self.get_range32() }.into(),
_ => unimplemented!("Unknown special value: {}", self.text),
_ => unimplemented!("Unknown special value: {}", self.get_str()),
}
}
}
4 changes: 2 additions & 2 deletions projects/valkyrie-parser/src/atomic/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl<'i> crate::RangeLiteralNode<'i> {
Err(e) => ctx.add_error(e),
}
}
value.span = v.span().clone()
value.span = v.get_range32()
}
Self::RangeLiteralIndex1(v) => {
value.kind = RangeKind::Offset;
Expand All @@ -22,7 +22,7 @@ impl<'i> crate::RangeLiteralNode<'i> {
Err(e) => ctx.add_error(e),
}
}
value.span = v.span().clone()
value.span = v.get_range32()
}
}
Ok(value)
Expand Down
12 changes: 6 additions & 6 deletions projects/valkyrie-parser/src/atomic/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ impl<'i> crate::TextRawNode<'i> {
pub(crate) fn build(&self, file: SourceID) -> StringTextNode {
let mut buffer = String::new();
if let Some(s) = &self.text_content_1() {
buffer.push_str(&s.get_text())
buffer.push_str(s.get_str())
}
if let Some(s) = &self.text_content_2() {
buffer.push_str(&s.get_text())
buffer.push_str(s.get_str())
}
if let Some(s) = &self.text_content_3() {
buffer.push_str(&s.get_text())
buffer.push_str(s.get_str())
}
if let Some(s) = &self.text_content_4() {
buffer.push_str(&s.get_text())
buffer.push_str(s.get_str())
}
if let Some(s) = &self.text_content_5() {
buffer.push_str(&s.get_text())
buffer.push_str(s.get_str())
}
if let Some(s) = &self.text_content_6() {
buffer.push_str(&s.get_text())
buffer.push_str(s.get_str())
}
StringTextNode { text: buffer, span: file.with_range(self.get_range32()) }
}
Expand Down
2 changes: 1 addition & 1 deletion projects/valkyrie-parser/src/atomic/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'i> crate::TuplePairNode<'i> {
Ok(ArgumentTerm {
modifiers: Default::default(),
key,
value: self.main_expression.build(ctx)?,
value: self.main_expression().build(ctx)?,
span: ctx.file.with_range(self.get_range32()),
})
}
Expand Down
Loading

0 comments on commit 2103d29

Please sign in to comment.