Parse error: Muliple annotations with line comment
See original GitHub issueThat code can not be parsed:
@Suppress("unused") //
@JsName("daName")
fun myname(){
....
If the both annotations are switched, it works just fine.
–> The exception occurs if:
- there are two annotations
- there is a line comment between these two annotations
Stack trace: ` ava.lang.IllegalStateException: Unrecognized modifier: // public API
at kastree.ast.psi.Converter$convertModifiers$1.invoke(Converter.kt:367)
at kastree.ast.psi.Converter$convertModifiers$1.invoke(Converter.kt:16)
at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:172)
at kotlin.sequences.FilteringSequence$iterator$1.calcNext(Sequences.kt:132)
at kotlin.sequences.FilteringSequence$iterator$1.hasNext(Sequences.kt:156)
at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:702)
at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:732)
at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:723)
at kastree.ast.psi.Converter.convertModifiers(Converter.kt:371)
at kastree.ast.psi.Converter.convertModifiers(Converter.kt:350)
at kastree.ast.psi.Converter.convertFunc(Converter.kt:304)
at kastree.ast.psi.Converter.convertDecl(Converter.kt:195)
at kastree.ast.psi.Converter.convertFile(Converter.kt:293)
at kastree.ast.psi.Parser.parseFile(Parser.kt:23)
at kastree.ast.psi.Parser.parseFile$default(Parser.kt:23)
`
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
"Multiple annotations found at this line" - Stack Overflow
Multiple annotations found at this line: - error: Error parsing XML: not well-formed (invalid token) - The value of attribute "android:text" ...
Read more >175193 – "Multiple annotations found at this line" error ... - Bugs
Bug 175193 - "Multiple annotations found at this line" error, even when syntax ... You need to log in before you can comment...
Read more >Support multi-line # type: comments for functions #1102 - GitHub
The code works by converting Python 2.7 per-argument type comments to Python 3 annotations in the typed_ast's conversion module -- this allows ...
Read more >What is the correct annotation syntax in Polyspace Bug Finder ...
I talked with a field application engineer for Polyspace and they confirmed that multi-line annotations are not valid with the current releases of...
Read more >Appendix: YAML Techniques - Helm
Folded Multi-line Strings. Sometimes you want to represent a string in your YAML with multiple lines, but want it to be treated as...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@drieks Now the parsing of “escaped” values in annotations work, but I have found another issue. It does not belong here, so I created a new issue in your repo https://github.com/kotlinx/ast/issues/1
@cretz I still prefer your parser, especially its speed, and it handles everything I have thrown at it except for the comments after annotations. Thank you for this library.
Hi @martinflorek,
maybe my Kotlin parsing library can help you: https://github.com/kotlinx/ast
It is a generic AST parsing library, Kotlin is currently the only supported language. The library is designed that other languages can be easily added. kotlinx.ast does not use the kotlin compiler for paring, it is using ANTLR (the kotlin variant https://github.com/Strumenta/antlr-kotlin) using the official kotlin grammer (https://kotlinlang.org/docs/reference/grammar.html)
One Component is “Klass”, a collection of language independent data classes used to represent and easily access the AST.
Your example code will be parsed fine: https://github.com/kotlinx/ast/commit/d4da88af8bdbcc9d4b5f2a125ee0b985301905e0
using kotlin code, this is:
There are some parts missing, for example the importList is not converted into an easy-to-use data class. But I’m already using the library for AST parsing. You can just open the project in IDEA or run
./gradlew clean check publishToMavenLocal
if you want to use it locally.Please let me know if you have any questions, or just open an issue 😃