0

I'm using Cayenne to parse SQL conditions, through org.apache.cayenne.exp.parser.ExpressionParser, which produces a series of org.apache.cayenne.exp.parser.Tokens, and I want to determine the type of each Token (like identifier, equal sign, number, string etc.).

The token type is definitely identified by the ExpressionParser, and it seems to me that it is stored in the int field Token.kind. The values that this field shows in my parsing tests are definitely consistent (for ex. = is always 5, literal strings are always 42, and operators are always 2 etc.).

My problem is just that I cannot find the Java class containing the constants to compare Token.kind values with.

The Javadoc for field Token.kind says:

An integer that describes the kind of this token. This numbering system is determined by JavaCCParser, and a table of these numbers is stored in the file ...Constants.java.

It does not specify the full name of the file, so I downloaded JavaCCParser and I checked several *Constants.* files found in javacc-5.0src.zip, javacc-6.0.zip, the two javacc.jar contained in those two zip, and cayenne-3.0.2-src.tar.gz.

None of the classes I found there seems to me to have constants that consistently match the values I see in my tests. The closest I was able to get to that was with class org.apache.cayenne.exp.parser.ExpressionParserConstants which for ex. contains int PROPERTY_PATH = 34 and int SINGLE_QUOTED_STRING = 42 which definitely match the actual tokens of my test expressions, but other tokens have no corresponding constant in that class, for ex. the = sign (kind = 5) and the and operator (kind = 2).

So my question is if anyone knows in which Java class are those constants defined.

4

1 回答 1

1

首先我要提一下,ExpressionParser 旨在解析非常具体的 Cayenne 表达式格式。它当然不能用来解析SQL。所以你可能看错了方向。

Parser 本身就是 JavaCC 基于这个语法文件生成的。解析器的标记在此文件的底部正式定义,并且非常特定于手头的任务。

于 2013-11-05T12:55:09.107 回答