public static ForStatement Parse(Scope scope, KeywordToken forToken) { var ret = new ForStatement(scope); var code = scope.Code; ret.AddToken(forToken); if (!code.ReadExact('(')) { return(ret); } var brackets = new BracketsToken(scope); brackets.AddOpen(code.Span); ret.AddToken(brackets); // Initializer var exp = ExpressionToken.TryParse(scope, _conditionEndTokens); if (exp != null) { brackets.AddToken(exp); } if (!code.ReadExact(';')) { return(ret); } // Condition exp = ExpressionToken.TryParse(scope, _conditionEndTokens); if (exp != null) { brackets.AddToken(exp); } if (!code.ReadExact(';')) { return(ret); } // Increment exp = ExpressionToken.TryParse(scope, _conditionEndTokens); if (exp != null) { brackets.AddToken(exp); } if (!code.ReadExact(')')) { return(ret); } brackets.AddClose(code.Span); // Body var bodyScope = scope.Clone(); bodyScope.BreakOwner = ret; bodyScope.ContinueOwner = ret; if (!code.PeekExact('{')) { return(ret); } var body = BracesToken.Parse(bodyScope, null); ret.AddToken(body); return(ret); }
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 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 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; } } } } } } }