teotigraphix / as3-commons-jasblocks

An ActionScript3 Java DOM for reading and writting ActionScript3 source code
9 stars 6 forks source link

Identifier detection error #1

Open volgar1x opened 11 years ago

volgar1x commented 11 years ago

Hello, I really enjoy your library because it provides a high-level API for reading and editing AS3 code but it fails for some reason to parse a simple statement while. I have never learnt how to use Antlr so I hope you will found where the bug is.

Here is the stacktrace

Caused by: org.as3commons.asblocks.ASBlocksSyntaxError: Unexpected token IDENT at line 72
    at org.as3commons.asblocks.impl.ASTUtils.buildSyntaxException(ASTUtils.java:399)
    at org.as3commons.asblocks.impl.ASTASParser.parseIn(ASTASParser.java:63)
    ... 5 more

And here is the code around the line where the parser fail

output.writeShort(this.aliases.length);
var _i1:uint = 0;
while(_i1<this.aliases.length) // line 72, parser fails here
{
    output.writeUTF(this.aliases[_i1]);
    _i1++;
}

I think Antlr fails to parse the < operator but I don't know how to fix this error by myself. I know you have not committed for a long time but any help will be accepted :D

teotigraphix commented 11 years ago

Hi,

Well actually I still am involved with AS3 and compilers but this one is deprecated so to speak.

It looks like its failing on this for some reason. Try taking that off and see if it works.

while(_i1 < aliases.length) 

Mike

volgar1x commented 11 years ago

I added by myself a IASThisExpression to the dom package (and its implementation of course) so the this keyword might not be the problem here. I edited my previous message while you were writing your comment : I think Antlr fails to parse the < operator.

teotigraphix commented 11 years ago

Hmm, yeah I spent months on that grammar. AS3 is VERY hard language to write a full grammar for.

The problem with < is that we have XML literals in AS3 so there is an ambiguity in the grammar dealing with this.

Although the while statement is such an obvious usecase, I can't not imagine I didn't run into this. I had a full documentor like asdoc running using this framework.

Mike

volgar1x commented 11 years ago

Ok, so how to fix this error ? I can't surround of space all operators of the project I'm working on

teotigraphix commented 11 years ago

I can't surround of space all operator

What does that mean?

As far as fixing this, I am sorry but the only thing you can do is try adjusting the grammar where the ambiguity exists and recompiling the parser and lexer.

I can't do this as I am offering the framework as is right now.

Tell me this, are you using this for only parsing? Or are you using the AST writing to create and edit source code?

Mike

volgar1x commented 11 years ago

I mean that the project I'm currently working on is so big that I can't edit one by one all error of < parsing.

I'm using your framework for only parsing.

teotigraphix commented 11 years ago

Ok well you have another option. Apache Flex's Falcon compiler. I am using this compiler in a HUGE project that cross compiles actionscript to javascript.

https://github.com/RandoriAS/randori-compiler

I wrote that whole compiler. My point is, that framework I am using is nearly perfect with parsing the whole as3 language and has AST and Definition resolution.

You caould actually extend my visitor framework that visits all AST nodes in a file to do the processing you are doing.

Mike

volgar1x commented 11 years ago

I don't know where do I start to look, there is not even a Maven artifact ... Furthermore, the visitor pattern can not solve my problem. I'm looking for a similar API than as3-commons-jasblocks

teotigraphix commented 11 years ago

Ok scratch what i said then since I don't know what you're doing.

Anyway, you are on your own fixing this :)

teotigraphix commented 11 years ago

BTW I plan on porting the AST (edit/create) api eventually using this new parser and compiler.

But that is a ways down the road.

volgar1x commented 11 years ago

Do you know if Falcon has any doc, please ?

I also find this library http://maven.badgers-in-foil.co.uk/sites/metaas/apidocs/index.html, have you forked this project ?