     console.log "Result: ", tokens
   catch e
     console.log e
+
+# Test the parser
+inequation = good[1]
+console.log "\nParsing: #{inequation}\n"
+
+tokens = lex inequation
+console.log "Tokens: #{tokens}"
+
+normalised = normalise_minus_coefficients tokens
+console.log "Normalised minus: #{normalised}"
+
+normalised = normalise_coefficients normalised
+console.log "Normalised coefficients: #{normalised}"
+
+parsed = parse normalised
+console.log "Parsed: #{parsed}"
+
+console.log parse normalise_coefficients normalise_minus_coefficients tokens


  throw "Parse error at '#{input}' (tokens: #{tokens}, last token: #{previous})"

# These inputs should all be parseable. Not a maximally reduced set,
# but I think this covers everything
good = ["2x + 0.5y < 350", "-3x+2y-50<0","-x-3y-1>0", "2<x+y", "2x+-5y+5+6>0"]

console.log "Good inputs:\n"
for i in good

lexers = [
  # Operators follow coefficients and variables. This is highest priority
  # so that x-5y is parsed as [x, -, 5, y], not [x, -5, y].
  new Lexer ["COEFFICIENT", "VARIABLE"], /^[+-]/, "OPERATOR"

  # Inequalities also follow coefficients or variables
  new Lexer ["COEFFICIENT", "VARIABLE"], /^[<>]/, "INEQUALITY"

  # Coefficients can only appear at the start of the expression or after an
  # operator or inequality. The value is either a number or "-", which means
  # -1.
  new Lexer [undefined, "INEQUALITY", "OPERATOR"], /^(-?[0-9]+(\.[0-9]+)?)|(-)/, "COEFFICIENT"

  # Variables follow everything except other variables. Only x and y are
  # allowed, since this is a two-variable inequality.
  new Lexer [undefined, "INEQUALITY", "COEFFICIENT", "OPERATOR"], /^[xyXY]/, "VARIABLE"
]

# Given a string and a RegExp.exec result, return the unmatched remainder
