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 for reserved chunk names #271

Merged
merged 1 commit into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions actr/chunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package actr

import "github.com/asmaloney/gactar/util/container"

// See "Default Chunks" pg. 80 of ACT-R manual.
var reservedChunkNames = []string{"busy", "clear", "empty", "error", "full", "failure", "free", "requested", "unrequested"}

type Chunk struct {
TypeName string
SlotNames []string
Expand All @@ -14,6 +17,12 @@ func IsInternalChunkType(name string) bool {
return name[0] == '_'
}

// IsReservedType checks if the slot name is reserved.
// See "Default Chunks" pg. 80 of ACT-R manual.
func IsReservedType(name string) bool {
return container.Contains(name, reservedChunkNames)
}

// LookupChunk looks up the chunk (by type name) in the model and returns it (or nil if it does not exist).
func (model Model) LookupChunk(typeName string) *Chunk {
for _, chunk := range model.Chunks {
Expand Down
17 changes: 15 additions & 2 deletions amod/amod_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func Example_gactarTraceActivationsNonBool() {
// ERROR: 'trace_activations' must be 'true' or 'false' (line 5, col 29)
}

func Example_chunkReservedType() {
func Example_chunkInternalType() {
generateToStdout(`
~~ model ~~
name: Test
Expand All @@ -114,7 +114,20 @@ func Example_chunkReservedType() {
~~ productions ~~`)

// Output:
// ERROR: cannot use reserved chunk type '_internal' (chunks beginning with '_' are reserved) (line 5, col 11)
// ERROR: cannot use reserved chunk type "_internal" (chunks beginning with '_' are reserved) (line 5, col 11)
}

func Example_chunkReservedType() {
generateToStdout(`
~~ model ~~
name: Test
~~ config ~~
chunks { [requested: foo bar] }
~~ init ~~
~~ productions ~~`)

// Output:
// ERROR: cannot use reserved chunk type "requested" (line 5, col 11)
}

func Example_chunkDuplicateType() {
Expand Down
7 changes: 6 additions & 1 deletion amod/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ type varAndIndex struct {
// reserved names.
func validateChunk(model *actr.Model, log *issueLog, chunk *chunkDecl) (err error) {
if actr.IsInternalChunkType(chunk.TypeName) {
log.errorTR(chunk.Tokens, 1, 2, "cannot use reserved chunk type '%s' (chunks beginning with '_' are reserved)", chunk.TypeName)
log.errorTR(chunk.Tokens, 1, 2, "cannot use reserved chunk type %q (chunks beginning with '_' are reserved)", chunk.TypeName)
return ErrCompile
}

if actr.IsReservedType(chunk.TypeName) {
log.errorTR(chunk.Tokens, 1, 2, "cannot use reserved chunk type %q", chunk.TypeName)
return ErrCompile
}

Expand Down