Skip to content

Commit

Permalink
Add struct fields to parser.
Browse files Browse the repository at this point in the history
Preparation for resolving rust-lang#11.
  • Loading branch information
withoutboats committed Mar 14, 2017
1 parent ef92330 commit 62d9d28
Show file tree
Hide file tree
Showing 4 changed files with 3,589 additions and 2,975 deletions.
6 changes: 6 additions & 0 deletions chalk-parse/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct StructDefn {
pub name: Identifier,
pub parameter_kinds: Vec<ParameterKind>,
pub where_clauses: Vec<WhereClause>,
pub fields: Vec<Field>,
}

pub struct TraitDefn {
Expand Down Expand Up @@ -174,6 +175,11 @@ pub enum WhereClause {
UnifyLifetimes { a: Lifetime, b: Lifetime },
}

pub struct Field {
pub name: Identifier,
pub ty: Ty,
}

pub enum Goal {
ForAll(Vec<ParameterKind>, Box<Goal>),
Exists(Vec<ParameterKind>, Box<Goal>),
Expand Down
16 changes: 14 additions & 2 deletions chalk-parse/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ Goal1: Box<Goal> = {
};

StructDefn: StructDefn = {
"struct" <n:Id><p:Angle<ParameterKind>> <w:WhereClauses> "{" "}" => StructDefn {
"struct" <n:Id><p:Angle<ParameterKind>> <w:WhereClauses> "{" <f:Fields> "}" => StructDefn {
name: n,
parameter_kinds: p,
where_clauses: w
where_clauses: w,
fields: f,
}
};

Expand Down Expand Up @@ -118,6 +119,17 @@ ProjectionTy: ProjectionTy = {
},
};

Fields: Vec<Field> = {
<Comma<Field>>,
};

Field: Field = {
<n:Id> ":" <t: Ty> => Field {
name: n,
ty: t,
}
};

WhereClauses: Vec<WhereClause> = {
"where" <Comma<WhereClause>>,
() => vec![],
Expand Down
Loading

0 comments on commit 62d9d28

Please sign in to comment.