mirror of
https://github.com/Dummi26/mers.git
synced 2025-03-10 14:13:52 +01:00
fix some bugs
This commit is contained in:
parent
d01da83866
commit
7acaafaa2f
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mers"
|
name = "mers"
|
||||||
version = "0.8.20"
|
version = "0.8.25"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "dynamically typed but type-checked programming language"
|
description = "dynamically typed but type-checked programming language"
|
||||||
@ -15,7 +15,7 @@ default = ["colored-output"]
|
|||||||
colored-output = ["mers_lib/ecolor-term", "mers_lib/pretty-print", "dep:colored"]
|
colored-output = ["mers_lib/ecolor-term", "mers_lib/pretty-print", "dep:colored"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
mers_lib = "0.8.20"
|
mers_lib = "0.8.25"
|
||||||
# mers_lib = { path = "../mers_lib" }
|
# mers_lib = { path = "../mers_lib" }
|
||||||
clap = { version = "4.3.19", features = ["derive"] }
|
clap = { version = "4.3.19", features = ["derive"] }
|
||||||
colored = { version = "2.1.0", optional = true }
|
colored = { version = "2.1.0", optional = true }
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mers_lib"
|
name = "mers_lib"
|
||||||
version = "0.8.24"
|
version = "0.8.25"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MIT OR Apache-2.0"
|
||||||
description = "library to use the mers language in other projects"
|
description = "library to use the mers language in other projects"
|
||||||
@ -9,7 +9,7 @@ readme = "README.md"
|
|||||||
repository = "https://github.com/Dummi26/mers"
|
repository = "https://github.com/Dummi26/mers"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["parse", "pretty-print", "ecolor-html"]
|
default = ["parse"]
|
||||||
|
|
||||||
# for parsing and running mers code (for most situations: just enable parse)
|
# for parsing and running mers code (for most situations: just enable parse)
|
||||||
parse = ["run"]
|
parse = ["run"]
|
||||||
|
@ -112,6 +112,7 @@ pub struct Source {
|
|||||||
comments: Vec<(usize, String)>,
|
comments: Vec<(usize, String)>,
|
||||||
i: usize,
|
i: usize,
|
||||||
sections: Vec<SectionMarker>,
|
sections: Vec<SectionMarker>,
|
||||||
|
allow_includes: bool,
|
||||||
}
|
}
|
||||||
impl Clone for Source {
|
impl Clone for Source {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
@ -123,6 +124,7 @@ impl Clone for Source {
|
|||||||
comments: self.comments.clone(),
|
comments: self.comments.clone(),
|
||||||
i: self.i,
|
i: self.i,
|
||||||
sections: vec![],
|
sections: vec![],
|
||||||
|
allow_includes: self.allow_includes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,12 +152,14 @@ impl Source {
|
|||||||
comments: vec![],
|
comments: vec![],
|
||||||
i: 0,
|
i: 0,
|
||||||
sections: vec![],
|
sections: vec![],
|
||||||
|
allow_includes: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn new_from_string(source: String) -> Self {
|
pub fn new_from_string(source: String) -> Self {
|
||||||
Self::new(SourceFrom::Unspecified, source)
|
Self::new(SourceFrom::Unspecified, source)
|
||||||
}
|
}
|
||||||
pub fn new(src_from: SourceFrom, source: String) -> Self {
|
pub fn new(src_from: SourceFrom, source: String) -> Self {
|
||||||
|
let allow_includes = matches!(src_from, SourceFrom::File(_));
|
||||||
let mut src = String::with_capacity(source.len());
|
let mut src = String::with_capacity(source.len());
|
||||||
let mut comment = (0, String::new());
|
let mut comment = (0, String::new());
|
||||||
let mut comments = Vec::new();
|
let mut comments = Vec::new();
|
||||||
@ -222,8 +226,13 @@ impl Source {
|
|||||||
comments,
|
comments,
|
||||||
i: 0,
|
i: 0,
|
||||||
sections: vec![],
|
sections: vec![],
|
||||||
|
allow_includes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn allow_includes(mut self, allow_includes: bool) -> Self {
|
||||||
|
self.allow_includes = allow_includes;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn src(&self) -> &String {
|
pub fn src(&self) -> &String {
|
||||||
&self.src
|
&self.src
|
||||||
|
@ -281,6 +281,14 @@ pub fn parse_no_chain(
|
|||||||
}
|
}
|
||||||
match src.next_word() {
|
match src.next_word() {
|
||||||
"include" => {
|
"include" => {
|
||||||
|
if !src.allow_includes {
|
||||||
|
return Err(CheckError::new()
|
||||||
|
.src(vec![(
|
||||||
|
(pos_in_src, src.get_pos(), srca).into(),
|
||||||
|
Some(EColor::HashIncludeCantLoadFile),
|
||||||
|
)])
|
||||||
|
.msg_str(format!("not allowed to use #include (only allowed when source code is read from a file, or if allow_includes is explicitly set)")));
|
||||||
|
}
|
||||||
let end_in_src = src.get_pos();
|
let end_in_src = src.get_pos();
|
||||||
src.skip_whitespace();
|
src.skip_whitespace();
|
||||||
let string_in_src = src.get_pos();
|
let string_in_src = src.get_pos();
|
||||||
|
@ -75,6 +75,7 @@ impl ThemeGen for DefaultTheme {
|
|||||||
type T = std::io::Stdout;
|
type T = std::io::Stdout;
|
||||||
fn color(&self, text: &str, color: Self::C, t: &mut Self::T) {
|
fn color(&self, text: &str, color: Self::C, t: &mut Self::T) {
|
||||||
use colored::{Color, Colorize};
|
use colored::{Color, Colorize};
|
||||||
|
use std::io::Write;
|
||||||
if let Some(color) = map_color(color) {
|
if let Some(color) = map_color(color) {
|
||||||
let _ = write!(
|
let _ = write!(
|
||||||
t,
|
t,
|
||||||
@ -92,6 +93,7 @@ impl ThemeGen for DefaultTheme {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn nocolor(&self, text: &str, t: &mut Self::T) {
|
fn nocolor(&self, text: &str, t: &mut Self::T) {
|
||||||
|
use std::io::Write;
|
||||||
let _ = write!(t, "{}", text);
|
let _ = write!(t, "{}", text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user