Skip to content

Commit

Permalink
try a method for matching delimiters
Browse files Browse the repository at this point in the history
  • Loading branch information
koddsson committed Jul 25, 2024
1 parent ae5b915 commit ebc79c1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions crates/hdx_parser/src/comparison.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{unexpected, Parse, Parser, Result};
use hdx_lexer::{Include, Token};
use hdx_lexer::{Include, Kind};

#[derive(Debug, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize), serde(tag = "type"))]
Expand All @@ -13,25 +13,29 @@ pub enum Comparison {

impl<'a> Parse<'a> for Comparison {
fn parse(parser: &mut Parser<'a>) -> Result<Comparison> {
Ok(match parser.next() {
Token::Delim('=') => Comparison::Equal,
Token::Delim('>') => {
if let Token::Delim('=') = parser.peek_with(Include::Whitespace) {
Ok(match (parser.next().kind(), parser.next().char()) {
(Kind::Delim, Some('=')) => Comparison::Equal,
(Kind::Delim, Some('>')) => {
if let (Kind::Delim, Some('=')) =
(parser.peek_with(Include::Whitespace).kind(), parser.peek_with(Include::Whitespace).char())
{
parser.advance_with(Include::Whitespace);
Comparison::GreaterThanEqual
} else {
Comparison::GreaterThan
}
}
Token::Delim('<') => {
if let Token::Delim('=') = parser.peek_with(Include::Whitespace) {
(Kind::Delim, Some('<')) => {
if let (Kind::Delim, Some('=')) =
(parser.peek_with(Include::Whitespace).kind(), parser.peek_with(Include::Whitespace).char())
{
parser.advance_with(Include::Whitespace);
Comparison::LessThanEqual
} else {
Comparison::LessThan
}
}
token => unexpected!(parser, token),
(token, _) => unexpected!(parser, token),
})
}
}

0 comments on commit ebc79c1

Please sign in to comment.