[Logo] smithproject.org
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
Compiler-Error using XmlParse  XML
Forum Index -> Getting Started
Author Message
Dominik



Joined: 21/08/2007 11:04:35
Messages: 3
Offline

Hi all,

i really like the idea of an open source coldfusion server so i just gave it a try on my debian (etch) vm.
i tried some of my/our old cf-apps: the first wont run because heavy usage of "cfexecute" (i noticed afterwards that its not yet supported) and the second application gave me an error when using the return of a function (XmlParse in this case) directly.
i just tried it with XmlParse but i guess its a general parsing error?!

i get a compiler error when trying this:

Code:
 <cfset rawxml = (some raw/text xml data)>
 <cfset xmlroot = XmlParse(rawxml).ROOTELEMENT>
 


this throws a smith error page (error type: compiler) with 2! errors:

[path]/_test.java:24: illegal start of expression
__ctx.getVar(new String[] {com.youngculture.smith.engine.cfutil.FuncLib.XmlParse(SmCast._stringValue("rawxml",)), "ROOTELEMENT",})
^
[path]/_test.java:24: ')' expected
__ctx.getVar(new String[] {com.youngculture.smith.engine.cfutil.FuncLib.XmlParse(SmCast._stringValue("rawxml",)), "ROOTELEMENT",})
 


since its a "compiler" error you even cant catch it with cftry/cfcatch.
the above code will only work if you do it in 2 steps and dont use the XmlParse() return directly:

Code:
 <cfset rawxml = (some raw/text xml data)>
 <cfset xmlroot = XmlParse(rawxml)>
 <cfset xmlroot = xmlroot.ROOTELEMENT>
 


i know this is only a small flaw but the first example runs perfectly with the "original" CF server.
if this (parsing) error affects all functions and not just XmlParse it would be even nicer to have this fixed.

anyways: keep up the good work. i will def. give smith some more tries ;)

regards,
dominik
orcus



Joined: 22/01/2007 16:10:52
Messages: 136
Offline

Hi Dominik,

thanks for your post. I'm checking what's wrong with XmlParse implementation... hope I'll come up with something.

Seems that Smith incorrectly emits list of arguments in generated Java code. There's this additional comma that's causing the problem:

SmCast._stringValue("rawxml",)

At first glance, seems that FunctionCallHandler.getArgTranslation() needs some fixing.

I'm working on it.


Edit:

Cause of this problem traces deep into NameHandler.translate() method which appends a comma to translated output. To avoid breaking other parts of code, the safest way would be to fix the FunctionCallHandler.getArgTranslation() as follows:

Code:
 
 	String currentArgTranslation = translateNode(
 			argsNode.getChild(i)).toString().trim();
 	if (currentArgTranslation.endsWith(",")) {
 		currentArgTranslation = currentArgTranslation.substring(0,
 				currentArgTranslation.length() - 1);
 	}
 

This fix will be included in the next build.
orcus



Joined: 22/01/2007 16:10:52
Messages: 136
Offline

Now, with the compiler-error out of the way, I came to another issue.

Error message: Compile of file "test.cfm" failed with status 1: _test.java: incompatible types
found : com.youngculture.smith.engine.cfutil.xml.XmlDocument
required: java.lang.String
__ctx.getVar(new String[] {com.youngculture.smith.engine.cfutil.FuncLib.XmlParse(SmCast._stringValue("rawxml")), "root",})


Dominik



Joined: 21/08/2007 11:04:35
Messages: 3
Offline

hi orcus,

thanks for the quick response!
i guess you already mentioned it but i gave it another and found out that its really not a problem with XmlParse() but a general parsing problem when working with function-returns in that way.
i tried the following for example:

Code:
 <cffunction name="MyFunc">
     <cfset var ret = StructNew()>
     <cfset ret.someelement = "TEST">
     <cfreturn ret>
 </cffunction>
 
 <cfset test = MyFunc().someelement>
 


this also throws a compiler error:

[path]_test.java:111: incompatible types
found : java.lang.Object
required: java.lang.String
__ctx.getVar(new String[] {__ctx.callFunction(new Object[] {"MyFunc",}, new Object[] {}, 0), "rootelement",})
^
1 error
 


looking forward to test the next build... ;)
dominik
orcus



Joined: 22/01/2007 16:10:52
Messages: 136
Offline

Hi Dominik,

just a few thoughts about the problem...

seems whenever smith encounters this dot notation used to access something inside a structure, all dot-separated items are treated as strings and passed to getVar() method in an array. the first one is looked for as the name of a structure and the following ones as fields / substructures.

I guess when smith is translating the array of strings passed to getVar(), it should check whether the first argument is a string and if it's not, structure should be assigned a temporary name, then this name should be used in the array passed to getVar(), instead of the structure itself.

At the moment, I'm not sure how complicated this would be to implement.



Edit:

I have updated implementation of getVar(), now it gets array of Object instead of array of String, so that first element in the array does not need to be variable name, but can be a structure just as well.

Now the following works:

Code:
  <cffunction name="MyFunc">
      <cfset var ret = StructNew()>
      <cfset ret.someelement = "TEST">
      <cfreturn ret>
  </cffunction>
  
  <cfset test = MyFunc().someelement>
 
  <cfdump var = "#test#" >
 


but unfortunately, if function requires arguments, they are not translated well (at the point of translation, TranslationContext.isVariableContext() should return false for this to work, but it appears to return true). Node processing during translation needs to be fixed somewhere.

Now, the following still does not work because string "rawxml" is passed as an argument to XmlParse() instead of its value: __ctx.getVar("rawxml"):

Code:
  <cfset rawxml = "<rootelement><item><val>X</val></item><item><val>Y</val></item></rootelement>" >
  <cfset xmlroot = XmlParse(rawxml).rootelement>
  
  <cfdump var="#xmlroot#" >
 



This requires some more work...

Calphool



Joined: 18/02/2008 08:49:05
Messages: 29
Offline

FYI Dominik, there's now a patch to provide CFExecute in SourceForge.
 
Forum Index -> Getting Started
Go to:   
Powered by JForum 2.1.6 © JForum Team