Beispiel #1
0
        // Due to the way generics are implemented, repeating the implementation
        // of this base-class method might improve performance (TODO: verify this idea)
        new protected int LA(int i)
        {
            bool fail;
            char result = CharSource.TryGet(InputPosition + i, out fail);

            return(fail ? -1 : result);
        }
Beispiel #2
0
        string ParseStringCore(int start)
        {
            Debug.Assert(_verbatim == (CharSource[start] == '@'));
            if (_verbatim)
            {
                start++;
            }
            char q;

            Debug.Assert((q = CharSource.TryGet(start, '\0')) == '"' || q == '\'' || q == '`');
            bool tripleQuoted = (_style & NodeStyle.BaseStyleMask) == NodeStyle.TDQStringLiteral ||
                                (_style & NodeStyle.BaseStyleMask) == NodeStyle.TQStringLiteral;

            string value;

            if (!_parseNeeded)
            {
                Debug.Assert(!tripleQuoted);
                value = (string)CharSource.Slice(start + 1, InputPosition - start - 2).ToString();
            }
            else
            {
                UString original = CharSource.Slice(start, InputPosition - start);
                value = UnescapeQuotedString(ref original, _verbatim, Error, _indent);
            }
            return(value);
        }
Beispiel #3
0
        protected string ParseStringValue(bool parseNeeded, bool isTripleQuoted)
        {
            if (SkipValueParsing)
            {
                return(null);
            }
            string value;

            if (parseNeeded)
            {
                UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);
                value = Les2Lexer.UnescapeQuotedString(ref original, Error, IndentString, true);
                Debug.Assert(original.IsEmpty);
            }
            else
            {
                Debug.Assert(CharSource.TryGet(InputPosition - 1, '?') == CharSource.TryGet(_startPosition, '!'));
                if (isTripleQuoted)
                {
                    value = CharSource.Slice(_startPosition + 3, InputPosition - _startPosition - 6).ToString();
                }
                else
                {
                    value = CharSource.Slice(_startPosition + 1, InputPosition - _startPosition - 2).ToString();
                }
            }
            return(value);
        }
Beispiel #4
0
        string ParseStringCore(bool isTripleQuoted)
        {
            if (SkipValueParsing)
            {
                return("");
            }
            string value;

            if (_parseNeeded)
            {
                UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);
                value = UnescapeQuotedString(ref original, Error, _indent);
                Debug.Assert(original.IsEmpty);
            }
            else
            {
                Debug.Assert(CharSource.TryGet(InputPosition - 1, '?') == CharSource.TryGet(_startPosition, '!'));
                if (isTripleQuoted)
                {
                    value = CharSource.Slice(_startPosition + 3, InputPosition - _startPosition - 6).ToString();
                }
                else
                {
                    value = CharSource.Slice(_startPosition + 1, InputPosition - _startPosition - 2).ToString();
                }
            }
            return(value);
        }
Beispiel #5
0
        Symbol ParseIdOrSymbol(int start, bool isBQString)
        {
            UString unparsed = CharSource.Slice(start, InputPosition - start);
            UString parsed;

            Debug.Assert(isBQString == (CharSource.TryGet(start, '\0') == '`'));
            Debug.Assert(!_verbatim);
            if (_idCache.TryGetValue(unparsed, out Symbol value))
            {
                return(value);
            }
            else
            {
                if (isBQString)
                {
                    parsed = UnescapeQuotedString(start);
                }
                else if (_parseNeeded)
                {
                    parsed = ScanNormalIdentifier(unparsed);
                }
                else
                {
                    parsed = unparsed;
                }
                return(_idCache[unparsed.ShedExcessMemory(50)] = (Symbol)parsed);
            }
        }
Beispiel #6
0
 protected UString UnescapeString(bool isTripleQuoted, bool allowExtraIndent = false)
 {
     if (SkipValueParsing)
     {
         return("");
     }
     if (_hasEscapes)
     {
         UString original = CharSource.Slice(_startPosition, InputPosition - _startPosition);
         _textValue = Les3Lexer.UnescapeQuotedString(ref original, Error, IndentString, allowExtraIndent);
         Debug.Assert(original.IsEmpty);
     }
     else
     {
         Debug.Assert(CharSource.TryGet(InputPosition - 1, '?') == CharSource.TryGet(_startPosition, '!'));
         if (isTripleQuoted)
         {
             _textValue = CharSource.Slice(_startPosition + 3, InputPosition - _startPosition - 6).ToString();
         }
         else
         {
             _textValue = CharSource.Slice(_startPosition + 1, InputPosition - _startPosition - 2).ToString();
         }
     }
     return(_textValue);
 }
Beispiel #7
0
        void ParseIdOrSymbol(int start, bool isBQString)
        {
            UString unparsed = CharSource.Slice(start, InputPosition - start);
            UString parsed;

            Debug.Assert(isBQString == (CharSource.TryGet(start, '\0') == '`'));
            Debug.Assert(!_verbatim);
            if (!_idCache.TryGetValue(unparsed, out _value))
            {
                if (isBQString)
                {
                    parsed = ParseStringCore(start);
                }
                else if (_parseNeeded)
                {
                    parsed = ScanNormalIdentifier(unparsed);
                }
                else
                {
                    parsed = unparsed;
                }
                _idCache[unparsed.ShedExcessMemory(50)] = _value = GSymbol.Get(parsed.ToString());
            }
        }
Beispiel #8
0
        protected UString GetUnescapedString(bool hasEscapes, bool isTripleQuoted)
        {
            UString value;

            if (hasEscapes)
            {
                UString original = Text();
                value = UnescapeQuotedString(ref original, Error, IndentString, true);
                Debug.Assert(original.IsEmpty);
            }
            else
            {
                Debug.Assert(CharSource.TryGet(InputPosition - 1, '?') == CharSource.TryGet(_startPosition, '!'));
                if (isTripleQuoted)
                {
                    value = CharSource.Slice(_startPosition + 3, InputPosition - _startPosition - 6).ToString();
                }
                else
                {
                    value = CharSource.Slice(_startPosition + 1, InputPosition - _startPosition - 2).ToString();
                }
            }
            return(value);
        }