Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit 8d15b01

Browse files
committed
Update gll and grammer.
1 parent 9758b24 commit 8d15b01

22 files changed

+290
-823
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ name = "snapshots"
3333
path = "src/bin/snapshots.rs"
3434

3535
[patch.'crates-io']
36-
gll = { git = "https://github.com/rust-lang/gll", rev = "617ecfc58a554c92226ec276063c99a09678fb05" }
37-
grammer = { git = "https://github.com/lykenware/grammer", rev = "eb47b51a9332c0e82d7c02d988e203d2a01f3654" }
36+
gll = { git = "https://github.com/rust-lang/gll", rev = "26d42a0117b9c48538ef20c872742e05070bb55e" }
37+
grammer = { git = "https://github.com/lykenware/grammer", rev = "6f6f1320336d84b75805907fb302a28cb6d4cfb0" }

build.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ fn main() {
1717
.filter(|entry| entry.path().extension().map_or(false, |ext| ext == "lyg"));
1818

1919
// Start with the builtin rules for proc-macro grammars.
20-
let mut cx = gll::proc_macro::Context::new();
20+
let mut cx = gll::grammer::proc_macro::Context::new();
2121
let cx = &mut cx;
22-
let mut grammar = gll::proc_macro::builtin(cx);
22+
let mut grammar = gll::grammer::proc_macro::builtin(cx);
2323

2424
// Add in each grammar fragment to the grammar.
2525
for fragment in fragments {

src/bin/coverage.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ use std::{
99
};
1010

1111
use derive_more::Add;
12-
use gll::{
13-
forest::{MoreThanOne, GrammarReflector},
14-
parse_node::ParseNodeShape,
15-
};
12+
use gll::grammer::forest::{GrammarReflector, MoreThanOne, NodeShape};
1613
use rayon::prelude::*;
1714
use rust_grammar::parse;
1815
use serde::{Deserialize, Serialize};
@@ -72,26 +69,29 @@ enum Command {
7269
},
7370
}
7471

75-
type ModuleContentsResult = Result<ModuleContentsHandle, Error<proc_macro2::Span>>;
72+
type ProcMacroPat =
73+
gll::grammer::proc_macro::Pat<&'static [gll::grammer::proc_macro::FlatTokenPat<&'static str>]>;
74+
75+
type ModuleContentsResult = Result<ModuleContentsHandle, Error<proc_macro2::Span, ProcMacroPat>>;
7676

7777
type ModuleContentsHandle = parse::OwnedHandle<
7878
proc_macro2::TokenStream,
7979
parse::ModuleContents<'static, 'static, proc_macro2::TokenStream>,
8080
>;
8181

82-
enum Error<A> {
82+
enum Error<A, Pat> {
8383
Lex(proc_macro2::LexError),
84-
Parse(gll::parser::ParseError<A>),
84+
Parse(gll::grammer::parser::ParseError<A, Pat>),
8585
}
8686

87-
impl<A> From<proc_macro2::LexError> for Error<A> {
87+
impl<A, Pat> From<proc_macro2::LexError> for Error<A, Pat> {
8888
fn from(error: proc_macro2::LexError) -> Self {
8989
Error::Lex(error)
9090
}
9191
}
9292

93-
impl<A> From<gll::parser::ParseError<A>> for Error<A> {
94-
fn from(error: gll::parser::ParseError<A>) -> Self {
93+
impl<A, Pat> From<gll::grammer::parser::ParseError<A, Pat>> for Error<A, Pat> {
94+
fn from(error: gll::grammer::parser::ParseError<A, Pat>) -> Self {
9595
Error::Parse(error)
9696
}
9797
}
@@ -139,15 +139,9 @@ fn report_file_result(
139139
"(missing location information; \
140140
set `RUSTFLAGS='--cfg procmacro2_semver_exempt'`)"
141141
);
142-
143142
}
144143

145-
// HACK(eddyb) this is inefficient - `expected` should be already
146-
// sorted for us, so this is a temporary workaround.
147-
let mut expected = error.expected.clone();
148-
expected.sort_by_cached_key(|x| format!("{:?}", x));
149-
150-
eprintln!("Expected: {:?}", expected);
144+
eprintln!("Expected: {:?}", error.expected);
151145
}
152146
(Err(Error::Lex(e)), _) => eprintln!("FAIL ({:?})", e),
153147
}
@@ -169,16 +163,16 @@ fn ambiguity_check(handle: &ModuleContentsHandle) -> Result<(), MoreThanOne> {
169163
}
170164
}
171165
};
172-
match forest.grammar.parse_node_shape(source.kind) {
173-
ParseNodeShape::Opaque => {}
174-
ParseNodeShape::Alias(_) => add_children(&[forest.unpack_alias(source)]),
175-
ParseNodeShape::Opt(_) => {
166+
match forest.grammar.node_shape(source.kind) {
167+
NodeShape::Opaque => {}
168+
NodeShape::Alias(_) => add_children(&[forest.unpack_alias(source)]),
169+
NodeShape::Opt(_) => {
176170
if let Some(child) = forest.unpack_opt(source) {
177171
add_children(&[child]);
178172
}
179173
}
180-
ParseNodeShape::Choice => add_children(&[forest.one_choice(source)?]),
181-
ParseNodeShape::Split(..) => {
174+
NodeShape::Choice => add_children(&[forest.one_choice(source)?]),
175+
NodeShape::Split(..) => {
182176
let (left, right) = forest.one_split(source)?;
183177
add_children(&[left, right])
184178
}

src/bin/snapshots.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@ use {
99
walkdir::WalkDir,
1010
};
1111

12+
type ProcMacroPat =
13+
gll::grammer::proc_macro::Pat<&'static [gll::grammer::proc_macro::FlatTokenPat<&'static str>]>;
14+
1215
fn parse_result_to_str<T: Debug>(
13-
mut result: Result<T, gll::parser::ParseError<proc_macro2::Span>>,
16+
result: Result<T, gll::grammer::parser::ParseError<proc_macro2::Span, ProcMacroPat>>,
1417
) -> String {
15-
if let Err(error) = &mut result {
16-
// HACK(eddyb) this is inefficient - `expected` should be already
17-
// sorted for us, so this is a temporary workaround.
18-
error.expected.sort_by_cached_key(|x| format!("{:?}", x));
19-
}
20-
18+
// FIXME(eddyb) print the location properly in case of error.
2119
format!("{:#?}", result)
2220
}
2321

0 commit comments

Comments
 (0)