mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
added macro support, syntax is !(macro-type ...), i.e. !(mers my_file.mers) or !(mers { "value to compute at compile-time".regex("\\S+").assume_no_enum() })
This commit is contained in:
parent
0a2c67c2d5
commit
09d0d29138
@ -121,7 +121,10 @@ impl Lib {
|
||||
fn_signature.next();
|
||||
} else {
|
||||
loop {
|
||||
let mut t = match parse::parse_type_adv(&mut fn_signature, true) {
|
||||
let mut t = match parse::implementation::parse_type_adv(
|
||||
&mut fn_signature,
|
||||
true,
|
||||
) {
|
||||
Ok(v) => v,
|
||||
Err(e) => panic!("{e}"),
|
||||
};
|
||||
@ -132,7 +135,8 @@ impl Lib {
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut fn_out = match parse::parse_type(&mut fn_signature) {
|
||||
let mut fn_out = match parse::implementation::parse_type(&mut fn_signature)
|
||||
{
|
||||
Ok(v) => v,
|
||||
Err(e) => panic!("{e}"),
|
||||
};
|
||||
|
@ -1,16 +1,20 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub fn path_from_string(path: &str, script_directory: &PathBuf) -> Option<PathBuf> {
|
||||
pub fn path_from_string(path: &str, script_path: &PathBuf) -> Option<PathBuf> {
|
||||
let path = PathBuf::from(path);
|
||||
if path.is_absolute() {
|
||||
return Some(path);
|
||||
}
|
||||
if let Some(p) = script_directory
|
||||
if let Some(p) = script_path
|
||||
.canonicalize()
|
||||
.unwrap_or_else(|_| script_directory.clone())
|
||||
.unwrap_or_else(|_| script_path.clone())
|
||||
.parent()
|
||||
{
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("path: parent path: {p:?}");
|
||||
let p = p.join(&path);
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("path: joined: {p:?}");
|
||||
if p.exists() {
|
||||
return Some(p);
|
||||
}
|
||||
|
@ -108,12 +108,27 @@ impl File {
|
||||
}
|
||||
pub fn skip_whitespaces(&mut self) {
|
||||
loop {
|
||||
match self.chars.get(self.pos.current_char_index) {
|
||||
Some(ch) if ch.1.is_whitespace() => _ = self.next(),
|
||||
match self.peek() {
|
||||
Some(ch) if ch.is_whitespace() => _ = self.next(),
|
||||
_ => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn collect_to_whitespace(&mut self) -> String {
|
||||
let mut o = String::new();
|
||||
loop {
|
||||
if let Some(ch) = self.next() {
|
||||
if ch.is_whitespace() {
|
||||
self.set_pos(*self.get_ppos());
|
||||
break;
|
||||
}
|
||||
o.push(ch);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
o
|
||||
}
|
||||
pub fn path(&self) -> &PathBuf {
|
||||
&self.path
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
use std::fmt::{self, Display, Formatter, Pointer};
|
||||
|
||||
use super::{global_info::GSInfo, val_data::VData, val_type::VType};
|
||||
use super::{code_macro::Macro, global_info::GSInfo, val_data::VData, val_type::VType};
|
||||
|
||||
pub enum SStatementEnum {
|
||||
Value(VData),
|
||||
@ -17,6 +17,7 @@ pub enum SStatementEnum {
|
||||
Match(String, Vec<(SStatement, SStatement)>),
|
||||
IndexFixed(SStatement, usize),
|
||||
EnumVariant(String, SStatement),
|
||||
Macro(Macro),
|
||||
}
|
||||
impl SStatementEnum {
|
||||
pub fn to(self) -> SStatement {
|
||||
@ -172,6 +173,9 @@ impl SStatementEnum {
|
||||
write!(f, "{variant}: ")?;
|
||||
inner.fmtgs(f, info)
|
||||
}
|
||||
Self::Macro(m) => {
|
||||
write!(f, "!({m})")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
pub mod builtins;
|
||||
pub mod code_macro;
|
||||
pub mod code_parsed;
|
||||
pub mod code_runnable;
|
||||
pub mod global_info;
|
||||
|
@ -16,6 +16,7 @@ use crate::{
|
||||
|
||||
use super::{
|
||||
builtins::BuiltinFunction,
|
||||
code_macro::Macro,
|
||||
code_parsed::{SBlock, SFunction, SStatement, SStatementEnum},
|
||||
code_runnable::{RBlock, RFunction, RScript, RStatement, RStatementEnum},
|
||||
};
|
||||
@ -351,7 +352,7 @@ fn statement(
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return Err(ToRunnableError::UseOfUndefinedFunction(v.clone()));
|
||||
return Err(ToRunnableError::UseOfUndefinedFunction(v.clone()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -565,6 +566,9 @@ fn statement(
|
||||
v
|
||||
}
|
||||
}, statement(s, ginfo, linfo)?),
|
||||
SStatementEnum::Macro(m) => match m {
|
||||
Macro::StaticMers(val) => RStatementEnum::Value(val.clone()),
|
||||
},
|
||||
}
|
||||
.to();
|
||||
// if force_output_type is set, verify that the real output type actually fits in the forced one.
|
||||
|
@ -47,6 +47,9 @@ impl PartialEq for VDataEnum {
|
||||
}
|
||||
|
||||
impl VData {
|
||||
pub fn safe_to_share(&self) -> bool {
|
||||
self.data.safe_to_share()
|
||||
}
|
||||
pub fn out(&self) -> VType {
|
||||
VType {
|
||||
types: vec![self.out_single()],
|
||||
@ -82,6 +85,15 @@ impl VDataEnum {
|
||||
|
||||
// get()
|
||||
impl VDataEnum {
|
||||
pub fn safe_to_share(&self) -> bool {
|
||||
match self {
|
||||
Self::Bool(_) | Self::Int(_) | Self::Float(_) | Self::String(_) | Self::Function(_) => {
|
||||
true
|
||||
}
|
||||
Self::Tuple(v) | Self::List(_, v) => v.iter().all(|v| v.safe_to_share()),
|
||||
Self::Thread(..) | Self::Reference(..) | Self::EnumVariant(..) => false,
|
||||
}
|
||||
}
|
||||
pub fn noenum(self) -> VData {
|
||||
match self {
|
||||
Self::EnumVariant(_, v) => *v,
|
||||
|
Loading…
Reference in New Issue
Block a user