Skip to content

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

VictorCampelo
Copy link

No description provided.

Copy link
Owner

@andreikop andreikop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @VictorCampelo

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)
Copy link
Owner

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"
Copy link
Owner

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?\)"
Copy link
Owner

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) #
Copy link
Owner

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] ?

Comment on lines +317 to +337
""" 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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

Comment on lines +339 to +341
regex = r"print\((\"[\!\+\-\*\\a-zA-Z0-9_ ,\[\]\.\%\:]+\s?\")\,?\s?([\+\-\*\\a-zA-Z0-9_ ,\[\]\.\%\(\)]+)*\)"

subst = "print(\\1, %(\\2))"
Copy link
Owner

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

Comment on lines +368 to +373
#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] = "
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add examples

Comment on lines +377 to +381
regex = r",\s*%\(\)"

subst = ""

line = re.sub(regex, subst, line, 0, re.VERBOSE | re.MULTILINE)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants