summaryrefslogtreecommitdiff
path: root/src/syntax
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-12-12 22:19:38 +0100
committerLaurenz <laurmaedje@gmail.com>2019-12-12 22:19:38 +0100
commitff107cf3e75acf041f8b7631337d299cdeaa1685 (patch)
tree40799f0337a5c2bc13166ff32a1f0b4f5c23bfe8 /src/syntax
parent3c0496bb6104f0e2a60520e42137ecc29f26e9fa (diff)
Tidying up 🧹
Diffstat (limited to 'src/syntax')
-rw-r--r--src/syntax/mod.rs12
-rw-r--r--src/syntax/parsing.rs7
-rw-r--r--src/syntax/tokens.rs17
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;