Fun with Cold Fusion Regular Expressions

| No Comments

All sorts of languages have Perl-style regexps these days, including ColdFusion. However, that doesn't mean that they're going to be easy to use. I wanted to write a version of XmlFormat (a function that escapes text for use in XML) that would not eat newlines. Pretty simple, no?

Here's the error message I got on my first attempt.

 Missing argument name.
When using named parameters to a function, every parameter must have a name.

 [...]

coldfusion.compiler.CFMLParserBase$MissingNameException: Missing argument name.
	at coldfusion.compiler.cfml40.FunctionParameters(cfml40.java:3374)
	at coldfusion.compiler.cfml40.ComplexReference(cfml40.java:3296)
	at coldfusion.compiler.cfml40.VariableReference(cfml40.java:3262)
	at coldfusion.compiler.cfml40.PrimaryExpression(cfml40.java:3153)
	at coldfusion.compiler.cfml40.UnaryExpression(cfml40.java:3087)
        [and much more of this wonderful stack trace]

Here's the code I was trying to run.

newText = REReplace(text, "\n", "
", "ALL");

U huh. Well it turns out that the parser (or was it really the lexer?) was getting confused by that unguarded hash (#). Normally those are used in ColdFusion to interpolate variables in strings. Okay, but zero marks for clear compiler error messages.

Solution? Double the hash (##).

About this Entry

This page contains a single entry by Christian published on July 28, 2004 5:27 PM.

How to Make a JAR File Not Execute was the previous entry in this blog.

Why I Still Like Perl is the next entry in this blog.

Find recent content on the main index or look in the archive to find all content.