Revision: 3923 Author: valhallasw Date: 2007-07-29 21:09:30 +0000 (Sun, 29 Jul 2007)
Log Message: ----------- Added lexer symbold STAR COLON SEMICOLON HASH Parser now accepts all input (but does not parse everything)
Modified Paths: -------------- trunk/pywikiparser/Lexer.py trunk/pywikiparser/Parser.py
Modified: trunk/pywikiparser/Lexer.py =================================================================== --- trunk/pywikiparser/Lexer.py 2007-07-29 20:29:29 UTC (rev 3922) +++ trunk/pywikiparser/Lexer.py 2007-07-29 21:09:30 UTC (rev 3923) @@ -25,6 +25,10 @@ ('PIPE', '| Pipe symbol'), ('EQUAL_SIGN', '= Equal sign'), ('APOSTROPHE', '' Apostrophe'), + ('STAR', '* Star sign'), + ('COLON', ': Colon'), + ('SEMICOLON', '; Semicolon'), + ('HASH', '# Hash symbol'), ('CURL_OPEN', '{ Curly bracket open'), ('CURL_CLOSE', '} Curly bracket close'), ('ANGL_OPEN', '< Angular bracket open'), @@ -56,7 +60,7 @@ try: c = self.getchar() while True: - if (c in ('[', ']', '{', '}', '<', '>', '=', ''')): + if (c in ('[', ']', '{', '}', '<', '>', '=', ''', '*', ':', ';', '#')): if text: yield (Tokens.TEXT, text) text = '' @@ -76,6 +80,10 @@ elif (c == '>'): yield (Tokens.ANGL_CLOSE, num) elif (c == '='): yield (Tokens.EQUAL_SIGN, num) elif (c == '''): yield(Tokens.APOSTROPHE, num) + elif (c == '*'): yield (Tokens.STAR, num) + elif (c == ':'): yield (Tokens.COLON, num) + elif (c == ';'): yield (Tokens.SEMICOLON, num) + elif (c == '#'): yield (Tokens.HASH, num) c = t elif (c == '|'): if text:
Modified: trunk/pywikiparser/Parser.py =================================================================== --- trunk/pywikiparser/Parser.py 2007-07-29 20:29:29 UTC (rev 3922) +++ trunk/pywikiparser/Parser.py 2007-07-29 21:09:30 UTC (rev 3923) @@ -58,6 +58,8 @@ def parseEOF(self): token = self.expect(Tokens.EOF) raise StopIteration + + # Special functions that directly access the storage tree
def parseNEWPAR(self): token = self.expect(Tokens.NEWPAR) @@ -113,6 +115,8 @@ self.bold = True return []
+ # Functions that return the input directly + def parseSQRE_CLOSE(self): token = self.expect(Tokens.SQRE_CLOSE) return [']'*token[1]] @@ -133,6 +137,22 @@ token = self.expect(Tokens.ANGL_CLOSE) return ['>'*token[1]]
+ def parseSTAR(self): + token = self.expect(Tokens.STAR) + return ['*'*token[1]] + + def parseCOLON(self): + token = self.expect(Tokens.COLON) + return [':'*token[1]] + + def parseSEMICOLON(self): + token = self.expect(Tokens.SEMICOLON) + return [';'*token[1]] + + def parseHASH(self): + token = self.expect(Tokens.HASH) + return ['#'*token[1]] + def parseTAB_NEWLINE(self): token = self.expect(Tokens.TAB_NEWLINE) return ['|-'] @@ -140,7 +160,11 @@ def parseTAB_CLOSE(self): token = self.expect(Tokens.TAB_CLOSE) return ['|}'] +
+ + # True parser callers + def parseWHITESPACE(self): return self.parseTEXT()
@@ -156,15 +180,66 @@ return []
def parseSQRE_OPEN(self): + try: + return self.parseWikilink() + except ParseError: pass + + self.lex.undo() + try: + return self.parseExternallink() + except ParseError: pass + + self.lex.undo() token = self.expect(Tokens.SQRE_OPEN) + return ['['*token[1]] + def parseCURL_OPEN(self): + try: + return self.parseTemplateparam() + except ParseError: pass + + self.lex.undo() + try: + return self.parseTemplate() + except ParseError: pass + + self.lex.undo() token = self.expect(Tokens.CURL_OPEN) + return ['{'*token[1]] + def parseANGL_OPEN(self): + try: + return self.parseHTML() + except ParseError: pass + + self.lex.undo() token = self.expect(Tokens.ANGL_OPEN) + return ['<'*token[1]] + def parseTAB_OPEN(self): + try: + return self.parseWikitable() + except ParseError: pass + + self.lex.undo() token = self.expect(Tokens.TAB_OPEN) - - - + return ['{|']
- \ No newline at end of file + def parseWikilink(self): + raise ParseError("Needs implementation") + + def parseExternallink(self): + raise ParseError("Needs implementation") + + def parseTemplateparam(self): + raise ParseError("Needs implementation") + + def parseTemplate(self): + raise ParseError("Needs implementation") + + def parseHTML(self): + raise ParseError("Needs implementation") + + def parseWikitable(self): + raise ParseError("Needs implementation") + \ No newline at end of file