diff options
Diffstat (limited to 'src/syntax')
| -rw-r--r-- | src/syntax/mod.rs | 12 | ||||
| -rw-r--r-- | src/syntax/parsing.rs | 7 | ||||
| -rw-r--r-- | src/syntax/tokens.rs | 17 |
3 files changed, 16 insertions, 20 deletions
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<E: ExpressionKind>(opt: ParseResult<Option<Spanned<E>>>) -> ParseResult<Spanned<E>> { 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<T> = crate::TypesetResult<T>; + /// Parses source code into a syntax tree given a context. pub fn parse(src: &str, ctx: ParseContext) -> ParseResult<SyntaxTree> { Parser::new(src, ctx).parse() @@ -404,9 +406,6 @@ impl<'s> Iterator for PeekableTokens<'s> { } } -/// The result type for parsing. -pub type ParseResult<T> = TypesetResult<T>; - #[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<char> { + fn peekc(&mut self) -> Option<char> { 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; |
