[DEV] set it work again and basic parse of merkdown

This commit is contained in:
Edouard DUPIN 2017-10-03 15:19:07 +02:00
parent aad7b58ad9
commit e27896b134
20 changed files with 583 additions and 44 deletions

View File

@ -12,7 +12,8 @@ import codeHLshell
def transcode(type, value):
if type == "c++":
if type == "c++" \
or type == "cpp":
value = codeHLcpp.transcode(value)
elif type == "java":
value = codeHLJava.transcode(value)

51
codeMarkDown/MD_Code.py Normal file
View File

@ -0,0 +1,51 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import codeHL
import re
##
## @brief Transcode balise :
## [code language=cpp]
## int main(void) {
## return 0;
## }
## [/code]
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
#value = re.sub(r'\[code(( |\t|\n|\r)+style=(.*))?\](.*?)\[/code\]',
"""
value = re.sub(r'```(( |\t|\n|\r){\.(.*?))?\}(.*?)\```',
replace_code, #r'<pre>\4</pre>',
value,
flags=re.DOTALL)
"""
value = re.sub(r'```(( |\t|\n|\r)*(\{\.(.*?)\}))?(.*?)\```',
replace_code, #r'<pre>\4</pre>',
value,
flags=re.DOTALL)
# TODO : remove the basic indentation of the element (to have a better display in the text tutorial ...
return value
def transcode_part2(value):
value = value.replace(":CODE:UNDER:SCORE:", "_")
value = value.replace(":CODE:STAR:", "*")
return value
def replace_code(match):
if match.group() == "":
return ""
#debug.info("plop: " + str(match.groups()))
#debug.info("code format: " + str(match.groups()[3]))
value = codeHL.transcode(match.groups()[3], match.groups()[4])
#value = value.replace("\n", "<br/>")
value = value.replace("_", ":CODE:UNDER:SCORE:")
value = value.replace("*", ":CODE:STAR:")
return '<pre>' + str(value) + '</pre>'

19
codeMarkDown/MD_Image.py Normal file
View File

@ -0,0 +1,19 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode balise:
## [img w=125 h=45]dossier/image.jpg[/img]
## [img w=125 h=45]http://plop.com/dossier/image.png[/img]
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
return value

View File

@ -0,0 +1,60 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode
## commencez les lignes par:
## *
## *
##
## +
## +
##
## resultat:
##
## -
## -
## -
##
## commencez les lignes par:
## -
## -
##
## resultat:
##
## 1.
## 2.
## 3.
##
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'\n(( - )|( * )|( # ))',
r'\n:INDENT:[STAR]',
value)
p = re.compile('((\:INDENT\:(.*?)\n)*)',
flags=re.DOTALL)
value = p.sub(replace_wiki_identation,
value)
value = re.sub(r'\[STAR\](.*?)\n',
r'<li>\1</li>',
value,
flags=re.DOTALL)
return value
def replace_wiki_identation(match):
if match.group() == "":
return ""
#debug.verbose("plop: " + str(match.group()))
value = "<ul>"
value += re.sub(r':INDENT:',
r'',
match.group())
value += "</ul>"
return transcode(value)

84
codeMarkDown/MD_Link.py Normal file
View File

@ -0,0 +1,84 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode:
## [http://votre_site.con] => http://votre_site.con
## [http://votre_site.con | text displayed] => text displayed
## [http://votre_site.con text displayed] => text displayed.
##
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
# named link : [[http://plop.html | link name]]
value = re.sub(r'\[\[http://(.*?) \| (.*?)\]\]',
r'<a href="http://\1">\2</a>',
value)
# direct link : [[http://plop.html]]
value = re.sub(r'\[\[http://(.*?)\]\]',
r'<a href="http://\1">http://\1</a>',
value)
# direct lib link : [lib[libname]]
value = re.sub(r'\[lib\[(.*?) \| (.*?)\]\]',
r'<a href="../\1">\2</a>',
value)
value = re.sub(r'\[doc\[(.*?) \| (.*?)\]\]',
r'<a href="\1.html">\2</a>',
value)
value = re.sub(r'\[tutorial\[(.*?) \| (.*?)\]\]',
r'<a href="tutorial_\1.html">\2</a>',
value)
value = re.sub(r'\[(lib|class|methode)\[(.*?)\]\]',
replace_link_class,
value)
"""
p = re.compile('\[\[(.*?)(|(.*?))\]\])',
flags=re.DOTALL)
value = p.sub(replace_link,
value)
"""
return value
"""
def replace_link(match):
if match.group() == "":
return ""
#debug.verbose("plop: " + str(match.group()))
value = "<ul>"
value += re.sub(r':INDENT:',
r'',
match.group())
value += "</ul>"
return transcode(value)
"""
def replace_link_class(match):
if match.group() == "":
return ""
#debug.info("plop: " + str(match.group()))
if match.groups()[0] == 'class':
className = match.groups()[1]
value = re.sub(':', '_', className)
return '<a href="class_' + value + '.html">' + className + '</a>'
elif match.groups()[0] == 'lib':
return match.groups()[1]
elif match.groups()[0] == 'methode':
return match.groups()[1]
else:
return match.groups()[1]

View File

@ -0,0 +1,17 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode thales specification ...
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
return value

42
codeMarkDown/MD_Table.py Normal file
View File

@ -0,0 +1,42 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode table:
## { | tableau_type_1
## | [b]colone 1[/b]
## ligne 1
## | colone 2 ligne 1
## |---
## | colone 1 ligne 1
## | colone 2 ligne 2
## |}
## Avec autant de ligne et de colone que vous voullez..
## Il est possible de faire des retour a la ligne dans une case du tableau...
## En bref sa tend a marcher comme sur un Wiki...
##
## result:
## +-------------------------------------+
## | colone 1 |
## +------------------+------------------+
## | ligne 1 | colone 2 ligne 1 |
## +------------------+------------------+
## | colone 1 ligne 1 | colone 2 ligne 2 |
## +------------------+------------------+
##
## TODO : Create simple table like :
## | colone 1 ||
## | ligne 1 | colone 2 ligne 1 |
## | colone 1 ligne 1 | colone 2 ligne 2|
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
return value

49
codeMarkDown/MD_Text.py Normal file
View File

@ -0,0 +1,49 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode .
## [b]texte ici[/b]
## [i]texte ici[/i]
## [u]texte ici[/u]
## [strike]texte ici[/strike]
## [color=olive]texte ici[/color]
## [color=#456FF33F]texte ici[/color]
## Left : [left]texte ici[/left]
## Center : [center]texte ici[/center]
## Right : [right]texte ici[/right]
## [size=22]sdfgsdfgsdgsfd[/size]
## [cadre]mettre les code ici[/cadre]
## @param[in] string String to transform.
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'\*\*(.*?)\*\*',
r'<strong>\1</strong>',
value,
flags=re.DOTALL)
value = re.sub(r'__(.*?)__',
r'<strong>\1</strong>',
value,
flags=re.DOTALL)
value = re.sub(r'\*(.*?)\*',
r'<em>\1</em>',
value,
flags=re.DOTALL)
value = re.sub(r'_(.*?)_',
r'<em>\1</em>',
value,
flags=re.DOTALL)
value = re.sub(r'____(.*?)\n',
r'<hr>',
value,
flags=re.DOTALL)
return value

73
codeMarkDown/MD_Title.py Normal file
View File

@ -0,0 +1,73 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode .
## =?=Page Title=?=
## ==Title 1==
## ===Title 2===
## ====Title 3====
## =====Title 4=====
## ======Title 5======
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
value = "\n" + value
value = re.sub(r'@tableofcontents',
r'',
value)
value = re.sub(r'\n(.*?)(( |\t)*\{.*\})*\n====*',
r'\n<h1>\1</h1>',
value)
value = re.sub(r'\n(.*?)(( |\t)*\{.*\})*\n---*',
r'\n<h2>\1</h2>',
value)
value = re.sub(r'\n###### (.*?)(( |\t)*\{.*\})* ######',
r'\n<h6>\1</h6>',
value)
value = re.sub(r'\n###### (.*?)(( |\t)*\{.*\})*',
r'\n<h6>\1</h6>',
value)
value = re.sub(r'\n##### (.*?)(( |\t)*\{.*\})* #####',
r'\n<h5>\1</h5>',
value)
value = re.sub(r'\n##### (.*?)(( |\t)*\{.*\})*',
r'\n<h5>\1</h5>',
value)
value = re.sub(r'\n#### (.*?)(( |\t)*\{.*\})* ####',
r'\n<h4>\1</h4>',
value)
value = re.sub(r'\n#### (.*?)(( |\t)*\{.*\})*',
r'\n<h4>\1</h4>',
value)
value = re.sub(r'\n### (.*?)(( |\t)*\{.*\})* ###',
r'\n<h3>\1</h3>',
value)
value = re.sub(r'\n### (.*?)(( |\t)*\{.*\})*',
r'\n<h3>\1</h3>',
value)
value = re.sub(r'\n## (.*?)(( |\t)*\{.*\})* ##',
r'\n<h2>\1</h2>',
value)
value = re.sub(r'\n## (.*?)(( |\t)*\{.*\})*',
r'\n<h2>\1</h2>',
value)
value = value[1:]
return value

View File

@ -0,0 +1,23 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
_comment_code = "[comment]:"
##
## @brief Transcode balise:
## line start with [comment]:
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
out = "";
for elem in value.split("\n"):
if len(elem) >= len(_comment_code) \
and elem[:len(_comment_code)] == _comment_code:
continue
out += elem + "\n"
return out

View File

@ -0,0 +1,30 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
##
## @brief Transcode balise:
## \n\n ==> <br/>
## @param[in] value String to transform.
## @return Transformed string.
##
def transcode(value):
value = re.sub(r'\r\n',
r'\n',
value)
value = re.sub(r'\n\n',
r'<br/>',
value)
value = re.sub(r'<br/>',
r'<br/>\n',
value)
return value

View File

@ -0,0 +1,61 @@
#!/usr/bin/python
import monkDebug as debug
import sys
import monkTools
import re
"""
import BB_Link
import BB_Image
import BB_Table
import BB_Specification
"""
import MD_Text
import MD_IndentAndDot
import MD_Title
import MD_comment
import MD_lineReturn
import MD_Code
##
## @brief Transcode input data in the corect format.
## @param[in] string String to transform.
## @return Transformed string.
##
def transcode(value):
# remove html property
value = re.sub(r'&', r'&amp;', value)
value = re.sub(r'<', r'&lt;', value)
value = re.sub(r'>', r'&gt;', value)
value = re.sub(r'\r\n', r'\n', value)
value = re.sub(r'\n\r', r'\n', value)
value = re.sub(r'\r', r'\n', value)
value = MD_comment.transcode(value)
value = MD_Title.transcode(value)
value = MD_IndentAndDot.transcode(value)
value = MD_Code.transcode(value)
value = MD_lineReturn.transcode(value)
value = MD_Text.transcode(value)
"""
value = BB_Text.transcode(value)
value = BB_Link.transcode(value)
value = BB_Image.transcode(value)
value = BB_Table.transcode(value)
value = BB_Specification.transcode(value)
"""
value = MD_Code.transcode_part2(value)
return value
##
## @brief transcode a BBcode file in a html file
## @return True if the file is transformed
##
def transcode_file(inputFileName, outputFileName):
inData = monkTools.file_read_data(inputFileName)
if inData == "":
return False
outData = transcode(inData)
debug.warning(" out: " + outputFileName)
monkTools.file_write_data(outputFileName, outData)
return True

View File

@ -246,5 +246,5 @@ class MonkArg:
for element in self.list_properties :
listOfPropertiesArg += element.get_porperties()
print(" " + sys.argv[0] + listOfPropertiesArg + " ...")
for element in self.list_properties :
element.display()
for element in self.m_list_properties :
element.display()

View File

@ -10,22 +10,34 @@ class Enum(Node.Node):
debug.error("Can not parse enum : " + str(stack))
return
self.typedef = False
if stack[0] == 'typedef':
if len(stack) > 0 \
and stack[0] == 'typedef':
self.typedef = True
stack[1:]
if len(stack) == 0:
if len(stack) > 0 \
and stack[0] == 'enum':
stack[1:]
else:
debug.error("Can not parse enum : " + str(stack))
return
if len(stack) == 1:
localEnumName = ""
else:
self.is_class = False
if len(stack) > 0 \
and stack[0] == 'class':
self.is_class = True
stack[1:]
if len(stack) >= 1:
localEnumName = stack[1]
else:
debug.error("Can not parse enum : " + str(stack))
return
Node.Node.__init__(self, 'enum', localEnumName, file, lineNumber, documentation)
self.list_element = []
def to_str(self) :
if self.is_class == True:
return "enum class " + self.name + " { ... };"
return "enum " + self.name + " { ... };"
def enum_append(self, stack):

View File

@ -6,6 +6,7 @@ import monkTools as tools
import os
import re
import codeBB
import codeMarkDown
import collections
import monkModule as module
import monkNode as node
@ -765,8 +766,11 @@ def generate(my_lutin_doc, outFolder) :
localHeader += "\n"
outData += codeBB.transcode(localHeader)
#debug.info(localHeader)
outData += codeBB.transcode(inData)
outData += generic_footer
if docInputName[-2:] == "bb":
outData += codeBB.transcode(inData)
elif docInputName[-2:] == "md":
outData += codeMarkDown.transcode(inData)
outData += genericFooter
tools.file_write_data(outputFileName, outData)
for docInputName,outpath in my_lutin_doc.list_doc_file :
@ -777,7 +781,12 @@ def generate(my_lutin_doc, outFolder) :
inData = tools.file_read_data(docInputName)
if inData == "":
continue
outData = generic_header + codeBB.transcode(inData) + generic_footer
outData = generic_header
if docInputName[-2:] == "bb":
outData += codeBB.transcode(inData)
elif docInputName[-2:] == "md":
outData += codeMarkDown.transcode(inData)
outData += generic_footer
tools.file_write_data(outputFileName, outData)

View File

@ -15,6 +15,7 @@ class Methode(Node.Node):
self.inline = False
self.const = False # the end of line cont methode is sont for the class ...
self.noexcept = False
self.override = False
self.delete = False
# remove constructer inside declaration ...
@ -61,7 +62,10 @@ class Methode(Node.Node):
stack = stack[:len(stack)-2]
self.delete = True
while stack[0] in ['virtual', 'static', 'inline']:
while len(stack) > 0\
and ( stack[0] == 'virtual'\
or stack[0] == 'static'\
or stack[0] == 'inline')::
if stack[0] == 'virtual':
self.virtual = True
stack = stack[1:]

View File

@ -112,7 +112,7 @@ class Module:
debug.info('Parse documantation code : ' + self.name)
if self.path_parsing != "":
for root, dirnames, filenames in os.walk(self.path_parsing):
tmpList = fnmatch.filter(filenames, "*.h")
tmpList = fnmatch.filter(filenames, "*.hpp")
# Import the module :
for filename in tmpList:
fileCompleteName = os.path.join(root, filename)
@ -127,16 +127,21 @@ class Module:
#self.structure_lib.debug_display()
if self.path_global_doc != "":
for root, dirnames, filenames in os.walk(self.path_global_doc):
tmpList = fnmatch.filter(filenames, "*.bb")
tmpList = fnmatch.filter(filenames, "*.md")
# Import the module :
for filename in tmpList:
fileCompleteName = os.path.join(root, filename)
tutorialPath = os.path.join(self.path_global_doc, "tutorial/")
pathBase = fileCompleteName[len(self.path_global_doc):len(fileCompleteName)-3]
while len(pathBase) > 0 \
and pathBase[0] == '/':
pathBase = pathBase[1:]
debug.verbose(" Find a doc file : fileCompleteName='" + fileCompleteName + "'")
if fileCompleteName[:len(tutorialPath)] == tutorialPath:
debug.warning("add_tutorial_doc : '" + fileCompleteName + "' ==> '" + pathBase + "'")
self.add_tutorial_doc(fileCompleteName, pathBase)
else:
debug.warning("add_file_doc : '" + fileCompleteName + "' ==> '" + pathBase + "'")
self.add_file_doc(fileCompleteName, pathBase)
##

View File

@ -2,11 +2,13 @@
import os
import sys
import re
import copy
import monkTools as tools
sys.path.append(tools.get_current_path(__file__) + "/ply/ply/")
sys.path.append(tools.get_current_path(__file__) + "/codeBB/")
sys.path.append(tools.get_current_path(__file__) + "/codeMarkDown/")
sys.path.append(tools.get_current_path(__file__) + "/codeHL/")
import lex
@ -84,7 +86,7 @@ t_EXCLAMATION = r'!'
def t_PRECOMP(t):
r'\#.*?\n'
t.value = re.sub(r'\#\#multiline\#\#', "\\\n", t.value)
t.lexer.lineno += len(filter(lambda a: a=="\n", t.value))
t.lexer.lineno += len(list(filter(lambda a: a=="\n", t.value)))
return t
def t_COMMENT_SINGLELINE_DOC_PREVIOUS(t):
r'//(/|!)<.*?\n'
@ -129,7 +131,8 @@ t_STRING_LITERAL = r'"([^"\\]|\\.)*"'
#Found at http://ostermiller.org/findcomment.html
def t_COMMENT_MULTILINE_DOC(t):
r'/\*(\*|!)(\n|.)*?\*/'
t.lexer.lineno += len(filter(lambda a: a=="\n", t.value))
filter_result = list(filter(lambda a: a=="\n", t.value))
t.lexer.lineno += len(filter_result)
t.value = re.sub("( |\t)*\*", "", t.value[3:-2])
while t.value[0] == '\n':
if len(t.value) <= 2:
@ -164,7 +167,7 @@ def t_COMMENT_MULTILINE_DOC(t):
return t
def t_COMMENT_MULTILINE(t):
r'/\*(\n|.)*?\*/'
t.lexer.lineno += len(filter(lambda a: a=="\n", t.value))
t.lexer.lineno += len(list(filter(lambda a: a=="\n", t.value)))
def t_NEWLINE(t):
r'\n+'
t.lexer.lineno += len(t.value)
@ -607,31 +610,27 @@ class parse_file():
def is_a_function(stack) :
# in a function we need to have functionName + ( + )
if len(stack) < 3:
tmp = copy.deepcopy(stack);
while len(tmp) > 0\
and ( tmp[-1] == 'const'\
or tmp[-1] == 'noexcept'\
or tmp[-1] == 'override'\
or tmp[-1] == 'volatile'):
tmp = tmp[:-1]
if len(tmp) < 3:
return False
if ':' in stack:
if ':' in tmp:
res = []
for element in stack:
for element in tmp:
if element != ':':
res.append(element)
else:
break
stack = res
if stack[len(stack)-2] == '=' \
and stack[len(stack)-1] == '0':
stack = stack[:len(stack)-2]
if stack[len(stack)-2] == '=' \
and stack[len(stack)-1] == 'delete':
stack = stack[:len(stack)-2]
# find ')' element :
id = len(stack)-1
while id >= 0:
if stack[id] == ')':
break;
id -= 1
if id >= 0:
for elem in stack[id+1:]:
if elem not in ['const', 'noexcept', 'override']:
return False
tmp = res
if tmp[-2] == '=' \
and tmp[-1] == '0':
tmp = tmp[:-2]
#can end with 2 possibilities : ')', 'const' or ')'
if tmp[-1] == ')':
return True
return False
return False

View File

@ -14,15 +14,15 @@ global_basic_type = ['void', 'bool', \
'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'uint128_t', \
'T', 'CLASS_TYPE']
global_class_link = {
"std::string" : "http://www.cplusplus.com/reference/string/string/",
"etk::String" : "http://www.cplusplus.com/reference/string/string/",
"std::u16string" : "http://www.cplusplus.com/reference/string/u16string/",
"std11::u16string" : "http://www.cplusplus.com/reference/string/u16string/",
"std::u32string" : "http://www.cplusplus.com/reference/string/u32string/",
"etk::UString" : "http://www.cplusplus.com/reference/string/u32string/",
"std11::u32string" : "http://www.cplusplus.com/reference/string/u32string/",
"std::wstring" : "http://www.cplusplus.com/reference/string/wstring/",
"std::vector" : "http://www.cplusplus.com/reference/vector/vector/",
"etk::Vector" : "http://www.cplusplus.com/reference/vector/vector/",
"std::list" : "http://www.cplusplus.com/reference/list/list/",
"std::pair" : "http://www.cplusplus.com/reference/utility/pair/",
"etk::Pair" : "http://www.cplusplus.com/reference/utility/pair/",
"std::tuple" : "http://www.cplusplus.com/reference/tuple/tuple/",
"std::shared_ptr" : "http://www.cplusplus.com/reference/memory/shared_ptr/",
@ -34,7 +34,7 @@ global_class_link = {
"std::enable_shared_from_this" : "http://www.cplusplus.com/reference/memory/enable_shared_from_this/",
"std11::enable_shared_from_this" : "http://www.cplusplus.com/reference/memory/enable_shared_from_this/",
"std::mutex" : "http://www.cplusplus.com/reference/mutex/mutex/",
"ethread::Mutex" : "http://www.cplusplus.com/reference/mutex/mutex/",
"std11::mutex": "http://www.cplusplus.com/reference/mutex/mutex/",
"std::unique_lock" : "http://www.cplusplus.com/reference/mutex/unique_lock/",

View File

@ -648,7 +648,7 @@ from compiler import misc, syntax, pycodegen
class GardenSnakeCompiler(object):
def __init__(self):
self.parser = GardenSnakeParser()
def compile(self, code, filename="<string>"):
def compile(self, code, filename="<etk/String.hpp>"):
tree = self.parser.parse(code)
#print tree
misc.set_filename(filename, tree)