Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check field-num uniqueness #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions parser/grammar.peg
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,31 @@ StructLike ← name:Identifier __ '{' __ fields:FieldList '}' EOS {
FieldList ← fields:(Field __)* {
fs := fields.([]interface{})
flds := make([]*Field, len(fs))
ids := make(map[int]bool, len(fs))
for i, f := range fs {
flds[i] = f.([]interface{})[0].(*Field)

if ids[flds[i].ID] {
return nil, fmt.Errorf("multiple fields with the same identifier: %d", flds[i].ID)
}

ids[flds[i].ID] = true
}
return flds, nil
}

Field ← id:IntConstant _ ':' _ req:FieldReq? _ typ:FieldType _ name:Identifier __ def:('=' _ ConstValue)? ListSeparator? {
FieldID ← id:IntConstant _ ':' {
return int(id.(int64)), nil
}

Field ← id:FieldID? _ req:FieldReq? _ typ:FieldType _ name:Identifier __ def:('=' _ ConstValue)? ListSeparator? {
parsedID := -1
if id != nil {
parsedID = id.(int)
}

f := &Field{
ID : int(id.(int64)),
ID : parsedID,
Name : string(name.(Identifier)),
Type : typ.(*Type),
}
Expand Down