Skip to content

Commit

Permalink
added helper scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
forntoh committed Aug 24, 2021
1 parent 17ffd86 commit f07a193
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
src/main.cpp
debug.log
_site/
.jekyll-cache/
.scripts/
.jekyll-cache/
69 changes: 69 additions & 0 deletions .scripts/keywords.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import re
import click

prefixes = [':', '*', '}', '/', '#', 'for ', 'if ', 'switch ', 'case ', 'return ', 'class ', 'explicit ']
sufixes = [';', '-', '=', ',', '*', '.', '= {', '{}']

pre_key_1 = """#######################################
# Syntax Coloring Map
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
"""

pre_key_2 = """
#######################################
# Methods and Functions (KEYWORD2)
#######################################
"""

pre_lit_1 = """
#######################################
# Constants (LITERAL1)
#######################################
"""

@click.command()
@click.argument('files', type=click.Path("r"), nargs=-1)

def build(files):
literal_1_data = ""
keyword_1_data = ""
keyword_2_data = ""

for file in files:
with open(file, "r") as a_file:
for line in a_file:
stripped_line = line.strip()

if len(stripped_line) > 9 and not stripped_line.startswith(tuple(prefixes)) and not stripped_line.endswith(tuple(sufixes)):
if re.search(r"^.+\s[a-z][A-Za-z]+\(.*", stripped_line) != None:
methodName = re.findall(r"\w+", stripped_line)[1]
keyword_2_data += methodName + " KEYWORD2\n"
if len(stripped_line) > 7 and stripped_line.startswith('class '):
if re.search(r"\w+", stripped_line) != None:
methodName = re.findall(r"\w+", stripped_line)[1]
keyword_1_data += methodName + " KEYWORD1\n"
if len(stripped_line) > 7 and stripped_line.startswith('#ifndef') and not stripped_line.endswith('_H'):
if re.search(r"\w+", stripped_line) != None:
methodName = re.findall(r"\w+", stripped_line)[1]
if re.search(methodName, literal_1_data) == None:
literal_1_data += methodName + " LITERAL1\n"

with open("keywords.txt", "w") as a_file:
a_file.truncate()
a_file.write(pre_key_1)
a_file.write(keyword_1_data)
a_file.write(pre_key_2)
a_file.write(keyword_2_data)
a_file.write(pre_lit_1)
a_file.write(literal_1_data)
print("Done")

if __name__ == '__main__':
build()
39 changes: 39 additions & 0 deletions .scripts/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import re
import click

@click.command()
@click.argument('files', type=click.Path("r"), nargs=-1)
@click.argument('version')

def build(files, version):

for file in files:
data = ''
separator = ''
if file.endswith('.json'): separator = ": "
else: separator = '='

with open(file, "r") as a_file:
for line in a_file:
stripped_line = line.strip()
key = stripped_line.split(separator, 1)[0]

if re.search("version", key) != None:
anchor = ''
suffix = ''
prefix = ''
if separator == ': ':
anchor = '"'
suffix = ','
prefix = ' '
data+=(prefix + key + separator + anchor + version + anchor + suffix + '\n')
else:
data+=line

with open(file, "w") as a_file:
a_file.truncate()
a_file.write(data)
print("Done")

if __name__ == '__main__':
build()
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"frameworks": "arduino",
"platforms": "*",
"export": {
"exclude": ["*.md", "examples/*/*.md", ".github/"]
"exclude": ["*.md", "examples/*/*.md", ".github/", ".scripts/", "version"]
}
}
3 changes: 3 additions & 0 deletions version
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

python .scripts/version.py library.* $1

0 comments on commit f07a193

Please sign in to comment.