Grammar-Kit | Grammar files support & parser/PSI generation for IntelliJ IDEA
kandi X-RAY | Grammar-Kit Summary
kandi X-RAY | Grammar-Kit Summary
See [Parsing Expression Grammar (PEG)] for basic syntax. Use ::= for ← symbol. You can also use [ .. ] for optional sequences and { | | } for choices as these variants are popular in real-world grammars. Grammar-Kit source code is the main example of Grammar-Kit application. The grammar for BNF parser and PSI generation can be found [here] grammars/Grammar.bnf).
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Match tokens
- ResolveESCHAR
- Getter for STRING
- Compress a comment
- Advances to the next regular expression
- Reports an error
- Dumps a grammar file
- Main entry point
- Gets the languages to inject
- Collects all options of a file
- Performs the actual saving
- Collect all navigation marker information
- Return a list of keywords for a given position
- Generates the runnable
- Resolves the block
- Calculate the attribute values
- Display the PSI file
- An annotate pn element
- Builds a template and runs it
- Adds information about a psi element
- Suggest keywords for a given position
- Generates lexer text for lexer
- Reads a file
- Accept a visitor for a reference
- Generate the HTML documentation
- Checks for problems
Grammar-Kit Key Features
Grammar-Kit Examples and Code Snippets
Community Discussions
Trending Discussions on Grammar-Kit
QUESTION
I'm working on IntelliJ support for a DSL using the Grammar-Kit. I have a rule in the bnf file which requires an EOF (end of file) token at the end:
rule ::= ( object | (( LCURL EOL* properties EOL* RCURL ) | properties ) ) EOL* EOF
I assumed I can simpy create a lexer rule in the flex file <> { return EOF;}
and that's it..
Unfortunately somewhere deeper in the IntelliJ code the logic which handles lexer's advance()
method does not finish unless it gets a null from the lexer causing an infinite loop as the end of file returns a not-null token.
Is there any elegant (simple) way to handle an End Of File in the Grammar-Kit allowing the 'end of file' to be used in the Parser definition (the bnf)?
...ANSWER
Answered 2019-Jun-10 at 12:24In the end I've simply put an adapter between the generated lexer and its consumer which replaces functionality of the lexer's advance() method. If the EOF has been reached then the next time it will return null. Something like this:
QUESTION
Is there a way to do a negative lookahead in Grammar-kit?
Example: I have two tokens defined A and B and would like the define the a rule that matches A if it is not followed by B.
I tried to find it in this grammar, but I am not able to read it.
...ANSWER
Answered 2017-Aug-26 at 22:51Grammar-Kit is based on PEG (Parsing Expression Grammars).
- Positive lookahead:
&XXX
- Negative lookahead:
!XXX
QUESTION
From the documentation provided for grammar-kit, I cannot figure out how I am supposed to correctly handle something like comments. My lexer currently returns TokenType.WHITE_SPACE
for any comment blocks, but then no unique IElementType
is generated for me to do syntax highlighting on.
If I create an IElementType
and tell flex to return that for comments, I can perform syntax highlighting, but then that token is not a part of my language spec in the BNF, and so it is considered invalid.
What is the correct way to pass comments through as white space, but perform syntax highlighting on them in Intellij/grammar-kit/jflex?
...ANSWER
Answered 2017-May-19 at 13:05You can use Grammar-Kit implementation as a reference:
Using TokenType.WHITE_SPACE
for comments is a bad idea.
More details can be found here.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install Grammar-Kit
You can use Grammar-Kit like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the Grammar-Kit component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page