When I look at the 1.8.2 codebase, I see in:

    ant-1.8.2\src\main\org\apache\tools\ant\taskdefs\MacroDef.java

    /**
     * Check if a character is a valid character for an element or
     * attribute name.
     *
     * @param c the character to check
     * @return true if the character is a letter or digit or '.' or '-'
     *         attribute name
     */
    public static boolean isValidNameCharacter(char c) {
        // ? is there an xml api for this ?
        return Character.isLetterOrDigit(c) || c == '.' || c == '-';
    }

This seems to be at odds with the specification:

    http://www.w3.org/TR/xml/#sec-common-syn


         Names and Tokens

[4] |NameStartChar| ::= |":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]| [4a] |NameChar| ::= |NameStartChar <http://www.w3.org/TR/xml/#NT-NameStartChar> | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]|
[5]     |Name|     ::=  |NameStartChar <http://www.w3.org/TR/xml/#NT-NameStartChar> 
(NameChar <http://www.w3.org/TR/xml/#NT-NameChar>)*|
[6]     |Names|            ::=  |Name <http://www.w3.org/TR/xml/#NT-Name> (#x20 Name 
<http://www.w3.org/TR/xml/#NT-Name>)*|
[7]     |Nmtoken|          ::=  |(NameChar 
<http://www.w3.org/TR/xml/#NT-NameChar>)+|
[8]     |Nmtokens|         ::=  |Nmtoken <http://www.w3.org/TR/xml/#NT-Nmtoken> (#x20 
Nmtoken <http://www.w3.org/TR/xml/#NT-Nmtoken>)*|


I've also looked at:

    ant-1.8.2\src\main\org\apache\tools\ant\taskdefs\AntStructure.java

        /**
         * Does this String match the XML-NMTOKEN production?
         * @param s the string to test
         * @return true if the string matches the XML-NMTOKEN
         */
        public static final boolean isNmtoken(String s) {
            final int length = s.length();
            for (int i = 0; i < length; i++) {
                char c = s.charAt(i);
                // XXX - we are committing CombiningChar and Extender here
                if (!Character.isLetterOrDigit(c)
&& c != '.' && c != '-' && c != '_' && c != ':') {
                    return false;
                }
            }
            return true;
        }

Maybe I'm looking at the wrong part in the code for where *element* names (such as macrodef and scriptdef) are validated and where other names (such as property name="...") are validated. But, the Ant code doesn't match what is specified by the XML BNF. Also, the XML BNF doesn't seem to allow spaces in a *Name* object. Is there an Ant BNF specification that reflects the code?

Is there any formal specification for Ant syntax?  Where do I find it?

Sorry to be a bother!  But, I'm just trying to be very clear in understanding 
Ant and am hoping that a formal specification exists.

Many thanks!
Steve Amerige
SAS Institute, Deployment Software Developer


On 6/30/2011 9:31 AM, Dominique Devienne wrote:
On Thu, Jun 30, 2011 at 6:51 AM, Steve Amerige<steve.amer...@sas.com>  wrote:
I'm looking for the authoritative specification within Ant for the value of
the name attribute as in:

<property name="xxx" .../>
<macrodef name="xxx" ...>
<target name="xxx" ...>

and so forth.  I can't find within the Ant manual any BNF that defines what
a valid name is allowed to be.
Anything goes really, AFAIK. There is no specifications.

Some names will create issues, for example<target name="-foo">  can't
be called from the command line because -foo will be interpreted as a
CLI switch and since not found Ant will error out. This "behavior" is
relied upon to have "private" targets.

Also remember this is XML land, so attribute whitespace normalization
will apply (depending on the parser used possibly) which may result in
some whitespaces being removed.

But aside from these quirks, Ant does not put any restrictions on
names in general. --DD

PS: Also keep in mind that property expansion does occurs inside these
names, but I assume you mean the names after expansion.

Reply via email to