From 6d382b6572f1ea13969e8a9243ba4b2138479993 Mon Sep 17 00:00:00 2001 From: Nico Lehmann Date: Thu, 12 Dec 2024 00:22:56 -0300 Subject: [PATCH] Fix parsing of angle brackets for sorts and bit vectors --- crates/flux-syntax/src/grammar.lalrpop | 39 +++++++++++++++----------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/crates/flux-syntax/src/grammar.lalrpop b/crates/flux-syntax/src/grammar.lalrpop index 81da483fdb..6254c74f3a 100644 --- a/crates/flux-syntax/src/grammar.lalrpop +++ b/crates/flux-syntax/src/grammar.lalrpop @@ -160,14 +160,10 @@ ParamMode: surface::ParamMode = { } BaseSort: surface::BaseSort = { - "bitvec" "<" ">" =>? { - if let Ok(width) = lit.symbol.as_str().parse::() { - Ok(surface::BaseSort::BitVec(width)) - } else { - Err(ParseError::User { error: UserParseError::UnexpectedToken(lo, hi) }) - } + "bitvec" > => { + surface::BaseSort::BitVec(width) }, - > > ">")?> => { + > >?> => { let path = surface::SortPath { segments, args: args.unwrap_or_default(), @@ -177,6 +173,16 @@ BaseSort: surface::BaseSort = { }, } +BitVecWidth: usize = { + =>? { + if let Ok(width) = lit.symbol.as_str().parse::() { + Ok(width) + } else { + Err(ParseError::User { error: UserParseError::UnexpectedToken(lo, hi) }) + } + } +} + Sort: surface::Sort = { => surface::Sort::Base(base), "(" > ")" "->" => surface::Sort::Func { <> }, @@ -432,15 +438,7 @@ BaseTyKind: surface::BaseTyKind = { } } -GenericArgTys: Vec = { - "<" > ">", - "<" > ">(?=>)", -} - -GenericArgs: Vec = { - "<" > ">", - "<" > ">(?=>)", -} +GenericArgs: Vec = AngleBrackets>; GenericArg: surface::GenericArg = { "=" => surface::GenericArg { @@ -690,6 +688,13 @@ Ident: surface::Ident = { } } +// Something enclosed by angle brackets. This handles the case where there are two adjacent +// angle brackets which we tokenize differently to account for the right shift operator. +AngleBrackets: T = { + "<" ">", + "<" ">(?=>)", +} + Sep: Vec = { S)*> => { if let Some(e) = e { v.push(e); } @@ -781,6 +786,6 @@ extern { "else" => Token::Else, "::" => Token::PathSep, "_" => Token::Underscore, - ".." => Token::DotDot, + ".." => Token::DotDot, } }