Skip to content

Commit

Permalink
Make >> and >>> parseable for A<B<T>>
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejonah1200 committed Oct 5, 2023
1 parent ed2e628 commit 345d6c3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#![feature(trait_alias)]
#![feature(return_position_impl_trait_in_trait)]
#![feature(iter_collect_into)]
// #![feature(iter_map_windows)]

use std::{ops::Range, path::Path};

Expand Down
16 changes: 14 additions & 2 deletions src/parsing/parsers/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use chumsky::{
recursive::recursive,
select,
span::SimpleSpan,
Parser,
IterParser, Parser, prelude::Rich,
};
use itertools::Itertools;

use crate::parsing::{
ast::expressions::{CallKind, Expression},
Expand Down Expand Up @@ -241,7 +242,18 @@ macro_rules! binary_parser {
#[rustfmt::skip] binary_parser!(operation_chain, comparison, term, ops_parser!(GreaterEqual, LessEqual, Greater, Less));
#[rustfmt::skip] binary_parser!(binary, term, factor, ops_parser!(Plus, Minus)); // TODO: Newline split
#[rustfmt::skip] binary_parser!(binary, factor, bitops, ops_parser!(Asterisk, SlashSlash, Slash, Percent));
#[rustfmt::skip] binary_parser!(binary, bitops, unary, ops_parser!(Bar, Ampersand, GreaterGreater, LessLess, GreaterGreaterGreater));
#[rustfmt::skip] binary_parser!(binary, bitops, unary, ops_parser!(Bar, Ampersand, LessLess)
.or(
just(Token::Greater).span().repeated().at_least(2).at_most(3).collect_boxed_slice()
.try_map(|slice, _span|
if slice.iter().tuple_windows().all(|(a, b)| a.end == b.start) {
Ok(if slice.len() == 2 { Operation::ShiftRight } else { Operation::ShiftRightUnsigned })
} else {
Err(Rich::custom(_span, "there is a whitespace between the two/three >"))
}
)
)
);

pub fn operation_chain_parser<'a, NP, OP, I: TokenInput<'a>>(
next_parser: NP,
Expand Down
12 changes: 6 additions & 6 deletions src/parsing/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ pub enum Token {
#[token("^")]
Circumflex,

#[token(">>")]
GreaterGreater,
// #[token(">>")]
// GreaterGreater,
#[token("<<")]
LessLess,
#[token(">>>")]
GreaterGreaterGreater,
// #[token(">>>")]
// GreaterGreaterGreater,

#[token("&&")]
AmpersandAmpersand,
Expand Down Expand Up @@ -251,9 +251,9 @@ impl From<Token> for Operation {
Ampersand => AndBitwise,
Bar => OrBitwise,
Circumflex => XOR,
GreaterGreater => ShiftRight,
// GreaterGreater => ShiftRight,
LessLess => ShiftLeft,
GreaterGreaterGreater => ShiftRightUnsigned,
// GreaterGreaterGreater => ShiftRightUnsigned,
AmpersandAmpersand => And,
BarBar => Or,
Token::Greater => Operation::Greater,
Expand Down

0 comments on commit 345d6c3

Please sign in to comment.