Skip to content

Auto script - #34

Open
TaeSeanDo wants to merge 5 commits into
masterfrom
auto-script
Open

Auto script#34
TaeSeanDo wants to merge 5 commits into
masterfrom
auto-script

Conversation

@TaeSeanDo

Copy link
Copy Markdown
Contributor

No description provided.

@TaeSeanDo

Copy link
Copy Markdown
Contributor Author

I just have 1 question: For MissionScript, why does parenSplit split at '\(' and not '('?
Other than that, the code looks good.

@docprofsky

Copy link
Copy Markdown
Member

This is because String.split() uses a regular expression to determine where to split the string. A \ is used to escape special characters, such as (. When defining a string, a \ is used to insert special characters (\n for newline). To place a \ in a string, \\ has to be typed.

http://stackoverflow.com/questions/3481828/how-to-split-a-string-in-java/3481842#3481842

@RiverApril

Copy link
Copy Markdown

Oh maybe we should have it split on a semicolon instead of a new line so you could write multiple on a single line.

@docprofsky

Copy link
Copy Markdown
Member

How about a semicolon or a newline? I do not think we have much of a need for multiple statements on one line and I do not want to require semicolons for this.

@RiverApril

Copy link
Copy Markdown

Okay sounds good, feel free to make the change, or let me know if I should.

@docprofsky

Copy link
Copy Markdown
Member

I think it is fine without semicolons.

@docprofsky

Copy link
Copy Markdown
Member

Having a comment on a blank line breaks the parser.

@docprofsky

Copy link
Copy Markdown
Member

I think the best way to fix the comment without a preceding function function on that line is to use the presence of a ( to determine if there is a function on the part of the line before the comment (if present).

@RiverApril

Copy link
Copy Markdown

Where does it break? I think you could fix it by checking if the line starts with // before line 12. I'm guessing it's trying to parse the comment?

@docprofsky

Copy link
Copy Markdown
Member

No, it breaks because there is no open parenthesis on that line.

This is because the SmartDashboard does not
support typing newlines in a text field
@docprofsky

Copy link
Copy Markdown
Member

I have fixed the blank line issue.

@RiverApril

Copy link
Copy Markdown

Oh okay sorry, yes you're right.

return null;
}

if(!(returnValue instanceof Command)){

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Instead of checking what is returned, we should check the function signature. This can be done with getReturnType().

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Having done more research, I think the best way is to use instanceof Command. By using instanceof Command, a subclass of Command will also be accepted. Also, null instanceof T is always false [1], so we can remove the null check.

[1]: http://stackoverflow.com/a/7313605

} catch (NumberFormatException e) {
System.err.println("Failed to parse parameter as boolean or double: \""
+ parameter + "\"");
return null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should throw an exception here.
A ParseException or rethrowing the NumberFormatException is probably appropriate.

} else {
System.err.format("Too many opening parentheses in line %d: \"%s\"", lineIndex + 1,
lineWithoutComment);
return null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here is also a good place to throw an excerption.
Probably a ParseException.


} catch (NoSuchMethodException e) {
System.err.println("Failed to find method: " + signature + "");
return null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here is also a good place to throw an excerption.
Probably a ParseException, or maybe an IllegalArgumentException.

@docprofsky
docprofsky requested a review from RiverApril April 1, 2017 19:25
@docprofsky

Copy link
Copy Markdown
Member

@nedearb Can you review this, specifically the exceptions.

@RiverApril

Copy link
Copy Markdown

Looks fine, but have you tested it?

@docprofsky
docprofsky removed the request for review from RiverApril April 1, 2017 20:00

@RiverApril RiverApril left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good

@docprofsky

Copy link
Copy Markdown
Member

A better way of integrating the MissionScript parser with our missions is to make a ScriptMission that extends Mission. The ScriptMission would take a filename which it parse to generate its mission. The ScriptMission could reload the mission every time it is run or have a separate way of triggering it to reload its mission.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants