add pyparsing, lark not adapted to complex languages like SPIP or Markdown
This commit is contained in:
parent
8eec4033f8
commit
a455c8e4a2
@ -1,4 +1,5 @@
|
|||||||
peewee
|
|
||||||
lark
|
|
||||||
python-slugify[unidecode]
|
|
||||||
pyyaml
|
pyyaml
|
||||||
|
python-slugify[unidecode]
|
||||||
|
peewee
|
||||||
|
pyparsing
|
||||||
|
lark
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
from os import path
|
from os import path
|
||||||
|
|
||||||
from lark import Lark
|
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:
|
class content:
|
||||||
@ -13,18 +14,19 @@ class content:
|
|||||||
markdown = self.spip
|
markdown = self.spip
|
||||||
# Parses the body & display parse tree
|
# Parses the body & display parse tree
|
||||||
try:
|
try:
|
||||||
parsed = spipParser.parse(self.spip)
|
print(f" parse tree :\n")
|
||||||
print(f" parse tree :\n", parsed.pretty(), "\n")
|
print(larkParser.parse(self.spip).pretty())
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(" PARSING FAILED :\n", e)
|
print(" PARSING FAILED :\n", e)
|
||||||
return markdown
|
return markdown
|
||||||
|
|
||||||
|
|
||||||
# Parses a file & display its parse tree
|
# Parses a file & display its parse tree
|
||||||
def test(filename):
|
def test(filename):
|
||||||
print(f"--- Parsing of {filename} ---\n")
|
raw = open(path.dirname(__file__) + "/" + filename).read()
|
||||||
parsed = spipParser.parse(open(path.dirname(__file__) + "/" + filename).read())
|
print(f"--- Parse tree of {filename} ---\n\n")
|
||||||
print(parsed, "\n")
|
print(larkParser.parse(raw))
|
||||||
print(f"--- Parse tree of {filename} ---\n\n", parsed.pretty(), "\n")
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Test
|
# Test
|
||||||
|
Loading…
Reference in New Issue
Block a user