コード例 #1
0
 def transit(self) -> State:
     if CONTENT_STACK.content == chr(0):
         # NO_SAVE_REG.set(True)
         CONTENT_STACK.pop_all()
         return StopState()
     # TAG or Mark
     if self.tag:
         res, reason = is_tag_start(CONTENT_STACK.content)
         # match tag start symbol
         if res:
             NO_STEP_REG.set(True)
             return TagStart()
         else:
             # too lang for tag start
             if reason in [OVER_MAX_LENGTH, NOT_MATCH]:
                 self.tag = False
             # not match this time: try mark or eat more rune
             elif reason == POSSIBLE:
                 self.tag = True
             else:
                 return StopState()
     if self.mark:
         res, reason = is_mark(CONTENT_STACK.content)
         if res:
             NO_STEP_REG.set(True)
             # match tag start symbol
             return Mark()
         else:
             # too lang for MARK
             if reason in [OVER_MAX_LENGTH, NOT_MATCH]:
                 self.mark = False
             # not match this time: eat more rune
             elif reason == POSSIBLE:
                 self.mark = True
             else:
                 return StopState()
     if self.block_end:
         res, reason = is_block_end(CONTENT_STACK.content)
         if res:
             NO_STEP_REG.set(True)
             return BlockEnd()
         else:
             if reason in [OVER_MAX_LENGTH, NOT_MATCH]:
                 self.block_end = False
             elif reason == POSSIBLE:
                 self.block_end = True
             else:
                 return StopState()
     if True in [self.tag, self.mark, self.block_end]:
         return self
     # not tag or mark
     # other contents
     self.content += CONTENT_STACK.pop_all()
     self.tag = True
     self.mark = True
     self.block_end = True
     SAVE_REG.set(True)
     return self
コード例 #2
0
 def save(self):
     # TODO BUILD AST
     # if NO_SAVE_REG.get():
     #     NO_SAVE_REG.set(False)
     #     return
     # if FORCE_SAVE_REG.get():
     #     self.transit_list.append(self.last)
     #     FORCE_SAVE_REG.set(False)
     if SAVE_REG.get():
         if self.transit_list[-1].name != self.last.name:
             self.transit_list.append(self.last)
         SAVE_REG.set(False)
コード例 #3
0
 def transit(self) -> State:
     res, reason = is_tag_name(CONTENT_STACK.content)
     if res:
         self.content = CONTENT_STACK.pop_all()
         SAVE_REG.set(True)
         return TagEnd()
     else:
         if reason in [OVER_MAX_LENGTH, NOT_MATCH]:
             return StopState()
         elif reason == POSSIBLE:
             return self
         else:
             return StopState()
コード例 #4
0
 def transit(self) -> State:
     res, reason = is_block_start(CONTENT_STACK.content)
     if res:
         self.content = CONTENT_STACK.pop_all()
         TAG_STACK.append(self.content)
         SAVE_REG.set(True)
         return Content()
     else:
         if reason in [OVER_MAX_LENGTH, NOT_MATCH]:
             NO_STEP_REG.set(True)
             return Content()
         elif reason == POSSIBLE:
             # NO_SAVE_REG.set(True)
             return self
         else:
             return StopState()
コード例 #5
0
 def transit(self) -> State:
     res, reason = is_tag_end(CONTENT_STACK.content)
     if res:
         if TAG_STACK[-1] != CONTENT_STACK.content:
             return StopState()
         else:
             self.content = CONTENT_STACK.pop_all()
             TAG_STACK.pop(-1)
             SPACE_EAT_REG.set(True)
             SAVE_REG.set(True)
             return BlockStart()
     else:
         if reason in [OVER_MAX_LENGTH, NOT_MATCH]:
             return StopState()
         elif reason == POSSIBLE:
             return self
         else:
             return StopState()
コード例 #6
0
 def transit(self) -> State:
     self.content = CONTENT_STACK.pop_all()
     TAG_STACK.pop(-1)
     SAVE_REG.set(True)
     return Content()
コード例 #7
0
 def transit(self) -> State:
     self.content = CONTENT_STACK.pop_all()
     TAG_STACK.append(self.content)
     SAVE_REG.set(True)
     return TagReadName()
コード例 #8
0
 def transit(self) -> State:
     self.content = CONTENT_STACK.pop_all()
     SPACE_EAT_REG.set(True)
     SAVE_REG.set(True)
     return BlockStart()