Thomas E Enebo wrote:
On Tue, 25 Apr 2006, Mirko Stocker defenestrated me:
On Tuesday 25 April 2006 19:44, Thomas E Enebo wrote:
We don't and neither does C Ruby. �Our parser is based on theirs and
we both eat comments in the lexing process.
Ok, would it be much work? Could you give me some ideas on how to do it? Unfortunately, I don't have much experience on these things :)

I think this is not real tough to do, but it does have a number of steps:

1. Lexer (RubyYaccLexer) needs a new Token to store CommentToken values.
2. Grammar needs a new production to deal with this token.  I think this
   may be as simple as adding a rule to 'primary' to accept a comment
   token.  I guess I would need to look at it.
3. New Node for ast needs to be made CommentNode
4. NodeVisitor needs new visitCommentNode added.
5. All impls of NodeVisitor need to be updated to support new method:
   with noops  (AbstractNodeVisitor may do it for most of them)

The biggest challenge is determining where in grammar we should accept
the token.  It seems it is possible anywhere we can get a newlineNode.
Off the top of my head, I think primary may be the right place.

We are busy trying to get Rails working by JavaOne, but if I get frustrated
and want to take a break I may add this.  If you want to take a shot at
it then go for it.  The previous steps outlines all tasks neccesary.
I can provide guidance if need be (and teach you how to build grammar
using Jay).

-Tom

Hello

I'm working together with Mirko on the ruby refactoring plugin for Eclipse. At the moment my part in this project is to introduce the comment nodes into jruby. I'm poring over this issue for several hours but I've not been able to succeed.
I followed the steps above:
1. I managed to get the lexer to return a new token: tCOMMENT by changing the case '#' block that jumped the comments . The token contains the position and the content of the comment.

case '#': /* it's a comment */
ISourcePosition startPos = getPosition(null, true);
StringBuffer commentText = new StringBuffer();
commentText.append(c);
while ((c = src.read()) != '\n') {
commentText.append(c);
if (c == EOF) {
break;
}
}
src.unread(c);;
yaccValue = new Token(commentText.toString(), getPosition(startPos, false));
return Tokens.tCOMMENT;

I'm not quite sure whether I understood the mode of operation of the lexer completely but I think this code should return the necessary information about the comment token.


2. This is the point where I'm stuck. I extended the production rule for primary by adding the following line:
| tCOMMENT { $$ = new CommentNode(getPosition($<ISourcePositionHolder>1)); }
In the debugger I can see that the rule is applied but when the parser proceeds the errorFlag gets set with the result of a syntax error. Actually I'm a bit confused about this production rule thing as it's the first time I'm working with it.

3. I've created a new CommentNode class.
4. I've updated the NodeVisitor
5. I've updated the implementations.

Could you support me in constructing the production rules for the comments?


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0709&bid&3057&dat1642
_______________________________________________
Jruby-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jruby-devel

Reply via email to