Open meteorquake opened 6 months ago
Extra note to this, 'As' can also be used in some SQL for casting (e.g. MySql) -
CAST(expression AS newtype)
So the 'As' referred to here should not be within function brackets.
I think that can be computed by starting a new bracket count when a Select keyword is encountered.
So in this example
Select * From (
Select *, val*prob AS valprob, Cast(age AS int) From table
Where Cast(age as int)<50
) tblalias
the first bracket ups the bracket count to 1 but the second 'Select' then pushes the bracket count on a select-stack and restarts the bracket count at 0, and when it closes off (brackets becoming 0, at ") tblalias" there) the select-stack is popped to get the prior bracket count (as 1, immediately reduced to 0 by the bracket) and continues... this distinguishes function brackets from subquery brackets.
However it might be simpler just to colour the word-phrase after every As but watch for the word Cast and when As occurs within Cast() don't colour the word-phrase that follows the As within it. The advantage of the more complex method is that it can be used to colour table aliases implied without any 'As' (the tblalias in the example, which is short for As tblalias). However I think the main utility is for highlighting calculated field names and if people want it to be used for table aliases too they just need to include the table alias 'As'.
Thanks for all the updates since I last posted!
For SQL, I wonder how easy it would be to add a colour option for the phrase after an "As" clause, as this would highlight the alias name of user-defined fields. It would make life vastly easier in long SQL statements to have those names stand out. So e.g.
would all highlight the fullname/full name (the delimiters could be highlighted or not, probably not)
In the case of the From, the As is optional but I think if simplicity is required the As could trigger it, though it wouldn't be too hard to spot an implied table-type As So e.g. -
etc
Cheers, David