internal LuaClassifier(ITextBuffer buffer, IClassificationTypeRegistryService typeService) { _buffer = buffer; _grammar = new LuaGrammar(); _parser = new Irony.Parsing.Parser(_grammar); _parser.Context.Mode = Irony.Parsing.ParseMode.VsLineScan; _luaTags = new Dictionary <Irony.Parsing.TokenType, ClassificationTag>(); _luaTags[Irony.Parsing.TokenType.Text] = BuildTag(typeService, PredefinedClassificationTypeNames.Character); _luaTags[Irony.Parsing.TokenType.Keyword] = BuildTag(typeService, PredefinedClassificationTypeNames.Keyword); _luaTags[Irony.Parsing.TokenType.Identifier] = BuildTag(typeService, PredefinedClassificationTypeNames.Identifier); _luaTags[Irony.Parsing.TokenType.String] = BuildTag(typeService, PredefinedClassificationTypeNames.String); _luaTags[Irony.Parsing.TokenType.Literal] = BuildTag(typeService, PredefinedClassificationTypeNames.Literal); _luaTags[Irony.Parsing.TokenType.Operator] = BuildTag(typeService, PredefinedClassificationTypeNames.Operator); _luaTags[Irony.Parsing.TokenType.LineComment] = BuildTag(typeService, PredefinedClassificationTypeNames.Comment); _luaTags[Irony.Parsing.TokenType.Comment] = BuildTag(typeService, PredefinedClassificationTypeNames.Comment); _commentTag = BuildTag(typeService, PredefinedClassificationTypeNames.Comment); _funcionTag = BuildTag(typeService, "function"); _tableTag = BuildTag(typeService, "table"); InitializeLineStates(_buffer.CurrentSnapshot); }
/// <summary> /// Prevents a default instance of the <see cref="ShaderParser"/> class from being created. /// </summary> /// <param name="languageData">The language data.</param> /// <param name="root">The root of the language.</param> private ShaderParser(ShaderLanguageData languageData, NonTerminal root) { LanguageData = languageData; Grammar = (ShaderGrammar)languageData.Grammar; Tokenizer = new Tokenizer(languageData); Parser = new Irony.Parsing.Parser(languageData, null, root); }
private static ParseTree Parse(string input, bool allowPartial) { ParseTree parseTree = null; IronyParser.Context.Mode = allowPartial ? ParseMode.CommandLine : ParseMode.File; try { parseTree = IronyParser.Parse(input); } catch (Exception) { var msg = "The parser internally crashed and gets reinitialized." + Environment.NewLine + "Although this shouldn't happen, it's likely that it happened because of invalid syntax."; IronyParser = new IronyParser(Grammar); throw new ParseException(msg); } if (parseTree.HasErrors()) // ParseTreeStatus is Error { var logMessage = parseTree.ParserMessages.First(); throw new ParseException(logMessage.Message, logMessage.Location.Line, logMessage.Location.Column, parseTree.SourceText); } return(parseTree); }
void RefreshFile(object arg) { Irony.Parsing.Parser parser = new Irony.Parsing.Parser(Grammar.LuaGrammar.Instance); var tree = parser.Parse(_cur.TextBuffer.CurrentSnapshot.GetText()); OnFileContentChanged(_cur.TextBuffer.CurrentSnapshot, tree); }
public PieScanner(IVsTextBuffer buffer) { m_buffer = buffer; grammar = new PieGrammar(); parser = new Irony.Parsing.Parser(grammar); parser.Context.Mode = Irony.Parsing.ParseMode.VsLineScan; }
void ReParse() { ITextSnapshot newSnapshot = buffer.CurrentSnapshot; List <Region> newRegions = new List <Region>(); LuaLanguage.LuaGrammar grammar = new LuaLanguage.LuaGrammar(); Irony.Parsing.Parser parser = new Irony.Parsing.Parser(grammar); var tree = parser.Parse(newSnapshot.GetText()); if (tree.Root != null) { FindHiddenRegions(newSnapshot, tree.Root, ref newRegions); } //determine the changed span, and send a changed event with the new spans List <Span> oldSpans = new List <Span>(this.regions.Select(r => AsSnapshotSpan(r, this.snapshot) .TranslateTo(newSnapshot, SpanTrackingMode.EdgeExclusive) .Span)); List <Span> newSpans = new List <Span>(newRegions.Select(r => AsSnapshotSpan(r, newSnapshot).Span)); NormalizedSpanCollection oldSpanCollection = new NormalizedSpanCollection(oldSpans); NormalizedSpanCollection newSpanCollection = new NormalizedSpanCollection(newSpans); //the changed regions are regions that appear in one set or the other, but not both. NormalizedSpanCollection removed = NormalizedSpanCollection.Difference(oldSpanCollection, newSpanCollection); int changeStart = int.MaxValue; int changeEnd = -1; if (removed.Count > 0) { changeStart = removed[0].Start; changeEnd = removed[removed.Count - 1].End; } if (newSpans.Count > 0) { changeStart = Math.Min(changeStart, newSpans[0].Start); changeEnd = Math.Max(changeEnd, newSpans[newSpans.Count - 1].End); } this.snapshot = newSnapshot; this.regions = newRegions; if (changeStart <= changeEnd) { ITextSnapshot snap = this.snapshot; if (this.TagsChanged != null) { this.TagsChanged(this, new SnapshotSpanEventArgs( new SnapshotSpan(this.snapshot, Span.FromBounds(changeStart, changeEnd)))); } } }
public void IronyJson() { var result = new Irony.Parsing.Parser(new IronyJsonGrammar()).Parse(JsonString); if (result.HasErrors()) { throw new Exception("Parsing failed"); } }
void RefreshFile(object arg) { Irony.Parsing.Parser parser = new Irony.Parsing.Parser(Grammar.LuaGrammar.Instance); var tree = parser.Parse(_cur.TextBuffer.CurrentSnapshot.GetText()); //降低文本变化的敏感度,选择性刷新? //if(!tree.HasErrors()) OnFileContentChanged(_cur.TextBuffer.CurrentSnapshot, tree); }
public LuaSyntaxErrorTagger(ITextBuffer buffer) { this.buffer = buffer; Babe.Lua.Editor.TextViewCreationListener.FileContentChanged += TextViewCreationListener_FileContentChanged; Irony.Parsing.Parser parser = new Irony.Parsing.Parser(LuaGrammar.Instance); var tree = parser.Parse(buffer.CurrentSnapshot.GetText()); ReParse(buffer.CurrentSnapshot, tree); }
public OutliningTagger(ITextBuffer buffer) { this.buffer = buffer; this.snapshot = buffer.CurrentSnapshot; this.regions = new List <Region>(); Babe.Lua.Editor.TextViewCreationListener.FileContentChanged += TextViewCreationListener_FileContentChanged; Irony.Parsing.Parser parser = new Irony.Parsing.Parser(LuaGrammar.Instance); var tree = parser.Parse(snapshot.GetText()); ReParse(snapshot, tree); }
private void ReParse() { int previousCount = errorTokens.Count; errorTokens.Clear(); ITextSnapshot newSnapshot = this.buffer.CurrentSnapshot; string text = newSnapshot.GetText(); Irony.Parsing.Parser parser = new Irony.Parsing.Parser(grammar); var newErrors = new List <Irony.Parsing.Token>(); var parseTree = parser.Parse(text); foreach (var token in parseTree.Tokens) { if (token.IsError()) { errorTokens.Add(token); } } if (parseTree.HasErrors()) { var tok = parseTree.Tokens.Last(); errorTokens.Add(tok); //if (tok.Length != 0) // errorTokens.Add(tok); //else //it is EOF error so before the end(use -2) // errorTokens.Add(parseTree.Tokens[parseTree.Tokens.Count - 2]); msgParse = parseTree.ParserMessages[0].ToString(); } else { msgParse = ""; } if (previousCount != 0 || errorTokens.Count != 0) { if (this.TagsChanged != null) { this.TagsChanged(this, new SnapshotSpanEventArgs( new SnapshotSpan(newSnapshot, 0, newSnapshot.Length))); } } }
static void Main(string[] args) { TotemGrammar tg = new TotemGrammar(); Irony.Parsing.Parser parser = new Irony.Parsing.Parser(tg); var tree = parser.Parse(new StreamReader(File.OpenRead("test.pole")).ReadToEnd(), "test.pole"); if (!tree.HasErrors()) { var generator = new Generator("test", Path.Combine(Environment.CurrentDirectory, "test.exe"), tg); var rootNode = tree.Root; generator.GenerateProgram(rootNode); generator.Save(); } else { Console.WriteLine("Error in input"); Console.ReadLine(); } }
public OutliningTagger(ITextBuffer buffer) { this.buffer = buffer; this.snapshot = buffer.CurrentSnapshot; this.regions = new List <Region>(); Babe.Lua.Editor.TextViewCreationListener.FileContentChanged += TextViewCreationListener_FileContentChanged; Irony.Parsing.Parser parser = new Irony.Parsing.Parser(LuaGrammar.Instance); var tree = parser.Parse(snapshot.GetText()); try { ReParse(snapshot, tree); } catch (Exception ex) { if (UploadError) { UploadError = false; Logger.LogMessage("LuaOutliner.ReParse error.\r\nPosition : " + ex.TargetSite + "\r\nMessage : " + ex.Message); } } }
private static ParseTree Parse(string input, bool allowPartial) { ParseTree parseTree = null; IronyParser.Context.Mode = allowPartial ? ParseMode.CommandLine : ParseMode.File; try { parseTree = IronyParser.Parse(input); } catch (Exception) { var msg = "The parser internally crashed and gets reinitialized." + Environment.NewLine + "Although this shouldn't happen, it's likely that it happened because of invalid syntax."; IronyParser = new IronyParser(Grammar); throw new ParseException(msg); } if (parseTree.HasErrors()) // ParseTreeStatus is Error { var logMessage = parseTree.ParserMessages.First(); throw new ParseException(logMessage.Message, logMessage.Location.Line, logMessage.Location.Column, parseTree.SourceText); } return parseTree; }
public static List <MultiValue> FromStringValue(CDataWrapper value) { var parser = new Irony.Parsing.Parser(new Grammars.PCodeGrammar()); var tree = parser.Parse(value); if (tree.Status != Irony.Parsing.ParseTreeStatus.Parsed) { throw new FormatException("failed to parse pcode"); } var list = new List <MultiValue>(); var labels = new Dictionary <string, int>(); foreach (var line in tree.Root.ChildNodes) { var label = line.ChildNodes.SingleOrDefault(c => c.Term.Name == "LABEL"); if (label != null) { labels.Add(label.ChildNodes[0].Token.ValueString, list.Count); } var statement = line.ChildNodes.SingleOrDefault(c => c.Term.Name == "STATEMENT"); if (statement != null) { var code = statement.ChildNodes[0]; MultiValueOpcode op; object arg = null; if (_SimpleOps.ContainsKey(code.Term.Name) == true) { op = _SimpleOps[code.Term.Name]; } else { switch (code.Term.Name) { case "OP_J__": { op = MultiValueOpcode.J__; arg = code.ChildNodes[1].Token.ValueString; break; } case "OP_JZ_": { op = MultiValueOpcode.JZ_; arg = code.ChildNodes[1].Token.ValueString; break; } case "OP_S_V": { op = MultiValueOpcode.S_V; StaticVariableType sv; if (MultiValue.TryParseStaticVariable(code.ChildNodes[1].Token.Text, out sv) == false) { throw new FormatException("invalid static variable type"); } arg = sv; break; } case "OP_STR": { op = MultiValueOpcode.STR; arg = code.ChildNodes[1].Token.ValueString; break; } case "OP_INT": { op = MultiValueOpcode.INT; arg = code.ChildNodes[1].Token.Value; break; } case "OP_FLT": { op = MultiValueOpcode.FLT; arg = code.ChildNodes[1].Token.Value; break; } case "OP_OBJ": { op = MultiValueOpcode.OBJ; arg = code.ChildNodes[1].Token.ValueString; break; } case "OP_RP_": { op = MultiValueOpcode.RP_; arg = code.ChildNodes[1].Token.ValueString; break; } case "OP_IDS": { op = MultiValueOpcode.IDS; arg = code.ChildNodes[1].Token.ValueString; break; } case "OP_FUN": { op = MultiValueOpcode.FUN; arg = code.ChildNodes[1].Token.ValueString; break; } default: { throw new NotImplementedException(); } } } list.Add(new MultiValue() { Op = op, Arg = arg, }); } } foreach (var mv in list.Where( item => item.Op == MultiValueOpcode.J__ || item.Op == MultiValueOpcode.JZ_)) { var label = (string)mv.Arg; if (labels.ContainsKey(label) == false) { throw new InvalidOperationException(); } mv.Arg = (long)labels[label]; } return(list); }
public Form1() { InitializeComponent(); Parser = new Irony.Parsing.Parser(new DCPUC.Grammar()); }
public CILParser() { _ironyParser = new Irony.Parsing.Parser(new CILGrammar()); _astBuilder = new CILASTBuilder(); }
static Parser() { Grammar = new PowerShellGrammar(); IronyParser = new IronyParser(Grammar); }
public CILParser() { _parser = new Irony.Parsing.Parser(new CILGrammar()); _astBuilder = new ProgramBuilder(); }