Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add update and set sql keywords #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions browser/sql-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
};

Lexer.prototype.keywordToken = function() {
return this.tokenizeFromWord('SELECT') || this.tokenizeFromWord('DISTINCT') || this.tokenizeFromWord('FROM') || this.tokenizeFromWord('WHERE') || this.tokenizeFromWord('GROUP') || this.tokenizeFromWord('ORDER') || this.tokenizeFromWord('BY') || this.tokenizeFromWord('HAVING') || this.tokenizeFromWord('LIMIT') || this.tokenizeFromWord('JOIN') || this.tokenizeFromWord('LEFT') || this.tokenizeFromWord('RIGHT') || this.tokenizeFromWord('INNER') || this.tokenizeFromWord('OUTER') || this.tokenizeFromWord('ON') || this.tokenizeFromWord('AS') || this.tokenizeFromWord('UNION') || this.tokenizeFromWord('ALL');
return this.tokenizeFromWord('SELECT') || this.tokenizeFromWord('DISTINCT') || this.tokenizeFromWord('FROM') || this.tokenizeFromWord('WHERE') || this.tokenizeFromWord('GROUP') || this.tokenizeFromWord('ORDER') || this.tokenizeFromWord('BY') || this.tokenizeFromWord('HAVING') || this.tokenizeFromWord('LIMIT') || this.tokenizeFromWord('JOIN') || this.tokenizeFromWord('LEFT') || this.tokenizeFromWord('RIGHT') || this.tokenizeFromWord('INNER') || this.tokenizeFromWord('OUTER') || this.tokenizeFromWord('ON') || this.tokenizeFromWord('AS') || this.tokenizeFromWord('UNION') || this.tokenizeFromWord('ALL') || this.tokenizeFromWord('UPDATE') || this.tokenizeFromWord('SET');
};

Lexer.prototype.dotToken = function() {
Expand Down Expand Up @@ -193,7 +193,7 @@
return str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};

SQL_KEYWORDS = ['SELECT', 'FROM', 'WHERE', 'GROUP BY', 'ORDER BY', 'HAVING', 'AS'];
SQL_KEYWORDS = ['SELECT', 'FROM', 'WHERE', 'GROUP BY', 'ORDER BY', 'HAVING', 'AS', 'UPDATE', 'SET'];

SQL_FUNCTIONS = ['AVG', 'COUNT', 'MIN', 'MAX', 'SUM'];

Expand Down
4 changes: 2 additions & 2 deletions lib/lexer.js

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

6 changes: 4 additions & 2 deletions src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class Lexer
@tokenizeFromWord('ON') or
@tokenizeFromWord('AS') or
@tokenizeFromWord('UNION') or
@tokenizeFromWord('ALL')
@tokenizeFromWord('ALL') or
@tokenizeFromWord('UPDATE') or
@tokenizeFromWord('SET')

dotToken: -> @tokenizeFromWord('DOT', '.')
operatorToken: -> @tokenizeFromList('OPERATOR', SQL_OPERATORS)
Expand Down Expand Up @@ -124,7 +126,7 @@ class Lexer
regexEscape: (str) ->
str.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&")

SQL_KEYWORDS = ['SELECT', 'FROM', 'WHERE', 'GROUP BY', 'ORDER BY', 'HAVING', 'AS']
SQL_KEYWORDS = ['SELECT', 'FROM', 'WHERE', 'GROUP BY', 'ORDER BY', 'HAVING', 'AS', 'UPDATE', 'SET']
SQL_FUNCTIONS = ['AVG', 'COUNT', 'MIN', 'MAX', 'SUM']
SQL_SORT_ORDERS = ['ASC', 'DESC']
SQL_OPERATORS = ['=', '>', '<', 'LIKE', 'IS NOT', 'IS']
Expand Down
12 changes: 12 additions & 0 deletions test/lexer.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ describe "SQL Lexer", ->
[ 'LITERAL', 'id', 1 ]
["EOF", "", 1]
]

it 'eats update', ->
tokens = lexer.tokenize('update a set f1 = f2')
tokens.should.eql [
['UPDATE', 'update', 1]
['LITERAL', 'a', 1]
['SET', 'set', 1]
['LITERAL', 'f1', 1 ]
['OPERATOR', '=', 1 ]
['LITERAL', 'f2', 1 ]
['EOF', '', 1]
]