Add the "verify" script

In addition to the new script, this changes the V2 parser to be able
to continue past the first error found so that as many errors as
possible may be displayed.
This commit is contained in:
Andrew Miner
2015-01-14 15:57:27 -08:00
parent 89a8e2b539
commit 291f94da57
3 changed files with 64 additions and 11 deletions
+5 -3
View File
@@ -15,10 +15,12 @@ module.exports = class ModVersionParser
@CURRENT_VERSION = '2'
constructor: ->
constructor: (options={})->
options.showAllErrors ?= false
@_parsers =
'1': new V1
'2': new V2
'1': new V1 options
'2': new V2 options
parse: (data)->
if not data? then throw new Error 'mod description data is missing'
@@ -15,6 +15,12 @@ StringBuilder = require '../string_builder'
module.exports = class V2
constructor: (options={})->
options.showAllErrors ?= false
@showAllErrors = options.showAllErrors
# Class Methods ################################################################################
@COMMAND = /\ *([^:]*):?(.*)/
@COMMENT = /([^\\]?)#.*/
@@ -25,6 +31,8 @@ module.exports = class V2
@STACK = /^([0-9]+) +(.*)$/
# Public Methods ###############################################################################
parse: (text)->
@_modVersionData = {}
@_lineNumber = 1
@@ -36,7 +44,8 @@ module.exports = class V2
for command in commands
@_execute command
return @_buildModVersion @_modVersionData
modVersion = @_handleErrors @_buildModVersion, @_modVersionData
return modVersion
unparse: (modVersion)->
builder = new StringBuilder context:modVersion
@@ -48,11 +57,8 @@ module.exports = class V2
_execute: (command)->
method = this["_command_#{command.name}"]
if not method? then throw new Error "Unknown command: #{command.name}"
try
method.apply this, command.args
catch e
e.message = "line #{@_lineNumber}: #{e.message}"
throw e
@_handleErrors method, command.args
_parseLine: (line)->
line = line.replace V2.COMMENT, '$1'
@@ -73,6 +79,17 @@ module.exports = class V2
return commands
_handleErrors: (callback, args...)->
if args.length is 1 and _.isArray(args[0]) then args = args[0]
try
callback.apply this, args
catch e
e.message = "line #{@_lineNumber}: #{e.message}"
if not @showAllErrors then throw e
console.error e.message
# Command Methods ##############################################################################
_command_description: (descriptionParts...)->
@@ -178,7 +195,7 @@ module.exports = class V2
modVersion = new ModVersion attributes
for itemData in modVersionData.items
@_buildItem modVersion, itemData
@_handleErrors @_buildItem, modVersion, itemData
return modVersion
@@ -190,7 +207,7 @@ module.exports = class V2
item = new Item modVersion:modVersion, name:itemData.name, isGatherable:itemData.gatherable
for recipeData in itemData.recipes
@_buildRecipe modVersion, item, recipeData
@_handleErrors @_buildRecipe, modVersion, item, recipeData
return item