amod

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Example (ChunkDuplicateName)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks {
    	[something: foo bar]
    	[something: foo bar]
	}
	==init==
	==productions==`)
Output:

ERROR: duplicate chunk name: 'something' (line 7, col 6)
Example (ChunkReservedName)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [_internal: foo bar] }
	==init==
	==productions==`)
Output:

ERROR: cannot use reserved chunk name '_internal' (chunks beginning with '_' are reserved) (line 5, col 11)
Example (GactarUnrecognizedField)
generateToStdout(`
	==model==
	name: Test
	==config==
	gactar { foo: bar }
	==init==
	==productions==`)
Output:

ERROR: unrecognized field in gactar section: 'foo' (line 5, col 10)
Example (ImaginalFieldRange)
generateToStdout(`
	==model==
	name: Test
	==config==
	modules {
		imaginal { delay: -0.5 }
	}
	==init==
	==productions==`)
Output:

ERROR: imaginal delay '-0.500000' must be a positive number (line 6, col 20)
Example (ImaginalFieldType)
generateToStdout(`
	==model==
	name: Test
	==config==
	modules {
		imaginal { delay: "gack" }
	}
	==init==
	==productions==`)
Output:

ERROR: imaginal delay 'gack' must be a number (line 6, col 20)
Example (ImaginalFieldUnrecognized)
generateToStdout(`
	==model==
	name: Test
	==config==
	modules {
		imaginal { foo: bar }
	}
	==init==
	==productions==`)
Output:

ERROR: unrecognized field 'foo' in imaginal config (line 6, col 13)
Example (ImaginalFields)
generateToStdout(`
	==model==
	name: Test
	==config==
	modules {
		imaginal { delay: 0.2 }
		memory { latency: 0.5 }
	}
	==init==
	==productions==`)
Output:

Example (Initializer1)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks {
		[remember: person]
		[author: person object]
	}
	==init==
	memory {
		[remember: me]
		[author: me software]
	}
	==productions==`)
Output:

Example (Initializer2)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [author: person object year] }
	==init==
	goal [author: Fred Book 1972]
	==productions==`)
Output:

Example (Initializer3)
// memory with one init is allowed
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [author: person object year] }
	==init==
	memory [author: Jane Book 1982]
	==productions==`)
Output:

Example (InitializerInvalidChunk1)
// Check memory with invalid chunk
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	memory { [author: me software] }
	==productions==`)
Output:

ERROR: could not find chunk named 'author' (line 6, col 11)
Example (InitializerInvalidChunk2)
// Check buffer with invalid chunk
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	goal [author: Fred Book 1972]
	==productions==`)
Output:

ERROR: could not find chunk named 'author' (line 6, col 7)
Example (InitializerInvalidSlots)
// Check invalid number of slots in init
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [author: person object year] }
	==init==
	memory { [author: me software] }
	==productions==`)
Output:

ERROR: invalid chunk - 'author' expects 3 slots (line 7, col 10)
Example (InitializerMultipleInits)
// Check buffer with multiple inits
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [author: person object year] }
	==init==
	goal { [author: Fred Book 1972] [author: Jane Book 1982] }
	==productions==`)
Output:

ERROR: module 'goal' should only have one pattern in initialization (line 7, col 1)
Example (InitializerUnknownBuffer)
// Check unknown buffer
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [author: person object year] }
	==init==
	something [author: Fred Book 1972]
	==productions==`)
Output:

ERROR: module 'something' not found in initialization (line 7, col 1)
Example (MemoryFieldUnrecognized)
generateToStdout(`
	==model==
	name: Test
	==config==
	modules {
		memory { foo: bar }
	}
	==init==
	==productions==`)
Output:

ERROR: unrecognized field 'foo' in memory (line 6, col 11)
Example (ModelAuthors)
generateToStdout(`
	==model==
	name: Test
	authors {
    	'Andy Maloney <andy@example.com>' // did all the work
    	'Hiro Protagonist <hiro@example.com>' // fixed some things
	}
	==config==
	==init==
	==productions==`)
Output:

Example (ModelExampleBadChunk)
generateToStdout(`
	==model==
	name: Test
	examples { [foo: bar] }
	==config==
	==init==
	==productions==`)
Output:

ERROR: could not find chunk named 'foo' (line 4, col 13)
Example (ModelExamples)
generateToStdout(`
	==model==
	name: Test
	examples { [foo: bar] }
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==`)
Output:

Example (Modules)
generateToStdout(`
	==model==
	name: Test
	==config==
	modules {
		imaginal { delay: 0.2 }
	}
	==init==
	==productions==`)
Output:

Example (ModulesUnrecognized)
generateToStdout(`
	==model==
	name: Test
	==config==
	modules {
		foo { delay: 0.2 }
	}
	==init==
	==productions==`)
Output:

ERROR: unrecognized module in config: 'foo' (line 6, col 2)
Example (ProductionChunkNotFound)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { goal [foo: error] }
		do { print 42 }
	}`)
Output:

ERROR: could not find chunk named 'foo' (line 8, col 16)
Example (ProductionClearStatement)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { clear goal }
	}`)
Output:

Example (ProductionClearStatementInvalidBuffer)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { clear some_buffer }
	}`)
Output:

ERROR: buffer 'some_buffer' not found in production 'start' (line 10, col 7)
Example (ProductionInvalidAnonVarInSet1)
// https://github.com/asmaloney/gactar/issues/57
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: ?] }
		do { set goal.thing to ? }
	}`)
Output:

ERROR: cannot set 'goal.thing' to anonymous var ('?') in production 'start' (line 10, col 25)
Example (ProductionInvalidAnonVarInSet2)
// https://github.com/asmaloney/gactar/issues/57
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: ?] }
		do { set goal to [foo: ?] }
	}`)
Output:

ERROR: cannot set 'goal.thing' to anonymous var ('?') in production 'start' (line 10, col 25)
Example (ProductionInvalidMemory)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { another_goal [add: ? ?one1 ? ?one2 ? None?ans ?] }
		do { print 'foo' }
	}`)
Output:

ERROR: buffer 'another_goal' not found in production 'start' (line 8, col 10)
Example (ProductionMatchInternal)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { retrieval [_status: error] }
		do { print 42 }
	}`)
Output:

Example (ProductionMatchInternalInvalidStatus1)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { goal [_status: something] }
		do { print 42 }
	}`)
Output:

ERROR: invalid _status 'something' for 'goal' in production 'start' (should be 'busy', 'empty', 'error', 'full') (line 8, col 25)
Example (ProductionMatchInternalInvalidStatus2)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { retrieval [_status: something] }
		do { print 42 }
	}`)
Output:

ERROR: invalid _status 'something' for 'retrieval' in production 'start' (should be 'busy', 'empty', 'error', 'full') (line 8, col 30)
Example (ProductionMatchInternalSlots)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { retrieval [_status: busy error] }
		do { print 42 }
	}`)
Output:

ERROR: invalid chunk - '_status' expects 1 slot (line 8, col 20)
Example (ProductionMultipleStatement)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing1 thing2] }
	==init==
	==productions==
	start {
		match { goal [foo: ?next ?other] }
		do {
        	recall [foo: ?next ?]
			set goal to [foo: ?other 42]
		}
	}`)
Output:

Example (ProductionPrintStatement1)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing1 thing2] }
	==init==
	==productions==
	start {
		match { goal [foo: ? ?other] }
		do { print 42, ?other, "blat" }
	}`)
Output:

Example (ProductionPrintStatement2)
// Test print with vars from two different buffers
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing1 thing2] }
	==init==
	==productions==
	start {
		match {
			goal [foo: ? ?other]
			retrieval [foo: ? ?other1]
		}
		do { print 42, ?other, ?other1, "blat" }
	}`)
Output:

Example (ProductionPrintStatement3)
// print without args
// https://github.com/asmaloney/gactar/issues/7
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { retrieval [_status: error] }
		do { print }
	}`)
Output:

Example (ProductionPrintStatementAnonymousVar)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { retrieval [_status: error] }
		do { print ? }
	}`)
Output:

ERROR: cannot print anonymous var ('?') in production 'start' (line 9, col 13)
Example (ProductionPrintStatementInvalidID)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { retrieval [_status: error] }
		do { print fooID }
	}`)
Output:

ERROR: cannot use ID 'fooID' in print statement (line 9, col 13)
Example (ProductionPrintStatementInvalidVar)
generateToStdout(`
	==model==
	name: Test
	==config==
	==init==
	==productions==
	start {
		match { retrieval [_status: error] }
		do { print ?fooVar }
	}`)
Output:

ERROR: print statement variable '?fooVar' not found in matches for production 'start' (line 9, col 13)
Example (ProductionRecallStatement)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing1 thing2] }
	==init==
	==productions==
	start {
		match { goal [foo: ?next ?] }
		do { recall [foo: ?next ?] }
	}`)
Output:

Example (ProductionRecallStatementInvalidPattern)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing1 thing2] }
	==init==
	==productions==
	start {
		match { goal [foo: ?next ?] }
		do { recall [foo: ?next ? bar] }
	}`)
Output:

ERROR: invalid chunk - 'foo' expects 2 slots (line 10, col 14)
Example (ProductionRecallStatementMultiple)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing1 thing2] }
	==init==
	==productions==
	start {
		match { goal [foo: ?next ?] }
		do {
			recall [foo: ?next ?]
			recall [foo: ? ?next]
		}
	}`)
Output:

ERROR: only one recall statement per production is allowed in production 'start' (line 12, col 3)
Example (ProductionRecallStatementVarNotFound)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] [bar: other thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { recall [bar: ?next ?] }
	}`)
Output:

ERROR: recall statement variable '?next' not found in matches for production 'start' (line 10, col 20)
Example (ProductionSetStatementAssignNonPattern)
// Check setting buffer to non-pattern
// https://github.com/asmaloney/gactar/issues/28
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { set goal to 6 }
	}`)
Output:

ERROR: buffer 'goal' must be set to a pattern in production 'start' (line 10, col 19)
Example (ProductionSetStatementAssignNonsense)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { set goal to blat }
	}`)
Output:

ERROR: unexpected token "blat" (expected (SetValue | Pattern)) (line 10, col 19)
Example (ProductionSetStatementAssignPattern)
// Check assignment of pattern to slot
// https://github.com/asmaloney/gactar/issues/17
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { set goal.thing to [foo: ding] }
	}`)
Output:

ERROR: cannot set a slot ('goal.thing') to a pattern in production 'start' (line 10, col 11)
Example (ProductionSetStatementCompoundVar)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: ?ding] }
		do { set goal to [foo: ?ding!5] }
	}`)
Output:

ERROR: cannot set 'goal.thing' to compound var in production 'start' (line 10, col 25)
Example (ProductionSetStatementInvalidSlot)
// Check setting to buffer not used in the match
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { set goal.bar to 'blat' }
	}`)
Output:

ERROR: slot 'bar' does not exist in chunk 'foo' for match buffer 'goal' in production 'start' (line 10, col 16)
Example (ProductionSetStatementNil)
// Check setting to nil
generateToStdout(`
	==model==
	name: Test
	==config==
	modules {
		imaginal { delay: 0.2 }
	}
	chunks {
		[foo: thing]
		[ack: knowledge]
	}
	==init==
	==productions==
	start {
		match {
			goal [foo: blat]
			imaginal [ack: bar]
		}
		do {
			set goal.thing to nil
			set imaginal.knowledge to nil
		}
	}`)
Output:

Example (ProductionSetStatementNonBuffer)
// Check setting to non-existent buffer in set statement
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { set foo.bar to 'blat' }
	}`)
Output:

ERROR: buffer 'foo' not found (line 10, col 11)
ERROR: match buffer 'foo' not found in production 'start' (line 10, col 11)
Example (ProductionSetStatementNonBuffer2)
// Check setting to buffer not used in the match
generateToStdout(`
	==model==
	name: Test
	==config==
	modules { imaginal { delay: 0.2 } }
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { set imaginal.bar to 'blat' }
	}`)
Output:

ERROR: match buffer 'imaginal' not found in production 'start' (line 11, col 11)
Example (ProductionSetStatementNonVar1)
// Check setting to non-existent var
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { set goal.thing to ?ding }
	}`)
Output:

ERROR: set statement variable '?ding' not found in matches for production 'start' (line 10, col 25)
Example (ProductionSetStatementNonVar2)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: blat] }
		do { set goal to [foo: ?ding] }
	}`)
Output:

ERROR: set statement variable '?ding' not found in matches for production 'start' (line 10, col 25)
Example (ProductionSetStatementPattern)
// Check setting to pattern
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		description: "This is a description"
		match { goal [foo: blat] }
		do { set goal to [foo: ding] }
	}`)
Output:

Example (ProductionSetStatementVar)
// Check setting to var
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: ?blat] }
		do { set goal.thing to ?blat }
	}`)
Output:

Example (ProductionUnusedVar1)
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing] }
	==init==
	==productions==
	start {
		match { goal [foo: ?blat] }
		do { set goal to [foo: ding] }
	}`)
Output:

ERROR: variable ?blat is not used - should be simplified to '?' (line 9, col 21)
Example (ProductionUnusedVar2)
// Check that using a var twice in a buffer match does not get
// marked as unused.
generateToStdout(`
	==model==
	name: Test
	==config==
	chunks { [foo: thing1 thing2] }
	==init==
	==productions==
	start {
		match { goal [foo: ?blat ?blat] }
		do { set goal to [foo: ding] }
	}`)
Output:

Index

Examples

Constants

View Source
const (
	LexemeEOF lexemeType
)

Variables

View Source
var LexerDefinition lexer.Definition = lexer_def{}

LexerDefinition provides the interface for the participle parser

Functions

func OutputEBNF

func OutputEBNF()

OutputEBNF outputs the extended Backus–Naur form (EBNF) of the amod grammar to stdout. See: https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form

func ParseChunk

func ParseChunk(model *actr.Model, chunk string) (*actr.Pattern, error)

ParseChunk is used to parse goals when given as input from a user.

func SetDebug

func SetDebug(debug bool)

SetDebug turns debugging on and off. This will output the tokens as they are generated.

Types

type CompileError added in v0.2.0

type CompileError struct{}

func (CompileError) Error added in v0.2.0

func (e CompileError) Error() string

type Log added in v0.5.0

type Log struct {
	issues.Log
}

Log wraps issues.Log so we can provide extra convenience functions.

func GenerateModel

func GenerateModel(buffer string) (model *actr.Model, log *Log, err error)

GenerateModel generates a model from the text in the buffer.

func GenerateModelFromFile

func GenerateModelFromFile(fileName string) (model *actr.Model, log *Log, err error)

GenerateModelFromFile generates a model from the file 'fileName'.

func (*Log) ErrorT added in v0.5.0

func (l *Log) ErrorT(tokens []lexer.Token, s string, a ...interface{})

ErrorT constructs our location information from tokens and uses that to add an error.

func (*Log) ErrorTR added in v0.5.0

func (l *Log) ErrorTR(tokens []lexer.Token, start, end int, s string, a ...interface{})

ErrorT constructs our location information from a range of tokens and uses that to add an error.

type ParseError added in v0.2.0

type ParseError struct{}

func (ParseError) Error added in v0.2.0

func (e ParseError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL