diff --git a/src/parser/parser.js b/src/parser/parser.js index 85f9db2..68a63e9 100644 --- a/src/parser/parser.js +++ b/src/parser/parser.js @@ -114,6 +114,8 @@ const grammar = { // Extremely ugly hack because a command with spaces (e.g. <>) // Lexes as BeginCommand Identifier Text EndCommand ['BeginCommand Identifier Text EndCommand', '$$ = new yy.CommandNode($2 + " " + $3);'], + ['BeginCommand Identifier LeftParen RightParen EndCommand', '$$ = new yy.CommandNode($2 + "()");'], /// <> + ['BeginCommand Identifier LeftParen arguments RightParen EndCommand', '$$ = new yy.CommandNode($2 + "()");'], /// <> ], arguments: [ @@ -125,6 +127,8 @@ const grammar = { ['Number', '$$ = new yy.NumericLiteralNode($1);'], ['String', '$$ = new yy.StringLiteralNode($1);'], ['Variable', '$$ = new yy.VariableNode($1.substring(1));'], + ['True', '$$ = new yy.BooleanLiteralNode($1);'], + ['False', '$$ = new yy.BooleanLiteralNode($1);'], ], }, }; diff --git a/tests/test_parser.js b/tests/test_parser.js index a8f9d0b..7526d39 100644 --- a/tests/test_parser.js +++ b/tests/test_parser.js @@ -171,4 +171,92 @@ describe('Parser', () => { expect(results).to.deep.equal(expected); }); + + it('can pass commands with myCommand() formatting - can parse some text followed a command', () => { + const results = parser.parse('some text<>'); + + const expected = [ + new nodes.TextNode('some text'), + new nodes.CommandNode('commandtext()'), + ]; + + expect(results).to.deep.equal(expected); + }); + + it('can pass commands with myCommand() formatting - can parse some text followed by a newline and a command', () => { + const results = parser.parse('some text\n<>'); + + const expected = [ + new nodes.TextNode('some text'), + new nodes.CommandNode('commandtext()'), + ]; + + expect(results).to.deep.equal(expected); + }); + + it('can pass commands with myCommand() formatting - correctly ignores a double newline', () => { + const results = parser.parse('some text\n\n<>'); + + const expected = [ + new nodes.TextNode('some text'), + new nodes.CommandNode('commandtext()'), + ]; + + expect(results).to.deep.equal(expected); + }); + + it('can pass commands with myCommand() formatting - correctly ignores a bunch of newlines', () => { + const results = parser.parse('some text\n\n\n\n\n\n<>\n'); + + const expected = [ + new nodes.TextNode('some text'), + new nodes.CommandNode('commandtext()'), + ]; + + expect(results).to.deep.equal(expected); + }); + + it('can pass commands with myCommand("test",true,22) formatting - can parse some text followed a command', () => { + const results = parser.parse('some text<>'); + + const expected = [ + new nodes.TextNode('some text'), + new nodes.CommandNode('commandtext()'), // will also add parameter parsing when this pull gets approved. Command node needs refactoring to support it + ]; + + expect(results).to.deep.equal(expected); + }); + + it('can pass commands with myCommand("test",true,22) formatting - can parse some text followed by a newline and a command', () => { + const results = parser.parse('some text\n<>'); + + const expected = [ + new nodes.TextNode('some text'), + new nodes.CommandNode('commandtext()'), // will also add parameter parsing when this pull gets approved. Command node needs refactoring to support it + ]; + + expect(results).to.deep.equal(expected); + }); + + it('can pass commands with myCommand("test",true,22) formatting - correctly ignores a double newline', () => { + const results = parser.parse('some text\n\n<>'); + + const expected = [ + new nodes.TextNode('some text'), + new nodes.CommandNode('commandtext()'), // will also add parameter parsing when this pull gets approved. Command node needs refactoring to support it + ]; + + expect(results).to.deep.equal(expected); + }); + + it('can pass commands with myCommand("test",true,22) formatting - correctly ignores a bunch of newlines', () => { + const results = parser.parse('some text\n\n\n\n\n\n<>\n'); + + const expected = [ + new nodes.TextNode('some text'), + new nodes.CommandNode('commandtext()'), // will also add parameter parsing when this pull gets approved. Command node needs refactoring to support it + ]; + + expect(results).to.deep.equal(expected); + }); });