Skip to content
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

Support comments in schema #3133

Merged
merged 5 commits into from Mar 14, 2019
Merged

Conversation

srfrog
Copy link
Contributor

@srfrog srfrog commented Mar 13, 2019

This PR adds support for comments in schemas. Comments begin with # and end with new line or when EOF is reached. A schema with only comments is treated as a no-op.

Example:

#
# This is a comment
#
user: bool .
user.name: string @index(exact) . # this should be unique
user.email: string @index(exact) . # this should be unique and lower-cased
user.password: password .
user.code: string . # for password recovery (can be null)
node: bool .
node.hashid: string @index(exact) . # @username/hashid
node.owner: uid @reverse . # (can be null)
node.parent: uid . # [uid] (use facet)
node.xdata: string . # store custom json data
#
# End of test
#

Example with type system:

# User is a service user
type User {
   # TODO: add more fields
   Name: string # e.g., srfrog
                # expanded comment
                # embedded # comments # here
}
# /User

Closes #3130


This change is Reviewable

srfrog added 3 commits March 13, 2019 13:08
This adds comment detection to lexer. A comment starts with # and ends with
new line or EOF. When new line is detected, it's emitted so the caller can handle it.
If EOF is found, that should end further parsing.
@srfrog srfrog requested a review from a team March 13, 2019 20:17
Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @srfrog)


schema/state.go, line 111 at r1 (raw file):

// lexComment lexes a comment text.
func lexComment(l *lex.Lexer) lex.StateFn {

There's another func like this in gql/state.go. Can you move that func within lex pkg, and use that in both places?

Copy link
Contributor Author

@srfrog srfrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 3 files reviewed, 1 unresolved discussion (waiting on @manishrjain)


schema/state.go, line 111 at r1 (raw file):

Previously, manishrjain (Manish R Jain) wrote…

There's another func like this in gql/state.go. Can you move that func within lex pkg, and use that in both places?

They are named the same but don't work the same. This one is specific to schema lexText function and needs newlines emitted. I will rename this one to lexTextComment to remove ambiguity.

Package gql has another function called lexComment that works slightly
different to this one, so I renamed this one to avoid confusion.
Copy link
Contributor

@manishrjain manishrjain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Thanks for taking care of this quickly.

Reviewed 2 of 3 files at r1, 1 of 1 files at r2.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @manishrjain)

@srfrog srfrog merged commit 17435ef into master Mar 14, 2019
@srfrog srfrog deleted the srfrog/issue-3130_comments_in_schema branch March 14, 2019 03:26
dna2github pushed a commit to dna2fork/dgraph that referenced this pull request Jul 19, 2019
* schema/state.go: add comment state to lexer

This adds comment detection to lexer. A comment starts with # and ends with
new line or EOF. When new line is detected, it's emitted so the caller can handle it.
If EOF is found, that should end further parsing.

* schema/parse_test.go: add test for comments in schema types

* gql/parser.go: fixed typo

* schema/state.go: rename func lexComment to lexTextComment

Package gql has another function called lexComment that works slightly
different to this one, so I renamed this one to avoid confusion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants