Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
🐛 Fixed single character literal bug
Browse files Browse the repository at this point in the history
closes #2

- There should be no restriction on the length of a literal
- This is a horrible bug that has always existed in the language
- Fixed by changing the format of the literal token to expect 1 valid start char followed by 0 or more chars
NOTE:
- This also had an impact on colon processing
- As a result of this fix, it is now invalid to have a colon at the start of a literal
- We can revisit this if it turns out to be a problem
  • Loading branch information
ErisDS committed Jul 17, 2018
1 parent 1b06acb commit a42627b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/nql.l
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

%options case-insensitive

badcharsincnot [^\s'"\+\,\(\)\>\<=\[\]\-]
badcharsincnot [^\s'"\+\,\(\)\>\<=\[\]\-:]
badcharsnonot [^\s'"\+\,\(\)\>\<=\[\]]
escapable ['"\+\,\(\)\>\<=\[\]]

Expand All @@ -19,7 +19,7 @@ escapable ['"\+\,\(\)\>\<=\[\]]
[0-9]+(\.[0-9]+)?\b(?![\-]) return 'NUMBER';
'[' return 'LBRACKET';
']' return 'RBRACKET';
{badcharsincnot}(\\{escapable}|{badcharsnonot})+ return 'LITERAL';
{badcharsincnot}{1}(\\{escapable}|{badcharsnonot})* return 'LITERAL';
['](\\['"]|[^'"])+?['] return 'STRING';
'(' return 'LPAREN';
')' return 'RPAREN';
Expand Down
18 changes: 13 additions & 5 deletions test/lexer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('Lexer', function () {
it('can recognise <=', function () {
lex('<=').should.eql([{token: 'LTE', matched: '<='}]);
});

it('cannot recognise :', function () {
(function () {
lex(':');
Expand Down Expand Up @@ -317,11 +318,8 @@ describe('Lexer', function () {
});

describe('LITERAL vs PROP', function () {
it('should match colon in string as PROP before, literal after', function () {
lex(':test').should.eql([
{token: 'LITERAL', matched: ':test'}
]);

// We currently do not allow colons to exist at the start of a literal
it('should match colon correctly', function () {
lex('te:st').should.eql([
{token: 'PROP', matched: 'te:'},
{token: 'LITERAL', matched: 'st'}
Expand All @@ -330,6 +328,16 @@ describe('Lexer', function () {
lex('test:').should.eql([
{token: 'PROP', matched: 'test:'}
]);

// We can't match 2 colons, as this would put one at the start of the literal
(function () {
lex('te::st');
}).should.throw(lexicalError);

// We can't match a colon at the start of a literal
(function () {
lex(':test');
}).should.throw(lexicalError);
});

it('should only match colon-at-end as PROP if PROP is valPROP', function () {
Expand Down

0 comments on commit a42627b

Please sign in to comment.