Syntax.parse() doesn't handle named Parameters properly
Project: | JNode Core |
Component: | Code |
Category: | bug report |
Priority: | normal |
Assigned: | Stephen Crawley |
Status: | closed |
Jump to:
Currently, the Syntax.parse() and Syntax.complete() methods ignore any the Parameter descriptors for named Parameters. As a result "alias -r dir" is misparsed as a request to add an alias called "-r" for a class called "dir".
I strongly suspect that this has never worked. The first checkin for the file had a bunch of commented out code with the following comment:
// TODO: it didn't handle correctly the parameters starting with "-"
I'm currently working on a fix for this. I'm assuming that we want the user to enter a Parameter name as "-name". I'm also assuming that "-name" can be the value of a Parameter, provided that the corresponding Argument's isValidValue says that it is OK. (For example, according to FileArgument "-name" is a valid file name!)
Unfortunately, there is no javadoc on the org.jnode.shell.help.* classes to say what the original implementor(s) intended the behavior to be.
- Login to post comments
#1
Here is a patch that allows Syntax.parse() and Syntax.complete() to handle named Parameters in a Syntax.
The problem is that this enabling named Parameters reveals a previously hidden problem with ambiguous syntaxes. For example, consider the syntaxes for the 'cat' command:
cat -u <URL> ...
cat [ <FileName> ... ]
The command line string "cat -u ftp://foo" can actually be matched against the syntax in two ways. Using the first syntax, "-u" matches the parameter name, and "ftp://foo" matches the URL. Using the second syntax, "-u" and "ftp://foo" match two FileName.
To mitigate this problem, I have tweaked the "visit" code so that an argument starting with a "-" will only match a Parameter name, or an OptionArgument. For cases where the user needs to enter some other Argument that starts with a "-", I have added support for "--" markers as per the GNU command-line option meta-syntax; c.f. getopt.
Incidentally, the current way that syntax system deals with ambiguous Syntaxes is to accept the first Syntax that fully matches the command line arguments when parsing. Unfortunately, completion works differently. It performs completion using all alternative Syntaxes, and then uses the one that results in the longest completion. This behavior is a bit peculiar.
#2
Committed.
#3