Skip to content

Commit 56a2e06

Browse files
committed
migrate to logos for human_encoding
1 parent 80f3821 commit 56a2e06

File tree

6 files changed

+659
-670
lines changed

6 files changed

+659
-670
lines changed

Cargo-recent.lock

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ version = "0.11.1"
5151
source = "registry+https://github.com/rust-lang/crates.io-index"
5252
checksum = "32637268377fc7b10a8c6d51de3e7fba1ce5dd371a96e342b34e6078db558e7f"
5353

54+
[[package]]
55+
name = "beef"
56+
version = "0.5.2"
57+
source = "registry+https://github.com/rust-lang/crates.io-index"
58+
checksum = "3a8241f3ebb85c056b509d4327ad0358fbbba6ffb340bf388f26350aeda225b1"
59+
5460
[[package]]
5561
name = "bitcoin"
5662
version = "0.32.8"
@@ -160,6 +166,12 @@ version = "0.1.5"
160166
source = "registry+https://github.com/rust-lang/crates.io-index"
161167
checksum = "3a3076410a55c90011c298b04d0cfa770b00fa04e1e3c97d3f6c9de105a03844"
162168

169+
[[package]]
170+
name = "fnv"
171+
version = "1.0.7"
172+
source = "registry+https://github.com/rust-lang/crates.io-index"
173+
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
174+
163175
[[package]]
164176
name = "getrandom"
165177
version = "0.2.16"
@@ -238,6 +250,12 @@ dependencies = [
238250
"wasm-bindgen",
239251
]
240252

253+
[[package]]
254+
name = "lazy_static"
255+
version = "1.5.0"
256+
source = "registry+https://github.com/rust-lang/crates.io-index"
257+
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
258+
241259
[[package]]
242260
name = "libc"
243261
version = "0.2.178"
@@ -254,6 +272,40 @@ dependencies = [
254272
"cc",
255273
]
256274

275+
[[package]]
276+
name = "logos"
277+
version = "0.15.1"
278+
source = "registry+https://github.com/rust-lang/crates.io-index"
279+
checksum = "ff472f899b4ec2d99161c51f60ff7075eeb3097069a36050d8037a6325eb8154"
280+
dependencies = [
281+
"logos-derive",
282+
]
283+
284+
[[package]]
285+
name = "logos-codegen"
286+
version = "0.15.1"
287+
source = "registry+https://github.com/rust-lang/crates.io-index"
288+
checksum = "192a3a2b90b0c05b27a0b2c43eecdb7c415e29243acc3f89cc8247a5b693045c"
289+
dependencies = [
290+
"beef",
291+
"fnv",
292+
"lazy_static",
293+
"proc-macro2",
294+
"quote",
295+
"regex-syntax",
296+
"rustc_version",
297+
"syn",
298+
]
299+
300+
[[package]]
301+
name = "logos-derive"
302+
version = "0.15.1"
303+
source = "registry+https://github.com/rust-lang/crates.io-index"
304+
checksum = "605d9697bcd5ef3a42d38efc51541aa3d6a4a25f7ab6d1ed0da5ac632a26b470"
305+
dependencies = [
306+
"logos-codegen",
307+
]
308+
257309
[[package]]
258310
name = "memchr"
259311
version = "2.7.6"
@@ -368,6 +420,15 @@ version = "0.8.8"
368420
source = "registry+https://github.com/rust-lang/crates.io-index"
369421
checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58"
370422

423+
[[package]]
424+
name = "rustc_version"
425+
version = "0.4.1"
426+
source = "registry+https://github.com/rust-lang/crates.io-index"
427+
checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92"
428+
dependencies = [
429+
"semver",
430+
]
431+
371432
[[package]]
372433
name = "rustversion"
373434
version = "1.0.22"
@@ -427,6 +488,12 @@ dependencies = [
427488
"secp256k1-sys",
428489
]
429490

491+
[[package]]
492+
name = "semver"
493+
version = "1.0.27"
494+
source = "registry+https://github.com/rust-lang/crates.io-index"
495+
checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2"
496+
430497
[[package]]
431498
name = "serde"
432499
version = "1.0.228"
@@ -519,8 +586,8 @@ dependencies = [
519586
"getrandom 0.2.16",
520587
"ghost-cell",
521588
"hex-conservative 0.2.2",
589+
"logos",
522590
"miniscript",
523-
"santiago",
524591
"serde",
525592
"serde_json",
526593
"simplicity-sys 0.6.2",

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ elements = { version = "0.25.0", optional = true, default-features = false }
2929
ghost-cell = { version = "0.2.6", default-features = false }
3030
hashes = { package = "bitcoin_hashes", version = "0.14" }
3131
hex = { package = "hex-conservative", version = "0.2.1" }
32-
santiago = "1.3"
32+
logos = "0.15"
3333
simplicity-sys = { version = "0.6.2", path = "./simplicity-sys" }
3434
serde = { version = "1.0.103", features = ["derive"], optional = true }
3535

src/human_encoding/README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ With that said, the rest of the document defines the encoding.
1515

1616
## Syntax
1717

18-
The syntax is defined in `src/human_encoding/parse/ast.rs`. It currently uses the
19-
`santiago` parser generator, but we would like to move away from this, probably to
20-
an ad-hoc parser, to avoid poor asymptotic behavior and to get better error messages.
18+
The syntax is defined in `src/human_encoding/parse/ast.rs`.
2119

2220
Comments are started by `--` and end at the next newline. This is the only aspect
2321
in which whitespace is significant.

src/human_encoding/error.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
//! Parsing Errors
44
5-
use santiago::lexer::Lexeme;
65
use std::collections::BTreeMap;
76
use std::sync::{Arc, Mutex};
87
use std::{error, fmt, iter};
@@ -19,22 +18,6 @@ pub struct ErrorSet {
1918
errors: BTreeMap<Option<Position>, Vec<Error>>,
2019
}
2120

22-
impl<T> From<santiago::parser::ParseError<T>> for ErrorSet {
23-
fn from(e: santiago::parser::ParseError<T>) -> Self {
24-
let lex = e.at.map(|rc| (*rc).clone());
25-
match lex.as_ref().map(|lex| &lex.position).map(Position::from) {
26-
Some(pos) => ErrorSet::single(pos, Error::ParseFailed(lex)),
27-
None => ErrorSet::single_no_position(Error::ParseFailed(lex)),
28-
}
29-
}
30-
}
31-
32-
impl From<santiago::lexer::LexerError> for ErrorSet {
33-
fn from(e: santiago::lexer::LexerError) -> Self {
34-
ErrorSet::single(e.position, Error::LexFailed(e.message))
35-
}
36-
}
37-
3821
impl ErrorSet {
3922
/// Constructs a new empty error set.
4023
pub fn new() -> Self {
@@ -260,10 +243,10 @@ pub enum Error {
260243
NameRepeated(Arc<str>),
261244
/// Program did not have a `main` expression
262245
NoMain,
263-
/// Parsing failed (the parser provides us some extra information, but beyond
264-
/// the line and column, it does not seem very useful to a user, so we drop it).
265-
ParseFailed(Option<Lexeme>),
266-
/// Lexing failed; here santiago provides us an error message which is useful
246+
/// Parsing failed; the string (if any) is a description of the token at which
247+
/// parsing failed.
248+
ParseFailed(Option<String>),
249+
/// Lexing failed
267250
LexFailed(String),
268251
/// A number was parsed in some context but was out of range.
269252
NumberOutOfRange(String),
@@ -327,7 +310,7 @@ impl fmt::Display for Error {
327310
write!(f, "number {} was out of allowable range", n)
328311
}
329312
Error::ParseFailed(None) => f.write_str("could not parse"),
330-
Error::ParseFailed(Some(ref lex)) => write!(f, "could not parse `{}`", lex.raw),
313+
Error::ParseFailed(Some(ref raw)) => write!(f, "could not parse `{}`", raw),
331314
Error::LexFailed(ref msg) => write!(f, "could not parse: {}", msg),
332315
Error::TypeCheck(ref e) => fmt::Display::fmt(e, f),
333316
Error::Undefined(ref s) => write!(f, "reference to undefined symbol `{}`", s),

src/human_encoding/mod.rs

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,16 @@ pub use self::error::{Error, ErrorSet};
2424
pub use self::named_node::NamedCommitNode;
2525

2626
/// Line/column pair
27-
///
28-
/// There is a similar type provided by the `santiago` library but it does not implement
29-
/// `Copy`, among many other traits, which makes it unergonomic to use. Santiago positions
30-
/// can be converted using `.into()`.
3127
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Default, Hash)]
3228
pub struct Position {
3329
line: usize,
3430
column: usize,
3531
}
3632

37-
impl<'a> From<&'a santiago::lexer::Position> for Position {
38-
fn from(position: &'a santiago::lexer::Position) -> Position {
39-
Position {
40-
line: position.line,
41-
column: position.column,
42-
}
43-
}
44-
}
45-
46-
impl From<santiago::lexer::Position> for Position {
47-
fn from(position: santiago::lexer::Position) -> Position {
48-
Position {
49-
line: position.line,
50-
column: position.column,
51-
}
33+
impl Position {
34+
/// Create a new position from line and column.
35+
pub fn new(line: usize, column: usize) -> Self {
36+
Position { line, column }
5237
}
5338
}
5439

0 commit comments

Comments
 (0)