Skip to content
Merged
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
1 change: 0 additions & 1 deletion SYNTAX.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ RustyLR supports rich regular expression patterns on the right-hand side of prod
- **`P?`** : Matches zero or one occurrence of pattern `P` (binds as an `Option<P>`).
- **`$sep(P, P_separator, repetition)`** : Matches repetitions of `P` separated by `P_separator`. The `repetition` argument can be `*` (zero or more) or `+` (one or more). Binds as a `Vec<P>`.
- **`(P1 P2 | P3)`** : Grouping and alternation.
- **`P / term`** or **`P / [term1 term2]`** : Lookahead assertion. Matches `P` only if followed by the lookahead symbol(s), without consuming them.
- **`'a'` / `b'a'`** : Character/byte literals (only valid if `%tokentype` is `char` or `u8`).
- **`"abcd"` / `b"abcd"`** : String/byte string literals (only valid if `%tokentype` is `char` or `u8`).
- **`P - TerminalSet`** : Matches pattern `P` but excludes any terminal in the `TerminalSet`.
Expand Down
11 changes: 0 additions & 11 deletions rusty_lr_core/src/builder/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct ExpandCache<Term> {
#[derive(Debug, Clone)]
pub struct Rule<Term, NonTerm> {
pub rule: ProductionRule<Term, NonTerm>,
pub lookaheads: Option<BTreeSet<Term>>,
/// for reduce/reduce conflict resolving
pub priority: usize,
}
Expand Down Expand Up @@ -71,7 +70,6 @@ impl<Term, NonTerm> Grammar<TerminalSymbol<Term>, NonTerm> {
&mut self,
name: NonTerm,
rule: Vec<Token<TerminalSymbol<Term>, NonTerm>>,
lookaheads: Option<BTreeSet<TerminalSymbol<Term>>>,
precedence: Option<Precedence>,
priority: usize,
) -> usize
Expand All @@ -86,7 +84,6 @@ impl<Term, NonTerm> Grammar<TerminalSymbol<Term>, NonTerm> {
rule,
precedence,
},
lookaheads,
priority,
};
self.rules.push(rule);
Expand Down Expand Up @@ -324,14 +321,6 @@ impl<Term, NonTerm> Grammar<TerminalSymbol<Term>, NonTerm> {
} else {
c.lookaheads.clone()
};
// check for force lookahead
let lookaheads =
if let Some(force_lookaheads) = self.rules[c.rule].lookaheads.as_ref() {
lookaheads.intersection(force_lookaheads).copied().collect()
} else {
lookaheads
};

new_rules.push((
ShiftedRuleRef {
rule: c.rule,
Expand Down
2 changes: 0 additions & 2 deletions rusty_lr_core/src/parser/nonterminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ pub enum NonTerminalType {

/// terminal set enclosed in brackets ( [a-zA-Z0-9] )
TerminalSet,
/// rule with explicit lookaheads
Lookahead,

/// sequence of tokens enclosed in parentheses ( a B c ... )
Group,
Expand Down
2 changes: 1 addition & 1 deletion rusty_lr_core/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl<Term, NonTerm> TreeNonTerminal<Term, NonTerm> {
}

// remove parent, directly add children
Some(NonTerminalType::Lookahead) | Some(NonTerminalType::TerminalSet) => self
Some(NonTerminalType::TerminalSet) => self
.tokens
.iter()
.flat_map(|token| token.to_term_tree(term_to_display, nonterm_to_display))
Expand Down
1 change: 0 additions & 1 deletion rusty_lr_executable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ Reduce on Terminals: {
question => { Pattern -> TerminalSet }
minus => { Pattern -> TerminalSet }
exclamation => { Pattern -> TerminalSet }
slash => { Pattern -> TerminalSet }
dot => { Pattern -> TerminalSet }
dollar => { Pattern -> TerminalSet }
comma => { Pattern -> TerminalSet }
Expand Down
29 changes: 0 additions & 29 deletions rusty_lr_parser/src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,6 @@ impl Grammar {
tokens,
reduce_action,
separator_location: rule.separator_location,
lookaheads: None,
prec,
dprec,
is_used: true,
Expand Down Expand Up @@ -1759,7 +1758,6 @@ impl Grammar {
],
reduce_action: None,
separator_location: Location::CallSite,
lookaheads: None,
prec: None,
dprec: None,
is_used: true,
Expand Down Expand Up @@ -1814,11 +1812,6 @@ impl Grammar {
// check other, error terminals used
for nonterm in &grammar.nonterminals {
for rule in &nonterm.rules {
if let Some(lookaheads) = &rule.lookaheads {
if lookaheads.contains(&grammar.other_terminal_index) {
grammar.other_used = true;
}
}
for token in &rule.tokens {
if token.token
== Token::Term(TerminalSymbol::Term(grammar.other_terminal_index))
Expand Down Expand Up @@ -1895,7 +1888,6 @@ impl Grammar {
.map(|token| (token.token, &token.reduce_action_chains))
.collect::<Vec<_>>();
let reduce_chains = &term_mapped.reduce_action_chains;
let lookaheads = &rule.lookaheads;
let prec = rule.prec.map(Located::into_value);
let dprec = rule.dprec.map_or(0, Located::into_value);
let reduce_action_token_index =
Expand All @@ -1911,7 +1903,6 @@ impl Grammar {
prefix,
suffix,
reduce_chains,
lookaheads,
prec,
dprec,
reduce_action_token_index,
Expand Down Expand Up @@ -2056,20 +2047,6 @@ impl Grammar {
token.token = Token::Term(TerminalSymbol::Term(new_class));
}
}
// - lookaheads in the rule
if let Some(lookaheads) = &mut rule.lookaheads {
let new_lookaheads = std::mem::take(lookaheads)
.into_iter()
.map(|old_class| {
let new_class = old_class_to_new_class[old_class];
if new_class == self.other_terminal_class_id {
other_was_used = true;
}
new_class
})
.collect();
*lookaheads = new_lookaheads;
}
new_rules.push(rule);
}
nonterm.rules = new_rules;
Expand Down Expand Up @@ -2530,12 +2507,6 @@ impl Grammar {
grammar.add_rule(
nonterm_id,
tokens,
rule.lookaheads.as_ref().map(|lookaheads| {
lookaheads
.iter()
.map(|&t| TerminalSymbol::Term(t))
.collect()
}),
rule.prec.map(Located::into_value),
rule.dprec.map_or(0, Located::into_value),
);
Expand Down
2 changes: 0 additions & 2 deletions rusty_lr_parser/src/nonterminal_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ pub struct Rule {
pub reduce_action: Option<ReduceAction>,
/// span of '|' or ':' before this production rule
pub separator_location: Location,
/// force lookahead tokens for this pattern.
pub lookaheads: Option<BTreeSet<usize>>,
/// %prec definition
pub prec: Option<Located<rusty_lr_core::rule::Precedence>>,
/// %dprec definition
Expand Down
43 changes: 0 additions & 43 deletions rusty_lr_parser/src/parser/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@ pub enum PatternArgs {
/// a group delimited by '[' and ']' containing terminal set
TerminalSet(TerminalSet),

/// force lookahead tokens for this pattern.
/// lookaheads will not be consumed.
Lookaheads {
pattern: Box<PatternArgs>,
lookaheads: Box<PatternArgs>,
},

/// ( Pattern+ )
/// alternatives is a list of alternatives (separated by '|'),
/// each alternative is a list of patterns.
Expand Down Expand Up @@ -153,12 +146,6 @@ impl std::fmt::Display for PatternArgs {
PatternArgs::Question { base, .. } => write!(f, "{}?", base),
PatternArgs::Exclamation { base, .. } => write!(f, "{}", base),
PatternArgs::TerminalSet(terminal_set) => write!(f, "{}", terminal_set),
PatternArgs::Lookaheads {
pattern,
lookaheads,
} => {
write!(f, "{}/{}", pattern, lookaheads)
}
PatternArgs::Group { alternatives, .. } => {
write!(
f,
Expand Down Expand Up @@ -266,21 +253,6 @@ impl PatternArgs {
Ok(pattern)
}
}
PatternArgs::Lookaheads {
pattern,
lookaheads,
} => {
let (negate, terminal_set) = lookaheads.to_terminal_set(grammar)?;
let pattern = Pattern {
internal: PatternInternal::Lookaheads(
Box::new(pattern.into_pattern(grammar, put_exclamation)?),
negate,
terminal_set,
),
pretty_name,
};
Ok(pattern)
}
PatternArgs::Group { alternatives, .. } => {
if alternatives.len() == 1 && alternatives[0].len() == 1 {
let line = alternatives.into_iter().next().unwrap();
Expand Down Expand Up @@ -429,9 +401,6 @@ impl PatternArgs {
PatternArgs::Star { .. } => Err(ParseError::OnlyTerminalSet(self.location())),
PatternArgs::Question { .. } => Err(ParseError::OnlyTerminalSet(self.location())),
PatternArgs::Exclamation { base, .. } => base.to_terminal_set(grammar),
PatternArgs::Lookaheads { pattern, .. } => {
Err(ParseError::OnlyTerminalSet(pattern.location()))
}
PatternArgs::Group { alternatives, .. } => {
if alternatives.len() == 1 && alternatives[0].len() == 1 {
alternatives[0][0].to_terminal_set(grammar)
Expand Down Expand Up @@ -503,10 +472,6 @@ impl PatternArgs {
op_location: op_span,
} => base.location().merge(op_span),
PatternArgs::TerminalSet(terminal_set) => terminal_set.location(),
PatternArgs::Lookaheads {
pattern,
lookaheads,
} => pattern.location().merge(&lookaheads.location()),
PatternArgs::Group {
open_location: open_span,
close_location: close_span,
Expand All @@ -529,14 +494,6 @@ impl PatternArgs {
PatternArgs::Question { base, .. } => base.range_resolve(grammar),
PatternArgs::Exclamation { base, .. } => base.range_resolve(grammar),
PatternArgs::TerminalSet(terminal_set) => terminal_set.range_resolve(grammar),
PatternArgs::Lookaheads {
pattern,
lookaheads,
} => {
pattern.range_resolve(grammar)?;
lookaheads.range_resolve(grammar)?;
Ok(())
}
PatternArgs::Group { alternatives, .. } => {
for line in alternatives {
for pattern in line {
Expand Down
4 changes: 0 additions & 4 deletions rusty_lr_parser/src/parser/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub enum Lexed {
Caret(Punct),
Minus(Punct),
Exclamation(Punct),
Slash(Punct),
Dot(Punct),
Dollar(Punct),
Comma(Punct),
Expand Down Expand Up @@ -83,7 +82,6 @@ impl Lexed {
Lexed::Caret(punct) => stream.append(punct),
Lexed::Minus(punct) => stream.append(punct),
Lexed::Exclamation(punct) => stream.append(punct),
Lexed::Slash(punct) => stream.append(punct),
Lexed::Dot(punct) => stream.append(punct),
Lexed::Dollar(punct) => stream.append(punct),
Lexed::Comma(punct) => stream.append(punct),
Expand Down Expand Up @@ -180,7 +178,6 @@ impl std::fmt::Display for Lexed {
Lexed::Caret(_) => write!(f, "'^'"),
Lexed::Minus(_) => write!(f, "'-'"),
Lexed::Exclamation(_) => write!(f, "'!'"),
Lexed::Slash(_) => write!(f, "'/'"),
Lexed::Dot(_) => write!(f, "'.'"),
Lexed::Dollar(_) => write!(f, "'$'"),
Lexed::Comma(_) => write!(f, "','"),
Expand Down Expand Up @@ -280,7 +277,6 @@ pub fn feed_recursive(
'-' => context.feed_location(Lexed::Minus(punct), location)?,
'=' => context.feed_location(Lexed::Equal(punct), location)?,
'!' => context.feed_location(Lexed::Exclamation(punct), location)?,
'/' => context.feed_location(Lexed::Slash(punct), location)?,
'.' => context.feed_location(Lexed::Dot(punct), location)?,
'%' => context.feed_location(Lexed::Percent(punct), location)?,
'$' => context.feed_location(Lexed::Dollar(punct), location)?,
Expand Down
7 changes: 1 addition & 6 deletions rusty_lr_parser/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ use rusty_lr_core::rule::ReduceType;
%token caret Lexed::Caret(_);
%token minus Lexed::Minus(_);
%token exclamation Lexed::Exclamation(_);
%token slash Lexed::Slash(_);
%token dot Lexed::Dot(_);
%token dollar Lexed::Dollar(_);
%token comma Lexed::Comma(_);
Expand Down Expand Up @@ -270,7 +269,6 @@ TerminalSet(TerminalSet): lbracket caret? TerminalSetItem* rbracket {
;

%left minus;
%left slash;
%left star plus question exclamation;

Pattern(PatternArgs): ident {
Expand All @@ -297,9 +295,6 @@ Pattern(PatternArgs): ident {
| TerminalSet {
PatternArgs::TerminalSet( TerminalSet )
}
| p1=Pattern slash lh=Pattern {
PatternArgs::Lookaheads { pattern: Box::new(p1), lookaheads: Box::new(lh) }
}
| lparen $sep( Pattern*, pipe, + ) rparen {
PatternArgs::Group { alternatives: Pattern, open_location: @lparen, close_location: @rparen }
}
Expand Down Expand Up @@ -658,4 +653,4 @@ GrammarLine : Rule { data.rules.push(Rule); }
| Directive
;

Grammar: GrammarLine+;
Grammar: GrammarLine+;
Loading