@litexa/core
Version:
Litexa, a programming language for writing Alexa skills
86 lines (77 loc) • 2.67 kB
text/coffeescript
{ ParserError } = require('./errors.coffee').lib
lib = {}
module.exports = lib
class lib.DatabaseReferencePart
constructor: () ->
isDB: true
needsEscaping: true
toString: -> return "@#{@ref.toString()}"
toUtterance: ->
throw new ParserError null, "you cannot use a database reference in an utterance"
toLambda: (options) ->
return "context.db.read('#{@ref.base}')#{@ref.toLambdaTail()}"
express: (context) ->
return "STUB" if context.noDatabase
return "" + .readFrom(context.db)
toRegex: ->
return "([\\S\u00A0]+)"
toTestRegex: ->
toLocalization: (localization) ->
return
class lib.StaticVariableReferencePart
constructor: () ->
needsEscaping: true
isStatic: -> true
toString: -> return "DEPLOY.#{@ref.toString()}"
toUtterance: ->
throw new ParserError null, "you cannot use a static reference in an utterance"
toLambda: (options) ->
return "litexa.DEPLOY.#{@ref.toLambda()}"
express: (context) ->
return eval "context.lambda.litexa.DEPLOY.#{@ref.toLambda()}"
evaluateStatic: (context) ->
return eval "context.skill.projectInfo.DEPLOY.#{@ref.toLambda()}"
toRegex: ->
throw "missing toRegex function for StaticVariableReferencePart"
toTestRegex: ->
toLocalization: (localization) ->
return
class lib.DatabaseReferenceCallPart
constructor: (, ) ->
isDB: true
needsEscaping: true
toString: ->
args = (a.toString() for a in ).join ', '
return "@#{@ref.toString()}(#{args})"
toUtterance: ->
throw new ParserError null, "you cannot use a database reference in an utterance"
toLambda: (options) ->
args = (a.toLambda(options) for a in ).join ', '
return "(await context.db.read('#{@ref.base}')#{@ref.toLambdaTail()}(#{args}))"
express: (context) ->
return "STUB" if context.noDatabase
return "" + .readFrom(context.db)
toRegex: ->
return "([\\S\u00A0]+)"
toTestRegex: ->
toLocalization: (localization) ->
return
class lib.SlotReferencePart
constructor: () ->
isSlot: true
needsEscaping: true
visit: (depth, fn) -> fn(depth, @)
toString: -> return "$#{@name}"
toUtterance: -> [ "{#{@name}}" ]
toLambda: (options) -> return "context.slots.#{@name.toLambda(options)}"
express: (context) ->
if
return "$#{@name}"
return "" + context.slots[]
toRegex: ->
cleanName = .toString().replace(/\./g, '_')
return "(?<#{cleanName}>[\\$\\S\u00A0]+)"
toTestRegex: ->
toTestScore: -> return 1
toLocalization: (localization) ->
return