 {Point, Range} = require 'atom'
 Goal = require './goal'
 
-commentRegex = ///
-  (--[^\r\n]*[\r\n])
-///
-
-goalBracketRegex = ///
-  (\{![^!\}]*!\})
-///
-
-goalQMRegex = ///
-  # single ?
-  ([\s\(\{\_\;\.\"@]
-  \?
-  [\s\)\}\_\;\.\"@])
-  |
-  # consequtive ?
-  (?=\?[\s\)\}\_\;\.\"@])
-  (\?
-  [\s\)\}\_\;\.\"@])
-///
+commentRegex = /(--[^\r\n]*[\r\n])/
+goalBracketRegex = /(\{![^!\}]*!\})/
+goalQuestionMarkGroupRegex =
+    /// (
+        [\s\(\{\_\;\.\"@]\?
+        (?:\s\?)*
+        [\s\)\}\_\;\.\"@]
+    )///
+goalQuestionMarkRegex =
+    /// ([\s\(\{\_\;\.\"@])(?=\?)
+    |   (\?[\s\)\}\_\;\.\"@])
+    ///
 
 # manages all Goals in a editor
 class GoalManager extends EventEmitter

          data = /\{!(.*)!\}/.exec(obj.content)[1].replace(/^\s\s*/, '').replace(/\s\s*$/, '')
          obj.content = "{! #{data + paddingSpaces} !}"
          return obj
        else if obj.type is 'goal QM'
          goalIndex = goalIndices[index]
          index += 1
          paddingSpaces = ' '.repeat(goalIndex.toString().length)
          switch obj.content.length
            when 3 then obj.content = "#{obj.content[0]}{! #{paddingSpaces} !}#{obj.content[2]}"
            when 2 then obj.content = "{! #{paddingSpaces} !}#{obj.content[1]}"
          return obj
        else
          return obj

    text = @agda.editor.getText()

    tokens = new Lexer text
      .lex commentRegex, 'raw', 'comment'
      .lex goalBracketRegex, 'raw', 'goal bracket'
      .lex goalQuestionMarkGroupRegex, 'raw', 'goal ?s'
      .lex goalQuestionMarkRegex, 'goal ?s', 'goal ?'
      .result

    # for counting goals
