From ff107cf3e75acf041f8b7631337d299cdeaa1685 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Thu, 12 Dec 2019 22:19:38 +0100 Subject: =?UTF-8?q?Tidying=20up=20=F0=9F=A7=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/syntax/mod.rs | 12 ++++-------- src/syntax/parsing.rs | 7 +++---- src/syntax/tokens.rs | 17 +++++++++-------- 3 files changed, 16 insertions(+), 20 deletions(-) (limited to 'src/syntax') diff --git a/src/syntax/mod.rs b/src/syntax/mod.rs index a3fe06bd..2f64bc9b 100644 --- a/src/syntax/mod.rs +++ b/src/syntax/mod.rs @@ -6,14 +6,9 @@ use unicode_xid::UnicodeXID; use crate::func::LayoutFunc; use crate::size::{Size, ScaleSize}; -mod tokens; -#[macro_use] -mod parsing; -mod span; - -pub use span::{Span, Spanned}; -pub use tokens::{tokenize, Tokens}; -pub use parsing::{parse, ParseContext, ParseResult}; +pub_use_mod!(tokens); +pub_use_mod!(parsing); +pub_use_mod!(span); /// A logical unit of the incoming text stream. #[derive(Debug, Copy, Clone, Eq, PartialEq)] @@ -185,6 +180,7 @@ impl FuncArgs { } } +/// Extract the option expression kind from the option or return an error. fn expect(opt: ParseResult>>) -> ParseResult> { match opt { Ok(Some(spanned)) => Ok(spanned), diff --git a/src/syntax/parsing.rs b/src/syntax/parsing.rs index 9fe6c584..d887d898 100644 --- a/src/syntax/parsing.rs +++ b/src/syntax/parsing.rs @@ -1,10 +1,12 @@ //! Parsing of token streams into syntax trees. -use crate::TypesetResult; use crate::func::Scope; use crate::size::Size; use super::*; +/// The result type for parsing. +pub type ParseResult = crate::TypesetResult; + /// Parses source code into a syntax tree given a context. pub fn parse(src: &str, ctx: ParseContext) -> ParseResult { Parser::new(src, ctx).parse() @@ -404,9 +406,6 @@ impl<'s> Iterator for PeekableTokens<'s> { } } -/// The result type for parsing. -pub type ParseResult = TypesetResult; - #[cfg(test)] #[allow(non_snake_case)] diff --git a/src/syntax/tokens.rs b/src/syntax/tokens.rs index 95b2ea3e..cca8bee3 100644 --- a/src/syntax/tokens.rs +++ b/src/syntax/tokens.rs @@ -1,5 +1,6 @@ use std::str::CharIndices; use smallvec::SmallVec; + use super::*; /// Builds an iterator over the tokens of the source code. @@ -266,7 +267,7 @@ fn is_newline_char(character: char) -> bool { /// A (index, char) iterator with double lookahead. #[derive(Debug, Clone)] -pub struct PeekableChars<'s> { +struct PeekableChars<'s> { string: &'s str, chars: CharIndices<'s>, peeked: SmallVec<[Option<(usize, char)>; 2]>, @@ -276,7 +277,7 @@ pub struct PeekableChars<'s> { impl<'s> PeekableChars<'s> { /// Create a new iterator from a string. - pub fn new(string: &'s str) -> PeekableChars<'s> { + fn new(string: &'s str) -> PeekableChars<'s> { PeekableChars { string, chars: string.char_indices(), @@ -287,17 +288,17 @@ impl<'s> PeekableChars<'s> { } /// Peek at the next element. - pub fn peek(&mut self) -> Option<(usize, char)> { + fn peek(&mut self) -> Option<(usize, char)> { self.peekn(0) } /// Peek at the char of the next element. - pub fn peekc(&mut self) -> Option { + fn peekc(&mut self) -> Option { self.peekn(0).map(|p| p.1) } /// Peek at the element after the next element. - pub fn peekn(&mut self, n: usize) -> Option<(usize, char)> { + fn peekn(&mut self, n: usize) -> Option<(usize, char)> { while self.peeked.len() <= n { let next = self.next_inner(); self.peeked.push(next); @@ -307,15 +308,15 @@ impl<'s> PeekableChars<'s> { } /// Return the next value of the inner iterator mapped with the offset. - pub fn next_inner(&mut self) -> Option<(usize, char)> { + fn next_inner(&mut self) -> Option<(usize, char)> { self.chars.next().map(|(i, c)| (self.base + i, c)) } - pub fn string_index(&mut self) -> usize { + fn string_index(&mut self) -> usize { self.index } - pub fn set_string_index(&mut self, index: usize) { + fn set_string_index(&mut self, index: usize) { self.chars = self.string[index..].char_indices(); self.base = index; self.index = 0; -- cgit v1.2.3