__copyright__ = """
If not otherwise stated, any source code generated by Coco/R (other than Coco/R itself) does not fall under the GNU General Public License.
"""
import typing
from functools import wraps
from CoCoRuntime.parser import Parser
from CoCoRuntime.scanner import Position
from .Scanner import ScannerEnum


def _generateSet() -> typing.Tuple[typing.Tuple[bool, ...], ...]:
	T = True
	x = False
	return (T, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x, x), (x, x, x, T, x, T, x, x, x, x, x, x, T, T, x, x, x)


class MyParser(Parser):
	__slots__ = ()

	@wraps(Parser.__init__)
	def __init__(self, *args, **kwargs):
		"""This ctor is mandatory, don't delete it: otherwise self.__class__.ENUM will be None"""
		super().__init__(*args, **kwargs)

	ENUM = ScannerEnum
	__main_production_name__ = "scpi"
	__EOF_sym__ = 0

	def pragmas(self) -> None:
		pass

	def identifierFragment(self) -> None:
		if self.la.kind == 13:
			self.Get()
		elif self.la.kind == 12:
			self.Get()
		else:
			self.SynErr(17)

	def identifierOrStringConstant(self) -> None:
		self.identifierFragment()
		while self.la.kind == 12 or self.la.kind == 13:
			self.identifierFragment()

	def scpi(self) -> None:
		self.command()

	def command(self) -> None:
		self.addrR()
		if self.la.kind == 14:
			self.argsSeparatedWithSpace()

	def addrR(self) -> None:
		self.cmdNameR()
		if self.la.kind == 9:
			self.Get()

	def argsSeparatedWithSpace(self) -> None:
		self.Expect(14)
		self.argsR()

	def argsR(self) -> None:
		if self.StartOf(1):
			self.regularArgs()
		elif self.la.kind == 1:
			self.optionalArgs()
		else:
			self.SynErr(18)

	def argument(self) -> None:
		self.Expect(3)
		self.identifierOrStringConstant()
		self.Expect(4)

	def nameArgOrOptionalArg(self) -> None:
		if self.la.kind == 3:
			self.argument()
		elif self.la.kind == 1:
			self.nameOptionalArg()
		else:
			self.SynErr(19)

	def nameOptionalArg(self) -> None:
		self.Expect(1)
		self.argument()
		self.Expect(2)

	def regularArgs(self) -> None:
		self.queryArg()
		if self.la.kind == 7:
			self.restArgs()

	def optionalArgs(self) -> None:
		self.Expect(1)
		self.regularArgs()
		self.Expect(2)

	def queryArg(self) -> None:
		if self.la.kind == 3:
			self.argument()
		elif self.la.kind == 12 or self.la.kind == 13:
			self.alternative()
		elif self.la.kind == 5:
			self.argInCurlyBraces()
		else:
			self.SynErr(20)

	def restArgs(self) -> None:
		self.argPart()
		while self.la.kind == 7:
			self.argPart()

	def argPart(self) -> None:
		self.Expect(7)
		self.Expect(14)
		self.queryArg()
		if self.la.kind == 1:
			self.optionalArgsParts()

	def optionalArgsParts(self) -> None:
		self.Expect(1)
		self.restArgs()
		self.Expect(2)

	def alternative(self) -> None:
		self.identifierOrStringConstant()
		self.Expect(8)
		self.identifierOrStringConstant()

	def argInCurlyBraces(self) -> None:
		self.Expect(5)
		self.queryArg()
		self.Expect(6)

	def cmdNameR(self) -> None:
		if self.la.kind == 11:
			self.special()
		elif self.la.kind == 1 or self.la.kind == 10:
			self.addrPath()
		else:
			self.SynErr(21)

	def addrToken(self) -> None:
		self.Expect(10)
		self.nameR()

	def nameR(self) -> None:
		self.identifierOrStringConstant()
		if self.la.kind == 1 or self.la.kind == 3:
			self.nameArgOrOptionalArg()

	def addrPart(self) -> None:
		if self.la.kind == 10:
			self.addrToken()
		elif self.la.kind == 1:
			self.optionalAddr()
		else:
			self.SynErr(22)

	def optionalAddr(self) -> None:
		self.Expect(1)
		self.addrPath()
		self.Expect(2)

	def addrPath(self) -> None:
		self.addrPart()
		while self.la.kind == 1 or self.la.kind == 10:
			self.addrPart()

	def special(self) -> None:
		self.Expect(11)
		self.nameR()

	set = _generateSet()
	errorMessages = "EOF expected", "OptionalStart expected", "OptionalEnd expected", "ArgumentStart expected", "ArgumentEnd expected", "OpeningBrace expected", "ClosingBrace expected", "Comma expected", "AlternativeDelimiter expected", "QueryMarker expected", "Prefix expected", "SpecialPrefix expected", "integer expected", "identifierFragmentWithoutDigits expected", "WSS expected", "number expected", "??? expected", "invalid identifierFragment", "invalid argsR", "invalid nameArgOrOptionalArg", "invalid queryArg", "invalid cmdNameR", "invalid addrPart"
