-
Notifications
You must be signed in to change notification settings - Fork 77
/
Types.ts
126 lines (100 loc) · 4.44 KB
/
Types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/********************************************************************************
** Types
This module contains type and class declarations for parse results and interpretations.
You don't have to edit this file (unless you add things to the grammar).
********************************************************************************/
export class ShrdliteResult {
constructor(
public input : string,
public parse : Command,
public interpretation : DNFFormula,
public plan : string[],
) {}
}
//////////////////////////////////////////////////////////////////////
// Parse results
export type Command =
TakeCommand
| DropCommand
| MoveCommand
/*
// Here's an example of a new command
// Don't forget to add a class definition below
// The corresponding grammar rule(s) must also be added to Grammar.ne
| WhereisCommand
*/
;
export class TakeCommand {
constructor(public entity : Entity) {}
toString() : string {return `TakeCommand(${this.entity.toString()})`};
clone() : TakeCommand {return new TakeCommand(this.entity.clone())};
}
export class DropCommand {
constructor(public location : Location) {}
toString() : string {return `DropCommand(${this.location.toString()})`};
clone() : DropCommand {return new DropCommand(this.location.clone())};
}
export class MoveCommand {
constructor(public entity : Entity,
public location : Location) {}
toString() : string {return `MoveCommand(${this.entity.toString()}, ${this.location.toString()})`};
clone() : MoveCommand {return new MoveCommand(this.entity.clone(), this.location.clone())};
}
/*
// Here's an example of a class definition for a new command
// Don't forget to add it to the type definition of 'Command' above
// The corresponding grammar rule(s) must also be added to Grammar.ne
export class WhereisCommand {
constructor(public entity : Entity) {}
toString() : string {return `WhereisCommand(${this.entity.toString()})`};
clone() : WhereisCommand {return new WhereisCommand(this.entity.clone())};
}
*/
export class Location {
constructor(public relation : string,
public entity : Entity) {}
toString() : string {return `Location(${this.relation}, ${this.entity.toString()})`}
clone() : Location {return new Location(this.relation, this.entity.clone())};
}
export class Entity {
constructor(public quantifier : string,
public object : Object) {}
toString() : string {return `Entity(${this.quantifier}, ${this.object.toString()})`};
clone() : Entity {return new Entity(this.quantifier, this.object.clone())};
}
export type Object = RelativeObject | SimpleObject;
export class RelativeObject {
constructor(public object : Object,
public location : Location) {}
toString() : string {return `RelativeObject(${this.object.toString()}, ${this.location.toString()})`};
clone() : RelativeObject {return new RelativeObject(this.object.clone(), this.location.clone())};
}
export class SimpleObject {
constructor(public form : Form,
public size : Size | null,
public color : Color | null) {}
toString() : string {return `SimpleObject(${this.form}, ${this.size}, ${this.color})`};
clone() : SimpleObject {return new SimpleObject(this.form, this.size, this.color)};
}
export type Size = "small" | "large";
export type Color = "red" | "black" | "blue" | "green" | "yellow" | "white";
export type Form = "anyform" | "brick" | "plank" | "ball" | "pyramid" | "box" | "table" | "floor";
//////////////////////////////////////////////////////////////////////
// Interpretations
export class DNFFormula {
constructor(public conjuncts : Conjunction[] = []) {}
toString() : string {return this.conjuncts.map((conj) => conj.toString()).join(" | ")};
}
export class Conjunction {
constructor(public literals : Literal[] = []) {}
toString() : string {return this.literals.map((lit) => lit.toString()).join(" & ")};
}
// A Literal represents a relation that is intended to hold among some objects.
export class Literal {
constructor(
public relation : string, // The name of the relation in question
public args : string[], // The arguments to the relation
public polarity : boolean = true, // Whether the literal is positive (true) or negative (false)
) {}
toString() : string {return (this.polarity ? "" : "-") + this.relation + "(" + this.args.join(",") + ")"};
}