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

Make lines between begin and finish for py, r, dom, run, vision steps run as a single block #167

Closed
kensoh opened this issue May 21, 2018 · 8 comments
Assignees
Labels

Comments

@kensoh
Copy link
Member

kensoh commented May 21, 2018

At the moment, only code lines within js begin and js finish run as a single block of code. The other steps (py, r, dom, run, vision), the lines are run line by line in their respective targets.

This is problem for some edge cases where subsequent lines of code has to be treated as part of the previous lines, for example in the case of an if statement or consecutive dom steps with if and action statements.

This issue is to evaluate and collapse lines of code for the respective begin and finish steps, so that the lines of code are executed as a single within in the target / process (py, r, dom, run, vision) etc. At the moment js begin and js finish already collapse the consecutive lines, but as part of this change, it can be done in a more robust way instead of regex substitution.

@kensoh kensoh added the feature label May 21, 2018
@kensoh
Copy link
Member Author

kensoh commented May 21, 2018

The part of the code to be patched would be in this section of tagui_parse.php -

https://github.com/kelaberetiv/TagUI/blob/28b5d26f146edd476d6cb8c2ae5fc9fc9af10d89/src/tagui_parse.php#L114

@kensoh
Copy link
Member Author

kensoh commented May 23, 2018

2 ideas so far from @Aussiroth and @lohvht -

  • separating and special handling for begin and finish in parse_intent()
  • generation of temp begin and finish files to be exec during run-time

@Aussiroth
Copy link
Contributor

Aussiroth commented Jun 4, 2018

This block of code causes issues due to extra backslashes being introduced when trying to add newlines to separate run blocks of code.

run begin
python 'abcd'.py
run finish
echo run_result```

@Aussiroth
Copy link
Contributor

Problem with incorrect escaping of \n has been fixed, however, trying a code block such as

run begin
python abcd.py
python efgh.py
run finish

results in the command prompt on windows sending a python command to open the file abcd.py\npython instead of running the 2 commands as separate lines.

Possibly omit run blocks from being condensed into one due to issues like this, as well as typical usage scenario in the command prompt/bash shell to be running one line at a time.

@kensoh
Copy link
Member Author

kensoh commented Jun 7, 2018

@Aussiroth nice work!! I'm merging and then committing with some adjustments. Going to keep your 11 commits without squashing in order to not lose the commit details you made as you iterate through to this iteration. As spoken and discussed with @lohvht we will keep run step out of scope for this. Outstanding is the Python indentation, I'll have a look at that.

@kensoh
Copy link
Member Author

kensoh commented Jun 12, 2018

Ok above commits make the indentation works now for py and vision blocks! @Aussiroth have a look when you have time to have some sanity checks to see if edge cases are not covered, and you can close the issue if no problem. fyi @lohvht

I'll assign myself out of the issue for now.

Now cutting edge works for below and for the test py section in positive_test script.

py begin
a = 1
b = 1
if a == 1:
        b = 2
print(b)
py finish
echo py_result

py_result = 0

if (true)
{
        py begin
        a = 1
        b = 1
        if a == 1:
                b = 2
        print(b)
        py finish
}
echo py_result

@kensoh kensoh removed their assignment Jun 12, 2018
@Aussiroth
Copy link
Contributor

I tested a script with a good amount of nested if/for statements and it worked fine, so seems good!

py begin
import math

for i in range (1, 2):
	count = {}
	inStr = "ordeals"
	for i in range(0, len(inStr)):
		curr = inStr[i:i+1]
		if curr in count:
			count[curr] = count[curr] + 1
		else:
			count[curr] = 1
	sol = math.factorial(len(inStr))
	divide = 1;
	for k in count:
		v = count[k]
		if v > 1:
			divide = divide * math.factorial(v)
	print(int(sol//divide))
py finish
echo py_result

Result here is 5040.

@kensoh
Copy link
Member Author

kensoh commented Jun 13, 2018

Cool! Adding on, nested py begin and finish blocks work as well -

py_result = 0
if (true)
{

        py begin
        import math

        for i in range (1, 2):
                count = {}
                inStr = "ordeals"
                for i in range(0, len(inStr)):
                        curr = inStr[i:i+1]
                        if curr in count:
                                count[curr] = count[curr] + 1
                        else:
                                count[curr] = 1
                sol = math.factorial(len(inStr))
                divide = 1;
                for k in count:
                        v = count[k]
                        if v > 1:
                                divide = divide * math.factorial(v)
                print(int(sol//divide))
        py finish
}
echo py_result

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

No branches or pull requests

2 participants