-
Notifications
You must be signed in to change notification settings - Fork 79
This add new cases check #17
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some comments.
And one more generic issue.
Initially I wrote this script like use-one-and-drop tool, but it seems like it is used by somebody and even developed further. But it can not grow without unit tests. It is not mandatory requirement, I'll merge this PR as is when minor issues fixed, but would be really cool if you can create some tests.
|
||
# subst = "\\2\\4(\\5):\\n\\2" | ||
|
||
# line = re.sub(regex, subst, line, 0, re.VERBOSE | re.MULTILINE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is dead. Do we need it in the repo?
V | ||
d | ||
""" | ||
regex = r"(double|int|char|float)\s+\*\s?(\w+)\b" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You replace only 4 standard types, but there are much more. And user defined types might exist. Is it possible to write more generic reg exp but still avoid false positive matches?
\s
is declared mandatory after type name, but int* i
is very common coding style.
I think variable name can include digits and underscores. Just make sure digit is not the first letter.
for j in range(1,c-1,1): | ||
|
||
""" | ||
regex = r"for\s?\(\s?(\s?(\w+)\b\s?=\s?(\d+|\w+)\b\s?)?;\s?((\w+)\s?(>|>=|<|<=|==|!=)?\s?((\w+|\d+)?\s?(\-|\+|\*|\/)?\s?(\w+|\d+)?))?\s?;\s?(\w+\s?(\+\+|\-\-|\+|\-)(\d+)?(\w+)?)?\s?\)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this reg exp replace both for(j = 1; j < c - 1; j+=1)
and for(j = 1; j >= c - 1; j-=1)
with for j in range(1,c-1,1):
?
In this case hard-to-track bug might be introduced which is not visible for human who edits generated code.
V | ||
i | ||
""" | ||
line = re.sub('(int|double|float|char) ', '', line) # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we join this reg exp with reg exp which removes pointers and write something generic like
[optional const] [optional unsigned] [standard type name] [optional star, at least one space before or after star, or just space without star] [variable name which starts from letter or underscore and might contain digits] ?
""" remove ++ | ||
|
||
i++ | ||
V | ||
i+=1 | ||
""" | ||
line = re.sub('\+\+', '+=1', line) # | ||
|
||
""" remove -- | ||
|
||
i-- | ||
V | ||
i-=1 | ||
""" | ||
line = re.sub('--', '-=1', line) # | ||
|
||
line = re.sub(';', '', line) # | ||
|
||
# ALTER % IN PRINT TO STR() FUNCTION | ||
|
||
line = re.sub('printf', 'print', line) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool!
regex = r"print\((\"[\!\+\-\*\\a-zA-Z0-9_ ,\[\]\.\%\:]+\s?\")\,?\s?([\+\-\*\\a-zA-Z0-9_ ,\[\]\.\%\(\)]+)*\)" | ||
|
||
subst = "print(\\1, %(\\2))" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add comments for this code with examples before -> after? I don't understand it
#FILL ARRAY | ||
regex = r""" | ||
([a-zA-Z0-9_]+)\s*\[([a-zA-Z0-9_]+)\s*((\+=)|(\-=)|(\+\+))\s*([0-9]*)\]\s*\=*\s* | ||
""" | ||
|
||
subst = "\\2\\3\\7\n\\1[\\2] = " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add examples
regex = r",\s*%\(\)" | ||
|
||
subst = "" | ||
|
||
line = re.sub(regex, subst, line, 0, re.VERBOSE | re.MULTILINE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add examples
No description provided.