예제 #1
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);
        }
예제 #2
0
 public static void OnError(this FlagsLexer lexer, Action <object, ErrorEventArgs> handler)
 {
     OnError(lexer, "ErrorHandler", handler);
 }