Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
adding variables to the src
  • Loading branch information
jackpilowsky committed Dec 15, 2020
commit bd07ce82250be42e68c1c169340b50f0df87037e
6 changes: 6 additions & 0 deletions src/grammar.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ grammar =
o 'UserFunction'
o 'Boolean'
o 'Parameter'
o 'Variable'
]

List: [
Expand Down Expand Up @@ -197,6 +198,11 @@ grammar =
o 'Literal DOT LITERAL', -> new LiteralValue($1, $3)
]

Variable: [
o 'VARIABLE', -> new VariableValue($1,"{","}")
]


Function: [
o "FUNCTION LEFT_PAREN AggregateArgumentList RIGHT_PAREN", -> new FunctionValue($1, $3)
]
Expand Down
8 changes: 7 additions & 1 deletion src/lexer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Lexer
constructor: (sql, opts={}) ->
@sql = sql
@preserveWhitespace = opts.preserveWhitespace || false
@variableTokens = opts.variableTokens || []
@tokens = []
@currentLine = 1
i = 0
Expand All @@ -25,6 +26,7 @@ class Lexer
@parameterToken() or
@parensToken() or
@whitespaceToken() or
@variableToken() or
@literalToken()
throw new Error("NOTHING CONSUMED: Stopped at - '#{@chunk.slice(0,30)}'") if bytesConsumed < 1
i += bytesConsumed
Expand Down Expand Up @@ -65,6 +67,10 @@ class Lexer
break if ret > 0
ret

variableToken: ->
if @variableTokens.length > 0
@tokenizeFromList('VARIABLE', @variableTokens)

keywordToken: ->
@tokenizeFromWord('SELECT') or
@tokenizeFromWord('DISTINCT') or
Expand Down Expand Up @@ -156,8 +162,8 @@ class Lexer
NUMBER = /^[0-9]+(\.[0-9]+)?/
STRING = /^'([^\\']*(?:\\.[^\\']*)*)'/
DBLSTRING = /^"([^\\"]*(?:\\.[^\\"]*)*)"/
VARIABLE = /^[\{][a-zA-Z0-9]+[\}]/;



exports.tokenize = (sql, opts) -> (new Lexer(sql, opts)).tokens

4 changes: 4 additions & 0 deletions src/nodes.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ exports.Union = class Union
all = if @all then ' ALL' else ''
"UNION#{all}\n#{@query.toString()}"

exports.VariableValue = class VariableValue
constructor: (@value, @openingDelimiter="{", closingDelimiter="}") -> null
toString: -> "#{@openingDelimiter}#{@value}#{@closingDelimiter}"

exports.LiteralValue = class LiteralValue
constructor: (@value, @value2=null) ->
if @value2
Expand Down