summaryrefslogtreecommitdiff
path: root/src/parsing.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2019-06-22 15:32:19 +0200
committerLaurenz <laurmaedje@gmail.com>2019-06-22 15:32:19 +0200
commit099ce71aba54a40455b7ce35768c8fe003f7b16a (patch)
treed0a475e91967882d4608dea59ceb41c9a6232e07 /src/parsing.rs
parentc7ee2b393a369325b3578557e045f2ff94ceab8f (diff)
Unify font classes + By-value-contexts ⚖
Diffstat (limited to 'src/parsing.rs')
-rw-r--r--src/parsing.rs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/parsing.rs b/src/parsing.rs
index 81a729ab..79066e47 100644
--- a/src/parsing.rs
+++ b/src/parsing.rs
@@ -326,12 +326,12 @@ impl Iterator for PeekableChars<'_> {
/// Parses source code into a syntax tree given a context.
#[inline]
-pub fn parse(src: &str, ctx: &ParseContext) -> ParseResult<SyntaxTree> {
+pub fn parse(src: &str, ctx: ParseContext) -> ParseResult<SyntaxTree> {
Parser::new(src, ctx).parse()
}
/// The context for parsing.
-#[derive(Debug)]
+#[derive(Debug, Copy, Clone)]
pub struct ParseContext<'a> {
/// The scope containing function definitions.
pub scope: &'a Scope,
@@ -343,7 +343,7 @@ struct Parser<'s> {
src: &'s str,
tokens: PeekableTokens<'s>,
state: ParserState,
- ctx: &'s ParseContext<'s>,
+ ctx: ParseContext<'s>,
tree: SyntaxTree,
}
@@ -360,12 +360,12 @@ enum ParserState {
impl<'s> Parser<'s> {
/// Create a new parser from the source and the context.
- fn new(src: &'s str, ctx: &'s ParseContext) -> Parser<'s> {
+ fn new(src: &'s str, ctx: ParseContext<'s>) -> Parser<'s> {
Parser {
src,
tokens: PeekableTokens::new(tokenize(src)),
- ctx,
state: ParserState::Body,
+ ctx,
tree: SyntaxTree::new(),
}
}
@@ -813,7 +813,7 @@ mod parse_tests {
pub struct TreeFn(pub SyntaxTree);
impl Function for TreeFn {
- fn parse(_: &FuncHeader, body: Option<&str>, ctx: &ParseContext)
+ fn parse(_: &FuncHeader, body: Option<&str>, ctx: ParseContext)
-> ParseResult<Self> where Self: Sized {
if let Some(src) = body {
parse(src, ctx).map(|tree| TreeFn(tree))
@@ -822,7 +822,7 @@ mod parse_tests {
}
}
- fn layout(&self, _: &LayoutContext) -> LayoutResult<Option<Layout>> { Ok(None) }
+ fn layout(&self, _: LayoutContext) -> LayoutResult<Option<Layout>> { Ok(None) }
}
/// A testing function without a body.
@@ -830,7 +830,7 @@ mod parse_tests {
pub struct BodylessFn;
impl Function for BodylessFn {
- fn parse(_: &FuncHeader, body: Option<&str>, _: &ParseContext)
+ fn parse(_: &FuncHeader, body: Option<&str>, _: ParseContext)
-> ParseResult<Self> where Self: Sized {
if body.is_none() {
Ok(BodylessFn)
@@ -839,32 +839,32 @@ mod parse_tests {
}
}
- fn layout(&self, _: &LayoutContext) -> LayoutResult<Option<Layout>> { Ok(None) }
+ fn layout(&self, _: LayoutContext) -> LayoutResult<Option<Layout>> { Ok(None) }
}
}
/// Test if the source code parses into the syntax tree.
fn test(src: &str, tree: SyntaxTree) {
let ctx = ParseContext { scope: &Scope::new() };
- assert_eq!(parse(src, &ctx).unwrap(), tree);
+ assert_eq!(parse(src, ctx).unwrap(), tree);
}
/// Test with a scope containing function definitions.
fn test_scoped(scope: &Scope, src: &str, tree: SyntaxTree) {
let ctx = ParseContext { scope };
- assert_eq!(parse(src, &ctx).unwrap(), tree);
+ assert_eq!(parse(src, ctx).unwrap(), tree);
}
/// Test if the source parses into the error.
fn test_err(src: &str, err: &str) {
let ctx = ParseContext { scope: &Scope::new() };
- assert_eq!(parse(src, &ctx).unwrap_err().to_string(), err);
+ assert_eq!(parse(src, ctx).unwrap_err().to_string(), err);
}
/// Test with a scope if the source parses into the error.
fn test_err_scoped(scope: &Scope, src: &str, err: &str) {
let ctx = ParseContext { scope };
- assert_eq!(parse(src, &ctx).unwrap_err().to_string(), err);
+ assert_eq!(parse(src, ctx).unwrap_err().to_string(), err);
}
/// Create a text node.