From 7721f210c16e19b1c2af90f69130386b89bb5104 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 29 Jun 2022 10:26:39 +0200 Subject: Add support for sharing identifiers, references before definitions --- src/parser.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/parser.rs') diff --git a/src/parser.rs b/src/parser.rs index 32b7f36..f11f0d1 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -4,24 +4,32 @@ use crate::content::flow::flow; use crate::tokenizer::{as_codes, Code, Event, Point}; +/// To do: could we do without `HashSet`, so we don’t need `std`? +use std::collections::HashSet; + +/// Information needed, in all content types, when parsing markdown. +/// +/// Importantly, this contains a set of known definitions. +/// It also references the input value as [`Code`][]s. +#[derive(Debug)] pub struct ParseState { - /// To do. + /// List of codes. pub codes: Vec, - /// To do. - pub definitions: Vec, + /// Set of defined identifiers. + pub definitions: HashSet, } /// Turn a string of markdown into events. /// /// Passes the codes back so the compiler can access the source. pub fn parse(value: &str) -> (Vec, Vec) { - let parse_state = ParseState { + let mut parse_state = ParseState { codes: as_codes(value), - definitions: vec![], + definitions: HashSet::new(), }; let events = flow( - &parse_state, + &mut parse_state, Point { line: 1, column: 1, -- cgit