Skip to content

Commit

Permalink
Merge pull request #91 from bruce-dunwiddie/develop
Browse files Browse the repository at this point in the history
Fixed argument parsing for CAST function
  • Loading branch information
bruce-dunwiddie authored May 6, 2022
2 parents 4ae590d + c1cf197 commit a7c7d87
Show file tree
Hide file tree
Showing 22 changed files with 647 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Text;

using TSQL.Tokens;
using TSQL.Tokens.Parsers;

namespace TSQL.Clauses.Parsers
{
Expand Down Expand Up @@ -43,6 +44,10 @@ public TSQLOptionClause Parse(ITSQLTokenizer tokenizer)
tokenizer.MoveNext();
}

TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
option);

return option;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using TSQL.Statements;
using TSQL.Statements.Parsers;
using TSQL.Tokens;
using TSQL.Tokens.Parsers;

namespace TSQL.Clauses.Parsers
{
Expand All @@ -22,8 +23,11 @@ public TSQLSetOperatorClause Parse(ITSQLTokenizer tokenizer)

set.Tokens.Add(tokenizer.Current);

if (tokenizer.MoveNext() &&
tokenizer.Current.IsKeyword(TSQLKeywords.ALL))
TSQLTokenParserHelper.ReadThroughAnyCommentsOrWhitespace(
tokenizer,
set.Tokens);

if (tokenizer.Current.IsKeyword(TSQLKeywords.ALL))
{
set.Tokens.Add(tokenizer.Current);

Expand All @@ -47,6 +51,10 @@ public TSQLSetOperatorClause Parse(ITSQLTokenizer tokenizer)
tokenizer.MoveNext();
}

TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
set);

int level = 0;

while (tokenizer.Current.IsCharacter(TSQLCharacters.OpenParentheses))
Expand All @@ -58,6 +66,10 @@ public TSQLSetOperatorClause Parse(ITSQLTokenizer tokenizer)
tokenizer.MoveNext();
}

TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
set);

TSQLSelectStatement select = new TSQLLimitedSelectStatementParser(tokenizer).Parse();

set.Select = select;
Expand All @@ -73,6 +85,10 @@ public TSQLSetOperatorClause Parse(ITSQLTokenizer tokenizer)
tokenizer.MoveNext();
}

TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
set);

return set;
}
}
Expand Down
37 changes: 13 additions & 24 deletions TSQL_Parser/TSQL_Parser/Elements/Parsers/TSQLSelectColumnParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using TSQL.Expressions;
using TSQL.Expressions.Parsers;
using TSQL.Tokens;
using TSQL.Tokens.Parsers;

namespace TSQL.Elements.Parsers
{
Expand All @@ -22,17 +23,9 @@ public TSQLSelectColumn Parse(ITSQLTokenizer tokenizer)

column.Tokens.AddRange(columnExpression.Tokens);

while (
tokenizer.Current != null &&
(
tokenizer.Current.IsWhitespace() ||
tokenizer.Current.IsComment())
)
{
column.Tokens.Add(tokenizer.Current);

tokenizer.MoveNext();
}
TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
column);

// check for operator =, when expression type is column, and return new column expression with alias
// e.g. IsFinishedGoods = p.FinishedGoodsFlag
Expand All @@ -57,32 +50,28 @@ public TSQLSelectColumn Parse(ITSQLTokenizer tokenizer)
}
else
{
if (
tokenizer.Current != null &&
tokenizer.Current.IsKeyword(TSQLKeywords.AS))
if (tokenizer.Current.IsKeyword(TSQLKeywords.AS))
{
column.Tokens.Add(tokenizer.Current);

tokenizer.MoveNext();

while (
tokenizer.Current.IsWhitespace() ||
tokenizer.Current.IsComment())
{
column.Tokens.Add(tokenizer.Current);

tokenizer.MoveNext();
}
TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
column);
}

if (tokenizer.Current != null &&
tokenizer.Current.Type.In(
tokenizer.Current.Type.In(
TSQLTokenType.Identifier,
TSQLTokenType.SystemIdentifier,
TSQLTokenType.IncompleteIdentifier))
{
column.Tokens.Add(tokenizer.Current);

if (tokenizer.Current.Type == TSQLTokenType.Identifier)
if (tokenizer.Current.Type.In(
TSQLTokenType.Identifier,
TSQLTokenType.SystemIdentifier))
{
column.ColumnAlias = tokenizer.Current.AsIdentifier;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;

using TSQL.Tokens;
using TSQL.Tokens.Parsers;

namespace TSQL.Expressions.Parsers
{
Expand All @@ -21,34 +22,18 @@ public TSQLArgumentList Parse(ITSQLTokenizer tokenizer)
// need to do this before starting the argument loop
// so we can handle an empty argument list of just whitespace
// and comments
while (
tokenizer.Current != null &&
(
tokenizer.Current.IsComment() ||
tokenizer.Current.IsWhitespace()
))
{
tokens.Add(tokenizer.Current);

tokenizer.MoveNext();
}
TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
tokens);

while (
tokenizer.Current != null &&
!tokenizer.Current.IsCharacter(TSQLCharacters.CloseParentheses))
{
while (
tokenizer.Current != null &&
(
tokenizer.Current.IsComment() ||
tokenizer.Current.IsWhitespace()
))
{
tokens.Add(tokenizer.Current);
TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
tokens);

tokenizer.MoveNext();
}

TSQLExpression argument = factory.Parse(tokenizer);

tokens.AddRange(argument.Tokens);
Expand All @@ -58,13 +43,12 @@ public TSQLArgumentList Parse(ITSQLTokenizer tokenizer)
if (tokenizer.Current.IsCharacter(TSQLCharacters.Comma))
{
tokens.Add(tokenizer.Current);
}

if (
tokenizer.Current != null &&
!tokenizer.Current.IsCharacter(TSQLCharacters.CloseParentheses))
{
tokenizer.MoveNext();

TSQLTokenParserHelper.ReadCommentsAndWhitespace(
tokenizer,
tokens);
}
}

Expand Down
Loading

0 comments on commit a7c7d87

Please sign in to comment.