private static void ParseTag(Scope scope, GroupToken parent, KeywordToken tagToken, string[] endTokens) { var code = scope.Code; parent.AddToken(tagToken); var resetPos = code.Position; if (code.ReadTagName() && ProbeEnvironment.IsValidTagName(code.Text)) { parent.AddToken(new KeywordToken(scope, code.Span, code.Text)); if (code.ReadStringLiteral()) { parent.AddToken(new StringLiteralToken(scope, code.Span, code.Text)); return; } } else { code.Position = resetPos; } var exp = ExpressionToken.TryParse(scope, endTokens); if (exp != null) { parent.AddToken(exp); } }
public static ComparisonOperator Parse(Scope scope, Token lastToken, OperatorToken opToken, IEnumerable <string> endTokens) { var ret = new ComparisonOperator(scope); if (lastToken != null) { ret._expectedDataType = lastToken.ValueDataType; if (ret._expectedDataType != null) { ret.AddToken(lastToken); } } ret.AddToken(opToken); if (endTokens == null || !endTokens.Any()) { endTokens = _endTokens; } else { endTokens = endTokens.Concat(_endTokens).ToArray(); } var rightExp = ExpressionToken.TryParse(scope, endTokens, expectedDataType: ret._expectedDataType); if (rightExp != null) { ret.AddToken(rightExp); } return(ret); }
public static ReturnStatement Parse(Scope scope, KeywordToken returnToken) { var ret = new ReturnStatement(scope); ret.AddToken(returnToken); var code = scope.Code; if (code.ReadExact(';')) { ret.AddToken(new StatementEndToken(scope, code.Span)); return(ret); } var exp = ExpressionToken.TryParse(scope, null, expectedDataType: scope.ReturnDataType); if (exp != null) { ret.AddToken(exp); } if (code.ReadExact(';')) { ret.AddToken(new StatementEndToken(scope, code.Span)); } return(ret); }
public static RowColStatement Parse(Scope scope, KeywordToken rowColToken) { var ret = new RowColStatement(scope); ret.AddToken(rowColToken); var code = scope.Code; if (code.PeekExact('+') || code.PeekExact('-')) { ret.AddToken(new OperatorToken(scope, code.MovePeekedSpan(), code.Text)); } if (code.ReadNumber()) { ret.AddToken(new NumberToken(scope, code.Span, code.Text)); } var exp = ExpressionToken.TryParse(scope, null); if (exp != null) { ret.AddToken(exp); } if (code.PeekExact(';')) { ret.AddToken(new StatementEndToken(scope, code.Span)); } return(ret); }
private static void ParseFunctionAttributes(Scope scope, GroupToken parentToken) { var code = scope.Code; while (!code.EndOfFile) { if (code.PeekExact(';') || code.PeekExact('{') || code.PeekExact('}')) { return; } if (code.ReadWord()) { switch (code.Text) { case "description": case "prompt": case "comment": case "BEGINHLP": case "accel": { parentToken.AddToken(new KeywordToken(scope, code.Span, code.Text)); var exp = ExpressionToken.TryParse(scope, _attribEndTokens); if (exp != null) { parentToken.AddToken(exp); } } break; case "nomenu": case "ENDHLP": parentToken.AddToken(new KeywordToken(scope, code.Span, code.Text)); break; case "tag": { parentToken.AddToken(new KeywordToken(scope, code.Span, code.Text)); if (code.ReadTagName()) { parentToken.AddToken(new KeywordToken(scope, code.Span, code.Text)); } var exp = ExpressionToken.TryParse(scope, _attribEndTokens); if (exp != null) { parentToken.AddToken(exp); } } break; default: return; } } else { break; } } }
private void ParseCreateStringdef() { var code = Code; var word = code.PeekWordR(); var sd = DkDict.Dict.GetStringdef(word); if (sd != null) { AddToken(new IdentifierToken(Scope, code.Span, word, sd.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createStringdefEndTokens); if (exp != null) { AddToken(exp); } } while (!code.EndOfFile) { if (code.ReadExact(';')) { AddToken(new StatementEndToken(Scope, code.Span)); break; } if (code.ReadStringLiteral()) { AddToken(new StringLiteralToken(Scope, code.Span, code.Text)); if (code.ReadNumber()) { AddToken(new NumberToken(Scope, code.Span, code.Text)); } continue; } else if (code.ReadExactWholeWord("description")) { AddToken(new KeywordToken(Scope, code.Span, "description")); while (code.ReadStringLiteral()) { AddToken(new StringLiteralToken(Scope, code.Span, code.Text)); } } else { var exp = ExpressionToken.TryParse(Scope, _createStringdefEndTokens); if (exp != null) { AddToken(exp); } else { break; } } } }
private void ParseCreateTypedef() { var code = Code; var word = code.PeekWordR(); if (!string.IsNullOrEmpty(word)) { var td = DkDict.Dict.GetTypedef(word); if (td != null) { AddToken(new IdentifierToken(Scope, code.Span, word, td.Definition)); } else { var exp = ExpressionToken.TryParse(Scope, _createTypedefEndTokens); if (exp != null) { AddToken(exp); } } var dt = DataType.TryParse(new DataType.ParseArgs { Code = code, Scope = Scope, TokenCreateCallback = token => { AddToken(token); }, VisibleModel = true, AllowTags = true }); if (dt != null) { if (code.PeekWordR() == "description") { AddToken(new KeywordToken(Scope, code.Span, "description")); while (code.ReadStringLiteral()) { AddToken(new StringLiteralToken(Scope, code.Span, code.Text)); } } if (code.ReadExact(';')) { AddToken(new StatementEndToken(Scope, code.Span)); } } } }
public static CastStatement Parse(Scope scope, BracketsToken castToken, IEnumerable <string> endTokens) { var ret = new CastStatement(scope); ret.AddToken(castToken); ret._castDataType = castToken.CastDataType; var exp = ExpressionToken.TryParse(scope, endTokens, expectedDataType: ret._castDataType); if (exp != null) { ret.AddToken(exp); } return(ret); }
public static FormatStatement Parse(Scope scope, KeywordToken formatToken) { var ret = new FormatStatement(scope); ret.AddToken(formatToken); var code = scope.Code; while (true) { if (code.ReadExact(';')) { ret.AddToken(new StatementEndToken(scope, code.Span)); break; } var word = code.PeekWordR(); if (string.IsNullOrEmpty(word)) { break; } if (word == "rows" || word == "cols" || word == "genpages" || word == "outfile") { ret.AddToken(new KeywordToken(scope, code.MovePeekedSpan(), word)); if (code.ReadExact('=')) { ret.AddToken(new OperatorToken(scope, code.Span, "=")); } var exp = ExpressionToken.TryParse(scope, _endTokens); if (exp != null) { ret.AddToken(exp); } else { break; } } else { break; } } return(ret); }
public static ConditionalOperator Parse(Scope scope, Token lastToken, OperatorToken opToken, IEnumerable <string> endTokens, DataType expectedDataType) { var ret = new ConditionalOperator(scope); if (lastToken != null) { ret.AddToken(lastToken); } ret.AddToken(opToken); if (endTokens == null) { endTokens = _endTokens; } else { endTokens = endTokens.Concat(_endTokens).ToArray(); } var leftResultExp = ExpressionToken.TryParse(scope, endTokens, expectedDataType: expectedDataType); if (leftResultExp != null) { ret.AddToken(leftResultExp); ret._completionDataType = leftResultExp.ValueDataType; if (scope.Code.ReadExact(':')) { var rightResultExp = ExpressionToken.TryParse(scope, endTokens, expectedDataType: expectedDataType); if (rightResultExp != null) { ret.AddToken(rightResultExp); } } } return(ret); }
public static AssignmentOperator Parse(Scope scope, Token lastToken, OperatorToken opToken, IEnumerable <string> endTokens) { var ret = new AssignmentOperator(scope); if (lastToken != null) { ret._expectedDataType = lastToken.ValueDataType; if (ret._expectedDataType != null) { ret.AddToken(lastToken); } } ret.AddToken(opToken); var rightExp = ExpressionToken.TryParse(scope, endTokens, expectedDataType: ret._expectedDataType); if (rightExp != null) { ret.AddToken(rightExp); } return(ret); }
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)); } }
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 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)); } }
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 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 ParseCreateTable(KeywordToken tableToken) { AddToken(tableToken); var code = Code; // Table name if (!code.ReadWord()) { return; } var table = DkDict.Dict.GetTable(code.Text); if (table != null) { AddToken(new IdentifierToken(Scope, code.Span, code.Text, table.Definition)); } else { AddToken(new UnknownToken(Scope, code.Span, code.Text)); } // Table number if (!code.ReadNumber()) { return; } AddToken(new NumberToken(Scope, code.Span, code.Text)); // Table number+1 if (Code.ReadNumber()) { AddToken(new NumberToken(Scope, code.Span, code.Text)); } ExpressionToken exp; // Attributes ParseTableAttributes(_createTableEndTokens); BracketsToken brackets = null; BracesToken braces = null; GroupToken parent = null; if (code.ReadExact('(')) { brackets = new BracketsToken(Scope); brackets.AddOpen(code.Span); AddToken(brackets); parent = brackets; } else if (code.ReadExact('{')) { braces = new BracesToken(Scope); braces.AddOpen(code.Span); AddToken(braces); parent = braces; } else { return; } // Columns while (!code.EndOfFile) { if (code.ReadExact(')') || code.ReadExact('}')) { if (brackets != null) { brackets.AddClose(code.Span); } else if (braces != null) { braces.AddClose(code.Span); } return; } if (code.ReadExact(',')) { parent.AddToken(new DelimiterToken(Scope, code.Span)); continue; } if (!TryParseColumnDefinition(Scope, parent, table != null ? table.Definition : null, true)) { if ((exp = ExpressionToken.TryParse(Scope, _columnEndTokens)) != null) { parent.AddToken(exp); } else { break; } } } }
private void ParseTableAttributes(string[] endTokens) { var code = Code; string word; ExpressionToken exp; while (true) { if (code.PeekExact('(') || code.PeekExact('{')) { break; } if (!code.Peek()) { break; } if (!string.IsNullOrEmpty(word = code.PeekWordR())) { if (word == "updates" || word == "display" || word == "modal" || word == "nopick" || word == "pick") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), code.Text)); continue; } if (word == "database" || word == "snapshot" || word == "prompt" || word == "comment" || word == "image" || word == "description" || word == "updates") { AddToken(new KeywordToken(Scope, code.MovePeekedSpan(), code.Text)); if ((exp = ExpressionToken.TryParse(Scope, endTokens)) != null) { AddToken(exp); } continue; } if (word == "tag") { ParseTag(Scope, this, new KeywordToken(Scope, code.MovePeekedSpan(), "tag"), endTokens); continue; } if ((exp = ExpressionToken.TryParse(Scope, endTokens)) != null) { AddToken(exp); } else { break; } } else { if ((exp = ExpressionToken.TryParse(Scope, endTokens)) != null) { AddToken(exp); } else { break; } } } }
private static bool TryParseColumnDefinition(Scope scope, GroupToken parent, Definition parentDef, bool includeNameAndDataType) { string word; var code = scope.Code; ExpressionToken exp; if (includeNameAndDataType) { // Column name if (parentDef != null && parentDef.AllowsChild) { if (!string.IsNullOrEmpty(word = code.PeekWordR())) { var childDef = parentDef.GetChildDefinitions(word).FirstOrDefault(); if (childDef != null) { parent.AddToken(new IdentifierToken(scope, code.MovePeekedSpan(), code.Text, childDef)); } } else { return(false); } } else { return(false); } // Data type if ((exp = ExpressionToken.TryParse(scope, _columnEndTokens)) != null) { parent.AddToken(exp); } } // Column attributes while (!code.EndOfFile) { if (code.PeekExact(')') || code.PeekExact('}') || code.PeekExact(',')) { break; } if (!string.IsNullOrEmpty(word = code.PeekWordR())) { if (word == "prompt" || word == "comment" || word == "group" || word == "row" || word == "col" || word == "rows" || word == "cols" || word == "image") { parent.AddToken(new KeywordToken(scope, code.MovePeekedSpan(), code.Text)); if ((exp = ExpressionToken.TryParse(scope, _columnEndTokens)) != null) { parent.AddToken(exp); } continue; } if (word == "endgroup" || word == "form" || word == "formonly" || word == "zoom" || word == "tool") { parent.AddToken(new KeywordToken(scope, code.MovePeekedSpan(), code.Text)); continue; } if (word == "tag") { ParseTag(scope, parent, new KeywordToken(scope, code.MovePeekedSpan(), "tag"), _columnEndTokens); continue; } if ((exp = ExpressionToken.TryParse(scope, _columnEndTokens)) != null) { parent.AddToken(exp); } else { break; } } else { if ((exp = ExpressionToken.TryParse(scope, _columnEndTokens)) != null) { parent.AddToken(exp); } else { break; } } } if (code.ReadExact(',')) { parent.AddToken(new DelimiterToken(scope, code.Span)); } return(true); }
public static ExtractStatement Parse(Scope scope, KeywordToken extractKeywordToken) { var code = scope.Code; var tokens = new List <Token>(); tokens.Add(extractKeywordToken); var permanent = false; if (code.ReadExactWholeWord("permanent")) { var permToken = new KeywordToken(scope, code.Span, "permanent"); tokens.Add(permToken); permanent = true; } ExtractTableDefinition exDef = null; string name = null; if (!code.ReadWord()) { // Not correct syntax; exit here. return(new ExtractStatement(scope, tokens) { _fields = new ExtractFieldDefinition[0] }); } else if ((exDef = scope.DefinitionProvider.GetGlobalFromFile <ExtractTableDefinition>(code.Text).FirstOrDefault()) == null) { // The extract definition would have been added by the preprocessor. If it's not recognized here, then it's incorrect syntax. return(new ExtractStatement(scope, tokens) { _fields = new ExtractFieldDefinition[0] }); } else { name = code.Text; tokens.Add(new ExtractTableToken(scope, code.Span, name, exDef)); } var ret = new ExtractStatement(scope, tokens); ret._name = name; ret._permanent = permanent; var scope2 = scope.CloneIndent(); scope2.Hint |= ScopeHint.SuppressControlStatements | ScopeHint.SuppressFunctionDefinition | ScopeHint.SuppressVarDecl; var fieldTokens = new List <ExtractFieldToken>(); while (!code.EndOfFile) { if (code.ReadExact(';')) { ret.AddToken(new StatementEndToken(scope2, code.Span)); break; } ExtractFieldDefinition fieldDef; if ((fieldDef = exDef.GetField(code.PeekWordR())) != null) { var fieldToken = new ExtractFieldToken(scope, code.MovePeekedSpan(), code.Text, fieldDef); fieldTokens.Add(fieldToken); ret.AddToken(fieldToken); } else { break; } if (!code.PeekExact("==") && code.PeekExact('=')) { var equalsToken = new OperatorToken(scope, code.MovePeekedSpan(), code.Text); ret.AddToken(equalsToken); } else { break; } var oldValue = code.StopAtLineEnd; code.StopAtLineEnd = true; try { while (true) { var exp = ExpressionToken.TryParse(scope, null, expectedDataType: fieldDef.DataType); if (exp != null) { ret.AddToken(exp); if (fieldDef.DataType == null) { fieldDef.SetDataType(exp.ValueDataType); } } else { break; } } } finally { code.StopAtLineEnd = oldValue; } } var fields = new List <ExtractFieldDefinition>(); var rownoDef = new ExtractFieldDefinition("rowno", exDef.FilePosition, exDef); rownoDef.SetDataType(DataType.Unsigned9); fields.Add(rownoDef); fields.AddRange(from f in fieldTokens select f.SourceDefinition as ExtractFieldDefinition); ret._fields = fields.ToArray(); return(ret); }