Skip to content

Commit

Permalink
Implement parser using LALRPOP
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanzab committed Nov 28, 2016
1 parent c87c733 commit 96c4602
Show file tree
Hide file tree
Showing 10 changed files with 1,188 additions and 1,071 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@

target
Cargo.lock

parser/src/grammar.rs
25 changes: 20 additions & 5 deletions base/src/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ pub struct Spanned<T, Pos> {
pub value: T,
}

impl<T, Pos> Spanned<T, Pos> {
pub fn map<U, F>(self, mut f: F) -> Spanned<U, Pos>
where F: FnMut(T) -> U,
{
Spanned {
span: self.span,
value: f(self.value),
}
}
}

impl<T: PartialEq, Pos> PartialEq for Spanned<T, Pos> {
fn eq(&self, other: &Spanned<T, Pos>) -> bool {
self.value == other.value
Expand All @@ -236,6 +247,14 @@ impl<T: fmt::Display, Pos: fmt::Display> fmt::Display for Spanned<T, Pos> {
}
}

pub fn span<Pos>(start: Pos, end: Pos) -> Span<Pos> {
Span {
start: start,
end: end,
expansion_id: NO_EXPANSION,
}
}

pub fn spanned<T, Pos>(span: Span<Pos>, value: T) -> Spanned<T, Pos> {
Spanned {
span: span,
Expand All @@ -245,11 +264,7 @@ pub fn spanned<T, Pos>(span: Span<Pos>, value: T) -> Spanned<T, Pos> {

pub fn spanned2<T, Pos>(start: Pos, end: Pos, value: T) -> Spanned<T, Pos> {
Spanned {
span: Span {
start: start,
end: end,
expansion_id: NO_EXPANSION,
},
span: span(start, end),
value: value,
}
}
7 changes: 7 additions & 0 deletions parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ description = "The parser for the gluon programming language"
repository = "https://github.com/gluon-lang/gluon"
documentation = "https://docs.rs/gluon"

build = "build.rs"

[dependencies]
combine-language = "=2.0.0-beta4"
combine = "=2.0.0-beta3"
env_logger = { version = "0.3.4", optional = true }
lalrpop = "0.12.0"
lalrpop-util = "0.12.0"
log = "0.3.6"
gluon_base = { path = "../base", version = "0.2.2" }
collect-mac = "0.1.0"

[build-dependencies]
lalrpop = "0.12.0"

[features]
test = ["env_logger"]
7 changes: 7 additions & 0 deletions parser/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern crate lalrpop;

fn main() {
lalrpop::Configuration::new()
.process_current_dir()
.unwrap();
}
Loading

0 comments on commit 96c4602

Please sign in to comment.