private TreeViewItem CreateTableTvi(DkDict.Table table) { var tvi = CreateStandardTvi(_tableImg, table.Name, table.Prompt, new TextBox { Text = table.Definition.QuickInfoTextStr }, true); tvi.Expanded += TableTvi_Expanded; tvi.Tag = table; tvi.MouseRightButtonDown += TableTvi_MouseRightButtonDown; var menu = new ContextMenu(); var menuItem = new MenuItem(); menuItem.Header = "Go To Definition"; menuItem.Click += TableGoToDefinition_Click; menuItem.Tag = table; menu.Items.Add(menuItem); menuItem = new MenuItem(); menuItem.Header = "Find All References"; menuItem.Click += TableFindAllReferences_Click; menuItem.Tag = table; menu.Items.Add(menuItem); tvi.ContextMenu = menu; return(tvi); }
public TableDefinition(string name, DkDict.Table table, bool orig, FilePosition filePos) : base(name, filePos, DkDict.Table.GetExternalRefId(name)) { #if DEBUG if (table == null) { throw new ArgumentNullException("table"); } #endif _prompt = table.Prompt; _comment = table.Comment; _description = table.Description; _orig = orig; _table = table; }
public static SelectStatement Parse(Scope parentScope, KeywordToken selectToken) { var ret = new SelectStatement(parentScope, selectToken); var scope = parentScope.Clone(); scope.BreakOwner = ret; scope.ContinueOwner = ret; var code = scope.Code; if (code.ReadStringLiteral()) { ret.AddToken(new StringLiteralToken(scope, code.Span, code.Text)); } if (code.ReadExact('*')) { ret.AddToken(new OperatorToken(scope, code.Span, "*")); } if (!code.ReadExactWholeWord("from")) { return(ret); } ret.AddToken(new KeywordToken(scope, code.Span, "from")); ExtractTableDefinition extractDef = null; DkDict.Table table = null; if (code.ReadWord()) { if ((table = DkDict.Dict.GetTable(code.Text)) != null) { ret.AddToken(new TableToken(scope, code.Span, code.Text, table.Definition)); } else if ((extractDef = scope.DefinitionProvider.GetAny <ExtractTableDefinition>(code.TokenStartPostion, code.Text).FirstOrDefault()) != null) { ret.AddToken(new IdentifierToken(scope, code.Span, code.Text, extractDef)); } else { ret.AddToken(new UnknownToken(scope, code.Span, code.Text)); } } if (code.ReadExactWholeWord("of")) { ret.AddToken(new KeywordToken(scope, code.Span, "of")); if (code.ReadWord()) { if ((table = DkDict.Dict.GetTable(code.Text)) != null) { ret.AddToken(new TableToken(scope, code.Span, code.Text, table.Definition)); } else { ret.AddToken(new UnknownToken(scope, code.Span, code.Text)); } } } else if (code.ReadExact(',')) { ret.AddToken(new DelimiterToken(scope, code.Span)); var expectingComma = false; while (!code.EndOfFile) { if (code.PeekExact('{')) { break; } if (expectingComma) { if (code.ReadExact(',')) { ret.AddToken(new DelimiterToken(scope, code.Span)); expectingComma = false; } else { break; } } else if (code.ReadWord()) { if ((table = DkDict.Dict.GetTable(code.Text)) != null) { ret.AddToken(new TableToken(scope, code.Span, code.Text, table.Definition)); } else { ret.AddToken(new UnknownToken(scope, code.Span, code.Text)); } expectingComma = true; } else { break; } } } // WHERE and ORDER BY var gotWhere = false; var gotOrderBy = false; while (!code.EndOfFile) { if (code.PeekExact('{')) { break; } if (!gotWhere && code.ReadExactWholeWord("where")) { ret.AddToken(new KeywordToken(scope, code.Span, code.Text)); gotWhere = true; var exp = ExpressionToken.TryParse(scope, _whereEndTokens); if (exp != null) { ret.AddToken(exp); } else { break; } } else if (!gotOrderBy && code.ReadExactWholeWord("order")) { ret.AddToken(new KeywordToken(scope, code.Span, code.Text)); gotOrderBy = true; if (!code.ReadExactWholeWord("by")) { break; } ret.AddToken(new KeywordToken(scope, code.Span, code.Text)); while (!code.EndOfFile) { if (code.PeekExact('{')) { break; } if (code.ReadExact(',')) { ret.AddToken(new DelimiterToken(scope, code.Span)); continue; } if (code.ReadExactWholeWord("asc") || code.ReadExactWholeWord("desc")) { ret.AddToken(new KeywordToken(scope, code.Span, code.Text)); continue; } if (TryParseColumn(scope, ret, true, extractDef)) { continue; } break; } } else { break; } } // Body if (code.ReadExact('{')) { var braces = new BracesToken(scope); braces.AddOpen(code.Span); ret.AddToken(braces); while (!code.EndOfFile) { if (code.ReadExact('}')) { braces.AddClose(code.Span); break; } if (code.ReadExactWholeWord("for")) { braces.AddToken(new KeywordToken(scope, code.Span, "for")); if (!code.ReadExactWholeWord("each")) { continue; } braces.AddToken(new KeywordToken(scope, code.Span, "each")); if (!code.ReadExact(':')) { continue; } braces.AddToken(new OperatorToken(scope, code.Span, ":")); } else if (code.ReadExactWholeWord("before") || code.ReadExactWholeWord("after")) { braces.AddToken(new KeywordToken(scope, code.Span, code.Text)); if (!code.ReadExactWholeWord("group")) { continue; } braces.AddToken(new KeywordToken(scope, code.Span, "group")); if (code.ReadExactWholeWord("all")) { braces.AddToken(new KeywordToken(scope, code.Span, "all")); if (!code.ReadExact(':')) { continue; } braces.AddToken(new OperatorToken(scope, code.Span, ":")); } else if (TryParseColumn(scope, braces, false, extractDef)) { if (!code.ReadExact(':')) { continue; } braces.AddToken(new OperatorToken(scope, code.Span, ":")); } } else if (code.ReadExactWholeWord("default")) { braces.AddToken(new KeywordToken(scope, code.Span, "default")); if (!code.ReadExact(':')) { continue; } braces.AddToken(new OperatorToken(scope, code.Span, ":")); } else { var stmt = StatementToken.TryParse(scope); if (stmt != null) { braces.AddToken(stmt); } } } } return(ret); }
private void ParseCreateIndex() { var code = Code; DkDict.RelInd relind = null; DkDict.Table table = null; string word; if (code.ReadExactWholeWord("primary")) { AddToken(new KeywordToken(Scope, code.Span, "primary")); } if (code.ReadExactWholeWord("nopick")) { AddToken(new KeywordToken(Scope, code.Span, "nopick")); } if (code.ReadExactWholeWord("NOPICK")) { AddToken(new KeywordToken(Scope, code.Span, "NOPICK")); } if (!string.IsNullOrEmpty(word = code.PeekWordR())) { if ((relind = DkDict.Dict.GetRelInd(word)) != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, relind.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens); if (exp != null) { AddToken(exp); } } } else { var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens); if (exp != null) { AddToken(exp); } } if (code.ReadExactWholeWord("on")) { AddToken(new KeywordToken(Scope, code.Span, "on")); if (!string.IsNullOrEmpty(word = code.PeekWordR()) && (table = DkDict.Dict.GetTable(word)) != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens); if (exp != null) { AddToken(exp); } } } while (!code.EndOfFile) { if (code.PeekExact('(') || code.PeekExact('{')) { break; } if (!string.IsNullOrEmpty(word = code.PeekWordR())) { if (word == "description") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "description")); var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens); if (exp != null) { AddToken(exp); } } else if (word == "tag") { ParseTag(Scope, this, new KeywordToken(Scope, code.MovePeekedSpan(), "tag"), _createIndexEndTokens); } else { var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } else { var exp = ExpressionToken.TryParse(Scope, _createIndexEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } if (code.ReadExact('(') || code.ReadExact('{')) { var brackets = new BracketsToken(Scope); brackets.AddOpen(code.Span); AddToken(brackets); DkDict.Column field = null; while (!code.EndOfFile) { if (code.ReadExact(')') || code.ReadExact('}')) { brackets.AddClose(code.Span); break; } if (code.ReadExact(',')) { brackets.AddToken(new DelimiterToken(Scope, code.Span)); } if (table != null && !string.IsNullOrEmpty(word = code.PeekWordR()) && (field = table.GetColumn(word)) != null) { brackets.AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, field.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createIndexColumnEndTokens); if (exp != null) { brackets.AddToken(exp); } else { break; } } } } }
private void ParseCreateRelationship(KeywordToken relationshipToken) { AddToken(relationshipToken); var code = Code; var word = code.PeekWordR(); var relind = DkDict.Dict.GetRelInd(word); if (relind != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, relind.Definition)); if (code.ReadNumber()) { AddToken(new NumberToken(Scope, code.Span, code.Text)); } } else { var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } } DkDict.Table table = null; var done = false; while (!code.EndOfFile && !done) { if (!string.IsNullOrEmpty(word = code.PeekWordR())) { if (word == "updates") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word)); } else if (word == "prompt" || word == "comment" || word == "image" || word == "description") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word)); var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } } else if (word == "one" || word == "many") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word)); word = code.PeekWordR(); if (!string.IsNullOrEmpty(word)) { table = DkDict.Dict.GetTable(word); if (table != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } } } else { var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } } } else if (word == "to") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "to")); if (code.ReadExactWholeWord("one") || code.ReadExactWholeWord("many")) { AddToken(new KeywordToken(Scope, code.Span, code.Text)); word = code.PeekWordR(); if (!string.IsNullOrEmpty(word)) { table = DkDict.Dict.GetTable(word); if (table != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } } } else { var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } } } } else if (word == "order") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "order")); if (code.ReadExactWholeWord("by")) { AddToken(new KeywordToken(Scope, code.Span, "by")); if (code.ReadExactWholeWord("unique")) { AddToken(new KeywordToken(Scope, code.Span, "unique")); } while (!code.EndOfFile) { if (code.PeekExact('(') || code.PeekExact('{')) { break; } if (table != null && !string.IsNullOrEmpty(word = code.PeekWordR())) { var field = table.GetColumn(word); if (field != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, field.Definition)); } else { break; } } else { break; } } } } else if (word == "tag") { ParseTag(Scope, this, new KeywordToken(Scope, code.MovePeekedSpan(), "tag"), _createRelationshipEndTokens); } else { var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } else if (code.ReadExact('(') || code.ReadExact('{')) { var brackets = new BracketsToken(Scope); brackets.AddOpen(code.Span); AddToken(brackets); while (!code.EndOfFile) { if (code.ReadExact(')') || code.ReadExact('}')) { brackets.AddClose(code.Span); done = true; break; } if (!TryParseColumnDefinition(Scope, brackets, relind != null ? relind.Definition : null, true)) { var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } } else { var exp = ExpressionToken.TryParse(Scope, _createRelationshipEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } }
private void ParseAlterTable() { var code = Code; DkDict.Table table = null; ExpressionToken exp; var word = code.PeekWordR(); if (!string.IsNullOrEmpty(word) && (table = DkDict.Dict.GetTable(word)) != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition)); } else { if ((exp = ExpressionToken.TryParse(Scope, _alterTableEndTokens)) != null) { AddToken(exp); } } ParseTableAttributes(_alterTableEndTokens); if (code.ReadExact(';')) { AddToken(new StatementEndToken(Scope, code.Span)); return; } if (code.ReadExactWholeWord("before") || code.ReadExactWholeWord("after")) { AddToken(new KeywordToken(Scope, code.Span, code.Text)); } if (code.ReadExactWholeWord("column")) { AddToken(new KeywordToken(Scope, code.Span, code.Text)); } if (table != null) { var field = table.GetColumn(code.PeekWordR()); if (field != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), code.Text, field.Definition)); } else { if ((exp = ExpressionToken.TryParse(Scope, _alterTableEndTokens)) != null) { AddToken(exp); } } } if (code.ReadExactWholeWord("add") || code.ReadExactWholeWord("alter") || code.ReadExactWholeWord("drop") || code.ReadExactWholeWord("move")) { AddToken(new KeywordToken(Scope, code.Span, code.Text)); } if (code.ReadExactWholeWord("column")) { AddToken(new KeywordToken(Scope, code.Span, code.Text)); } if (code.ReadExactWholeWord("sametype")) { AddToken(new KeywordToken(Scope, code.Span, code.Text)); } else { var dataType = DataType.TryParse(new DataType.ParseArgs { Code = code, Scope = Scope, TokenCreateCallback = token => { AddToken(token); }, VisibleModel = true, AllowTags = true }); } TryParseColumnDefinition(Scope, this, table != null ? table.Definition : null, false); if (code.ReadExact(';')) { AddToken(new StatementEndToken(Scope, code.Span)); } }
private void ParseCreateWorkspace() { var code = Code; var word = code.PeekWordR(); if (!string.IsNullOrEmpty(word)) { AddToken(new UnknownToken(Scope, code.MovePeekedSpan(), word)); } else { return; } while (true) { if (code.PeekExact('(')) { break; } if (!string.IsNullOrEmpty(word = code.PeekWordR())) { if (word == "prompt" || word == "comment" || word == "description" || word == "image") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word)); var exp = ExpressionToken.TryParse(Scope, _createWorkspaceEndTokens); if (exp != null) { AddToken(exp); } } else if (word == "tag") { ParseTag(Scope, this, new KeywordToken(Scope, code.MovePeekedSpan(), "tag"), _createWorkspaceEndTokens); } else { var exp = ExpressionToken.TryParse(Scope, _createWorkspaceEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } else { var exp = ExpressionToken.TryParse(Scope, _createWorkspaceEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } if (code.ReadExact('(')) { var brackets = new BracketsToken(Scope); brackets.AddOpen(code.Span); AddToken(brackets); while (true) { if (code.ReadExact(')')) { brackets.AddClose(code.Span); break; } if (code.ReadExact(',')) { brackets.AddToken(new DelimiterToken(Scope, code.Span)); } if (code.ReadWord()) { brackets.AddToken(new UnknownToken(Scope, code.Span, code.Text)); DkDict.Table table = null; do { table = DkDict.Dict.GetTable(code.PeekWordR()); if (table != null) { brackets.AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), code.Text, table.Definition)); if (code.ReadExact('\\')) { brackets.AddToken(new OperatorToken(Scope, code.Span, code.Text)); } } }while (table != null); while (true) { if (code.ReadExact(',')) { brackets.AddToken(new DelimiterToken(Scope, code.Span)); break; } if (!string.IsNullOrEmpty(word = code.PeekWordR())) { if (word == "prompt" || word == "comment") { brackets.AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word)); var exp = ExpressionToken.TryParse(Scope, _createWorkspaceColumnEndTokens); if (exp != null) { brackets.AddToken(exp); } } else if (word == "preload") { brackets.AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word)); } else if (word == "tag") { ParseTag(Scope, brackets, new KeywordToken(Scope, code.MovePeekedSpan(), "tag"), _createWorkspaceColumnEndTokens); } else { var exp = ExpressionToken.TryParse(Scope, _createWorkspaceColumnEndTokens); if (exp != null) { brackets.AddToken(exp); } else { break; } } } else { var exp = ExpressionToken.TryParse(Scope, _createWorkspaceColumnEndTokens); if (exp != null) { brackets.AddToken(exp); } else { break; } } } } } } }
private void ParseCreateTimeRelationship() { var code = Code; var word = code.PeekWordR(); var relind = DkDict.Dict.GetRelInd(word); if (relind != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, relind.Definition)); } else { return; } if (code.ReadNumber()) { AddToken(new NumberToken(Scope, code.Span, code.Text)); } else { return; } DkDict.Table table = null; while (!code.EndOfFile) { if (code.PeekExact('(') || code.PeekExact('{')) { break; } if (!string.IsNullOrEmpty(word = code.PeekWordR())) { if (word == "prompt" || word == "comment" || word == "description") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), word)); var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens); if (exp != null) { AddToken(exp); } } else if (word == "tag") { ParseTag(Scope, this, new KeywordToken(Scope, code.MovePeekedSpan(), word), _createTimeRelationshipEndTokens); } else if (word == "order") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "order")); if (code.ReadExactWholeWord("by")) { AddToken(new KeywordToken(Scope, code.Span, "by")); while (!code.EndOfFile) { if (code.PeekExact('(') || code.PeekExact('{')) { break; } if (!string.IsNullOrEmpty(word = code.PeekWordR())) { var field = table != null?table.GetColumn(word) : null; if (field != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, field.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } } } } else if (word == "to") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), "to")); if ((table = DkDict.Dict.GetTable(word)) != null) { AddToken(new IdentifierToken(Scope, code.Span, word, table.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens); if (exp != null) { AddToken(exp); } } } else if ((table = DkDict.Dict.GetTable(word)) != null) { AddToken(new IdentifierToken(Scope, code.MovePeekedSpan(), word, table.Definition)); if (code.ReadExactWholeWord("to")) { AddToken(new KeywordToken(Scope, code.Span, "to")); if ((table = DkDict.Dict.GetTable(word)) != null) { AddToken(new IdentifierToken(Scope, code.Span, word, table.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens); if (exp != null) { AddToken(exp); } } } } else { var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } else { var exp = ExpressionToken.TryParse(Scope, _createTimeRelationshipEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } if (code.PeekExact('(')) { AddToken(BracketsToken.Parse(Scope, expectedDataType: null)); } }