-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathfetlang_reference_make.py
More file actions
executable file
·114 lines (91 loc) · 3.72 KB
/
Copy pathfetlang_reference_make.py
File metadata and controls
executable file
·114 lines (91 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
# This script creates markdown files in the docs directory documenting elements
# of each fetish, as well as creates a table of contents
#
# Requires Python >=3.6
import json
from common import *
def getReferenceDirectory():
return getDocsDirectory() + "/reference/"
def getContentsPath():
return getDocsDirectory() + "/reference.md"
def getCodePairPossibilities():
types = ["fraction", "chain", "stream", "reference"]
pairs = []
for a in types:
for b in types:
pairs.append(f"{a}/{b}")
return pairs
def loadJsonFile(filename):
a = open(filename, "r")
j = json.loads(a.read())
a.close()
return j
def getMarkdownSection(fetish_file, section):
if section.replace(" ", "_") in fetish_file:
markdown = f"## {section.title()}\n"
for element in fetish_file[section.replace(" ", "_")]:
if "description" in element:
markdown += f"### {element['name']}\n"
if "description" in element:
markdown += element["description"] + " \n\n"
if "grammars" in element:
markdown += "Grammar: "
for grammar in element["grammars"]:
markdown += grammar + (
", " if grammar != element["grammars"][-1] else ""
)
markdown += " \n"
if "examples" in element:
markdown += "Examples: \n"
for example in element["examples"]:
markdown += "`" + example + "` \n\n"
if "type" in element:
markdown += f"Type: {element['type']} \n"
if "gender" in element:
markdown += f"Gender: {element['gender']} \n"
if "code" in element:
markdown += "C Code: "
if section == "builtins":
markdown += "`" + element["code"] + "` \n\n"
else:
markdown += " \n\n"
for pair in getCodePairPossibilities():
if pair in element["code"]:
markdown += f" /* {pair} overload */\n {element['code'][pair]} \n\n"
return markdown
return ""
def getReferencePageMarkdown(fetish_name):
fetish_file = loadJsonFile(getFetishFileOfFetish(fetish_name))
markdown = f"# {fetish_name.title()}\n{fetish_file['description']}\n"
markdown += getMarkdownSection(fetish_file, "operators")
markdown += getMarkdownSection(fetish_file, "comparison operators")
markdown += getMarkdownSection(fetish_file, "builtins")
return markdown
def makeReferencePage(fetish_name):
markdown = getReferencePageMarkdown(fetish_name)
filename = getReferenceDirectory() + fetish_name + ".md"
fp = open(filename, "w")
fp.write(markdown)
fp.close()
return filename
def getShortDescription(fetish):
descriptions = {
"core": "The included-by-default fetish that defines the language",
"assertiveness": "Contains assertion operators. Useful for unit tests",
"obedience": "File IO operators",
"manhandling": "Filesystem operators",
}
return descriptions[fetish]
def makeReferencePages():
contents = "# Fetish Reference\n"
for fetish in getListOfFetishes():
ref_page = makeReferencePage(fetish)
contents += f"""{fetish.title()} - {getShortDescription(fetish)}
[C Reference](c_reference/{fetish}.md)
[Fetlang Reference](reference/{fetish}.md) \n\n"""
fp = open(getContentsPath(), "w")
fp.write(contents)
fp.close()
if __name__ == "__main__":
makeReferencePages()