add pyparsing, lark not adapted to complex languages like SPIP or Markdown

This commit is contained in:
Guilhem Fauré 2023-05-09 16:34:02 +02:00
parent 8eec4033f8
commit a455c8e4a2
2 changed files with 13 additions and 10 deletions

View File

@ -1,4 +1,5 @@
peewee
lark
python-slugify[unidecode]
pyyaml
python-slugify[unidecode]
peewee
pyparsing
lark

View File

@ -1,8 +1,9 @@
from os import path
from lark import Lark
from pyparsing import Word, alphas
spipParser = Lark(open(path.dirname(__file__) + "/spip.lark"))
larkParser = Lark(open(path.dirname(__file__) + "/spip.lark"))
class content:
@ -13,18 +14,19 @@ class content:
markdown = self.spip
# Parses the body & display parse tree
try:
parsed = spipParser.parse(self.spip)
print(f" parse tree :\n", parsed.pretty(), "\n")
print(f" parse tree :\n")
print(larkParser.parse(self.spip).pretty())
except Exception as e:
print(" PARSING FAILED :\n", e)
return markdown
# Parses a file & display its parse tree
def test(filename):
print(f"--- Parsing of {filename} ---\n")
parsed = spipParser.parse(open(path.dirname(__file__) + "/" + filename).read())
print(parsed, "\n")
print(f"--- Parse tree of {filename} ---\n\n", parsed.pretty(), "\n")
raw = open(path.dirname(__file__) + "/" + filename).read()
print(f"--- Parse tree of {filename} ---\n\n")
print(larkParser.parse(raw))
if __name__ == "__main__":
# Test