views:

93

answers:

1

I'm fairly new to JFlex and JSyntaxPane although I have managed to hack together a lexer for XPath.

The problem I find myself in is that I'm working on a project that supports a subset of XPath with a few proprietary features. Nasty I know.

If this were a regular Java problem I'd turn to inheritance but it doesn't seem possible to achieve inheritance by having one lexer extend a previously generated one.

e.g

import jsyntaxpane.Token;
import jsyntaxpane.TokenType;

%% 

%public
%class ProprietaryLexer
%extends XPathLexer
%unicode
%char
%type Token

This seems to cause a load of errors telling me I can't extend some final methods. Is this a problem specific to the DefaultJFlexLexer in JSyntaxpane or am I just doing it wrong? Has anyone been in a similar situation and found a way to achieve some kind of ad hoc inheritance in a bunch of lexers?

+1  A: 

JFlex generates several final methods, hence the errors. I can think of two possible workarounds:

  1. Simply copy the rules from XPathLexer into ProprietaryLexer and extend them as necessary.
  2. (dangerous) Modify the skeleton file to not have final methods, then proceed as you were doing. I have never attempted this, so I can't guarantee that it will even compile.

It would certainly be nice if JFlex had an %inherit command, though.

Michael Myers
I flagged this as the answer because I ended up doing option 1. It's not ideal but I looks like these lexers haven't needed much maintenance so it is an acceptable compromise.
Tom Martin