Re: Lexical Group problems

Skip to first unread message

Arsène von Wyss

May 8, 2013, 7:35:15 AM5/8/13
Instead of 'AS SELECT' as terminal name, which expects a single, plain space to match, you could probably use a more complex terminal regex, such as 'AS' {Whitepace}+ 'SELECT' {Whitepace}

Happy coding, Arsène

On Sunday, April 28, 2013 2:56:50 PM UTC+2, Neil Anderson wrote:

I'm trying to create a group to capture the query part of CREATE VIEW sql statement, an example is:

CREATE VIEW schema.view AS SELECT 1 col1 FROM dual;

For the application I am working on it is sufficient to capture the text of the SELECT query without checking it is valid etc. So I started with a grammar like this:

{Id Ch Standard}   = {Alphanumeric} + [_#$]
{Id Ch Extended}   = {All Printable} - ['"']
Id = ({Letter}{Id Ch Standard}* | '"'{Id Ch Extended}+'"')
Query Start = 'AS SELECT'
Query End = ';'
Query Block @= { Nesting = All, Advance = Character }

"Start Symbol" = <Grammar>
<Grammar> ::= <Root>

<Root> ::=  <CreateView>
<ObjectName> ::= Id '.' Id
               | Id
<CreateView> ::= CREATE  VIEW <ObjectName>  Query

All seems to work but it requires AS SELECT to be on the same line, a new line between AS and SELECT breaks it. How do I create a group like this where the
whitespace is not important? I believe I have to include the 'AS' keyword because otherwise the Query block would clash with the syntax for GRANTS, ie GRANT SELECT ON schema.table TO user;

Thanks for your help,

Neil Anderson

May 21, 2013, 6:14:25 AM5/21/13
Hi Arsène,

Yes I thought that should work too but it seems that using anything other than a single literal string for the Start and End symbols of a group results in a syntax error (5.2 of the Parser Builder). Does your suggestion work when you try it?

Reply all
Reply to author
0 new messages