Skip to content

Instantly share code, notes, and snippets.

@hcorion
Last active December 23, 2016 23:37
Show Gist options
  • Save hcorion/104e46ddee6d3137d2f65e74f1690c6d to your computer and use it in GitHub Desktop.
Save hcorion/104e46ddee6d3137d2f65e74f1690c6d to your computer and use it in GitHub Desktop.
import strutils
let vars = ["ACC", "BAK", "NIL"]
proc isNumber*(input: string): bool =
for i in 0..input.len-1:
if not input[i].isDigit:
return false
return true
proc checkVar[T](input: string): T =
if not input.isNumber:
var valid = false
for d in 0..vars.len-1:
if input == vars[d]:
valid = true
if valid:
return input
else:
return ""
else:
return input.parseInt
var newVar = checkVar("TES")
if newVar is string:
if newVar == "":
errors.add ASMError(text: "Instruction " & instruction.label & " was given an unkown variable " & io[0], line: i+1)
break finishedLine
elif newVar is int:
echo "The instruction, " & instruction.label & " has a correct numeric input: ", newVar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment