 #
 # This module is separated for isolation during testing. It is not meant to be
 # exposed as part of the public API.
+
+# We don't count an initial newline as a line.
+error = (message, pattern, index) ->
+  if pattern.indexOf("\n") != -1
+    lines = pattern.substring(0, index).split /\n/
+    lines.shift() if lines[0] is ""
+    "#{message} at line #{lines.length} character #{lines.pop().length + 1}"
+  else
+    "#{message} at character #{index + 1}"
 
 BASE = { "0x": 16, "0": 8, "X": 10 }
 

    throw  new Error error "invalid pattern", pattern, index

  fields

    index += part.length + delimiter.length

    array.push alternate

# Parse a part of a pattern. The `next` regular expression is replaced when we
# match bit packing patterns, with a regular expression that excludes modifiers
