![]() ![]() ![]() The token for the "soft keyword" record is "activated" at the key point where we need it and everywhere else, the "record" is simply tokenized as an identifier. Modifiers(EnumSet.of(PUBLIC, PROTECTED, PRIVATE, ABSTRACT, FINAL, STATIC, STRICTFP)) So, the RecordDeclaration, new stable feature in JDK 16 is defined as follows: RecordDeclaration : These token types are turned off by default and turned on at key moments. They are activated at the beginning of the expansion that follows and at the end, the set of active tokens is reset to what it was before.Īt the very top of the grammarfile, we have the option: DEACTIVATE_TOKENS=RSIGNEDSHIFT, RUNSIGNEDSHIFT, RECORD What it means is that in the following expansion, delimited by parentheses, these two tokens are activated. The use of the ACTIVATE_TOKENS is fairly straightforward. Here is how the ShiftExpression construct is implemented in the current Java grammar: ShiftExpression :ĪCTIVATE_TOKENS RSIGNEDSHIFT,RUNSIGNEDSHIFT Well, the easiest way to explain this is with an actual code example. ![]() However, the truth is that it was still a kludge! But now that we can activate and deactivate tokens on an as-needed basis, there is a far more elegant solution. I was quite pleased with the solution I describe there because it was definitely far better than the 3-part kludge that I had been using before that, and way way better than the 5-part kludge that the legacy code used. At first sight, it does not seem like this should be so hard to deal with, but it is surprisingly difficult to find a palatable solution. We need to parse > as two consecutive > tokens, while, in other contexts, the > it does need to be identified a single token. In an earlier article I (rather proudly) outlined my solution (of the time) to a certain rather pesky little problem in Java parsing. It resulted from my rewriting of the lexical code generation that I describe here. The new feature that I describe here, the ability to activate and deactivate tokens is such a case. Sometimes, when you complete a major code cleanup, features that were previously pie in the sky become low-hanging fruit to pluck. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |