Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bython parser improvement #31

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
179ce3a
c++ style single line comments implemented
filipefjn May 15, 2019
305e8ac
started the implementation of a recursive parser
filipefjn May 16, 2019
f658382
added '#' scope on recursive parser
filipefjn May 16, 2019
d64fe83
recommited all the changes with my name set on git
filipefjn May 16, 2019
091f466
Merge branch 'master' of https://github.com/filipefjn/bython
filipefjn May 16, 2019
1fab9b0
implemented tests for: comments (c, c++ and python styled), strings (…
filipefjn May 16, 2019
6af238d
unified the global and brace scopes conditional
filipefjn May 16, 2019
4a12556
outputting the .py file for the first time
filipefjn May 17, 2019
a4d6e9c
implemented a function for removing indentation
filipefjn May 17, 2019
070f19a
implemented functions for preparing braces and removing empty lines. …
filipefjn May 17, 2019
a5ca359
implemented indentation
filipefjn May 17, 2019
2713ce1
fixed python dicts
filipefjn May 17, 2019
a349d6c
fixed error when there's a comment after a call and before the openin…
filipefjn May 20, 2019
daa7e3e
implemented the removal of semicolons
filipefjn May 20, 2019
83ed356
fixed double indentation and wrong indentation after dict
filipefjn May 20, 2019
6825876
implemented multi-line comments
filipefjn May 20, 2019
5041fa2
fixed doubled character after non-dicts
filipefjn May 20, 2019
d870bd1
disabled the remove_semicolons for now
filipefjn May 20, 2019
5e9cd48
added some comments and minor fixes
filipefjn May 23, 2019
ca0ce33
fixed a few cases where comments would be removed
filipefjn May 24, 2019
258af8a
renamed a function to parse_file_recursively
filipefjn May 24, 2019
69bb5bf
added a debug mode
filipefjn May 24, 2019
e86c6a7
preparing for first release
filipefjn May 24, 2019
cf452c7
disabled one regex substitution and fixed an infinite loop
filipefjn May 24, 2019
d1aeeae
implemented a debug option for the cli
filipefjn May 24, 2019
611c1c2
fixed empty lines bug. filtered file now only appears when debug mode…
filipefjn May 25, 2019
5b69929
fixed '} else {'
filipefjn May 25, 2019
ffc4a9c
implemented parenthesis scope
filipefjn May 25, 2019
1ed72b6
added function descriptions and more comments
filipefjn May 26, 2019
65d15d2
put my name in the authors
filipefjn May 26, 2019
5dcc5cc
fixed infinite loop inside "/*" scope
filipefjn May 26, 2019
b35ca4c
Fixed an exception that happened when the file didn't end with a newline
filipefjn May 30, 2019
d3da4c5
Fixed an issue where the code was being duplicated
filipefjn May 30, 2019
3f38de3
Fixed an issue where spaces and tabs after closing braces were remove…
filipefjn May 30, 2019
311329c
else and elif fix
filipefjn Jun 7, 2019
8fdadbf
I just found out that python has a '//' operator. Disabling '//' comm…
filipefjn Jun 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bython/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
import bython.logger
import bython.importing

VERSION_NUMBER = "0.8"
VERSION_NUMBER = "0.9"
2 changes: 1 addition & 1 deletion bython/importing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def bython_import(module_name, globals, logger=None):

logger.log_info("Parsing %s" % path)
try:
bython.parser.parse_file(path, False, os.path.join(sys.path[0], "python_"))
bython.parser.parse_file_recursively(path, False, os.path.join(sys.path[0], "python_"))

error_during_parsing = None

Expand Down
426 changes: 422 additions & 4 deletions bython/parser.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion etc/bython.1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ Specify the name of output file (valid only if -c is present, throws an error if
.SH SEE ALSO
py2by(1)
.SH AUTHOR
Mathias Lohne and Tristan Pepin 2018
Mathias Lohne 2018,
Tristan Pepin 2018,
Filipe do Nascimento 2019
.SH LICENSE
This program is licensed under the MIT license. See [1] for details. TL;DR: Do whatever you want as long as you include the original copyright and license notice.
.TP
Expand Down
7 changes: 5 additions & 2 deletions scripts/bython
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def main():
formatter_class=argparse.RawTextHelpFormatter)
argparser.add_argument("-V", "--version",
action="version",
version="Bython v%s\nMathias Lohne and Tristan Pepin 2018" % VERSION_NUMBER)
version="Bython v%s\nMathias Lohne, Tristan Pepin and Filipe do Nascimento 2019" % VERSION_NUMBER)
argparser.add_argument("-v", "--verbose",
help="print progress",
action="store_true")
Expand All @@ -47,6 +47,9 @@ def main():
argparser.add_argument("-2", "--python2",
help="use python2 instead of python3 (default)",
action="store_true")
argparser.add_argument("-d", "--debug",
help="enable debug mode",
action="store_true")
argparser.add_argument("-o", "--output",
type=str,
help="specify name of output file (if -c is present)",
Expand Down Expand Up @@ -133,7 +136,7 @@ def main():
else:
outputname = cmd_args.output[0]

parser.parse_file(file, cmd_args.lower_true, path_prefix, outputname, import_translations)
parser.parse_file_recursively(file, cmd_args.lower_true, path_prefix, outputname, import_translations, cmd_args.debug)

except (TypeError, FileNotFoundError) as e:
logger.log_error("Error while parsing '%s'.\n%s" % (current_file_name, str(e)))
Expand Down
33 changes: 33 additions & 0 deletions test-code.by
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# this file is for testing purposes only
# TODO remove this file later

def print_hello_world() {
str = "he\"ll\"o"; # hello
str += ' world'; // world
/*
print("error - not yet implemented");
while(true) // remove
{ sleep(1000);

}
*/




mydictionary = {
'key1': "value1",
'key2': 2,
'key3': "hi",
}
if str == "hello world" {
print("its equal")
}
else
{
print("not equal")
}
print(str) /////# let's print it!
}

print_hello_world();
25 changes: 25 additions & 0 deletions test-code.by.filtered
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# this file is for testing purposes only
# TODO remove this file later
def print_hello_world(){
str = "he\"ll\"o"; # hello
str += ' world'; // world
/*
print("error - not yet implemented");
while(true) // remove{
sleep(1000);
}
*/
mydictionary ={
'key1': "value1",
'key2': 2,
'key3': "hi",
}
if str == "hello world"{
print("its equal")
}
else{
print("not equal")
}
print(str) /////# let's print it!
}
print_hello_world();
25 changes: 25 additions & 0 deletions test-code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# this file is for testing purposes only
# TODO remove this file later
def print_hello_world():
str = ""he\"ll\"o"; # hello
str += '' world'; # world
/*
print("error - not yet implemented");
while(true) // remove{
sleep(1000);
}
*/
mydictionary ={
'key1': "value1",
'key2': 2,
'key3': "hi",
}
if str === ""hello world":
print("its equal")

else:
print("not equal")

print(str) #///# let's print it!

print_hello_world();
6 changes: 6 additions & 0 deletions test-recursive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# this file is for testing purposes only
# TODO remove this file later

from bython.parser import parse_file_recursively

parse_file_recursively("test-code.by")