Beispiel #1
0
        private TokenType ScanStringSegment(bool isAtStartOfString)
        {
            // to handle interpolation, strings are broken down into multiple segments, to detect the portions of string between the 'holes'.
            // 'complete' string: a string with no holes (no interpolation), e.g. "'hello'"
            // string 'left piece': the portion of an interpolated string up to the first hole, e.g. "'hello$"
            // string 'middle piece': the portion of an interpolated string between two holes, e.g. "}hello${"
            // string 'right piece': the portion of an interpolated string after the last hole, e.g. "}hello'"

            while (true)
            {
                if (textWindow.IsAtEnd())
                {
                    AddDiagnostic(b => b.UnterminatedString());
                    return(isAtStartOfString ? TokenType.StringComplete : TokenType.StringRightPiece);
                }

                var nextChar = textWindow.Peek();

                if (IsNewLine(nextChar))
                {
                    // do not consume the new line character
                    AddDiagnostic(b => b.UnterminatedStringWithNewLine());
                    return(isAtStartOfString ? TokenType.StringComplete : TokenType.StringRightPiece);
                }

                textWindow.Advance();

                if (nextChar == '\'')
                {
                    return(isAtStartOfString ? TokenType.StringComplete : TokenType.StringRightPiece);
                }

                if (nextChar == '$' && !textWindow.IsAtEnd() && textWindow.Peek() == '{')
                {
                    textWindow.Advance();
                    return(isAtStartOfString ? TokenType.StringLeftPiece : TokenType.StringMiddlePiece);
                }

                if (nextChar != '\\')
                {
                    continue;
                }

                if (textWindow.IsAtEnd())
                {
                    AddDiagnostic(b => b.UnterminatedStringEscapeSequenceAtEof());
                    return(isAtStartOfString ? TokenType.StringComplete : TokenType.StringRightPiece);
                }

                nextChar = textWindow.Peek();
                textWindow.Advance();

                if (CharacterEscapes.ContainsKey(nextChar) == false)
                {
                    // the span of the error is the incorrect escape sequence
                    AddDiagnostic(textWindow.GetLookbehindSpan(2), b => b.UnterminatedStringEscapeSequenceUnrecognized(CharacterEscapeSequences));
                }
            }
        }
 public IDisposable AddCommandGroup(ICommandGroup group)
 {
     lock (_gate)
     {
         if (!CommandGroups.ContainsKey(group))
         {
             return(CommandGroups[group].GetDisposable());
         }
         var newRefDisposable = new RefCountDisposable(Disposable.Create(() => RemoveCommandGroup(group, true)));
         for (;;)
         {
             if (ImmutableInterlocked.Update(ref CommandGroups, (x, y) => x.Add(y, newRefDisposable), group))
             {
                 break;
             }
         }
         return(CommandGroups[group].GetDisposable());
     }
 }
        public bool SysColImmutableSortedDictionary()
        {
            var result = true;

            foreach (var key in keys)
            {
                result &= immutableSortedMap.ContainsKey(key);
            }

            return(result);
        }
        public ParseResult <V> TryParseAt <V>(ICharParser <V> parser, int pos, int len)
        {
            long     parserId = idgen.GetId(parser);
            PosLenId posLenId = new PosLenId(pos, len, parserId);

            if (memoTable.ContainsKey(posLenId))
            {
                return((ParseResult <V>)memoTable[posLenId]);
            }
            else
            {
                ParseResult <V> r = parser.TryParse(this, pos, len);
                memoTable = memoTable.SetItem(posLenId, r);
                return(r);
            }
        }
Beispiel #5
0
        public override OperationResult <TKey, TValue> Apply(ref ImmutableSortedDictionary <TKey, Sequenced <TValue> > dictionary)
        {
            if (dictionary == null)
            {
                throw new ArgumentNullException(nameof(dictionary));
            }

            if (dictionary.ContainsKey(Key))
            {
                var val = _sequenceId == -1 ? new Sequenced <TValue>(Value) : new Sequenced <TValue>(Value, _sequenceId);

                _sequenceId = val.SequenceId;

                dictionary = dictionary.SetItem(Key, val);

                return(new UpdateOperationResult <TKey, TValue>(keyNotFound: false));
            }

            return(new UpdateOperationResult <TKey, TValue>(keyNotFound: true));
        }
Beispiel #6
0
        public DataModel(string sourceFilePath, DataModelMetadata metaData, IEnumerable <DataModelType> types)
        {
            this.SourceFilePath = sourceFilePath;
            this.MetaData       = metaData;

            _g4Lookup = ImmutableSortedDictionary.CreateRange(
                StringComparer.Ordinal, types.Select(type => Pair.Make(type.G4DeclaredName, type)));
            ImmutableSortedDictionary <string, DataModelType> .Builder csTypes = ImmutableSortedDictionary.CreateBuilder <string, DataModelType>(StringComparer.Ordinal);
            foreach (DataModelType type in _g4Lookup.Values)
            {
                string key = type.CSharpName;
                if (csTypes.ContainsKey(key))
                {
                    csTypes[key] = null;
                }
                else
                {
                    csTypes.Add(key, type);
                }
            }
        }
 public bool ContainsKey(Datum d)
 {
     return(dict.ContainsKey(d));
 }
Beispiel #8
0
        private TokenType ScanStringSegment(bool isAtStartOfString)
        {
            // to handle interpolation, strings are broken down into multiple segments, to detect the portions of string between the 'holes'.
            // 'complete' string: a string with no holes (no interpolation), e.g. "'hello'"
            // string 'left piece': the portion of an interpolated string up to the first hole, e.g. "'hello$"
            // string 'middle piece': the portion of an interpolated string between two holes, e.g. "}hello${"
            // string 'right piece': the portion of an interpolated string after the last hole, e.g. "}hello'"

            while (true)
            {
                if (textWindow.IsAtEnd())
                {
                    AddDiagnostic(b => b.UnterminatedString());
                    return(isAtStartOfString ? TokenType.StringComplete : TokenType.StringRightPiece);
                }

                var nextChar = textWindow.Peek();

                if (IsNewLine(nextChar))
                {
                    // do not consume the new line character
                    AddDiagnostic(b => b.UnterminatedStringWithNewLine());
                    return(isAtStartOfString ? TokenType.StringComplete : TokenType.StringRightPiece);
                }

                int escapeBeginPosition = textWindow.GetAbsolutePosition();
                textWindow.Advance();

                if (nextChar == '\'')
                {
                    return(isAtStartOfString ? TokenType.StringComplete : TokenType.StringRightPiece);
                }

                if (nextChar == '$' && !textWindow.IsAtEnd() && textWindow.Peek() == '{')
                {
                    textWindow.Advance();
                    return(isAtStartOfString ? TokenType.StringLeftPiece : TokenType.StringMiddlePiece);
                }

                if (nextChar != '\\')
                {
                    continue;
                }

                // an escape sequence was started with \
                if (textWindow.IsAtEnd())
                {
                    // the escape was unterminated
                    AddDiagnostic(b => b.UnterminatedStringEscapeSequenceAtEof());
                    return(isAtStartOfString ? TokenType.StringComplete : TokenType.StringRightPiece);
                }

                // the escape sequence has a char after the \
                // consume it
                nextChar = textWindow.Peek();
                textWindow.Advance();

                if (nextChar == 'u')
                {
                    // unicode escape

                    if (textWindow.IsAtEnd())
                    {
                        // string was prematurely terminated
                        // reusing the first check in the loop body to produce the diagnostic
                        continue;
                    }

                    nextChar = textWindow.Peek();
                    if (nextChar != '{')
                    {
                        // \u must be followed by {, but it's not
                        AddDiagnostic(textWindow.GetSpanFromPosition(escapeBeginPosition), b => b.InvalidUnicodeEscape());
                        continue;
                    }

                    textWindow.Advance();
                    if (textWindow.IsAtEnd())
                    {
                        // string was prematurely terminated
                        // reusing the first check in the loop body to produce the diagnostic
                        continue;
                    }

                    string codePointText = ScanHexNumber(textWindow);
                    if (textWindow.IsAtEnd())
                    {
                        // string was prematurely terminated
                        // reusing the first check in the loop body to produce the diagnostic
                        continue;
                    }

                    if (string.IsNullOrEmpty(codePointText))
                    {
                        // we didn't get any hex digits
                        AddDiagnostic(textWindow.GetSpanFromPosition(escapeBeginPosition), b => b.InvalidUnicodeEscape());
                        continue;
                    }

                    nextChar = textWindow.Peek();
                    if (nextChar != '}')
                    {
                        // hex digits must be followed by }, but it's not
                        AddDiagnostic(textWindow.GetSpanFromPosition(escapeBeginPosition), b => b.InvalidUnicodeEscape());
                        continue;
                    }

                    textWindow.Advance();

                    if (!TryParseCodePoint(codePointText, out _))
                    {
                        // code point is not actually valid
                        AddDiagnostic(textWindow.GetSpanFromPosition(escapeBeginPosition), b => b.InvalidUnicodeEscape());
                        continue;
                    }
                }
                else
                {
                    // not a unicode escape
                    if (SingleCharacterEscapes.ContainsKey(nextChar) == false)
                    {
                        // the span of the error is the incorrect escape sequence
                        AddDiagnostic(textWindow.GetLookbehindSpan(2), b => b.UnterminatedStringEscapeSequenceUnrecognized(CharacterEscapeSequences));
                    }
                }
            }
        }
Beispiel #9
0
 public bool ContainsKey(string key)
 {
     return(_fields.ContainsKey(key));
 }
Beispiel #10
0
 public bool ContainsPath(string path) => _items.ContainsKey(path);
Beispiel #11
0
        public static DataModel HoistTypes(DataModel source)
        {
            ImmutableSortedDictionary <string, HoistAction> hoistMap = GetViableHoistEdgeList(source);

            if (hoistMap.Count == 0)
            {
                return(source);
            }

            hoistMap = RemoveCycles(hoistMap);
            hoistMap = ApplyTransitiveProperty(hoistMap);
            var newTypes = new List <DataModelType>();

            foreach (DataModelType sourceType in source.Types)
            {
                if (hoistMap.ContainsKey(sourceType.G4DeclaredName))
                {
                    // This type is being eliminated
                    continue;
                }

                bool anythingDifferent = false;
                ImmutableArray <DataModelMember> .Builder newMembers = ImmutableArray.CreateBuilder <DataModelMember>();
                foreach (DataModelMember sourceMember in sourceType.Members)
                {
                    HoistAction todo;
                    if (hoistMap.TryGetValue(sourceMember.DeclaredName, out todo))
                    {
                        anythingDifferent = true;
                        newMembers.Add(new DataModelMember(
                                           todo.Becomes,
                                           sourceMember.CSharpName,
                                           sourceMember.SerializedName,
                                           sourceMember.SummaryText,
                                           sourceMember.ArgumentName,
                                           sourceMember.Pattern,
                                           sourceMember.Minimum,
                                           sourceMember.MinItems,
                                           sourceMember.UniqueItems,
                                           sourceMember.Default,
                                           sourceMember.Rank + todo.AddedRanks,
                                           sourceMember.Required
                                           ));
                    }
                    else
                    {
                        newMembers.Add(sourceMember);
                    }
                }

                if (anythingDifferent)
                {
                    newTypes.Add(new DataModelType(
                                     sourceType.RootObject,
                                     sourceType.SummaryText,
                                     sourceType.RemarksText,
                                     sourceType.G4DeclaredName,
                                     sourceType.CSharpName,
                                     sourceType.InterfaceName,
                                     newMembers.ToImmutable(),
                                     ImmutableArray <string> .Empty,
                                     ImmutableArray <string> .Empty,
                                     ImmutableArray <ToStringEntry> .Empty,
                                     sourceType.Base,
                                     sourceType.Kind
                                     ));
                }
                else
                {
                    newTypes.Add(sourceType);
                }
            }

            return(new DataModel(source.SourceFilePath, source.MetaData, newTypes));
        }
Beispiel #12
0
 internal bool Contains(DocumentReference docRef) => _keyIndex.ContainsKey(docRef);