Skip to content

Commit c61fb5d

Browse files
committed
Replace tabs with spaces
1 parent 3511ef1 commit c61fb5d

File tree

16 files changed

+127
-127
lines changed

16 files changed

+127
-127
lines changed

behavioral-patterns/chain-of-responsibility/main.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ emily.setNext(william).setNext(amelia).setNext(joseph);
2424

2525
// Various troubles occurred.
2626
for (let i = 0; i < 10; i++) {
27-
emily.support(new Trouble(i));
27+
emily.support(new Trouble(i));
2828
}

behavioral-patterns/interpreter/action.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export class Action extends Node {
2121

2222
parse(context) {
2323
// ˅
24-
const currentToken = context.getToken();
25-
if (currentToken !== 'forward' && currentToken !== 'right' && currentToken !== 'left') {
26-
throw new Error(currentToken + ' is unknown');
27-
}
24+
const currentToken = context.getToken();
25+
if (currentToken !== 'forward' && currentToken !== 'right' && currentToken !== 'left') {
26+
throw new Error(currentToken + ' is unknown');
27+
}
2828

2929
this.name = currentToken;
3030

@@ -34,7 +34,7 @@ export class Action extends Node {
3434

3535
toString() {
3636
// ˅
37-
return this.name;
37+
return this.name;
3838
// ˄
3939
}
4040

behavioral-patterns/interpreter/command-list.mjs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@ export class CommandList extends Node {
1616
constructor() {
1717
// ˅
1818
super();
19-
this.nodes = new Array();
19+
this.nodes = new Array();
2020
// ˄
2121
}
2222

2323
parse(context) {
2424
// ˅
25-
while (true) {
26-
if (context.getToken() == null) {
27-
throw new Error('Missing "end"');
28-
}
29-
else if (context.getToken() === 'end') {
30-
context.slideToken('end');
31-
break;
32-
}
33-
else {
34-
const aNode = new Command();
35-
aNode.parse(context);
36-
37-
this.nodes.push(aNode); // Hold the parsed node
38-
}
39-
}
25+
while (true) {
26+
if (context.getToken() == null) {
27+
throw new Error('Missing "end"');
28+
}
29+
else if (context.getToken() === 'end') {
30+
context.slideToken('end');
31+
break;
32+
}
33+
else {
34+
const aNode = new Command();
35+
aNode.parse(context);
36+
37+
this.nodes.push(aNode); // Hold the parsed node
38+
}
39+
}
4040
// ˄
4141
}
4242

4343
toString() {
4444
// ˅
45-
return '[' + this.nodes.join(', ') + ']';
45+
return '[' + this.nodes.join(', ') + ']';
4646
// ˄
4747
}
4848

behavioral-patterns/interpreter/command.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ export class Command extends Node {
2424
parse(context) {
2525
// ˅
2626
let aNode;
27-
if (context.getToken() === 'repeat') {
28-
aNode = new Repeat();
29-
aNode.parse(context);
30-
}
31-
else {
32-
aNode = new Action();
33-
aNode.parse(context);
34-
}
27+
if (context.getToken() === 'repeat') {
28+
aNode = new Repeat();
29+
aNode.parse(context);
30+
}
31+
else {
32+
aNode = new Action();
33+
aNode.parse(context);
34+
}
3535

3636
this.node = aNode; // Hold the parsed node
3737
// ˄
3838
}
3939

4040
toString() {
4141
// ˅
42-
return this.node.toString();
42+
return this.node.toString();
4343
// ˄
4444
}
4545

behavioral-patterns/interpreter/context.mjs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,45 +15,45 @@ export class Context {
1515

1616
constructor(text) {
1717
// ˅
18-
this.tokens = text.split(/\s+/);
19-
this.currentIndex = 0;
18+
this.tokens = text.split(/\s+/);
19+
this.currentIndex = 0;
2020
// ˄
2121
}
2222

2323
nextToken() {
2424
// ˅
25-
if (this.currentIndex < this.tokens.length) {
26-
return this.tokens[this.currentIndex++];
27-
}
28-
else {
29-
return null;
30-
}
25+
if (this.currentIndex < this.tokens.length) {
26+
return this.tokens[this.currentIndex++];
27+
}
28+
else {
29+
return null;
30+
}
3131
// ˄
3232
}
3333

3434
getToken() {
3535
// ˅
36-
return this.tokens[this.currentIndex];
36+
return this.tokens[this.currentIndex];
3737
// ˄
3838
}
3939

4040
slideToken(token) {
4141
// ˅
42-
if (token !== this.getToken()) {
43-
throw new Error('WARNING: ' + token + ' is expected but ' + this.getToken() + ' was found.');
44-
}
45-
this.nextToken();
42+
if (token !== this.getToken()) {
43+
throw new Error('WARNING: ' + token + ' is expected but ' + this.getToken() + ' was found.');
44+
}
45+
this.nextToken();
4646
// ˄
4747
}
4848

4949
getNumber() {
5050
// ˅
51-
try {
52-
return parseInt(this.getToken());
53-
}
54-
catch {
55-
throw new Error('WARNING: ' + this.getToken());
56-
}
51+
try {
52+
return parseInt(this.getToken());
53+
}
54+
catch {
55+
throw new Error('WARNING: ' + this.getToken());
56+
}
5757
// ˄
5858
}
5959

behavioral-patterns/interpreter/main.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ import readline from 'readline';
4141
const stream = fs.createReadStream(process.cwd() + '/program.txt', 'utf8');
4242
const reader = readline.createInterface({ input: stream });
4343
reader.on('line', (line) => {
44-
console.log('Before parsing : ' + line);
45-
const node = new Program();
46-
node.parse(new Context(line));
47-
console.log('After parsing : ' + node);
44+
console.log('Before parsing : ' + line);
45+
const node = new Program();
46+
node.parse(new Context(line));
47+
console.log('After parsing : ' + node);
4848
});

behavioral-patterns/interpreter/program.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ export class Program extends Node {
2323

2424
parse(context) {
2525
// ˅
26-
context.slideToken('program');
26+
context.slideToken('program');
2727

2828
const aCommandList = new CommandList();
29-
aCommandList.parse(context);
29+
aCommandList.parse(context);
3030

31-
this.commandList = aCommandList; // Hold the parsed command list
31+
this.commandList = aCommandList; // Hold the parsed command list
3232
// ˄
3333
}
3434

3535
toString() {
3636
// ˅
37-
return ('[program ' + this.commandList + ']');
37+
return ('[program ' + this.commandList + ']');
3838
// ˄
3939
}
4040

behavioral-patterns/interpreter/repeat.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,28 @@ export class Repeat extends Node {
1919
constructor() {
2020
// ˅
2121
super();
22-
this.number = 0;
23-
this.commandList = null;
22+
this.number = 0;
23+
this.commandList = null;
2424
// ˄
2525
}
2626

2727
parse(context) {
2828
// ˅
29-
context.slideToken('repeat');
29+
context.slideToken('repeat');
3030

31-
this.number = context.getNumber();
32-
context.slideToken(String(this.number));
31+
this.number = context.getNumber();
32+
context.slideToken(String(this.number));
3333

3434
const aCommandList = new CommandList();
35-
aCommandList.parse(context);
35+
aCommandList.parse(context);
3636

3737
this.commandList = aCommandList; // Hold the parsed command list
3838
// ˄
3939
}
4040

4141
toString() {
4242
// ˅
43-
return 'repeat ' + this.number + ' ' + this.commandList;
43+
return 'repeat ' + this.number + ' ' + this.commandList;
4444
// ˄
4545
}
4646

behavioral-patterns/iterator/book-shelf-iterator.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ export class BookShelfIterator extends Iterator {
1717
constructor(bookShelf) {
1818
// ˅
1919
super();
20-
this.index = 0;
21-
this.bookShelf = bookShelf;
20+
this.index = 0;
21+
this.bookShelf = bookShelf;
2222
// ˄
2323
}
2424

2525
hasNext() {
2626
// ˅
27-
return this.index < this.bookShelf.numberOfBooks;
27+
return this.index < this.bookShelf.numberOfBooks;
2828
// ˄
2929
}
3030

3131
next() {
3232
// ˅
33-
const book = this.bookShelf.getAt(this.index);
34-
this.index++;
35-
return book;
33+
const book = this.bookShelf.getAt(this.index);
34+
this.index++;
35+
return book;
3636
// ˄
3737
}
3838

behavioral-patterns/iterator/book-shelf.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ export class BookShelf extends Aggregate {
1818
constructor(maxsize) {
1919
// ˅
2020
super();
21-
this.books = new Array(maxsize);
22-
this._numberOfBooks = 0;
21+
this.books = new Array(maxsize);
22+
this._numberOfBooks = 0;
2323
// ˄
2424
}
2525

2626
iterator() {
2727
// ˅
28-
return new BookShelfIterator(this);
28+
return new BookShelfIterator(this);
2929
// ˄
3030
}
3131

3232
getAt(index) {
3333
// ˅
34-
return this.books[index];
34+
return this.books[index];
3535
// ˄
3636
}
3737

3838
add(book) {
3939
// ˅
40-
this.books[this._numberOfBooks] = book;
41-
this._numberOfBooks++;
40+
this.books[this._numberOfBooks] = book;
41+
this._numberOfBooks++;
4242
// ˄
4343
}
4444

0 commit comments

Comments
 (0)