示例#1
0
 private bool IsColumnTypeCompatible(IList list, TokenTypeEnum tokenType)
 {
     return((list is List <string>) ||              // all tokens can be added to a string list
            (tokenType == TokenTypeEnum.Missing) || // empty entries are allowed in all columns
            (tokenType == TokenTypeEnum.Double && list is List <double>) ||
            (tokenType == TokenTypeEnum.DateTime && list is List <DateTime>));
 }
 public Token(TokenTypeEnum type, string value)
 {
     this.type     = type;
     stringValue   = value;
     dateTimeValue = DateTime.MinValue;
     doubleValue   = 0.0;
 }
示例#3
0
        private void AddValue(TokenTypeEnum type, IList list, string strVal, double dblVal, DateTime dateTimeVal)
        {
            var dblList = list as List <double>;

            if (dblList != null)
            {
                AddValue(type, dblList, dblVal);
                return;
            }

            var strList = list as List <string>;

            if (strList != null)
            {
                AddValue(type, strList, strVal);
                return;
            }
            var dtList = list as List <DateTime>;

            if (dtList != null)
            {
                AddValue(type, dtList, dateTimeVal);
                return;
            }

            list.Add(strVal); // assumes List<object>
        }
示例#4
0
文件: Token.cs 项目: topas/dotLessen
 /// <summary>
 /// Initializes a new instance of the <see cref="Token"/> class.
 /// </summary>
 /// <param name="type">The type of token.</param>
 /// <param name="start">The start of token.</param>
 /// <param name="end">The end of token.</param>
 /// <param name="text">The text of token.</param>
 public Token(TokenTypeEnum type, int start, int end, string text)
 {
     this.Type = type;
     this.Start = start;
     this.End = end;
     this.Text = text;
 }
示例#5
0
文件: Token.cs 项目: topas/dotLessen
        /// <summary>
        /// Types to string.
        /// </summary>
        /// <param name="type">The type of token.</param>
        /// <returns>Token name</returns>
        public static string TypeToString(TokenTypeEnum type)
        {
            switch (type)
            {
                case TokenTypeEnum.Invalid: return "invalid";

                case TokenTypeEnum.Whitespace: return "whitespace";
                case TokenTypeEnum.Comment: return "comment";
                case TokenTypeEnum.Delimiter: return "delimiter";
                case TokenTypeEnum.Operator: return "operator";

                case TokenTypeEnum.CDataOpen: return "cdata-open";
                case TokenTypeEnum.CDataClose: return "cdata-close";

                case TokenTypeEnum.Identifier: return "identifier";
                case TokenTypeEnum.AtIdentifier: return "@identifier";
                case TokenTypeEnum.HashName: return "#name";
                case TokenTypeEnum.Function: return "function";
                case TokenTypeEnum.Variable: return "variable";

                case TokenTypeEnum.String: return "string";
                case TokenTypeEnum.Uri: return "uri";

                case TokenTypeEnum.Number: return "number";
                case TokenTypeEnum.Percentage: return "percentage";
                case TokenTypeEnum.Dimension: return "dimension";
                case TokenTypeEnum.UnicodeRange: return "unicode-range";
                case TokenTypeEnum.Color: return "color";
            }

            return "unknown";
        }
示例#6
0
        public override bool MoveNext(
            )
        {
            bool moved;

            while (moved = base.MoveNext())
            {
                TokenTypeEnum tokenType = TokenType;
                if (tokenType == TokenTypeEnum.Comment)
                {
                    continue; // Comments are ignored.
                }
                if (tokenType == TokenTypeEnum.Literal)
                {
                    string literalToken = (string)Token;
                    if (literalToken.StartsWith(Keyword.DatePrefix)) // Date.
                    {
                        /*
                         * NOTE: Dates are a weak extension to the PostScript language.
                         */
                        try
                        { Token = PdfDate.ToDate(literalToken); }
                        catch (ParseException)
                        { /* NOOP: gently degrade to a common literal. */ }
                    }
                }
                break;
            }
            return(moved);
        }
示例#7
0
 public TokenType(TokenTypeEnum name, string template, string htmlTag, TokenLocationType tokenLocationType)
 {
     Name              = name;
     Template          = template;
     HtmlTag           = htmlTag;
     TokenLocationType = tokenLocationType;
 }
示例#8
0
 public static TokenDefinition Create(
     Regex regex,
     TokenTypeEnum type,
     bool isIgnored = false
     )
 {
     return(new TokenDefinition(regex, type, isIgnored));
 }
示例#9
0
 public Token(String token, String regex, TokenTypeEnum tokenType, int numberOfArguements, int precedence)
 {
     this.token              = token;
     this.regex              = new Regex(regex);
     this.tokenType          = tokenType;
     this.numberOfArguements = numberOfArguements;
     this.precedence         = precedence;
 }
 private bool IsColumnTypeCompatible(IList list, TokenTypeEnum tokenType)
 {
     return((list is List <object>) ||              // unknown lists are compatible to everything (potential conversion)
            (list is List <string>) ||              // all tokens can be added to a string list
            (tokenType == TokenTypeEnum.Missing) || // empty entries are allowed in all columns
            (tokenType == TokenTypeEnum.Double && list is List <double>) ||
            (tokenType == TokenTypeEnum.DateTime && list is List <DateTime>));
 }
 private void ExpectType(TokenTypeEnum expectedToken)
 {
     if (tokenizer.PeekType() != expectedToken)
     {
         throw new ArgumentException("Error: Expected " + expectedToken + " got " + tokenizer.PeekType());
     }
     tokenizer.Skip();
 }
 public void Next(out TokenTypeEnum type, out string strVal, out double dblVal, out DateTime dateTimeVal)
 {
     type        = tokenTypes[tokenPos];
     strVal      = stringVals[tokenPos];
     dblVal      = doubleVals[tokenPos];
     dateTimeVal = dateTimeVals[tokenPos];
     Skip();
 }
示例#13
0
 // Expected token / not token
 public MismatchedTokenException(string[] tokenNames_, Token token_, int expecting_, bool matchNot, string fileName_) :
     base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
 {
     tokenNames   = tokenNames_;
     token        = token_;
     tokenText    = token_.getText();
     mismatchType = matchNot ? TokenTypeEnum.NotTokenType : TokenTypeEnum.TokenType;
     expecting    = expecting_;
 }
示例#14
0
 // Expected BitSet / not BitSet
 public MismatchedTokenException(string[] tokenNames_, Token token_, BitSet set_, bool matchNot, string fileName_) :
     base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
 {
     tokenNames   = tokenNames_;
     token        = token_;
     tokenText    = token_.getText();
     mismatchType = matchNot ? TokenTypeEnum.NotSetType : TokenTypeEnum.SetType;
     bset         = set_;
 }
示例#15
0
 // Expected range / not range
 public MismatchedTokenException(string[] tokenNames_, Token token_, int lower, int upper_, bool matchNot, string fileName_) :
     base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
 {
     tokenNames   = tokenNames_;
     token        = token_;
     tokenText    = token_.getText();
     mismatchType = matchNot ? TokenTypeEnum.NotRangeType : TokenTypeEnum.RangeType;
     expecting    = lower;
     upper        = upper_;
 }
示例#16
0
 internal Token(
     TokenTypeEnum type,
     string value,
     TokenPosition position
     )
 {
     Type     = type;
     Value    = value;
     Position = position;
 }
示例#17
0
 public Paragraph(int start, int end, string mdText, List <SingleToken> inlineTokens, List <SingleToken> startingTokens, TokenTypeEnum startingTokenType)
 {
     InlineTokens      = inlineTokens;
     StartingTokens    = startingTokens;
     Start             = start;
     End               = end;
     MdText            = mdText;
     StartingTokenType = startingTokenType;
     ValidTokens       = new List <SingleToken>();
 }
示例#18
0
 private TokenDefinition(
     Regex regex,
     TokenTypeEnum type,
     bool isIgnored
     )
 {
     Type      = type;
     Regex     = regex;
     IsIgnored = isIgnored;
 }
示例#19
0
 // Expected BitSet / not BitSet
 public MismatchedTokenException(string[] tokenNames_, AST node_, BitSet set_, bool matchNot) :
     base("Mismatched Token", "<AST>", -1, -1)
 {
     tokenNames = tokenNames_;
     node       = node_;
     tokenText  = node_ == null
         ? "<empty tree>"
         : node_.ToString();
     mismatchType = matchNot ? TokenTypeEnum.NotSetType : TokenTypeEnum.SetType;
     bset         = set_;
 }
示例#20
0
 // Expected token / not token
 public MismatchedTokenException(string[] tokenNames_, AST node_, int expecting_, bool matchNot) :
     base("Mismatched Token", "<AST>", -1, -1)
 {
     tokenNames = tokenNames_;
     node       = node_;
     tokenText  = node_ == null
         ? "<empty tree>"
         : node_.ToString();
     mismatchType = matchNot ? TokenTypeEnum.NotTokenType : TokenTypeEnum.TokenType;
     expecting    = expecting_;
 }
        private static IList ConvertList(TokenTypeEnum type, IList list, int estimatedNumberOfLines)
        {
            var    newList      = CreateList(type, estimatedNumberOfLines);
            object missingValue = GetMissingValue(type);

            for (int i = 0; i < list.Count; i++)
            {
                newList.Add(missingValue);
            }
            return(newList);
        }
示例#22
0
 public Token(string value, TokenTypeEnum tokenType)
 {
     try
     {
         _value     = value;
         _tokenType = tokenType;
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
        private static object GetMissingValue(TokenTypeEnum type)
        {
            switch (type)
            {
            case TokenTypeEnum.String: return(string.Empty);

            case TokenTypeEnum.Double: return(double.NaN);

            case TokenTypeEnum.DateTime: return(DateTime.MinValue);

            default: throw new ArgumentOutOfRangeException("type", type, "No missing value defined");
            }
        }
示例#24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Auth" /> class.
 /// </summary>
 /// <param name="accessToken">The access token string. (required).</param>
 /// <param name="app">The API application associated with the token. (required).</param>
 /// <param name="expiresOn">The token&#39;s expiration date..</param>
 /// <param name="refreshToken">The refresh token string..</param>
 /// <param name="scope">The scope or scopes that the token supports. (required).</param>
 /// <param name="tokenType">The token type.  Option descriptions:  * &#x60;bearer&#x60; - The token is of the &#x60;bearer&#x60; type.  (required).</param>
 /// <param name="user">The user associated with the token..</param>
 public Auth(string accessToken = default(string), ApiApp app = default(ApiApp), string expiresOn = default(string), string refreshToken = default(string), string scope = default(string), TokenTypeEnum tokenType = default(TokenTypeEnum), User user = default(User))
 {
     // to ensure "accessToken" is required (not null)
     this.AccessToken = accessToken ?? throw new ArgumentNullException("accessToken is a required property for Auth and cannot be null");
     // to ensure "app" is required (not null)
     this.App = app ?? throw new ArgumentNullException("app is a required property for Auth and cannot be null");
     // to ensure "scope" is required (not null)
     this.Scope        = scope ?? throw new ArgumentNullException("scope is a required property for Auth and cannot be null");
     this.TokenType    = tokenType;
     this.ExpiresOn    = expiresOn;
     this.RefreshToken = refreshToken;
     this.User         = user;
 }
 // Expected range / not range
 public MismatchedTokenException(string[] tokenNames_, AST node_, int lower, int upper_, bool matchNot) :
     base("Mismatched Token", "<AST>", -1, -1)
 {
     tokenNames = tokenNames_;
     node = node_;
     if (node_ == null)
     {
         tokenText = "<empty tree>";
     }
     else
     {
         tokenText = node_.ToString();
     }
     mismatchType = matchNot ? TokenTypeEnum.NotRangeType : TokenTypeEnum.RangeType;
     expecting = lower;
     upper = upper_;
 }
示例#26
0
        /// <summary>
        /// 获取当前用户信息
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="tokenType"></param>
        /// <returns></returns>
        public static T GetCurrentUser <T>(TokenTypeEnum tokenType)
        {
            switch (tokenType)
            {
            case TokenTypeEnum.Admin_Login:
                return(AppHelper.CurrentUser <T>(adminTokenName));

            case TokenTypeEnum.Screen_Auth:
                return(AppHelper.CurrentUser <T>(homeScreenTokenName));

            case TokenTypeEnum.SignIn_Auth:
                return(AppHelper.CurrentUser <T>(homeSignInTokenName));

            default:
                throw new ApplicationException("不存在此类型的token");
            }
        }
示例#27
0
 // Expected range / not range
 public MismatchedTokenException(string[] tokenNames_, AST node_, int lower, int upper_, bool matchNot) :
     base("Mismatched Token", "<AST>", -1, -1)
 {
     tokenNames = tokenNames_;
     node       = node_;
     if (node_ == null)
     {
         tokenText = "<empty tree>";
     }
     else
     {
         tokenText = node_.ToString();
     }
     mismatchType = matchNot ? TokenTypeEnum.NotRangeType : TokenTypeEnum.RangeType;
     expecting    = lower;
     upper        = upper_;
 }
        private IList CreateList(TokenTypeEnum type, int estimatedNumberOfLines)
        {
            switch (type)
            {
            case TokenTypeEnum.String:
                return(new List <string>(estimatedNumberOfLines));

            case TokenTypeEnum.Double:
            case TokenTypeEnum.Missing: // assume double columns
                return(new List <double>(estimatedNumberOfLines));

            case TokenTypeEnum.DateTime:
                return(new List <DateTime>(estimatedNumberOfLines));

            default:
                throw new InvalidOperationException();
            }
        }
示例#29
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="tokenType"></param>
        public static void ToSigin(TokenTypeEnum tokenType, JwtPaylod payload)
        {
            switch (tokenType)
            {
            case TokenTypeEnum.Admin_Login:
                AppHelper.SignIn(payload, adminTokenName, tokenTimeSpanForAdmin);
                break;

            case TokenTypeEnum.Screen_Auth:
                AppHelper.SignIn(payload, homeScreenTokenName, tokenTimeSpanForHomeScreen);
                break;

            case TokenTypeEnum.SignIn_Auth:
                AppHelper.SignIn(payload, homeSignInTokenName, tokenTimeSpanForHomeSignIn);
                break;

            default:
                throw new ApplicationException("不存在此类型的token");
            }
        }
示例#30
0
        /// <summary>
        /// 登出
        /// </summary>
        /// <param name="tokenType"></param>
        public static void ToSignOut(TokenTypeEnum tokenType)
        {
            switch (tokenType)
            {
            case TokenTypeEnum.Admin_Login:
                AppHelper.SignOut(adminTokenName);
                break;

            case TokenTypeEnum.Screen_Auth:
                AppHelper.SignOut(homeScreenTokenName);
                break;

            case TokenTypeEnum.SignIn_Auth:
                AppHelper.SignOut(homeSignInTokenName);
                break;

            default:
                throw new ApplicationException("不存在此类型的token");
            }
        }
        private static IList CreateList(TokenTypeEnum type, int estimatedNumberOfLines)
        {
            switch (type)
            {
            case TokenTypeEnum.String:
                return(new List <string>(estimatedNumberOfLines));

            case TokenTypeEnum.Double:
                return(new List <double>(estimatedNumberOfLines));

            case TokenTypeEnum.DateTime:
                return(new List <DateTime>(estimatedNumberOfLines));

            case TokenTypeEnum.Missing: // List<object> represent list of unknown type
                return(new List <object>(estimatedNumberOfLines));

            default:
                throw new InvalidOperationException();
            }
        }
        private void AddValue(TokenTypeEnum type, IList list, string strVal, double dblVal, DateTime dateTimeVal)
        {
            // Add value if list has a defined type
            var dblList = list as List <double>;

            if (dblList != null)
            {
                AddValue(type, dblList, dblVal);
                return;
            }
            var strList = list as List <string>;

            if (strList != null)
            {
                AddValue(type, strList, strVal);
                return;
            }
            var dtList = list as List <DateTime>;

            if (dtList != null)
            {
                AddValue(type, dtList, dateTimeVal);
                return;
            }

            // Undefined list-type
            if (type == TokenTypeEnum.Missing)
            {
                // add null to track number of missing values
                list.Add(null);
            }
            else // first non-missing value for undefined list-type
            {
                var newList = ConvertList(type, list, estimatedNumberOfLines);
                // replace list
                var idx = values.IndexOf(list);
                values[idx] = newList;
                // recursively call AddValue
                AddValue(type, newList, strVal, dblVal, dateTimeVal);
            }
        }
示例#33
0
        private void AddSymbol(TokenTypeEnum type)
        {
            switch (type)
            {
            case TokenTypeEnum.TypeInt:
                symbols.Add(Symbols.Factory.CreateForIntType(scope, tokens.Current.Value));
                break;

            case TokenTypeEnum.TypeChar:
                symbols.Add(Symbols.Factory.CreateForCharType(scope, tokens.Current.Value));
                break;

            case TokenTypeEnum.TypeReal:
                symbols.Add(Symbols.Factory.CreateForFloatType(scope, tokens.Current.Value));
                break;

            default:
                AddError(tokens.Current);
                break;
            }
        }
示例#34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NumericToken"/> class.
 /// </summary>
 /// <param name="type">The type of token.</param>
 /// <param name="start">The start index.</param>
 /// <param name="end">The end index.</param>
 /// <param name="text">The text of token.</param>
 /// <param name="value">The value of number.</param>
 public NumericToken(TokenTypeEnum type, int start, int end, string text, decimal value)
     : base(type, start, end, text)
 {
     this.Number = value;
 }
 // Expected BitSet / not BitSet
 public MismatchedTokenException(string[] tokenNames_, IToken token_, BitSet set_, bool matchNot, string fileName_) :
     base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
 {
     tokenNames = tokenNames_;
     token = token_;
     tokenText = token_.getText();
     mismatchType = matchNot ? TokenTypeEnum.NotSetType : TokenTypeEnum.SetType;
     bset = set_;
 }
 // Expected token / not token
 public MismatchedTokenException(string[] tokenNames_, IToken token_, int expecting_, bool matchNot, string fileName_) :
     base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
 {
     tokenNames = tokenNames_;
     token = token_;
     tokenText = token_.getText();
     mismatchType = matchNot ? TokenTypeEnum.NotTokenType : TokenTypeEnum.TokenType;
     expecting = expecting_;
 }
 // Expected BitSet / not BitSet
 public MismatchedTokenException(string[] tokenNames_, AST node_, BitSet set_, bool matchNot) :
     base("Mismatched Token", "<AST>", -1, -1)
 {
     tokenNames = tokenNames_;
     node = node_;
     if (node_ == null)
     {
         tokenText = "<empty tree>";
     }
     else
     {
         tokenText = node_.ToString();
     }
     mismatchType = matchNot ? TokenTypeEnum.NotSetType : TokenTypeEnum.SetType;
     bset = set_;
 }
 // Expected range / not range
 public MismatchedTokenException(string[] tokenNames_, Token token_, int lower, int upper_, bool matchNot, string fileName_)
     : base("Mismatched Token", fileName_, token_.getLine(), token_.getColumn())
 {
     tokenNames = tokenNames_;
     token = token_;
     tokenText = token_.getText();
     mismatchType = matchNot ? TokenTypeEnum.NotRangeType : TokenTypeEnum.RangeType;
     expecting = lower;
     upper = upper_;
 }
示例#39
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NumericWithUnitToken"/> class.
 /// </summary>
 /// <param name="type">The type of token.</param>
 /// <param name="start">The start index.</param>
 /// <param name="end">The end index.</param>
 /// <param name="text">The text value.</param>
 /// <param name="value">The number value.</param>
 /// <param name="unit">The unit of number.</param>
 public NumericWithUnitToken(TokenTypeEnum type, int start, int end, string text, decimal value, string unit)
     : base(type, start, end, text, value)
 {
     this.Unit = unit;
 }
示例#40
0
        /**
          <summary>Moves the pointer to the next token.</summary>
          <remarks>To properly parse the current token, the pointer MUST be just before its starting
          (leading whitespaces are ignored). When this method terminates, the pointer IS
          at the last byte of the current token.</remarks>
          <returns>Whether a new token was found.</returns>
        */
        public virtual bool MoveNext(
      )
        {
            StringBuilder buffer = null;
              token = null;
              int c = 0;

              // Skip leading white-space characters.
              do
              {
            c = stream.ReadByte();
            if(c == -1)
              return false;
              } while(IsWhitespace(c)); // Keep goin' till there's a white-space character...

              // Which character is it?
              switch(c)
              {
            case Symbol.Slash: // Name.
            {
              tokenType = TokenTypeEnum.Name;

              /*
            NOTE: As name objects are simple symbols uniquely defined by sequences of characters,
            the bytes making up the name are never treated as text, so here they are just
            passed through without unescaping.
              */
              buffer = new StringBuilder();
              while(true)
              {
            c = stream.ReadByte();
            if(c == -1)
              break; // NOOP.
            if(IsDelimiter(c) || IsWhitespace(c))
              break;

            buffer.Append((char)c);
              }
              if(c > -1)
              {stream.Skip(-1);} // Restores the first byte after the current token.
            } break;
            case '0':
            case '1':
            case '2':
            case '3':
            case '4':
            case '5':
            case '6':
            case '7':
            case '8':
            case '9':
            case '.':
            case '-':
            case '+': // Number.
            {
              if(c == '.')
              {tokenType = TokenTypeEnum.Real;}
              else // Digit or signum.
              {tokenType = TokenTypeEnum.Integer;} // By default (it may be real).

              // Building the number...
              buffer = new StringBuilder();
              while(true)
              {
            buffer.Append((char)c);
            c = stream.ReadByte();
            if(c == -1)
              break; // NOOP.
            else if(c == '.')
              tokenType = TokenTypeEnum.Real;
            else if(c < '0' || c > '9')
              break;
              }
              if(c > -1)
              {stream.Skip(-1);} // Restores the first byte after the current token.
            } break;
            case Symbol.OpenSquareBracket: // Array (begin).
              tokenType = TokenTypeEnum.ArrayBegin;
              break;
            case Symbol.CloseSquareBracket: // Array (end).
              tokenType = TokenTypeEnum.ArrayEnd;
              break;
            case Symbol.OpenAngleBracket: // Dictionary (begin) | Hexadecimal string.
            {
              c = stream.ReadByte();
              if(c == -1)
            throw new ParseException("Unexpected EOF (isolated opening angle-bracket character).");
              // Is it a dictionary (2nd angle bracket)?
              if(c == Symbol.OpenAngleBracket)
              {
            tokenType = TokenTypeEnum.DictionaryBegin;
            break;
              }

              // Hexadecimal string (single angle bracket).
              tokenType = TokenTypeEnum.Hex;

              buffer = new StringBuilder();
              while(c != Symbol.CloseAngleBracket) // NOT string end.
              {
            if(!IsWhitespace(c))
            {buffer.Append((char)c);}

            c = stream.ReadByte();
            if(c == -1)
              throw new ParseException("Unexpected EOF (malformed hex string).");
              }
            } break;
            case Symbol.CloseAngleBracket: // Dictionary (end).
            {
              c = stream.ReadByte();
              if(c != Symbol.CloseAngleBracket)
            throw new ParseException("Malformed dictionary.",stream.Position);

              tokenType = TokenTypeEnum.DictionaryEnd;
            } break;
            case Symbol.OpenRoundBracket: // Literal string.
            {
              tokenType = TokenTypeEnum.Literal;

              buffer = new StringBuilder();
              int level = 0;
              while(true)
              {
            c = stream.ReadByte();
            if(c == -1)
              break;
            else if(c == Symbol.OpenRoundBracket)
              level++;
            else if(c == Symbol.CloseRoundBracket)
              level--;
            else if(c == '\\')
            {
              bool lineBreak = false;
              c = stream.ReadByte();
              switch(c)
              {
                case 'n':
                  c = Symbol.LineFeed;
                  break;
                case 'r':
                  c = Symbol.CarriageReturn;
                  break;
                case 't':
                  c = '\t';
                  break;
                case 'b':
                  c = '\b';
                  break;
                case 'f':
                  c = '\f';
                  break;
                case Symbol.OpenRoundBracket:
                case Symbol.CloseRoundBracket:
                case '\\':
                  break;
                case Symbol.CarriageReturn:
                  lineBreak = true;
                  c = stream.ReadByte();
                  if(c != Symbol.LineFeed)
                    stream.Skip(-1);
                  break;
                case Symbol.LineFeed:
                  lineBreak = true;
                  break;
                default:
                {
                  // Is it outside the octal encoding?
                  if(c < '0' || c > '7')
                    break;

                  // Octal.
                  int octal = c - '0';
                  c = stream.ReadByte();
                  // Octal end?
                  if(c < '0' || c > '7')
                  {c = octal; stream.Skip(-1); break;}
                  octal = (octal << 3) + c - '0';
                  c = stream.ReadByte();
                  // Octal end?
                  if(c < '0' || c > '7')
                  {c = octal; stream.Skip(-1); break;}
                  octal = (octal << 3) + c - '0';
                  c = octal & 0xff;
                  break;
                }
              }
              if(lineBreak)
                continue;
              if(c == -1)
                break;
            }
            else if(c == Symbol.CarriageReturn)
            {
              c = stream.ReadByte();
              if(c == -1)
                break;
              else if(c != Symbol.LineFeed)
              {c = Symbol.LineFeed; stream.Skip(-1);}
            }
            if(level == -1)
              break;

            buffer.Append((char)c);
              }
              if(c == -1)
            throw new ParseException("Malformed literal string.");
            } break;
            case Symbol.Percent: // Comment.
            {
              tokenType = TokenTypeEnum.Comment;

              buffer = new StringBuilder();
              while(true)
              {
            c = stream.ReadByte();
            if(c == -1
              || IsEOL(c))
              break;

            buffer.Append((char)c);
              }
            } break;
            default: // Keyword.
            {
              tokenType = TokenTypeEnum.Keyword;

              buffer = new StringBuilder();
              do
              {
            buffer.Append((char)c);
            c = stream.ReadByte();
            if(c == -1)
              break;
              } while(!IsDelimiter(c) && !IsWhitespace(c));
              if(c > -1)
              {stream.Skip(-1);} // Restores the first byte after the current token.
            } break;
              }

              if(buffer != null)
              {
            switch(tokenType)
            {
              case TokenTypeEnum.Keyword:
              {
            token = buffer.ToString();
            switch((string)token)
            {
              case Keyword.False:
              case Keyword.True: // Boolean.
                tokenType = TokenTypeEnum.Boolean;
                token =  bool.Parse((string)token);
                break;
              case Keyword.Null: // Null.
                tokenType = TokenTypeEnum.Null;
                token = null;
                break;
            }
              } break;
              case TokenTypeEnum.Name:
              case TokenTypeEnum.Literal:
              case TokenTypeEnum.Hex:
              case TokenTypeEnum.Comment:
            token = buffer.ToString();
            break;
              case TokenTypeEnum.Integer:
            token = Int32.Parse(
              buffer.ToString(),
              NumberStyles.Integer,
              StandardNumberFormatInfo
              );
            break;
              case TokenTypeEnum.Real:
            token = Double.Parse(
              buffer.ToString(),
              NumberStyles.Float,
              StandardNumberFormatInfo
              );
            break;
            }
              }
              return true;
        }
示例#41
0
 public Token(TokenTypeEnum type, string value) {
   this.type = type;
   stringValue = value;
   dateTimeValue = DateTime.MinValue;
   doubleValue = 0.0;
 }
示例#42
0
 /// <summary>
 /// Initializes a new instance of the <see cref="StringValueToken"/> class.
 /// </summary>
 /// <param name="type">The token type.</param>
 /// <param name="start">The start index.</param>
 /// <param name="end">The end index.</param>
 /// <param name="text">The token text.</param>
 /// <param name="value">The text value.</param>
 public StringValueToken(TokenTypeEnum type, int start, int end, string text, string value)
     : base(type, start, end, text)
 {
     this.UnquotedString = value;
 }