Ejemplo n.º 1
0
        public static Dictionary <string, IPapyrusFlag> GetFlags(this FlagsParser flagsParser)
        {
            var mappedDict = new Dictionary <string, IPapyrusFlag>();

            dynamic flagsDict = flagsParser.AsDynamic().DefinedFlags;

            foreach (var pair in flagsDict)
            {
                dynamic asDynamicPair = ReflectionMagic.PrivateReflectionUsingDynamicExtensions.AsDynamic(pair);
                mappedDict.Add(asDynamicPair.Key, new PapyrusFlag(asDynamicPair.Value));
            }

            return(mappedDict);
        }
Ejemplo n.º 2
0
        public FlagsFile(PapyrusProgram program, IScriptTextProvider textProvider, ILogger <FlagsFile> logger)
        {
            _program      = program;
            _textProvider = textProvider;

            _logger = logger;

            // TODO: Invalidate this
            _flagsFilePath = new CachedValue <string>(() => _program.GetFlagsFilePath().WaitForResult());

            _scriptText = new TokenEqualityCachedValue <ScriptText, string>(
                () => _textProvider.GetText(_flagsFilePath).WaitForResult(),
                (_) => _textProvider.GetTextVersion(_flagsFilePath).WaitForResult());

            _textProvider.OnScriptTextChanged += HandleScriptTextChanged;

            _parseResult = new TokenEqualityCachedValue <DiagnosticResult <dynamic>, string>(() =>
            {
                return(DiagnosticResult <dynamic> .TryWithDiagnostics((diagnostics) =>
                {
                    void errorHandler(object s, ErrorEventArgs e)
                    {
                        diagnostics.Add(e.ToDiagnostic());
                    }

                    var flagsLexer = new FlagsLexer(new CaseInsensitiveStringStream(_scriptText.Value.Text));
                    flagsLexer.OnError(errorHandler);

                    var flagsParser = new FlagsParser(new CommonTokenStream(flagsLexer));
                    flagsParser.OnError(errorHandler);

                    flagsParser.flags();

                    return flagsParser.AsDynamic().DefinedFlags;
                }));
            },
                                                                                             (_) => _scriptText.Value.Version);
        }