kotlinx / ast

Generic AST parsing library for kotlin multiplatform
Apache License 2.0
325 stars 23 forks source link

Understand the AST #16

Closed eiswind closed 4 years ago

eiswind commented 4 years ago

If I look at

https://github.com/kotlinx/ast/blob/master/grammar-kotlin-parser-test/src/commonMain/resources/testdata/Class.raw.txt

Starting at line 60 I wonder where this complexity comes from until we reach the actual literal at line 75.

Could someone please help me understand that?

drieks commented 4 years ago

Hi @eiswind, please have a look at the grammar file: https://kotlinlang.org/docs/reference/grammar.html#valueArgument

valueArgument is defined there:

valueArgument
  : annotation? (simpleIdentifier '=')? '*'? expression
  ;

So a valueArgument (Line 60 in Class.raw.txt) contains an expression (Line 61).

https://kotlinlang.org/docs/reference/grammar.html#expression Every Expression contains a disjunction (Line 62),

https://kotlinlang.org/docs/reference/grammar.html#disjunction A Disjunction contains a conjunction (Line 63) and so on.

You can use the summary function to remove all stuff that is not required, you can find the result here: https://github.com/kotlinx/ast/blob/master/grammar-kotlin-parser-test/src/commonMain/resources/testdata/Class.summary.txt

eiswind commented 4 years ago

@drieks Thanks for clearing that up!