Skip to content

Commit

Permalink
feat: Update to lalrpop 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
Marwes committed Apr 9, 2018
1 parent d3ac899 commit 4f59c4c
Show file tree
Hide file tree
Showing 8 changed files with 24,790 additions and 27 deletions.
4 changes: 2 additions & 2 deletions parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ build = "build.rs"
collect-mac = "0.1.0"
itertools = "0.6.0"
quick-error = "1.0.0"
lalrpop-util = "0.14.0"
lalrpop-util = "0.15.1"
log = "0.4"
pretty = "0.3.2"
gluon_base = { path = "../base", version = "0.7.1" } # GLUON
Expand All @@ -28,7 +28,7 @@ difference = "1.0"
pretty_assertions = "0.4"

[build-dependencies]
lalrpop = "0.14.0"
lalrpop = "0.15.1"

[features]
test = []
24,764 changes: 24,763 additions & 1 deletion parser/src/grammar.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions parser/src/infix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ pub fn reparse<Id>(
symbols: &IdentEnv<Ident = Id>,
operators: &OpTable,
) -> Result<SpannedExpr<Id>, Spanned<Error, BytePos>> {
use base::pos;
use self::Error::*;
use base::pos;

let make_op = |lhs: Box<SpannedExpr<Id>>, op, rhs: Box<SpannedExpr<Id>>| {
let span = pos::span(lhs.span.start, rhs.span.end);
Expand Down Expand Up @@ -402,8 +402,8 @@ mod tests {
use base::pos::{self, BytePos, Spanned};
use std::marker::PhantomData;

use super::{reparse, Fixity, InfixToken, Infixes, OpMeta, OpTable};
use super::Error::*;
use super::{reparse, Fixity, InfixToken, Infixes, OpMeta, OpTable};

pub struct MockEnv<T>(PhantomData<T>);

Expand Down
23 changes: 12 additions & 11 deletions parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,25 +275,26 @@ type ErrorEnv<'err, 'input> = &'err mut Errors<LalrpopError<'input>>;
pub type ParseErrors = Errors<Spanned<Error, BytePos>>;

macro_rules! layout {
($result_ok_iter: ident, $input: expr) => { {
($result_ok_iter:ident, $input:expr) => {{
let tokenizer = Tokenizer::new($input);
$result_ok_iter = RefCell::new(ResultOkIter::new(tokenizer));

Layout::new(SharedIter::new(&$result_ok_iter)).map(|token| {
// Return the tokenizer error if one exists
$result_ok_iter.borrow_mut()
.result(())
.map_err(|err| {
pos::spanned2(err.span.start.absolute,
err.span.end.absolute,
err.value.into())
})?;
$result_ok_iter.borrow_mut().result(()).map_err(|err| {
pos::spanned2(
err.span.start.absolute,
err.span.end.absolute,
err.value.into(),
)
})?;
let token = token.map_err(|err| pos::spanned(err.span, err.value.into()))?;
debug!("Lex {:?}", token.value);
let Span { start, end, .. } = token.span;
Ok((start.absolute, token.value, end.absolute))
})
} }
}
}
}

pub fn parse_partial_expr<Id>(
Expand All @@ -309,7 +310,7 @@ where

let mut parse_errors = Errors::new();

let result = grammar::parse_TopExpr(input, type_cache, symbols, &mut parse_errors, layout);
let result = grammar::TopExprParser::new().parse(input, type_cache, symbols, &mut parse_errors, layout);

// If there is a tokenizer error it may still exist in the result iterator wrapper.
// If that is the case we return that error instead of the unexpected EOF error that lalrpop
Expand Down Expand Up @@ -370,7 +371,7 @@ where

let type_cache = TypeCache::new();

let result = grammar::parse_LetOrExpr(input, &type_cache, symbols, &mut parse_errors, layout);
let result = grammar::LetOrExprParser::new().parse(input, &type_cache, symbols, &mut parse_errors, layout);

// If there is a tokenizer error it may still exist in the result iterator wrapper.
// If that is the case we return that error instead of the unexpected EOF error that lalrpop
Expand Down
4 changes: 2 additions & 2 deletions vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ gluon_check = { path = "../check", version = "0.7.1" } # GLUON
tokio-core = "0.1"

[build-dependencies]
lalrpop = { version = "0.14.0", optional = true }
lalrpop = { version = "0.15.1", optional = true }

[dev-dependencies]
env_logger = "0.5"
# HACK Trick crates.io into letting letting this be published with a dependency on gluon
# (which requires gluon_vm to be published)
gluon = { path = "..", version = "<0.9.0, >=0.7.0" } # GLUON

lalrpop-util = "0.14.0"
lalrpop-util = "0.15.1"
regex = "0.2.0"
serde_json = "1.0.0"

Expand Down
8 changes: 4 additions & 4 deletions vm/src/core/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ mod tests {
use base::symbol::Symbols;

use core::*;
use core::grammar::parse_Expr as parse_core_expr;
use core::grammar::ExprParser;

macro_rules! assert_eq_expr {
($actual: expr, $expected: expr) => {
Expand All @@ -767,7 +767,7 @@ mod tests {

let allocator = Allocator::new();

let actual_expr = parse_core_expr(&mut symbols, &allocator, $actual)
let actual_expr = ExprParser::new().parse(&mut symbols, &allocator, $actual)
.unwrap();

let actual_expr = {
Expand All @@ -776,7 +776,7 @@ mod tests {
.unwrap()
};

let expected_expr = parse_core_expr(&mut symbols, &allocator, $expected)
let expected_expr = ExprParser::new().parse(&mut symbols, &allocator, $expected)
.unwrap();

assert_deq!(*actual_expr, expected_expr);
Expand Down Expand Up @@ -874,7 +874,7 @@ mod tests {
let _ = ::env_logger::try_init();
let mut symbols = Symbols::new();
let global_allocator = Allocator::new();
let global = parse_core_expr(
let global = ExprParser::new().parse(
&mut symbols,
&global_allocator,
"let f x y = (#Int+) x y in { f }",
Expand Down
4 changes: 2 additions & 2 deletions vm/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ mod tests {
use base::symbol::{Symbol, SymbolModule, Symbols};
use base::types::TypeCache;

use core::grammar::parse_Expr as parse_core_expr;
use core::grammar::ExprParser;

use vm::RootedThread;

Expand Down Expand Up @@ -1931,7 +1931,7 @@ mod tests {
let core_expr = translator.translate(&expr);

let expected_expr =
parse_core_expr(&mut symbols, &translator.allocator, expected_str).unwrap();
ExprParser::new().parse(&mut symbols, &translator.allocator, expected_str).unwrap();
assert_deq!(PatternEq(&core_expr), expected_expr);
}

Expand Down
6 changes: 3 additions & 3 deletions vm/src/core/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ mod tests {
use base::symbol::Symbols;

use core;
use core::grammar::parse_Expr as parse_core_expr;
use core::grammar::ExprParser;

#[test]
fn unnecessary_allocation() {
Expand All @@ -338,7 +338,7 @@ mod tests {
"#;
let initial_expr = allocator
.arena
.alloc(parse_core_expr(&mut symbols, &allocator, initial_str).unwrap());
.alloc(ExprParser::new().parse(&mut symbols, &allocator, initial_str).unwrap());

let optimized_expr = optimize(&allocator, initial_expr);

Expand All @@ -349,7 +349,7 @@ mod tests {
in
l
"#;
let expected_expr = parse_core_expr(&mut symbols, &allocator, expected_str).unwrap();
let expected_expr = ExprParser::new().parse(&mut symbols, &allocator, expected_str).unwrap();
assert_deq!(*optimized_expr, expected_expr);
}
}

0 comments on commit 4f59c4c

Please sign in to comment.