Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions cfgrammar/src/lib/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,10 +594,10 @@ impl<T: Clone> TryFrom<&Value<T>> for YaccKind {
namespace,
member: (yk_value, yk_value_loc),
})) => {
if let Some((ns, ns_loc)) = namespace {
if ns != "yacckind" {
err_locs.push(ns_loc.clone());
}
if let Some((ns, ns_loc)) = namespace
&& ns != "yacckind"
{
err_locs.push(ns_loc.clone());
}
let yacckinds = [
("grmtools".to_string(), YaccKind::Grmtools),
Expand Down Expand Up @@ -635,20 +635,20 @@ impl<T: Clone> TryFrom<&Value<T>> for YaccKind {
member: (ak_str, ak_loc),
},
}) => {
if let Some((yk_ns, yk_ns_loc)) = yk_namespace {
if yk_ns != "yacckind" {
err_locs.push(yk_ns_loc.clone());
}
if let Some((yk_ns, yk_ns_loc)) = yk_namespace
&& yk_ns != "yacckind"
{
err_locs.push(yk_ns_loc.clone());
}

if yk_str != "original" {
err_locs.push(yk_loc.clone());
}

if let Some((ak_ns, ak_ns_loc)) = ak_namespace {
if ak_ns != "yaccoriginalactionkind" {
err_locs.push(ak_ns_loc.clone());
}
if let Some((ak_ns, ak_ns_loc)) = ak_namespace
&& ak_ns != "yaccoriginalactionkind"
{
err_locs.push(ak_ns_loc.clone());
}
let actionkinds = [
("noaction", YaccOriginalActionKind::NoAction),
Expand Down
16 changes: 8 additions & 8 deletions cfgrammar/src/lib/yacc/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,10 @@ impl GrammarAST {
if self.tokens.contains(k) {
continue;
}
if let Some(ref it) = self.implicit_tokens {
if it.contains_key(k) {
continue;
}
if let Some(ref it) = self.implicit_tokens
&& it.contains_key(k)
{
continue;
}
return Err(YaccGrammarError {
kind: YaccGrammarErrorKind::UnknownEPP(k.clone()),
Expand Down Expand Up @@ -454,10 +454,10 @@ impl GrammarAST {
for sym in &prod.symbols {
match sym {
Symbol::Rule(name, _) => {
if seen_rules.insert(name) {
if let Some(rule) = self.rules.get(name) {
todo.extend(&rule.pidxs);
}
if seen_rules.insert(name)
&& let Some(rule) = self.rules.get(name)
{
todo.extend(&rule.pidxs);
}
}
Symbol::Token(name, _) => {
Expand Down
2 changes: 1 addition & 1 deletion cfgrammar/src/lib/yacc/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ where
// Add the implicit rule: ~: "IMPLICIT_TOKEN_1" ~ | ... | "IMPLICIT_TOKEN_N" ~ | ;
let implicit_prods = &mut rules_prods[usize::from(rule_map[astrulename])];
// Add a production for each implicit token
for (t, _) in ast.implicit_tokens.as_ref().unwrap().iter() {
for t in ast.implicit_tokens.as_ref().unwrap().keys() {
implicit_prods.push(PIdx(prods.len().as_()));
prods.push(Some(vec![Symbol::Token(token_map[t]), Symbol::Rule(ridx)]));
prod_precs.push(Some(None));
Expand Down
86 changes: 43 additions & 43 deletions cfgrammar/src/lib/yacc/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,24 +388,24 @@ impl YaccParser<'_> {
}
continue;
}
if let YaccKind::Original(_) = self.yacc_kind {
if let Some(j) = self.lookahead_is("%actiontype", i) {
i = self.parse_ws(j, false)?;
let (j, n) = self.parse_to_eol(i)?;
let span = Span::new(i, j);
if let Some((_, orig_span)) = self.global_actiontype {
add_duplicate_occurrence(
errs,
YaccGrammarErrorKind::DuplicateActiontypeDeclaration,
orig_span,
span,
);
} else {
self.global_actiontype = Some((n, span));
}
i = self.parse_ws(j, true)?;
continue;
if let YaccKind::Original(_) = self.yacc_kind
&& let Some(j) = self.lookahead_is("%actiontype", i)
{
i = self.parse_ws(j, false)?;
let (j, n) = self.parse_to_eol(i)?;
let span = Span::new(i, j);
if let Some((_, orig_span)) = self.global_actiontype {
add_duplicate_occurrence(
errs,
YaccGrammarErrorKind::DuplicateActiontypeDeclaration,
orig_span,
span,
);
} else {
self.global_actiontype = Some((n, span));
}
i = self.parse_ws(j, true)?;
continue;
}
if let Some(j) = self.lookahead_is("%start", i) {
i = self.parse_ws(j, false)?;
Expand Down Expand Up @@ -556,36 +556,36 @@ impl YaccParser<'_> {
i = self.parse_ws(j, true)?;
continue;
}
if let YaccKind::Eco = self.yacc_kind {
if let Some(j) = self.lookahead_is("%implicit_tokens", i) {
i = self.parse_ws(j, false)?;
let num_newlines = self.num_newlines;
if self.ast.implicit_tokens.is_none() {
self.ast.implicit_tokens = Some(HashMap::new());
if let YaccKind::Eco = self.yacc_kind
&& let Some(j) = self.lookahead_is("%implicit_tokens", i)
{
i = self.parse_ws(j, false)?;
let num_newlines = self.num_newlines;
if self.ast.implicit_tokens.is_none() {
self.ast.implicit_tokens = Some(HashMap::new());
}
while j < self.src.len() && self.num_newlines == num_newlines {
let (j, n, span, _) = self.parse_token(i)?;
if self.ast.tokens.insert(n.clone()) {
self.ast.spans.push(span);
}
while j < self.src.len() && self.num_newlines == num_newlines {
let (j, n, span, _) = self.parse_token(i)?;
if self.ast.tokens.insert(n.clone()) {
self.ast.spans.push(span);
match self.ast.implicit_tokens.as_mut().unwrap().entry(n) {
Entry::Occupied(entry) => {
let orig_span = *entry.get();
add_duplicate_occurrence(
errs,
YaccGrammarErrorKind::DuplicateImplicitTokensDeclaration,
orig_span,
span,
);
}
match self.ast.implicit_tokens.as_mut().unwrap().entry(n) {
Entry::Occupied(entry) => {
let orig_span = *entry.get();
add_duplicate_occurrence(
errs,
YaccGrammarErrorKind::DuplicateImplicitTokensDeclaration,
orig_span,
span,
);
}
Entry::Vacant(entry) => {
entry.insert(span);
}
Entry::Vacant(entry) => {
entry.insert(span);
}
i = self.parse_ws(j, true)?;
}
continue;
i = self.parse_ws(j, true)?;
}
continue;
}
{
let k;
Expand Down Expand Up @@ -1703,7 +1703,7 @@ x"
#[test]
fn test_dup_precs() {
#[rustfmt::skip]
let srcs = vec![
let srcs = [
("
%left 'x'
%left 'x'
Expand Down
Loading