pykiss

Python Kisekae set viewer
git clone https://code.literati.org/pykiss.git
Log | Files | Refs | LICENSE

grammar.py (7297B)


      1 
      2 #........[ TOY PARSER GENERATOR ].........................!
      3 #                                                        ! !
      4 # Warning: This file was automatically generated by TPG ! | !
      5 # Do not edit this file unless you know what you do.   !  |  !
      6 #                                                     !   @   !
      7 #....................................................!!!!!!!!!!!
      8 #
      9 # For further information about TPG you can visit
     10 # http://christophe.delord.free.fr/en/tpg
     11 
     12 import tpg.base
     13 class KiSSParser(tpg.base.ToyParser,):
     14 
     15     def _init_scanner(self):
     16         self._lexer = tpg.base._Scanner(
     17             tpg.base._TokenDef(r"_tok_1", r"\("),
     18             tpg.base._TokenDef(r"_tok_2", r","),
     19             tpg.base._TokenDef(r"_tok_3", r"\)"),
     20             tpg.base._TokenDef(r"_tok_4", r"="),
     21             tpg.base._TokenDef(r"_kw_K", r"K"),
     22             tpg.base._TokenDef(r"_tok_5", r"%"),
     23             tpg.base._TokenDef(r"_tok_6", r"\["),
     24             tpg.base._TokenDef(r"_tok_7", r"#"),
     25             tpg.base._TokenDef(r"_tok_8", r"."),
     26             tpg.base._TokenDef(r"_tok_9", r"\*"),
     27             tpg.base._TokenDef(r"_tok_10", r":"),
     28             tpg.base._TokenDef(r"_tok_11", r"$"),
     29             tpg.base._TokenDef(r"_tok_12", r"*"),
     30             tpg.base._TokenDef(r"_tok_13", r";@EventHandler"),
     31             tpg.base._TokenDef(r"_tok_14", r";@"),
     32             tpg.base._TokenDef(r"spaces", r"\s+", None, 1),
     33             tpg.base._TokenDef(r"num", r"\d", int, 0),
     34             tpg.base._TokenDef(r"obj", r"#\d+", None, 0),
     35             tpg.base._TokenDef(r"filename", r"\S+", None, 0),
     36             tpg.base._TokenDef(r"name", r"\w+", None, 0),
     37             tpg.base._TokenDef(r"var", r"\w+", None, 0),
     38             tpg.base._TokenDef(r"string", r"\"[^\"]*\"", None, 0),
     39             tpg.base._TokenDef(r"int", r"-?\d+", int, 0),
     40         )
     41 
     42     def Field(self,):
     43         """ Field -> '\(' int ',' int '\)' """
     44         self._eat('_tok_1') # \(
     45         self._eat('int')
     46         self._eat('_tok_2') # ,
     47         self._eat('int')
     48         self._eat('_tok_3') # \)
     49 
     50     def Memsize(self,):
     51         """ Memsize -> '=' int 'K' """
     52         self._eat('_tok_4') # =
     53         self._eat('int')
     54         self._eat('_kw_K') # K
     55 
     56     def Palettefile(self,):
     57         """ Palettefile -> '%' filename """
     58         self._eat('_tok_5') # %
     59         self._eat('filename')
     60 
     61     def Bordercol(self,):
     62         """ Bordercol -> '\[' int """
     63         self._eat('_tok_6') # \[
     64         self._eat('int')
     65 
     66     def Cel(self,):
     67         """ Cel -> '#' int ('.' int)? filename ('\*' int)? (':' num?)? """
     68         self._eat('_tok_7') # #
     69         self._eat('int')
     70         __p1 = self._cur_token
     71         try:
     72             self._eat('_tok_8') # .
     73             self._eat('int')
     74         except self.TPGWrongMatch:
     75             self._cur_token = __p1
     76         self._eat('filename')
     77         __p2 = self._cur_token
     78         try:
     79             self._eat('_tok_9') # \*
     80             self._eat('int')
     81         except self.TPGWrongMatch:
     82             self._cur_token = __p2
     83         __p3 = self._cur_token
     84         try:
     85             self._eat('_tok_10') # :
     86             __p4 = self._cur_token
     87             try:
     88                 self._eat('num')
     89             except self.TPGWrongMatch:
     90                 self._cur_token = __p4
     91         except self.TPGWrongMatch:
     92             self._cur_token = __p3
     93 
     94     def Setinfo(self,):
     95         """ Setinfo -> '$' num Pos+ """
     96         self._eat('_tok_11') # $
     97         self._eat('num')
     98         __p1 = self._cur_token
     99         __n1 = 0
    100         while 1:
    101             try:
    102                 self.Pos()
    103                 __n1 += 1
    104                 __p1 = self._cur_token
    105             except self.TPGWrongMatch:
    106                 if __n1 >= 1:
    107                     self._cur_token = __p1
    108                     break
    109                 else:
    110                     self.WrongMatch()
    111 
    112     def Pos(self,):
    113         """ Pos -> int ',' int | '*' """
    114         __p1 = self._cur_token
    115         try:
    116             self._eat('int')
    117             self._eat('_tok_2') # ,
    118             self._eat('int')
    119         except self.TPGWrongMatch:
    120             self._cur_token = __p1
    121             self._eat('_tok_12') # *
    122 
    123     def KissLine(self,):
    124         """ KissLine -> Field | Memsize | Palettefile | Bordercol | Cel | Setinfo """
    125         __p1 = self._cur_token
    126         try:
    127             try:
    128                 self.Field()
    129             except self.TPGWrongMatch:
    130                 self._cur_token = __p1
    131                 try:
    132                     self.Memsize()
    133                 except self.TPGWrongMatch:
    134                     self._cur_token = __p1
    135                     self.Palettefile()
    136         except self.TPGWrongMatch:
    137             self._cur_token = __p1
    138             try:
    139                 self.Bordercol()
    140             except self.TPGWrongMatch:
    141                 self._cur_token = __p1
    142                 try:
    143                     self.Cel()
    144                 except self.TPGWrongMatch:
    145                     self._cur_token = __p1
    146                     self.Setinfo()
    147 
    148     def EventHandler(self,):
    149         """ EventHandler -> ';@EventHandler' """
    150         self._eat('_tok_13') # ;@EventHandler
    151 
    152     def Event(self,):
    153         """ Event -> name '\(' ArgList? '\)' """
    154         self._eat('name')
    155         self._eat('_tok_1') # \(
    156         __p1 = self._cur_token
    157         try:
    158             self.ArgList()
    159         except self.TPGWrongMatch:
    160             self._cur_token = __p1
    161         self._eat('_tok_3') # \)
    162 
    163     def Arg(self,):
    164         """ Arg -> int | obj | var | string """
    165         __p1 = self._cur_token
    166         try:
    167             try:
    168                 self._eat('int')
    169             except self.TPGWrongMatch:
    170                 self._cur_token = __p1
    171                 self._eat('obj')
    172         except self.TPGWrongMatch:
    173             self._cur_token = __p1
    174             try:
    175                 self._eat('var')
    176             except self.TPGWrongMatch:
    177                 self._cur_token = __p1
    178                 self._eat('string')
    179 
    180     def ArgList(self,):
    181         """ ArgList -> Arg (',' Arg)* """
    182         self.Arg()
    183         __p1 = self._cur_token
    184         while 1:
    185             try:
    186                 self._eat('_tok_2') # ,
    187                 self.Arg()
    188                 __p1 = self._cur_token
    189             except self.TPGWrongMatch:
    190                 self._cur_token = __p1
    191                 break
    192 
    193     def FKiss(self,):
    194         """ FKiss -> ';@' Event* """
    195         self._eat('_tok_14') # ;@
    196         __p1 = self._cur_token
    197         while 1:
    198             try:
    199                 self.Event()
    200                 __p1 = self._cur_token
    201             except self.TPGWrongMatch:
    202                 self._cur_token = __p1
    203                 break
    204 
    205     def START(self,):
    206         """ START -> KissLine+ EventHandler FKiss* """
    207         __p1 = self._cur_token
    208         __n1 = 0
    209         while 1:
    210             try:
    211                 self.KissLine()
    212                 __n1 += 1
    213                 __p1 = self._cur_token
    214             except self.TPGWrongMatch:
    215                 if __n1 >= 1:
    216                     self._cur_token = __p1
    217                     break
    218                 else:
    219                     self.WrongMatch()
    220         self.EventHandler()
    221         __p2 = self._cur_token
    222         while 1:
    223             try:
    224                 self.FKiss()
    225                 __p2 = self._cur_token
    226             except self.TPGWrongMatch:
    227                 self._cur_token = __p2
    228                 break
    229 
    230