Adding experimental online parser#2770
Conversation
a51166b to
608c3a7
Compare
| @@ -0,0 +1,2 @@ | |||
| export { Parser } from './parser'; | |||
| export * from './types'; | |||
There was a problem hiding this comment.
Can you please rename the folder to experimentalOnlineParser?
| export interface LanguageType { | ||
| rules: Rules; | ||
| } | ||
| export interface Rules { |
There was a problem hiding this comment.
Can you add GraphQLGrammar prefix to types for JSON ruleset?
| export declare type Styles = { | ||
| [name: string]: string; | ||
| }; | ||
| export declare type ParserConfig = { |
There was a problem hiding this comment.
For types related to parser can you please use OnlineParser prefix?
| export declare type ParserConfig = { | ||
| tabSize: number; | ||
| }; | ||
| export declare type ParserConfigOption = { |
There was a problem hiding this comment.
Can you please move Parser specific types into onlineParser.js?
and rename it to grammarTypes?
| @@ -0,0 +1,2 @@ | |||
| export { Parser } from './parser'; | |||
| export * from './types'; | |||
There was a problem hiding this comment.
Please use explicit exports and expose only parser related types.
| @@ -0,0 +1 @@ | |||
| export { default } from './rules'; | |||
| export class Parser { | ||
| state: ParserState; | ||
| lexer: Lexer; | ||
| styles: Styles; |
There was a problem hiding this comment.
Can you please move it to GraphiQL code?
| state: ParserState; | ||
| lexer: Lexer; | ||
| styles: Styles; | ||
| config: ParserConfig; |
There was a problem hiding this comment.
| config: ParserConfig; | |
| _config: ParserConfig; |
|
|
||
| export declare class Parser { | ||
| state: ParserState; | ||
| lexer: Lexer; |
There was a problem hiding this comment.
| lexer: Lexer; | |
| _lexer: Lexer; |
| } from './types'; | ||
|
|
||
| export declare class Parser { | ||
| state: ParserState; |
There was a problem hiding this comment.
| state: ParserState; | |
| _state: ParserState; |
| sol(): boolean; | ||
| parseToken(): Token; | ||
| indentation(): number; | ||
| private readonly parseTokenConstraint; |
There was a problem hiding this comment.
Can you please rename them and add just add underscore?
| private readonly getNextRule; | ||
| private readonly popMatchedRule; | ||
| private readonly rollbackRule; | ||
| pushRule( |
There was a problem hiding this comment.
public methods should be grouped together.
| state: ?ParserState, | ||
| styles: ?Styles, | ||
| config: ?ParserConfigOption, | ||
| source: string, |
There was a problem hiding this comment.
Nono-ptional parameters should go first.
| styles, | ||
| config, | ||
| source, | ||
| }: {| |
There was a problem hiding this comment.
Can you please convert to positional arguments?
especially since we need to remove styles.
| [name: string]: GraphQLGrammarRule; | ||
| } | ||
|
|
||
| export declare type GraphQLGrammarRule = |
| @@ -0,0 +1,76 @@ | |||
| // @flow | |||
There was a problem hiding this comment.
Please remove these lines in all files
| @@ -0,0 +1,938 @@ | |||
| { | |||
| "rules": { | |||
There was a problem hiding this comment.
Please remove rules wrapper.
There was a problem hiding this comment.
We might want to integrate this with ast later on or many include lex rules. So that is why I nested it.
There was a problem hiding this comment.
@hereisnaman In this case rules and lexerRules would be confusing so we would need to rename it anyway.
It's a not a stable API so we can always introduce wrapper latter if needed.
| @@ -0,0 +1,936 @@ | |||
| { | |||
There was a problem hiding this comment.
It looks like Deno doesn't support importing JSON:
denoland/deno#5633
Can you please convert it to rules.js and also merge it with grammarTypes.js?
On the plus side, we would be able to type-check rules content with TS.
Also please name the resulting file grammar.js.
There was a problem hiding this comment.
If it triggers a coverage check please add necessary files to list of excluded files inside .nycrc.
eba0adb to
4bfd46e
Compare
4bfd46e to
6b10dbe
Compare
This PR includes implementation of an experimental online parser based on JSON rules set. This parser can be used with IDEs to implement syntax highlighting and auto suggestions. It is a state-full parser which parser the source string incrementally i.e. emits the next token each time.