/// <summary> /// Initializes a new instance of the <see cref="GrammarMonitor" /> class. /// </summary> /// <param name="grammar">The grammar.</param> /// <param name="synchronizationContext">The synchronization context.</param> /// <exception cref="ArgumentNullException"> /// grammar /// or /// synchronizationContext are <see langword="null" /> /// </exception> /// <exception cref="T:System.Security.SecurityException"> /// The caller does not have the required permission to access the /// grammar assembly. /// </exception> /// <exception cref="T:System.UnauthorizedAccessException">Access to the grammar assembly is denied.</exception> public GrammarMonitor([NotNull] GrammarReference grammar, [NotNull] SynchronizationContext synchronizationContext) { Grammar = grammar ?? throw new ArgumentNullException(nameof(grammar)); _SynchronizationContext = synchronizationContext ?? throw new ArgumentNullException(nameof(synchronizationContext)); _Watcher = CreateAssemblyWatcher(new FileInfo(grammar.AssemblyPath)); }
private static void DisplayTokens(GrammarReference grammar, string data) { var analyzer = new Grammar.Analyzer(); var tokens = analyzer.Tokenize(grammar, data); foreach (var token in tokens) { Console.WriteLine(token.ToString()); } }
/// <summary> /// Initializes a new instance of the <see cref="ParserWorkItem" /> struct. /// </summary> /// <param name="grammar">The grammar to parse with.</param> /// <param name="parserRuleName">Name of the parser rule.</param> /// <param name="text">The text to parse.</param> /// <param name="options">The parser options.</param> /// <param name="parseWhen">The DateTime indicating when to parse.</param> /// <exception cref="ArgumentNullException"><paramref name="grammar" /> is <see langword="null" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="parserRuleName" /> is <see langword="null" /> or empty.</exception> public ParserWorkItem( [NotNull] GrammarReference grammar, [NotNull] string parserRuleName, string text, ParseOption options, DateTime parseWhen) { Grammar = grammar ?? throw new ArgumentNullException(nameof(grammar)); ParserRuleName = parserRuleName ?? throw new ArgumentNullException(nameof(parserRuleName)); Text = text; Options = options; ParseWhen = parseWhen; }
private static void LoadGui(string data, GrammarReference grammar, string parserRule) { { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var visualAnalyzer = new VisualAnalyzer(); visualAnalyzer.SetSourceCode(data); visualAnalyzer.SetGrammar(grammar); if (grammar.Parser != null || !parserRule.Equals("tokens", StringComparison.InvariantCultureIgnoreCase)) { visualAnalyzer.SetDefaultParserRule(parserRule); } Application.Run(visualAnalyzer); } }
/// <inheritdoc /> public void Parse(GrammarReference grammar, string parserRuleName, string text, ParseOption options) { lock (_Padlock) { var nextRun = CalculateNextRunTime(_PreviousNodeQty, 50, 5, 1000); var work = new ParserWorkItem(grammar, parserRuleName, text, options, nextRun); QueuedWork.Enqueue(work); _LastQueuedTime = DateTime.Now; if (ParserTask.IsCompleted) { ParserTask = new Task(ParserWorkLoop); } if (ParserTask.Status != TaskStatus.Running) { ParserTask.Start(); } } }
/// <summary> /// Attempts to load a the syntax highlighting guide from path for the specified grammar. /// </summary> /// <param name="grammar">The grammar to load a guide for.</param> /// <param name="scanner">The scanner to use.</param> /// <param name="loader">The loader to use.</param> /// <param name="searchPath">The search path.</param> /// <returns>A new <see cref="Tuple{ISyntaxHighlightingGuide, SyntaxHighlightingGuideReference}"/> or <see langword="null"/>.</returns> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="grammar" /> /// or /// <paramref name="scanner" /> /// or /// <paramref name="loader" /> /// or /// <paramref name="searchPath" /> are <see langword="null" /> or empty. /// </exception> /// <exception cref="T:System.IO.FileLoadException">A file that was found could not be loaded.</exception> /// <exception cref="T:System.IO.FileNotFoundException">The assembly path is an empty string ("") or does not exist.</exception> /// <exception cref="T:System.BadImageFormatException">The assembly path is not a valid assembly.</exception> public static Tuple <SyntaxHighlightingGuideReference, ISyntaxHighlightingGuide> LoadSyntaxGuideFromPath( [NotNull] GrammarReference grammar, [NotNull] Scanner scanner, [NotNull] Loader loader, [NotNull] string searchPath) { if (grammar == null) { throw new ArgumentNullException(nameof(grammar)); } if (scanner == null) { throw new ArgumentNullException(nameof(scanner)); } if (loader == null) { throw new ArgumentNullException(nameof(loader)); } if (string.IsNullOrEmpty(searchPath)) { throw new ArgumentNullException(nameof(searchPath)); } var guideReferences = scanner.LocateAllSyntaxGuides(searchPath); foreach (var reference in guideReferences) { var guide = loader.LoadSyntaxGuide(reference); if (guide != null && guide.GrammarName == grammar.GrammarName) { return(new Tuple <SyntaxHighlightingGuideReference, ISyntaxHighlightingGuide>(reference, guide)); } } return(null); }
/// <summary> /// Attempts to load a syntax highlighting guide for the grammar. /// </summary> /// <param name="grammar">The grammar to use.</param> /// <returns>A new <see cref="Tuple{ISyntaxHighlightingGuide, SyntaxHighlightingGuideReference}"/> or <see langword="null"/>.</returns> /// <exception cref="ArgumentNullException"><paramref name="grammar"/> is <see langword="null"/>.</exception> /// <exception cref="T:System.IO.FileLoadException">A file that was found could not be loaded.</exception> /// <exception cref="T:System.IO.FileNotFoundException">The assembly path is an empty string ("") or does not exist.</exception> /// <exception cref="T:System.BadImageFormatException">The assembly path is not a valid assembly.</exception> public static Tuple <SyntaxHighlightingGuideReference, ISyntaxHighlightingGuide> LoadSyntaxHighlightingGuide([NotNull] this GrammarReference grammar) { if (grammar == null) { throw new ArgumentNullException(nameof(grammar)); } var scanner = new Scanner(); var loader = new Loader(); // First try loading a guide from the target assembly's directory var pathRoot = Path.GetDirectoryName(grammar.AssemblyPath); Tuple <SyntaxHighlightingGuideReference, ISyntaxHighlightingGuide> guideResult = null; if (Directory.Exists(pathRoot)) { guideResult = SyntaxHighlighting.LoadSyntaxGuideFromPath(grammar, scanner, loader, pathRoot); if (guideResult != null) { return(guideResult); } } // Now try loading a guide from the Grun.Net Guides folder pathRoot = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase); // ReSharper disable once AssignNullToNotNullAttribute pathRoot = Path.Combine(pathRoot, "Guides"); if (Directory.Exists(pathRoot)) { guideResult = SyntaxHighlighting.LoadSyntaxGuideFromPath(grammar, scanner, loader, pathRoot); } return(guideResult); }