JetBrains / Grammar-Kit

Grammar files support & parser/PSI generation for IntelliJ IDEA
Other
715 stars 125 forks source link

How to write parser manually without using grammar-ki #356

Closed alamhubb closed 9 months ago

alamhubb commented 9 months ago

How to write parser manually without using grammar-kit? Are there any relevant examples?

https://plugins.jetbrains.com/docs/intellij/implementing-parser-and-psi.html#parser-implementation

image

YannCebron commented 9 months ago

There might still be some but it's not trivial to locate them in OSS plugins. In IntelliJ IDEA, Java plugin still uses manually written parser.

alamhubb commented 9 months ago

There might still be some but it's not trivial to locate them in OSS plugins. In IntelliJ IDEA, Java plugin still uses manually written parser.

Thanks, but I didn’t find the Java plugin repository in github that you mentioned. Could you please paste its github address or other url link? I searched for java in the idea and only found these, but not the java plugin.

image

YannCebron commented 9 months ago

See java/java-psi-impl/src/com/intellij/lang/java/parser/

alamhubb commented 9 months ago

See java/java-psi-impl/src/com/intellij/lang/java/parser/

very thanks

gregsh commented 9 months ago

As you can see Grammar-Kit parsers mostly look like ordinary, recursive-descend, hand-written parsers.

Differences:

  1. The structure is more regular
  2. Error recovery is extracted to GeneratedParserUtilBase.
YannCebron commented 9 months ago

Two more: https://github.com/JetBrains/intellij-community/tree/idea/233.13135.103/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertiesParser.java (very simple) https://github.com/JetBrains/intellij-community/blob/idea/233.13135.103/RegExpSupport/src/org/intellij/lang/regexp/RegExpParser.java (more complex)

alamhubb commented 9 months ago

Two more: https://github.com/JetBrains/intellij-community/tree/idea/233.13135.103/plugins/properties/properties-psi-impl/src/com/intellij/lang/properties/parsing/PropertiesParser.java (very simple) https://github.com/JetBrains/intellij-community/blob/idea/233.13135.103/RegExpSupport/src/org/intellij/lang/regexp/RegExpParser.java (more complex)

thanks very much,I will study hard