-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding experimental online parser #2770
Conversation
a51166b
to
608c3a7
Compare
608c3a7
to
375de5b
Compare
@@ -0,0 +1,2 @@ | |||
export { Parser } from './parser'; | |||
export * from './types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please rename the folder to experimentalOnlineParser
?
export interface LanguageType { | ||
rules: Rules; | ||
} | ||
export interface Rules { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please move Parser specific types into onlineParser.js
?
and rename it to grammarTypes
?
src/language/online-parser/index.js
Outdated
@@ -0,0 +1,2 @@ | |||
export { Parser } from './parser'; | |||
export * from './types'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use explicit exports and expose only parser related types.
@@ -0,0 +1 @@ | |||
export { default } from './rules'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so just remove this file
src/language/online-parser/parser.js
Outdated
export class Parser { | ||
state: ParserState; | ||
lexer: Lexer; | ||
styles: Styles; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please move it to GraphiQL code?
state: ParserState; | ||
lexer: Lexer; | ||
styles: Styles; | ||
config: ParserConfig; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
config: ParserConfig; | |
_config: ParserConfig; |
|
||
export declare class Parser { | ||
state: ParserState; | ||
lexer: Lexer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lexer: Lexer; | |
_lexer: Lexer; |
} from './types'; | ||
|
||
export declare class Parser { | ||
state: ParserState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state: ParserState; | |
_state: ParserState; |
sol(): boolean; | ||
parseToken(): Token; | ||
indentation(): number; | ||
private readonly parseTokenConstraint; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public methods should be grouped together.
src/language/online-parser/parser.js
Outdated
state: ?ParserState, | ||
styles: ?Styles, | ||
config: ?ParserConfigOption, | ||
source: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nono-ptional parameters should go first.
src/language/online-parser/parser.js
Outdated
styles, | ||
config, | ||
source, | ||
}: {| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please convert to positional arguments?
especially since we need to remove styles.
[name: string]: GraphQLGrammarRule; | ||
} | ||
|
||
export declare type GraphQLGrammarRule = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove declare
.
@@ -0,0 +1,76 @@ | |||
// @flow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove these lines in all files
@@ -0,0 +1,938 @@ | |||
{ | |||
"rules": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove rules
wrapper.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it triggers a coverage check please add necessary files to list of excluded files inside .nycrc
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll update.
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.