cloudspannerecosystem / memefish

memefish is the foundation to analyze Spanner SQL
https://cloudspannerecosystem.dev/memefish/
MIT License
76 stars 19 forks source link

modify ParseDDL to return nil if query has only comment.(has no idents) #31

Closed nktks closed 3 years ago

nktks commented 3 years ago

Hi!

I use https://github.com/cloudspannerecosystem/yo , and yo use memefish.

I want parse DDL such as

go run ./tools/parse -mode=ddl "# hoge"
2021/06/21 22:37:04 syntax error::1:7: expected token: CREATE, <ident>, but: <eof>

  1:  # hoge
            ^
exit status 1

And I changed parseDDL to return nil if first token kind is token.TokenEOF . Please review this change.

Thanks!

makenowjust commented 3 years ago

After getting this PR merged, a ParseDDLs result will contain nil only when the source has a trailing comment following to the last semicolon. Despite this behavior, an alone semicolon will be rejected by the parser. It seems natural to support an empty statement generally.

Another question I have is "why does it need to treat ParseDDL as special?" It makes more sense to me that ParseQuery and ParseDML do so.

nktks commented 3 years ago

Thanks for your review.

I'll try to use ParseDDLs for my usecase.

nktks commented 3 years ago

I can parse my usecase by using ParseDDLs. So I close this.

Another question I have is "why does it need to treat ParseDDL as special?"

Sorry, there is no reason... I just want to fix my case. yo using strings.Split(schema, ";") for parse multiple ddls in strings. So I'll change yo code.

Thanks.