Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqkz committed May 28, 2024
1 parent 9076664 commit 25b0248
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::io::{self, Read, Write};

use parser::parse_markdown_text;
use parser::parse_only_text;
#[allow(dead_code)]
mod parser;
extern crate nom;
Expand All @@ -13,7 +13,7 @@ fn main() -> io::Result<()> {

//println!("input: {:?}", buffer);

let output = parse_markdown_text(&buffer);
let output = parse_only_text(&buffer);

io::stdout().write_all(format!("output: {:?}", output).as_bytes())?;

Expand Down
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub enum Element<'a> {
Tag(&'a str),
/// [label](#tag)
LabelledTag {
label: Box<Element<'a>>,
label: Vec<Element<'a>>,
tag: &'a str
},
/// Represents a linebreak - \n
Expand Down
52 changes: 36 additions & 16 deletions src/parser/parse_from_text/text_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ use super::hashtag_content_char_ranges::hashtag_content_char;
use super::Element;
use nom::{
bytes::{
complete::{tag, take, take_while, take_while1},
complete::{tag, take, take_while, take_while1, is_not},
streaming::take_till1,
},
character::complete::char,
combinator::{peek, recognize, verify, consumed},
sequence::tuple,
sequence::{tuple, delimited},
AsChar, IResult, Offset, Slice,
};

Expand Down Expand Up @@ -254,17 +254,35 @@ fn bot_command_suggestion(input: &str) -> IResult<&str, Element, CustomError<&st
}

fn labelled_tag(input: &str) -> IResult<&str, Element, CustomError<&str>> {
let (input, label) = delimited(char('['), is_not("["), char(']'))(input)?;
let (_, label) = parse_text_element(label, None)?;
let (input, tag) = delimited(char('('), is_not("("), char(')'))(input)?;
let (_, tag) = consumed(hashtag)(tag)?;
Ok((
input,
Element::LabelledTag {
label: Box::new(label),
tag
}
))
let (input, label) = delimited(
char('['),
take_while1(|c| !matches!(c, '[' | ']')),
char(']')
)(input)?;
println!("Label: {label}");
let mut remaining = label;
let mut elements: Vec<Element> = vec![];
while let Ok((remaining, elm)) = parse_text_element(label, None) {
elements.push(elm);
}
println!("Elements: {:?}", elements);
let (input, tag) = delimited(
char('('),
take_while1(|c| !matches!(c, '(' | ')')),
char(')')
)(input)?;
let (_, (consumed, _output)) = consumed(hashtag)(tag)?;
if consumed == tag {
Ok((
input,
Element::LabelledTag {
label: elements,
tag: consumed,
}
))
} else {
Err(nom::Err::Error(CustomError::UnexpectedContent))
}
}

pub(crate) fn parse_text_element(
Expand All @@ -277,10 +295,12 @@ pub(crate) fn parse_text_element(
//
// Also as this is the text element parser,
// text elements parsers MUST NOT call the parser for markdown elements internally

if let Ok((i, elm)) = hashtag(input) {
{
println!("{:?}", labelled_tag(input));
}
if let Ok((i, elm)) = labelled_tag(input) {
Ok((i, elm))
} else if let Ok((i, elm)) = labelled_tag(input) {
} else if let Ok((i, elm)) = hashtag(input) {
Ok((i, elm))
} else if let Ok((i, elm)) = {
if prev_char == Some(' ') || prev_char.is_none() {
Expand Down

0 comments on commit 25b0248

Please sign in to comment.