Skip to content

Commit

Permalink
Setting up structures and naming conventions for eventually breaking …
Browse files Browse the repository at this point in the history
…down SELECT clause into expressions. #6
  • Loading branch information
bruce-dunwiddie committed Oct 4, 2020
1 parent c2dc132 commit ef0be6c
Show file tree
Hide file tree
Showing 31 changed files with 442 additions and 82 deletions.
14 changes: 7 additions & 7 deletions TSQL_Parser/TSQL_Parser/Clauses/Parsers/TSQLSubqueryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using System.Text;
using System.Threading.Tasks;

using TSQL.Elements;
using TSQL.Expressions;
using TSQL.Expressions.Parsers;
using TSQL.Statements;
using TSQL.Statements.Parsers;
using TSQL.Tokens;

namespace TSQL.Clauses.Parsers
Expand All @@ -20,7 +20,7 @@ internal static class TSQLSubqueryHelper
/// </summary>
public static void ReadUntilStop(
ITSQLTokenizer tokenizer,
TSQLExpression expression,
TSQLElement element,
List<TSQLFutureKeywords> futureKeywords,
List<TSQLKeywords> keywords,
bool lookForStatementStarts)
Expand Down Expand Up @@ -52,19 +52,19 @@ public static void ReadUntilStop(
{
TSQLSubqueryHelper.RecurseParens(
tokenizer,
expression,
element,
ref nestedLevel);
}
}

public static void RecurseParens(
ITSQLTokenizer tokenizer,
TSQLExpression expression,
TSQLElement element,
ref int nestedLevel)
{
if (tokenizer.Current.Type == TSQLTokenType.Character)
{
expression.Tokens.Add(tokenizer.Current);
element.Tokens.Add(tokenizer.Current);

TSQLCharacters character = tokenizer.Current.AsCharacter.Character;

Expand All @@ -90,11 +90,11 @@ public static void RecurseParens(
// not include the stop token within their token list.
TSQLCaseExpression caseExpression = new TSQLCaseExpressionParser().Parse(tokenizer);

expression.Tokens.AddRange(caseExpression.Tokens);
element.Tokens.AddRange(caseExpression.Tokens);
}
else
{
expression.Tokens.Add(tokenizer.Current);
element.Tokens.Add(tokenizer.Current);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions TSQL_Parser/TSQL_Parser/Clauses/TSQLClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
using System.Linq;
using System.Text;

using TSQL.Expressions;
using TSQL.Tokens;
using TSQL.Elements;

namespace TSQL.Clauses
{
public abstract class TSQLClause : TSQLExpression
public abstract class TSQLClause : TSQLElement
{

}
Expand Down
10 changes: 10 additions & 0 deletions TSQL_Parser/TSQL_Parser/Clauses/TSQLHavingClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;

using TSQL.Elements;

namespace TSQL.Clauses
{
public class TSQLHavingClause : TSQLClause
Expand All @@ -11,5 +13,13 @@ internal TSQLHavingClause()
{

}

public List<TSQLPredicate> Predicates
{
get
{
return null;
}
}
}
}
10 changes: 10 additions & 0 deletions TSQL_Parser/TSQL_Parser/Clauses/TSQLSelectClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;

using TSQL.Elements;

namespace TSQL.Clauses
{
public class TSQLSelectClause : TSQLClause
Expand All @@ -11,5 +13,13 @@ internal TSQLSelectClause()
{

}

public List<TSQLSelectColumn> Columns
{
get
{
return null;
}
}
}
}
10 changes: 10 additions & 0 deletions TSQL_Parser/TSQL_Parser/Clauses/TSQLWhereClause.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;

using TSQL.Elements;

namespace TSQL.Clauses
{
public class TSQLWhereClause : TSQLClause
Expand All @@ -11,5 +13,13 @@ internal TSQLWhereClause()
{

}

public List<TSQLPredicate> Predicates
{
get
{
return null;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
using System.Text;
using System.Threading.Tasks;

using TSQL.Clauses.Parsers;
using TSQL.Statements;
using TSQL.Tokens;

namespace TSQL.Expressions.Parsers
namespace TSQL.Elements.Parsers
{
internal class TSQLDefaultValuesExpressionParser
internal class TSQLDefaultValuesParser
{
public TSQLDefaultValuesExpression Parse(ITSQLTokenizer tokenizer)
public TSQLDefaultValues Parse(ITSQLTokenizer tokenizer)
{
TSQLDefaultValuesExpression defaultValues = new TSQLDefaultValuesExpression();
TSQLDefaultValues defaultValues = new TSQLDefaultValues();

if (!tokenizer.Current.IsKeyword(TSQLKeywords.DEFAULT))
{
Expand Down
16 changes: 16 additions & 0 deletions TSQL_Parser/TSQL_Parser/Elements/Parsers/TSQLSelectColumnParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TSQL.Elements.Parsers
{
internal class TSQLSelectColumnParser
{
public TSQLSelectColumn Parse(ITSQLTokenizer tokenizer)
{
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
using TSQL.Clauses.Parsers;
using TSQL.Tokens;

namespace TSQL.Expressions.Parsers
namespace TSQL.Elements.Parsers
{
internal class TSQLValuesExpressionParser
internal class TSQLValuesParser
{
public TSQLValuesExpression Parse(ITSQLTokenizer tokenizer)
public TSQLValues Parse(ITSQLTokenizer tokenizer)
{
TSQLValuesExpression valuesExpression = new TSQLValuesExpression();
TSQLValues values = new TSQLValues();

if (!tokenizer.Current.IsKeyword(TSQLKeywords.VALUES))
{
throw new InvalidOperationException("VALUES expected.");
}

valuesExpression.Tokens.Add(tokenizer.Current);
values.Tokens.Add(tokenizer.Current);

TSQLSubqueryHelper.ReadUntilStop(
tokenizer,
valuesExpression,
values,
// stop words come from usage in MERGE
new List<TSQLFutureKeywords>() {
TSQLFutureKeywords.OUTPUT
Expand All @@ -33,7 +33,7 @@ public TSQLValuesExpression Parse(ITSQLTokenizer tokenizer)
// INSERT INTO ... VALUES ... SELECT
lookForStatementStarts: true);

return valuesExpression;
return values;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.Text;
using System.Threading.Tasks;

namespace TSQL.Expressions
namespace TSQL.Elements
{
public class TSQLDefaultValuesExpression : TSQLExpression
public class TSQLDefaultValues : TSQLElement
{

}
Expand Down
48 changes: 48 additions & 0 deletions TSQL_Parser/TSQL_Parser/Elements/TSQLElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using TSQL.Tokens;

namespace TSQL.Elements
{
public abstract class TSQLElement
{

private readonly List<TSQLToken> _tokens = new List<TSQLToken>();

public List<TSQLToken> Tokens
{
get
{
return _tokens;
}
}

public int BeginPosition
{
get
{
return Tokens.First().BeginPosition;
}
}

public int EndPosition
{
get
{
return Tokens.Last().EndPosition;
}
}

public int Length
{
get
{
return EndPosition - BeginPosition + 1;
}
}
}
}
13 changes: 13 additions & 0 deletions TSQL_Parser/TSQL_Parser/Elements/TSQLPredicate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TSQL.Elements
{
public class TSQLPredicate : TSQLElement
{

}
}
29 changes: 29 additions & 0 deletions TSQL_Parser/TSQL_Parser/Elements/TSQLSelectColumn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using TSQL.Expressions;

namespace TSQL.Elements
{
public class TSQLSelectColumn : TSQLElement
{
public string Alias
{
get
{
return null;
}
}

public TSQLExpression Expression
{
get
{
return null;
}
}
}
}
7 changes: 7 additions & 0 deletions TSQL_Parser/TSQL_Parser/Elements/TSQLValues.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TSQL.Elements
{
public class TSQLValues : TSQLElement
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Tasks;

using TSQL.Clauses.Parsers;
using TSQL.Statements;
using TSQL.Tokens;

namespace TSQL.Expressions.Parsers
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using TSQL.Tokens;

namespace TSQL.Expressions.Parsers
{
internal class TSQLExpressionFactory
{
public TSQLExpression Parse(ITSQLTokenizer tokenizer)
{
if (tokenizer.Current.IsKeyword(TSQLKeywords.CASE))
{
return new TSQLCaseExpressionParser().Parse(tokenizer);
}
else
{
return null;
}
}
}
}
8 changes: 7 additions & 1 deletion TSQL_Parser/TSQL_Parser/Expressions/TSQLCaseExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ namespace TSQL.Expressions
{
public class TSQLCaseExpression : TSQLExpression
{

public override TSQLExpressionType Type
{
get
{
return TSQLExpressionType.Case;
}
}
}
}
Loading

0 comments on commit ef0be6c

Please sign in to comment.