public override string GetStandardTypeByKeyword(KeywordKind keyw) { switch (keyw) { case KeywordKind.ByteType: return("BYTE"); case KeywordKind.IntType: return("INTEGER"); case KeywordKind.DoubleType: return("REAL"); case KeywordKind.CharType: return("CHAR"); case KeywordKind.BoolType: return("BOOLEAN"); } return(null); }
public void Keyword(object input) { Random rand = new Random(); string keyword = new string(input.ToString().Select(c => rand.Next(0, 2) == 1 ? char.ToUpper(c) : char.ToLower(c)).ToArray()); KeywordKind kind = (KeywordKind)input; List <Token> tokens = Lexer.Lex(keyword); Assert.NotNull(tokens); Keyword token = Assert.IsType <Keyword>(tokens[0]); Assert.Equal(0, token.Start); Assert.Equal(keyword.Length, token.End); Assert.Equal(keyword, token.Value); Assert.Equal(keyword, string.Join("", tokens)); }
/// <summary> /// Get the Uri name equivalent of the given KeywordKind. /// </summary> /// <param name="keyword">The KeywordKind to get name for.</param> /// <returns>A $ keyword that represent the given keyword.</returns> internal static string GetNameFromKeywordKind(KeywordKind keyword) { switch (keyword) { case KeywordKind.Batch: return(UriQueryConstants.BatchSegment); case KeywordKind.Count: return(UriQueryConstants.CountSegment); case KeywordKind.Links: return(UriQueryConstants.LinkSegment); case KeywordKind.Metadata: return(UriQueryConstants.MetadataSegment); case KeywordKind.Value: return(UriQueryConstants.ValueSegment); } throw new InvalidOperationException("Should not have reached here with kind: " + keyword); }
/// <summary> /// Initializes a new instance of the <see cref="Keyword"/> class. /// </summary> /// <param name="value">The value.</param> /// <param name="kind">The kind.</param> public Keyword(string value, KeywordKind kind) { this.Value = value; this.Kind = kind; }
public override string GetStandardTypeByKeyword(KeywordKind keyw) { return null; }
public virtual string GetStandardTypeByKeyword(KeywordKind keyw) { switch (keyw) { case KeywordKind.ByteType : return "byte"; case KeywordKind.SByteType : return "shortint"; case KeywordKind.ShortType : return "smallint"; case KeywordKind.UShortType : return "word"; case KeywordKind.IntType : return "integer"; case KeywordKind.UIntType : return "longword"; case KeywordKind.Int64Type : return "int64"; case KeywordKind.UInt64Type : return "uint64"; case KeywordKind.DoubleType : return "real"; case KeywordKind.FloatType : return "single"; case KeywordKind.CharType : return "char"; case KeywordKind.BoolType : return "boolean"; case KeywordKind.PointerType : return "pointer"; } return null; }
/// <summary> /// Get the Uri name equivalent of the given KeywordKind. /// </summary> /// <param name="keyword">The KeywordKind to get name for.</param> /// <returns>A $ keyword that represent the given keyword.</returns> internal static string GetNameFromKeywordKind(KeywordKind keyword) { switch (keyword) { case KeywordKind.Batch: return UriQueryConstants.BatchSegment; case KeywordKind.Count: return UriQueryConstants.CountSegment; case KeywordKind.Links: return UriQueryConstants.LinkSegment; case KeywordKind.Metadata: return UriQueryConstants.MetadataSegment; case KeywordKind.Value: return UriQueryConstants.ValueSegment; } throw new InvalidOperationException("Should not have reached here with kind: " + keyword); }
public Keyword(string name, KeywordKind kind) { _name = name; _kind = kind; }
public virtual string FindExpressionFromAnyPosition(int off, string Text, int line, int col, out KeywordKind keyw, out string expr_without_brackets) { int i = off-1; expr_without_brackets = null; keyw = KeywordKind.None; if (i < 0) return ""; bool is_char = false; System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (Text[i] != ' ' && (Char.IsLetterOrDigit(Text[i]) || Text[i] == '_' || Text[i] == '&')) { //sb.Remove(0,sb.Length); while (i >= 0 && (Char.IsLetterOrDigit(Text[i]) || Text[i] == '_' || Text[i] == '&')) { //sb.Insert(0,Text[i]);//.Append(Text[i]); i--; } is_char = true; } i = off; if (i < Text.Length && Text[i] != ' ' && (Char.IsLetterOrDigit(Text[i]) || Text[i] == '_' || Text[i] == '&')) { while (i < Text.Length && (Char.IsLetterOrDigit(Text[i]) || Text[i] == '_')) { //sb.Append(Text[i]);//.Append(Text[i]); i++; } is_char = true; } if (is_char) { expr_without_brackets = FindExpression(i, Text, line, col, out keyw); } bool is_new = keyw == KeywordKind.New; bool meth_call = false; KeywordKind new_keyw = KeywordKind.None; int j = i; bool in_comment = false; bool brackets = false; while (j<Text.Length) { char c = Text[j]; if (c == '(' && !in_comment) { Stack<char> sk_stack = new Stack<char>(); in_comment = false; bool in_kav = false; sk_stack.Push('('); j++; while (j<Text.Length) { c = Text[j]; if (c == '(' && !in_kav) sk_stack.Push('('); else if (c == ')' && !in_kav) { if (sk_stack.Count == 0) { break; } else { sk_stack.Pop(); if (sk_stack.Count == 0) { i = j+1; meth_call = true; break; } } } else if (c == '\'' && !in_comment) { in_kav = !in_kav; } else if (c == '{' && !in_kav) { in_comment = true; } else if (c == '}' && !in_kav) { in_comment = false; } else if (c == '/' && !in_kav && !in_comment) { if (j+1 < Text.Length && Text[j+1] == '/') break; } j++; } break; } else if (c == '<' && !in_comment) { Stack<char> sk_stack = new Stack<char>(); sk_stack.Push('<'); j++; bool generic = false; while (j<Text.Length) { c = Text[j]; if (c == '>') { sk_stack.Pop(); if (sk_stack.Count == 0) { i = j + 1; generic = true; break; } } else if (c=='<') { sk_stack.Push('<'); } else if (!char.IsLetterOrDigit(c) && c != '&' && c != '.' && c != ' ' && c != '\t' && c != '\n' && c != ',') { break; } j++; } if (generic) { break; } } else if (c == '[' && !in_comment) { brackets = true; break; } else if (c == '{') { in_comment = true; } else if (c == '}') { if (!in_comment) break; else in_comment = false; } else if (c == ' ' || c == '\t' || c == '\n' || c == '\r') { } else { if (!in_comment) break; } j++; } if (is_new && string.Compare(expr_without_brackets.Trim(' ','\n','\t','\r'),"new",true) == 0 && !meth_call) { expr_without_brackets = null; return null; } if (is_char) { string ss = FindExpression(i, Text, line, col, out new_keyw); if (brackets && is_new) { int ind = ss.ToLower().IndexOf("new"); if (ind != -1) return ss.Substring(ind + 3); } return ss; } return null; }
public virtual string FindExpression(int off, string Text, int line, int col, out KeywordKind keyw) { int i = off - 1; int bound = 0; bool punkt_sym = false; keyw = KeywordKind.None; System.Text.StringBuilder sb = new StringBuilder(); Stack<char> tokens = new Stack<char>(); Stack<char> kav = new Stack<char>(); Stack<char> ugl_skobki = new Stack<char>(); int num_in_ident = -1; keyw = TestForKeyword(Text, i); if (keyw == KeywordKind.Punkt) return ""; while (i >= bound) { bool end = false; char ch = Text[i]; if (kav.Count == 0 && (char.IsLetterOrDigit(ch) || ch == '_' || ch == '&' || ch == '\'')) { num_in_ident = i; if (kav.Count == 0 && tokens.Count == 0) { int tmp = i; if (ch == '\'') { i--; if (kav.Count == 0) kav.Push('\''); while (i >= 0 && Text[i] != '\'') i--; if (i >= 0) i--; } else while (i >= 0 && (char.IsLetterOrDigit(Text[i]) || Text[i] == '_' || Text[i] == '&')) { i--; } while (i >= 0 && (Text[i] == ' ' || char.IsControl(Text[i]) || Text[i] == '}')) { if (Text[i] != '}') i--; else { while (i >= 0 && Text[i] != '{') //propusk kommentariev i--; if (i >= 0) i--; } } if (i >= 0 && (char.IsLetterOrDigit(Text[i]) || Text[i] == '_' || Text[i] == '&')) { bound = i + 1; TestForKeyword(Text, i, ref bound, punkt_sym, out keyw); } else if (i >= 0 && Text[i] == '\'') return ""; i = tmp; } else if (ch == '\'') kav.Push('\''); sb.Insert(0, ch);//.Append(Text[i]); } else if (ch == '.' || ch == '^' || ch == '&') { if (ch == '.' && i >= 1 && Text[i - 1] == '.') end = true; else sb.Insert(0, ch); if (ch != '.') punkt_sym = true; } else if (ch == '}') { if (kav.Count == 0) { while (i >= 0 && Text[i] != '{') { sb.Insert(0, Text[i]); i--; } if (i < 0) { break; } else if (Text[i] == '{') { sb.Insert(0, '{'); } } else sb.Insert(0, ch); } else if (ch == '{') { if (kav.Count == 0) { sb.Insert(0, ch); break; } else sb.Insert(0, ch); } else switch (ch) { case ')': case ']': if (kav.Count == 0) { string tmps = sb.ToString().Trim(' ', '\r', '\t', '\n'); if (tmps.Length >= 1 && (char.IsLetter(tmps[0]) || tmps[0] == '_' || tmps[0] == '&')) end = true; else tokens.Push(ch); } if (!end) { sb.Insert(0, ch); punkt_sym = true; } break; case '>': if (tokens.Count == 0) { if (ugl_skobki.Count > 0 || i == off - 1 || i + 1 < Text.Length && (Text[i + 1] == '.' || Text[i + 1] == '(')) { ugl_skobki.Push('>'); sb.Insert(0, ch); } else if (i >=1 && Text[i - 1] == '-') { if (!(kav.Count == 0 && tokens.Count == 0)) sb.Insert(0, ch); } else end = true; } else sb.Insert(0, ch); break; case '<': if (tokens.Count == 0) { if (ugl_skobki.Count > 0) { ugl_skobki.Pop(); sb.Insert(0, ch); } else end = true; } else sb.Insert(0, ch); break; case '[': case '(': if (kav.Count == 0) { if (tokens.Count > 0) { tokens.Pop(); punkt_sym = true; sb.Insert(0, ch); if (ch == '(') { int tmp = i--; /*while (i >= 0 && (char.IsLetterOrDigit(Text[i]) || Text[i] == '_' || Text[i] == '&')) { i--; }*/ while (i >= 0 && (Text[i] == ' ' || char.IsControl(Text[i]) || Text[i] == '}')) { if (Text[i] != '}') i--; else { while (i >= 0 && Text[i] != '{') //propusk kommentariev i--; if (i >= 0) i--; } } if (i >= 0 && (char.IsLetterOrDigit(Text[i]) || Text[i] == '_' || Text[i] == '&')) { bound = i + 1; TestForKeyword(Text, i, ref bound, punkt_sym, out keyw); if (keyw != KeywordKind.None && tokens.Count == 0) { end = true; } else bound = 0; } else if (i >= 0 && Text[i] == '\'') return ""; i = tmp; } } else end = true; } else sb.Insert(0, ch); punkt_sym = true; break; case '\'': if (kav.Count == 0) kav.Push(ch); else kav.Pop(); sb.Insert(0, ch); punkt_sym = true; break; default: if (!(ch == ' ' || char.IsControl(ch))) { if (kav.Count == 0) { if (ch == ',' && ugl_skobki.Count > 0) sb.Insert(0, ch); else if (tokens.Count == 0) end = true; else sb.Insert(0, ch); } else sb.Insert(0, ch); } else { if (Text[i] == '\n') { if (CheckForComment(Text, i - 1)) end = true; else sb.Insert(0, ch); } else sb.Insert(0, ch); } punkt_sym = true; break; } if (end) { if (CheckForComment(Text, i)) { int new_line_ind = sb.ToString().IndexOf('\n'); if (new_line_ind != -1) sb = sb.Remove(0, new_line_ind + 1); else sb = sb.Remove(0, sb.Length); } break; } i--; } //return RemovePossibleKeywords(sb); return sb.ToString(); }
private void TestForKeyword(string Text, int i, ref int bound, bool sym_punkt, out KeywordKind keyword) { StringBuilder sb = new StringBuilder(); while (i >= 0 && (char.IsLetterOrDigit(Text[i]) || Text[i] == '_')) { sb.Insert(0,Text[i]); i--; } while (i >= 0 && char.IsWhiteSpace(Text[i])) { i--; } if (i >= 0 && (Text[i] == '.' || Text[i] == '&')) sb.Insert(0, Text[i]); string s = sb.ToString().ToLower(); if (s == "new") { bound = i+1; keyword = KeywordKind.New; } else if ((s == "procedure" || s == "function") && !sym_punkt ) { keyword = KeywordKind.Function; } else if (s == "constructor" && !sym_punkt) { keyword = KeywordKind.Constructor; } else if (s == "destructor" && !sym_punkt) { keyword = KeywordKind.Destructor; } else if (s == "uses") { keyword = KeywordKind.Uses; } else if (s == "inherited") { keyword = KeywordKind.Inherited; } else if (s == "raise") { keyword = KeywordKind.Raise; } else if (keywords.ContainsKey(s)) { keyword = KeywordKind.CommonKeyword; } else keyword = KeywordKind.None; }
private void TestForKeyword(string Text, int i, ref int bound, bool sym_punkt, out KeywordKind keyword) { StringBuilder sb = new StringBuilder(); while (i >= 0 && (char.IsLetterOrDigit(Text[i]) || Text[i] == '_')) { sb.Insert(0, Text[i]); i--; } string s = sb.ToString().ToLower(); if (s == "new") { bound = i + 1; keyword = KeywordKind.New; } else if ((s == "sub" || s == "function") && !sym_punkt) { keyword = KeywordKind.Function; } else if (s == "imports") { keyword = KeywordKind.Uses; } else if (s == "throw") { keyword = KeywordKind.Raise; } else if (keywords.ContainsKey(s) && !ignored_keywords.ContainsKey(s)) { keyword = KeywordKind.CommonKeyword; } else keyword = KeywordKind.None; }
public override string GetStandardTypeByKeyword(KeywordKind keyw) { switch (keyw) { case KeywordKind.ByteType: return "Byte"; case KeywordKind.SByteType: return "SByte"; case KeywordKind.ShortType: return "Short"; case KeywordKind.UShortType: return "UShort"; case KeywordKind.IntType: return "Integer"; case KeywordKind.UIntType: return "UInteger"; case KeywordKind.Int64Type: return "Long"; case KeywordKind.UInt64Type: return "ULong"; case KeywordKind.DoubleType: return "Double"; case KeywordKind.FloatType: return "Single"; case KeywordKind.CharType: return "Char"; case KeywordKind.BoolType: return "Boolean"; } return null; }
public override string FindExpressionFromAnyPosition(int off, string Text, int line, int col, out KeywordKind keyw, out string expr_without_brackets) { int i = off - 1; expr_without_brackets = null; keyw = KeywordKind.None; if (i < 0) return ""; bool is_char = false; System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (Text[i] != ' ' && (Char.IsLetterOrDigit(Text[i]) || Text[i] == '_')) { //sb.Remove(0,sb.Length); while (i >= 0 && (Char.IsLetterOrDigit(Text[i]) || Text[i] == '_')) { //sb.Insert(0,Text[i]);//.Append(Text[i]); i--; } is_char = true; } i = off; if (i < Text.Length && Text[i] != ' ' && (Char.IsLetterOrDigit(Text[i]) || Text[i] == '_')) { while (i < Text.Length && (Char.IsLetterOrDigit(Text[i]) || Text[i] == '_')) { //sb.Append(Text[i]);//.Append(Text[i]); i++; } is_char = true; } if (is_char) { expr_without_brackets = FindExpression(i, Text, line, col, out keyw); } bool is_new = keyw == KeywordKind.New; bool meth_call = false; KeywordKind new_keyw = KeywordKind.None; int j = i; bool in_comment = false; while (j < Text.Length) { char c = Text[j]; if (c == '(' && !in_comment) { Stack<char> sk_stack = new Stack<char>(); in_comment = false; bool in_kav = false; sk_stack.Push('('); j++; while (j < Text.Length) { c = Text[j]; if (c == '(' && !in_kav) sk_stack.Push('('); else if (c == ')' && !in_kav) { if (sk_stack.Count == 0) { break; } else { sk_stack.Pop(); if (sk_stack.Count == 0) { i = j + 1; meth_call = true; break; } } } else if (c == '"') { in_kav = !in_kav; } else if (c == '\'' && !in_kav) { break; } j++; } break; } else if (c == '\n') { break; } else { if (!in_comment) break; } j++; } if (is_new && string.Compare(expr_without_brackets.Trim(' ', '\n', '\t', '\r'), "new", true) == 0 && !meth_call) { expr_without_brackets = null; return null; } if (is_char) { return FindExpression(i, Text, line, col, out new_keyw); } return null; }
private BuiltInType GetBuiltInTypeFromKind(KeywordKind kind) => kind switch {
public virtual string SkipNew(int off, string Text, ref KeywordKind keyw) { int tmp = off; string expr = null; while (off >= 0 && Char.IsLetterOrDigit(Text[off])) off--; while (off >= 0 && (Text[off] == ' ' || char.IsControl(Text[off]))) off--; if (off >= 1 && Text[off] == '=' && Text[off-1] == ':') { off -= 2; while (off >= 0 && (Text[off] == ' ' || char.IsControl(Text[off]))) off--; if (off >= 0 && (Text[off] == '_' || char.IsLetterOrDigit(Text[off]) || Text[off] == ']' || Text[off] == '>')) expr = FindExpression(off+1,Text,0,0,out keyw); } return expr; }
/// <summary> /// Create a new StarQueryToken given the parent (if any). /// </summary> /// <param name="keyword">The keyword kind of the segment.</param> /// <param name="parent">The parent segment, or null if this is the root segment.</param> public KeywordSegmentQueryToken(KeywordKind keyword, SegmentQueryToken parent) : base(QueryTokenUtils.GetNameFromKeywordKind(keyword), parent, null) { this.keyword = keyword; }
public virtual bool IsDefinitionIdentifierAfterKeyword(KeywordKind keyw) { if (keyw == PascalABCCompiler.Parsers.KeywordKind.Function || keyw == PascalABCCompiler.Parsers.KeywordKind.Constructor || keyw == PascalABCCompiler.Parsers.KeywordKind.Destructor || keyw == PascalABCCompiler.Parsers.KeywordKind.Type || keyw == PascalABCCompiler.Parsers.KeywordKind.Var || keyw == PascalABCCompiler.Parsers.KeywordKind.Unit || keyw == PascalABCCompiler.Parsers.KeywordKind.Const || keyw == PascalABCCompiler.Parsers.KeywordKind.Program || keyw == PascalABCCompiler.Parsers.KeywordKind.Punkt) return true; return false; }
public override string GetStandardTypeByKeyword(KeywordKind keyw) { switch (keyw) { case KeywordKind.ByteType: return "BYTE"; case KeywordKind.IntType: return "INTEGER"; case KeywordKind.DoubleType: return "REAL"; case KeywordKind.CharType: return "CHAR"; case KeywordKind.BoolType: return "BOOLEAN"; } return null; }
public virtual bool IsTypeAfterKeyword(KeywordKind keyw) { if (keyw == PascalABCCompiler.Parsers.KeywordKind.Colon || keyw == PascalABCCompiler.Parsers.KeywordKind.Of || keyw == PascalABCCompiler.Parsers.KeywordKind.TypeDecl) return true; return false; }
public virtual bool IsNamespaceAfterKeyword(KeywordKind keyw) { if (keyw == PascalABCCompiler.Parsers.KeywordKind.Uses) return true; return false; }