Can you provide a SpEL expression grammar file for antlr4 as known as SpringExpression.g4
?
Comment From: superdc
@sbrannen need help
Comment From: sbrannen
I am not aware of any formal grammar file for SpEL.
@aclement, please correct me if I'm wrong about that.
Comment From: superdc
@snicoll can you provide a spring expression language grammer file(https://github.com/spring-projects/spring-framework/blob/main/spring-expression/src/main/resources/org/springframework/expression/spel/generated/SpringExpressions.g) of anltr4,the grammer of this version is not suitable for antlr4
Comment From: sbrannen
The grammar file has apparently been around for a long time (unmodified):
https://github.com/spring-projects/spring-framework/blob/3.2.x/spring-expression/src/main/java/org/springframework/expression/spel/generated/SpringExpressions.g
Reopening to allow @aclement to elaborate on where SpringExpressions.g
came from.
Comment From: sbrannen
As explained in commit da112a7ea82fee786a309f24baeda57d15478ff7:
The antlr-based SpEL expression grammar file (
SpringExpressions.g
) was introduced during initial development and prototyping of the Spring Expression language; however, it was quickly abandoned in favor of a handcrafted implementation. Consequently, it has become obsolete over time and has never been actively maintained.
Since the grammar file is not used with the Spring Framework itself, the team has no plans to maintain it or release a new version compatible with later versions of antlr.
In light of that, I have repurposed this issue to remove the obsolete SpEL expression grammar file.
Comment From: superdc
As explained in commit da112a7:
The antlr-based SpEL expression grammar file (
SpringExpressions.g
) was introduced during initial development and prototyping of the Spring Expression language; however, it was quickly abandoned in favor of a handcrafted implementation. Consequently, it has become obsolete over time and has never been actively maintained.Since the grammar file is not used with the Spring Framework itself, the team has no plans to maintain it or release a new version compatible with later versions of antlr.
In light of that, I have repurposed this issue to remove the obsolete SpEL expression grammar file.
@sbrannen So now SpEL is not antlr-based,right?parser and lexer are produced by handcraft?
Comment From: sbrannen
@sbrannen So now SpEL is not antlr-based,right?parser and lexer are produced by handcraft?
That's correct.
Take a look at org.springframework.expression.spel.standard.InternalSpelExpressionParser
and the types in the org.springframework.expression.spel.ast
package for details.
Comment From: superdc
@sbrannen So now SpEL is not antlr-based,right?parser and lexer are produced by handcraft?
That's correct.
Take a look at
org.springframework.expression.spel.standard.InternalSpelExpressionParser
and the types in theorg.springframework.expression.spel.ast
package for details.
@sbrannen Can I know the reasons why SpEL turns into not antlr-based?We want to parse SpEL in frontend and construct our custom ast tree. One method is used antlr4 to generate parser, lexer and visitor,but now this method looks impractical.
Comment From: sbrannen
Can I know the reasons why SpEL turns into not antlr-based?
I was not the original developer of the Spring Expression language, but as far as I understand, using antlr turned out to be too cumbersome. Thus, the original developer, @aclement, decided it would be easier to handcraft the support.
Comment From: deanmaster
hello @sbrannen we have intention to build tooling support for projects to expresison their own needs in more friendly and controllable way.
- Using antlr4 would help a lot since it can support code completion from many platforms.
- If you don't use it any suggestion for testing a dedicate expression if it's working ? from unit test point of view.
Thanks a lot, Tuan Do
Comment From: sbrannen
If you don't use it any suggestion for testing a dedicate expression if it's working ? from unit test point of view.
You can use the tests in our test suite for inspiration -- for example, any of the tests in src/test/java
in the spring-expression
project, in particular EvaluationTests
.
Comment From: deanmaster
hello @sbrannen ,
Currently i'm implementation an autocompletion for SpEl in our project. Do you know how can I "extracted" from existing code? Or I have to manually create the grammar on my own ? Because everything in the package org.springframework.expression are basically java form which can't convert to any syntax which can be used to return as autocompletion suggestion.
Any suggestions are really helpful for me.
Thanks, Tuan Do
Comment From: sbrannen
Hi @deanmaster,
Do you know how can I "extracted" from existing code?
I doubt there is any way to extract the grammar automatically from the code, since the lexing and parsing is now handwritten.
The classes you'll need to look at are Tokenizer
, TokenKind
, and InternalSpelExpressionParser
in the org.springframework.expression.spel.standard
package.
Those classes sometimes refer to the original antlr grammar in comments.
Or I have to manually create the grammar on my own ?
Yes, I think you'll basically have to create your own grammar from scratch, but you can probably use the original antlr grammar as a starting point.
Comment From: deanmaster
thanks @sbrannen
I successfully migrated the original antlr grammar. Thanks for pointing to those classes I will have a look.
Comment From: jakeboone02
@deanmaster I was curious if you've made any significant progress with your antlr4 grammar. I'd be willing to pitch in if you want help; I have a use case in my react-querybuilder
project where I'm currently using spel2js
(an old JavaScript port) but would like to move to a static grammar file.
Comment From: deanmaster
@jakeboone02 i'm able to convert the grammar file to latest v4 ANTLR but obviously it does not reflects newest "java syntax" with current version of SpEl. We are pending this topic for now. In the future when i'm able to complete the grammarfile I can share it here