USING: prettyprint nested-comments formatting accessors arrays assocs calendar combinators fry kernel generalizations io io.streams.string macros math math.functions math.parser peg.ebnf quotations sequences splitting strings unicode.categories unicode.case vectors combinators.smart peg ; IN: scratchpad TUPLE: section name ; :
( str -- section ) >lower section boa ; TUPLE: punctuation name ; : ( str -- punctuation ) punctuation boa ; TUPLE: qualified table column ; : ( table col -- qual ) qualified boa ; TUPLE: comparison name ; : ( str -- comparison ) comparison boa ; EBNF: sql-parts select = ("select"|"SELECT"|"Select") => [[
]] from = ("from"|"FROM"|"From") => [[
]] where = ("where"|"WHERE"|"Where") => [[
]] order = ("order by"|"ORDER BY"|"Order By") => [[
]] group = ("group by"|"GROUP BY"|"Group By") => [[
]] slash = ("/") => [[
]] section = (select|from|where|order|group|slash) period = "." comma = "," comparing = ("=",">","<") full-column = plain-text:a period plain-text:b => [[ a b ]] plain-text = (!("%" | " " | "/" | "." | "," ).)+ => [[ >string ]] puncs = (period|comma) => [[ ]] sp = (" " | "\r" | "\n" | "\t" )+ => [[ drop f ]] text = (section|plain-text|sp|full-column|puncs) texts = text* => [[ sift ]] ;EBNF EBNF: sql-phrases tokenizer = select-part = . ?[ section? ]? => [[ name>> ]] text = . ?[ string? ]? => [[ ]] rule = select-part:a text:b => [[ a b 2array ]] ;EBNF CONSTANT: example-sql " select top 3 acctid as AccountID, acctnum AccountNum, blah 'blah blah blah' from grampa g join son on g.id = son.grampa where g.id < 3 and s.active = 1" example-sql sql-parts . ! example-sql sql-phrases . (* The steps I'm tripping on: 1) sql-phrases doesn't work 2) don't get how to make a rule to keep 'blah blah blah' together 3) some guidance how to group things: I don't understand why full-column rule doesn't grab g.id, for example *)