switched to Arc instead of Rc for input strings
This commit is contained in:
@@ -120,7 +120,7 @@ impl Dispatcher {
|
||||
)
|
||||
}
|
||||
|
||||
let mut func_parser = ParsedSrc::new(Rc::new(body));
|
||||
let mut func_parser = ParsedSrc::new(Arc::new(body));
|
||||
func_parser.parse_src()?; // Parse the function
|
||||
|
||||
let func = ShFunc::new(func_parser);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use std::{collections::VecDeque, fmt::Display, iter::Peekable, ops::{Bound, Deref, Range, RangeBounds}, str::Chars};
|
||||
use std::{collections::VecDeque, fmt::Display, iter::Peekable, ops::{Bound, Deref, Range, RangeBounds}, str::Chars, sync::Arc};
|
||||
|
||||
use bitflags::bitflags;
|
||||
|
||||
@@ -33,12 +33,12 @@ pub const OPENERS: [&'static str;6] = [
|
||||
#[derive(Clone,PartialEq,Default,Debug)]
|
||||
pub struct Span {
|
||||
range: Range<usize>,
|
||||
source: Rc<String>
|
||||
source: Arc<String>
|
||||
}
|
||||
|
||||
impl Span {
|
||||
/// New `Span`. Wraps a range and a string slice that it refers to.
|
||||
pub fn new(range: Range<usize>, source: Rc<String>) -> Self {
|
||||
pub fn new(range: Range<usize>, source: Arc<String>) -> Self {
|
||||
Span {
|
||||
range,
|
||||
source,
|
||||
@@ -48,7 +48,7 @@ impl Span {
|
||||
pub fn as_str(&self) -> &str {
|
||||
&self.source[self.start..self.end]
|
||||
}
|
||||
pub fn get_source(&self) -> Rc<String> {
|
||||
pub fn get_source(&self) -> Arc<String> {
|
||||
self.source.clone()
|
||||
}
|
||||
pub fn range(&self) -> Range<usize> {
|
||||
@@ -108,7 +108,7 @@ impl Tk {
|
||||
_ => self.span.as_str().to_string()
|
||||
}
|
||||
}
|
||||
pub fn source(&self) -> Rc<String> {
|
||||
pub fn source(&self) -> Arc<String> {
|
||||
self.span.source.clone()
|
||||
}
|
||||
/// Used to see if a separator is ';;' for case statements
|
||||
@@ -145,7 +145,7 @@ bitflags! {
|
||||
}
|
||||
|
||||
pub struct LexStream {
|
||||
source: Rc<String>,
|
||||
source: Arc<String>,
|
||||
pub cursor: usize,
|
||||
in_quote: bool,
|
||||
flags: LexFlags,
|
||||
@@ -175,7 +175,7 @@ bitflags! {
|
||||
}
|
||||
|
||||
impl LexStream {
|
||||
pub fn new(source: Rc<String>, flags: LexFlags) -> Self {
|
||||
pub fn new(source: Arc<String>, flags: LexFlags) -> Self {
|
||||
flog!(TRACE, "new lex stream");
|
||||
let flags = flags | LexFlags::FRESH | LexFlags::NEXT_IS_CMD;
|
||||
Self { source, cursor: 0, in_quote: false, flags }
|
||||
|
||||
@@ -24,17 +24,17 @@ macro_rules! try_match {
|
||||
|
||||
/// The parsed AST along with the source input it parsed
|
||||
///
|
||||
/// Uses Rc<String> instead of &str because the reference has to stay alive while errors are propagated upwards
|
||||
/// Uses Arc<String> instead of &str because the reference has to stay alive while errors are propagated upwards
|
||||
/// The string also has to stay alive in the case of pre-parsed shell function nodes, which live in the logic table
|
||||
/// Using &str for this use-case dramatically overcomplicates the code
|
||||
#[derive(Clone,Debug)]
|
||||
pub struct ParsedSrc {
|
||||
pub src: Rc<String>,
|
||||
pub src: Arc<String>,
|
||||
pub ast: Ast
|
||||
}
|
||||
|
||||
impl ParsedSrc {
|
||||
pub fn new(src: Rc<String>) -> Self {
|
||||
pub fn new(src: Arc<String>) -> Self {
|
||||
Self { src, ast: Ast::new(vec![]) }
|
||||
}
|
||||
pub fn parse_src(&mut self) -> ShResult<()> {
|
||||
|
||||
Reference in New Issue
Block a user