コード例 #1
0
 def table_row(self):
     res = ParseResult()
     start_pos = self.current_tok.pos_start
     error = False
     text = []
     while error == False:
         error = True
         if self.current_tok.type is tokenclass.TT_BAR:
             self.advance()
             node = self.alphanum()
             if not node is None:
                 text.append(node.text)
                 error = False
             else:
                 self.devance(1)
     if text == []:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "table sucks"))
     if not self.current_tok.type is tokenclass.TT_BAR:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "table row has no end"))
     self.advance()
     tok = self.current_tok
     if not tok.type == tokenclass.TT_NEWLINE:
             return res.failure(output.InvalidSyntaxError(
                     self.current_tok.pos_start, self.current_tok.pos_end,
                     "no newline after heading"))
     end_pos = self.current_tok.pos_start
     self.advance()
     return res.success(nodes.TableRowNode(text, start_pos, end_pos))
コード例 #2
0
 def list_level_3(self):
     res = ParseResult()
     for _ in range(2):
         if not self.current_tok.type == tokenclass.TT_IDENT:
             return res.failure(output.InvalidSyntaxError(
                     self.current_tok.pos_start, self.current_tok.pos_end,
                     "no starting ident"))
         self.advance()
     res = ParseResult()
     if not self.current_tok.type == tokenclass.TT_MINUS:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no starting dash"))
     self.advance()
     node = self.alphanummore()
     if node is None:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no text in heading"))
     text = node.text
     tok = self.current_tok
     if not tok.type == tokenclass.TT_NEWLINE:
             return res.failure(output.InvalidSyntaxError(
                     self.current_tok.pos_start, self.current_tok.pos_end,
                     "no newline after heading"))
     self.advance()
     return res.success(nodes.ListLevel3Node(text))
コード例 #3
0
 def tag(self):
     res = ParseResult()
     if not self.current_tok.type is (tokenclass.TT_LTAG):
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no tag start"))
     self.advance()
     if not self.current_tok.type in (tokenclass.TT_TEXT, tokenclass.TT_NUM):
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no tag text"))
     tag_name = self.current_tok.value
     self.advance()
     tag_value = ""
     if self.current_tok.type is (tokenclass.TT_COLON):
         self.advance()
         node = self.alphanum()
         if node is None:
             return res.failure(output.InvalidSyntaxError(
                     self.current_tok.pos_start, self.current_tok.pos_end,
                     "no tag text"))
         tag_value = node.text
     if not self.current_tok.type is (tokenclass.TT_RTAG):
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no tag end"))
     self.advance()
     if not self.current_tok.type is (tokenclass.TT_NEWLINE):
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no new line after tag"))
     self.advance()
     return res.success(nodes.TagNode(tag_name, tag_value))
コード例 #4
0
    def table_split(self):
        res = ParseResult()
        error = False
        text = []
        ratio = []
        col = 0
        while not error:
            error = True
            if self.current_tok.type is tokenclass.TT_BAR:
                self.advance()
                col += 1
                ratio.append(0)
                while self.current_tok.type is tokenclass.TT_MINUS:
                    self.advance()
                    error = False
                    ratio[col-1] += 1
                if error is True:
                    self.devance(1)
        if not self.current_tok.type is tokenclass.TT_BAR:
            return res.failure(output.InvalidSyntaxError(
                    self.current_tok.pos_start, self.current_tok.pos_end,
                    "table row has no end"))

        self.advance()
        tok = self.current_tok
        if not tok.type == tokenclass.TT_NEWLINE:
                return res.failure(output.InvalidSyntaxError(
                        self.current_tok.pos_start, self.current_tok.pos_end,
                        "no newline after heading"))
        self.advance()
        return res.success(nodes.TableSplitNode(ratio))
コード例 #5
0
 def table_top(self):
     res = ParseResult()
     heading = res.register(self.table_row())
     if res.error:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "table has no heading"))
     split = res.register(self.table_split())
     if res.error:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "table row has no split"))
     return res.success(nodes.TableHeadingNode(heading.columns, split.ratio))
コード例 #6
0
 def parse(self):
     res = self.body()
     if not res.error and self.current_tok.type != tokenclass.TT_EOF:
         res.failure(output.InvalidSyntaxError(
             self.current_tok.pos_start, self.current_tok.pos_end,
             "Expected prop or text secction"))
     return res
コード例 #7
0
 def text_list(self):
     res = ParseResult()
     node_list = []
     start = self.tok_idx
     node = None
     error = False
     while error == False:
         start = self.tok_idx
         node_list.append(node)
         node = res.register(self.list_level_3())
         if node == None:
             res.failure(None)
             self.goto(start)
             node = res.register(self.list_level_2())
         if node is None:
             res.failure(None)
             self.goto(start)
             node = res.register(self.list_level_1())
         if node == None:
             error = True
             self.goto(start)
     res.failure(None)
     if node_list == [None]:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no list elements"))
     return res.success(nodes.ListNode(node_list[1:]))
コード例 #8
0
 def text_comment(self):
     start = self.current_tok.pos_start
     res = ParseResult()
     if not self.current_tok.type is (tokenclass.TT_EXCLAIM):
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no exclaim starting comment"))
     text = ""
     self.advance()
     while not self.current_tok.type in (tokenclass.TT_NEWLINE, tokenclass.TT_EOF):
         if self.current_tok.value != None:
             text += self.current_tok.value
         elif self.current_tok.type == tokenclass.TT_MINUS:
             text += "-"
         elif self.current_tok.type == tokenclass.TT_COLON:
             text += ":"
         elif self.current_tok.type == tokenclass.TT_DOLLAR:
             text += "$"
         elif self.current_tok.type == tokenclass.TT_STAR:
             text += "*"
         elif self.current_tok.type == tokenclass.TT_EXCLAIM:
             text += "!"
         elif self.current_tok.type == tokenclass.TT_UNDERSCORE:
             text += "_"
         elif self.current_tok.type == tokenclass.TT_LPAREN:
             text += "("
         elif self.current_tok.type == tokenclass.TT_RPAREN:
             text += ")"
         self.advance()
     end = self.current_tok.pos_start
     self.advance()
     return res.success(nodes.TextCommentNode(text, start, end))
コード例 #9
0
 def prop_sec(self):
     res = ParseResult()
     node = self.prop_div()
     if node == None:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                "Start of Prop Section Expected"))
     node_list = []
     while node != None:
         node_list.append(node)
         node = self.prop_line()
     node = res.register(self.prop_div())
     if res.error:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "End of Prop Section Expected"))
     node_list.append(node)
     return res.success(nodes.PropSectionNode(node_list))
コード例 #10
0
 def text_par_end(self):
     res = ParseResult()
     if self.current_tok.type in (tokenclass.TT_NEWLINE, tokenclass.TT_EOF):
         self.advance()
         while self.current_tok.type is (tokenclass.TT_NEWLINE):
             self.advance()
         return res.success(nodes.TextParEndNode())
     return res.failure(output.InvalidSyntaxError(
             self.current_tok.pos_start, self.current_tok.pos_end,
             "End Paragraph Expected"))
コード例 #11
0
 def heading_3(self):
     res = ParseResult()
     for i in range(3):
         tok = self.current_tok
         if not tok.type == tokenclass.TT_HASH:
             return res.failure(output.InvalidSyntaxError(
                     self.current_tok.pos_start, self.current_tok.pos_end,
                     "not enough hashes"))
         self.advance()
     node = self.alphanummore()
     if node is None:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no text in heading"))
     text = node.text
     tok = self.current_tok
     if not tok.type == tokenclass.TT_NEWLINE:
             return res.failure(output.InvalidSyntaxError(
                     self.current_tok.pos_start, self.current_tok.pos_end,
                     "no newline after heading"))
     self.advance()
     return nodes.Heading3Node(text)
コード例 #12
0
 def text_sec(self):
     res = ParseResult()
     node = res.register(self.text_comment())
     if res.error:
         res.failure(None)
         node = res.register(self.text_list())
     if res.error:
         res.failure(None)
         node = res.register(self.text_line())
     if res.error:
         res.failure(None)
         node = res.register(self.tag())
     if res.error:
         res.failure(None)
         node = res.register(self.text_heading())
     if res.error:
         res.failure(None)
         node = res.register(self.text_table())
     if res.error:
         return res.failure(res.error)
     node_list = []
     while not res.error:
         res.failure(None)
         node_list.append(node)
         node = res.register(self.text_comment())
         if res.error:
             res.failure(None)
             node = res.register(self.text_list())
         if res.error:
             res.failure(None)
             node = res.register(self.text_line())
         if res.error:
             res.failure(None)
             node = res.register(self.tag())
         if res.error:
             res.failure(None)
             node = res.register(self.text_heading())
         if res.error:
             res.failure(None)
             node = res.register(self.text_table())
     res.failure(None)
     node = res.register(self.text_par_end())
     if res.error:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "End of text Section Expected"))
     node_list.append(node)
     return res.success(nodes.TextSectionNode(node_list))
コード例 #13
0
 def text_table(self):
     res = ParseResult()
     rows = []
     node = res.register(self.table_top())
     if res.error:
         return res.failure(res.error)
     top = node
     while node is not None:
         rows.append(node)
         node = res.register(self.table_row())
     res.failure(None)
     if len(rows) < 2:
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "not enough rows in table"))
     return res.success(nodes.TableNode(top, rows))
コード例 #14
0
 def text_line(self):
     res = ParseResult()
     text = ""
     node = self.alphanummore()
     while node is not None:
         text += node.text
         self.advance()
         node = res.register(self.alphanummore())
     res.failure(None)
     if text == "":
         return res.failure(output.InvalidSyntaxError(
                 self.current_tok.pos_start, self.current_tok.pos_end,
                 "no Text in line"))
     # if not self.current_tok.type in (tokenclass.TT_NEWLINE, tokenclass.TT_EOF):
     #     return res.failure(output.InvalidSyntaxError(
     #             self.current_tok.pos_start, self.current_tok.pos_end,
     #             "no end of line after text"))
     # self.advance()
     return res.success(nodes.TextLineNode(text))