简体   繁体   English

JFlex中可以继承吗?

[英]Is inheritance possible in JFlex?

I'm fairly new to JFlex and JSyntaxPane although I have managed to hack together a lexer for XPath . 我对JFlex和JSyntaxPane相当陌生,尽管我设法为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. 我发现自己遇到的问题是,我正在开发一个项目,该项目支持具有一些专有功能的XPath的子集。 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. 如果这是一个常规的Java问题,我将转向继承,但是通过让一个词法分析器扩展先前生成的词法分析器来实现继承似乎是不可能的。

eg 例如

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? 这是JSyntaxpane中DefaultJFlexLexer特有的问题,还是我做错了? Has anyone been in a similar situation and found a way to achieve some kind of ad hoc inheritance in a bunch of lexers? 有没有人遇到过类似的情况,并且找到了在大量词法分析器中实现某种即席继承的方法?

JFlex generates several final methods, hence the errors. JFlex生成了几种最终方法,因此产生了错误。 I can think of two possible workarounds: 我可以想到两种可能的解决方法:

  1. Simply copy the rules from XPathLexer into ProprietaryLexer and extend them as necessary. 只需将规则从XPathLexer复制到ProprietaryLexer并根据需要扩展它们。
  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. 但是,如果JFlex具有%inherit命令,那肯定会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM