mk3008 / Carbunql

Carbunql is an advanced Raw SQL editing library.
https://mk3008.github.io/Carbunql/
MIT License
41 stars 4 forks source link

Parse does not work if there is a line comment #341

Closed mk3008 closed 7 months ago

mk3008 commented 7 months ago

sample

with
dat(id) as ( 
    values
    (1)
    --comment
)
select * from dat

result

Carbunql.Analysis.SyntaxException: expect ')', actual 'select'
   at Carbunql.Analysis.ITokenReaderExtension.Read(ITokenReader source, String expect)
   at Carbunql.Analysis.Parser.VirtualTableParser.Parse(ITokenReader r)
   at Carbunql.Analysis.Parser.CommonTableParser.Parse(ITokenReader r)
   at Carbunql.Analysis.Parser.WithClauseParser.ParseCommonTables(ITokenReader r)+MoveNext()
   at System.Collections.Generic.List`1[[Carbunql.Clauses.CommonTable, Carbunql, Version=0.6.1.1, Culture=neutral, PublicKeyToken=null]]..ctor(IEnumerable`1 )
   at System.Linq.Enumerable.ToList[CommonTable](IEnumerable`1 source)
   at Carbunql.Analysis.Parser.WithClauseParser.Parse(ITokenReader r)
   at Carbunql.Analysis.Parser.CTEQueryParser.Parse(ITokenReader r)
   at Carbunql.Analysis.QueryParser.Parse(ITokenReader r)
   at Carbunql.Analysis.QueryParser.Parse(String text)
   at CarbunqlWeb.Pages.Format.OnChange(String value)
mk3008 commented 7 months ago

It is reproduced on the demo site, but not on the main branch. However, we were able to identify suspicious areas.

select 1+--
2

If symbols are used consecutively like this, they will be analyzed like this.

SELECT
     1 +-- 2

Expect the following.

SELECT
     1 + 2
mk3008 commented 7 months ago

The +-- lexeme problem is solved, but the sample code is not.

with
dat(id) as (
     values
     (1)
     --comment
)
select * from dat

I couldn't reproduce it in code, but maybe it's because the line break code isn't recognized correctly? We will continue to respond.

mk3008 commented 7 months ago

Fixed a bug where the end of line comments could not be recognized co… #343