/* sbt -- Simple Build Tool
 * Copyright 2009  Mark Harrah
 */
package sbt.impl

import scala.util.parsing.combinator.Parsers
import scala.util.parsing.input.CharSequenceReader
import scala.util.parsing.input.CharArrayReader.EofCh

/** Parses a command of the form:
* identifier argument*
* where argument may be quoted to include spaces and
* quotes and backslashes should be escaped.
* (Most of the complexity is for decent error handling.)*/
private[sbt] object object sbt.impl.CommandParserCommandParser extends scala.util.parsing.combinator.ParsersParsers
{
	type CharElem = CharChar
	def (String)Either[String,(String, List[String])]parse(StringcommandString: StringString): Either[String,(String, List[String])]Either[String, (String, List[String])] =
	{
		(sbt.impl.CommandParser.Input)sbt.impl.CommandParser.ParseResult[sbt.impl.CommandParser.~[String,List[String]]]command(scala.util.parsing.input.CharSequenceReadernew scala.util.parsing.input.CharSequenceReaderCharSequenceReader(StringcommandString.()java.lang.Stringtrim, Int(0)0)) Either[String,(String, List[String])]match
		{
			Right[Nothing,(String, List[String])]case Success(Stringid ~ List[String]args, sbt.impl.CommandParser.Inputnext) => ((String, List[String]))Right[Nothing,(String, List[String])]Right((String,List[String])(String, List[String])(Stringid, List[String]args))
			Left[java.lang.String,Nothing]case sbt.impl.CommandParser.NoSuccesserr: sbt.impl.CommandParser.NoSuccessNoSuccess =>
			{
				val scala.util.parsing.input.Positionpos = sbt.impl.CommandParser.NoSuccesserr.=> sbt.impl.CommandParser.Inputnext.=> scala.util.parsing.input.Positionpos
				(java.lang.String)Left[java.lang.String,Nothing]Left(java.lang.String("Could not parse command: (")"Could not parse command: (" (Any)java.lang.String+ scala.util.parsing.input.Positionpos.=> Intline (Any)java.lang.String+ java.lang.String(",")"," (Any)java.lang.String+ scala.util.parsing.input.Positionpos.=> Intcolumn (Any)java.lang.String+ java.lang.String("): ")"): " (Any)java.lang.String+ sbt.impl.CommandParser.NoSuccesserr.=> Stringmsg)
			}
		}
	}
	def => sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.~[String,List[String]]]command = (sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.~[String,List[String]]])sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.~[String,List[String]]]phrase(=> sbt.impl.CommandParser.Parser[String]identifier (=> sbt.impl.CommandParser.Parser[List[String]])sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.~[String,List[String]]]~! (=> sbt.impl.CommandParser.Parser[String]argument=> sbt.impl.CommandParser.Parser[List[String]]*))
	def => sbt.impl.CommandParser.Parser[String]identifier = => sbt.impl.CommandParser.Parser[String]unquoted (=> sbt.impl.CommandParser.Parser[String])sbt.impl.CommandParser.Parser[String]| (String)sbt.impl.CommandParser.Parser[Nothing]err(java.lang.String("Expected identifier")"Expected identifier")
	def => sbt.impl.CommandParser.Parser[String]argument = ( (=> sbt.impl.CommandParser.Parser[Char]whitespaceChar=> sbt.impl.CommandParser.Parser[List[Char]]+) (=> sbt.impl.CommandParser.Parser[String])sbt.impl.CommandParser.Parser[String]~> (=> sbt.impl.CommandParser.Parser[String]unquoted (=> sbt.impl.CommandParser.Parser[String])sbt.impl.CommandParser.Parser[String]| => sbt.impl.CommandParser.Parser[String]quoted) )
	
	def => sbt.impl.CommandParser.Parser[String]unquoted: sbt.impl.CommandParser.Parser[String]Parser[String] = ((=> sbt.impl.CommandParser.Parser[Char]unquotedChar (=> sbt.impl.CommandParser.Parser[List[Char]])sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.~[Char,List[Char]]]~! (=> sbt.impl.CommandParser.Parser[Char]unquotedMainChar=> sbt.impl.CommandParser.Parser[List[Char]]*)) ((sbt.impl.CommandParser.~[Char,List[Char]]) => String)sbt.impl.CommandParser.Parser[String]^^ String{ Stringcase Chara ~ List[Char]tail => (Chara (Char)List[Char]:: List[Char]tail).(String)StringmkString(java.lang.String("")"") })
	def => sbt.impl.CommandParser.Parser[String]quoted: sbt.impl.CommandParser.Parser[String]Parser[String] = => sbt.impl.CommandParser.Parser[Char]quote (=> sbt.impl.CommandParser.Parser[String])sbt.impl.CommandParser.Parser[String]~> => sbt.impl.CommandParser.Parser[String]quotedChars (=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[String]<~ (=> sbt.impl.CommandParser.Parser[Char]quote (=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[Char]| (String)sbt.impl.CommandParser.Parser[Nothing]err(java.lang.String("Missing closing quote character")"Missing closing quote character"))

	def => sbt.impl.CommandParser.Parser[String]quotedChars: sbt.impl.CommandParser.Parser[String]Parser[String] = (=> sbt.impl.CommandParser.Parser[Char]escape (=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[Char]| => sbt.impl.CommandParser.Parser[Char]nonescapeChar)implicit sbt.impl.CommandParser.toString : (sbt.impl.CommandParser.Parser[List[Char]])sbt.impl.CommandParser.Parser[String]*
	def => sbt.impl.CommandParser.Parser[Char]escape: sbt.impl.CommandParser.Parser[Char]Parser[Char] = => sbt.impl.CommandParser.Parser[Char]backslash (=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[Char]~> (=> sbt.impl.CommandParser.Parser[Char]escapeChar (=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[Char]| (String)sbt.impl.CommandParser.Parser[Nothing]err(java.lang.String("Illegal escape")"Illegal escape"))
	def => sbt.impl.CommandParser.Parser[Char]escapeChar: sbt.impl.CommandParser.Parser[Char]Parser[Char] = => sbt.impl.CommandParser.Parser[Char]quote (=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[Char]| => sbt.impl.CommandParser.Parser[Char]backslash
	def => sbt.impl.CommandParser.Parser[Char]nonescapeChar: sbt.impl.CommandParser.Parser[Char]Parser[Char] = (String,(sbt.impl.CommandParser.Elem) => Boolean)sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.Elem]elem(java.lang.String("")"", sbt.impl.CommandParser.Elemch => => Boolean!(Char)BooleanisEscapeChar(sbt.impl.CommandParser.Elemch) (Boolean)Boolean&& sbt.impl.CommandParser.Elemch (Char)Boolean!= Char('\032')EofCh)
	def => sbt.impl.CommandParser.Parser[Char]unquotedChar: sbt.impl.CommandParser.Parser[Char]Parser[Char] = (String,(sbt.impl.CommandParser.Elem) => Boolean)sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.Elem]elem(java.lang.String("")"", sbt.impl.CommandParser.Elemch => => Boolean!(Char)BooleanisEscapeChar(sbt.impl.CommandParser.Elemch) (Boolean)Boolean&& => Boolean!object java.lang.CharacterCharacter.(Char)BooleanisWhitespace(sbt.impl.CommandParser.Elemch) (Boolean)Boolean&& sbt.impl.CommandParser.Elemch (Char)Boolean!= Char('\032')EofCh)
	def => sbt.impl.CommandParser.Parser[Char]unquotedMainChar: sbt.impl.CommandParser.Parser[Char]Parser[Char] = => sbt.impl.CommandParser.Parser[Char]unquotedChar (=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[Char]| (=> sbt.impl.CommandParser.Parser[Unit]errorIfEscape (=> sbt.impl.CommandParser.Parser[Nothing])sbt.impl.CommandParser.Parser[Nothing]~> (String)sbt.impl.CommandParser.Parser[Nothing]failure(java.lang.String("")""))

	private def => sbt.impl.CommandParser.Parser[Unit]errorIfEscape = ((=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[Unit]not(=> sbt.impl.CommandParser.Parser[Char]quote) (=> sbt.impl.CommandParser.Parser[Unit])sbt.impl.CommandParser.Parser[Unit]| (String)sbt.impl.CommandParser.Parser[Nothing]err(java.lang.String("Unexpected quote character")"Unexpected quote character")) (=> sbt.impl.CommandParser.Parser[Unit])sbt.impl.CommandParser.Parser[Unit]~>
		((=> sbt.impl.CommandParser.Parser[Char])sbt.impl.CommandParser.Parser[Unit]not(=> sbt.impl.CommandParser.Parser[Char]backslash) (=> sbt.impl.CommandParser.Parser[Unit])sbt.impl.CommandParser.Parser[Unit]| (String)sbt.impl.CommandParser.Parser[Nothing]err(java.lang.String("Escape sequences can only occur in a quoted argument")"Escape sequences can only occur in a quoted argument"))

	private def (Char)BooleanisEscapeChar(Charch: CharChar) = Charch (Char)Boolean== Char('\')'\\' (Boolean)Boolean|| Charch (Char)Boolean== Char('"')'"'
	
	def => sbt.impl.CommandParser.Parser[Char]quote: sbt.impl.CommandParser.Parser[Char]Parser[Char] = implicit scala.util.parsing.combinator.Parsers.accept : (sbt.impl.CommandParser.Elem)sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.Elem]'"'
	def => sbt.impl.CommandParser.Parser[Char]backslash: sbt.impl.CommandParser.Parser[Char]Parser[Char] = implicit scala.util.parsing.combinator.Parsers.accept : (sbt.impl.CommandParser.Elem)sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.Elem]'\\'
	def => sbt.impl.CommandParser.Parser[Char]whitespaceChar: sbt.impl.CommandParser.Parser[Char]Parser[Char] = (String,(sbt.impl.CommandParser.Elem) => Boolean)sbt.impl.CommandParser.Parser[sbt.impl.CommandParser.Elem]elem(java.lang.String("whitespace")"whitespace", sbt.impl.CommandParser.Elemch => object java.lang.CharacterCharacter.(Char)BooleanisWhitespace(sbt.impl.CommandParser.Elemch))

	private implicit def implicit sbt.impl.CommandParser.toString : (sbt.impl.CommandParser.Parser[List[Char]])sbt.impl.CommandParser.Parser[String]toString(sbt.impl.CommandParser.Parser[List[Char]]p: sbt.impl.CommandParser.Parser[List[Char]]Parser[List[Char]]): sbt.impl.CommandParser.Parser[String]Parser[String] = sbt.impl.CommandParser.Parser[List[Char]]p ((List[Char]) => String)sbt.impl.CommandParser.Parser[String]^^ {List[Char]_ (String)StringmkString java.lang.String("")"" }
}