From d3426ec4f27ef884bfeb6e0387af6f9f430e71d7 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 29 May 2018 07:56:43 +0200 Subject: [PATCH] Trying to solve everything for Rc mode, but still lifetime problems #52 --- src/mango/lexing/code_lexer.rs | 12 +++++++----- src/mango/lexing/string_lexer.rs | 4 ++-- src/mango/lexing/typ.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/mango/lexing/code_lexer.rs b/src/mango/lexing/code_lexer.rs index 8a2e3b1b..9e3505eb 100644 --- a/src/mango/lexing/code_lexer.rs +++ b/src/mango/lexing/code_lexer.rs @@ -1,3 +1,5 @@ +#![feature(nll)] + use mango::io::typ::Reader; use mango::io::typ::ReaderResult::*; use mango::lexing::string_lexer::StringLexer; @@ -108,7 +110,7 @@ impl Lexer for CodeLexer { panic!() } // This is a new line, so there may be indents. - return self.lex_indents(reader); + return self.lex_indents(&mut *reader); } if let Match(_) = reader.matches("\\n\\r?") { // Newline WITHOUT line continuation. @@ -122,7 +124,7 @@ impl Lexer for CodeLexer { if let Match(_) = reader.matches("\\n\\r?") { // If semicolon is followed by a newline (redundant), then we need to deal with indents (but ignore the newline itself). // This will return the queue of tokens, including the semicolon. - return self.lex_indents(reader); + return self.lex_indents(&mut *reader); } // No newline, can just return the semicolon (which is certainly on the queue, and should be the only thing, but it is fine here if not). return Token(self.buffer.pop().unwrap()); @@ -163,10 +165,10 @@ impl Lexer for CodeLexer { } } - fn get_reader(&self) -> &Rc> { + fn get_reader(&self) -> Rc> { match self.reader_or_delegate { - ReaderOrDelegate::Reader(reader) => &reader, - ReaderOrDelegate::Delegate(delegate) => delegate.get_reader(), + ReaderOrDelegate::Reader(ref reader) => reader.clone(), + ReaderOrDelegate::Delegate(ref delegate) => delegate.get_reader(), } } } diff --git a/src/mango/lexing/string_lexer.rs b/src/mango/lexing/string_lexer.rs index 4218b871..8e4adc83 100644 --- a/src/mango/lexing/string_lexer.rs +++ b/src/mango/lexing/string_lexer.rs @@ -42,7 +42,7 @@ impl Lexer for StringLexer { } } - fn get_reader(&self) -> &Rc> { - &self.reader + fn get_reader(&self) -> Rc> { + self.reader.clone() } } diff --git a/src/mango/lexing/typ.rs b/src/mango/lexing/typ.rs index d82b19e1..8ea53ba5 100644 --- a/src/mango/lexing/typ.rs +++ b/src/mango/lexing/typ.rs @@ -17,5 +17,5 @@ pub trait Lexer { /// Every call to lex returns a token until the end of the input. fn lex(&mut self) -> MaybeToken; - fn get_reader(&self) -> &Rc>; + fn get_reader(&self) -> Rc>; }