public ProtoSpecToken(ProtoSpecTokenType type, string code, int startIndex, int length) { m_Type = type; m_Code = code; m_StartIndex = startIndex; m_Length = length; }
public ProtoSpecToken NextToken() { ProtoSpecToken token = null; char c = IgnoreWhiteSpaceAndComment(); switch (c) { case ':': token = new ProtoSpecToken(ProtoSpecTokenType.Colon, Code, CurrentPos, 1); CurrentPos += 1; break; case '=': token = new ProtoSpecToken(ProtoSpecTokenType.Equal, Code, CurrentPos, 1); CurrentPos += 1; break; case '{': token = new ProtoSpecToken(ProtoSpecTokenType.LeftBrace, Code, CurrentPos, 1); CurrentPos += 1; break; case '}': token = new ProtoSpecToken(ProtoSpecTokenType.RightBrace, Code, CurrentPos, 1); CurrentPos += 1; break; case '<': token = new ProtoSpecToken(ProtoSpecTokenType.LeftAngular, Code, CurrentPos, 1); CurrentPos += 1; break; case '>': token = new ProtoSpecToken(ProtoSpecTokenType.RightAngular, Code, CurrentPos, 1); CurrentPos += 1; break; case '.': token = new ProtoSpecToken(ProtoSpecTokenType.Dot, Code, CurrentPos, 1); CurrentPos += 1; break; case '\0': token = new ProtoSpecToken(ProtoSpecTokenType.EndOfFile, Code, CurrentPos, 0); break; default: if (char.IsDigit(c)) { int len = 0; int start = CurrentPos; do { len += 1; CurrentPos += 1; }while (char.IsDigit(Peek())); token = new ProtoSpecToken(ProtoSpecTokenType.Numeral, Code, start, len); } else if (char.IsLetter(c)) { int len = 0; int start = CurrentPos; do { len += 1; CurrentPos += 1; c = Peek(); }while (char.IsLetterOrDigit(c) || c == '_'); ProtoSpecTokenType type = m_KeywordTable.Match(Code, start, len); token = new ProtoSpecToken(type, Code, start, len); } break; } if (token == null) { token = new ProtoSpecToken(ProtoSpecTokenType.Unknow, Code, CurrentPos, 0); } return(token); }
private bool IsColumnType(ProtoSpecTokenType type) { return(type >= ProtoSpecTokenType.Byte && type <= ProtoSpecTokenType.TypeOf); }
public ProtoSpecKeyword(string keyword, ProtoSpecTokenType tokenType) { Keyword = keyword; TokenType = tokenType; }