public void Sample1() { const string xml = "<xml><something foo=\"bar\" /><baz>zoink</baz></xml>"; var subject = new XmlLexer(); var tokens = subject.GetTokens(xml).ToArray(); _output.WriteLine(tokens.DumpForCode()); Check.That(tokens).Contains( new Token(0, TokenTypes.Name.Tag, "<xml"), new Token(4, TokenTypes.Name.Tag, ">"), new Token(5, TokenTypes.Name.Tag, "<something"), new Token(15, TokenTypes.Text, " "), new Token(16, TokenTypes.Name.Attribute, "foo="), new Token(20, TokenTypes.Literal.String, "\"bar\""), new Token(25, TokenTypes.Text, " "), new Token(26, TokenTypes.Name.Tag, "/>"), new Token(28, TokenTypes.Name.Tag, "<baz"), new Token(32, TokenTypes.Name.Tag, ">"), new Token(33, TokenTypes.Text, "zoink"), new Token(38, TokenTypes.Error, "<"), new Token(39, TokenTypes.Text, "/baz>"), new Token(44, TokenTypes.Error, "<"), new Token(45, TokenTypes.Text, "/xml>") ); }
public void TestParse() { // ARRANGE WebClient wc = new WebClient(); //string markup = wc.DownloadString("http://www.wikipedia.org"); //string markup = wc.DownloadString("https://www.w3schools.com/xml/note.xml"); string markup = @" <Query> <Where> <And> <Gt> <FieldRef Name='Quantity' /> <Value Type='Number'>0</Value> </Gt> <Leq> <FieldRef Name='Price' /> <Value Type='Number'>2000</Value> </Leq> </And> </Where> </Query>"; // ACT // MarkupParser parser = new MarkupParser(); // parser.Parse( markup ); XmlLexer lexer = new XmlLexer(); lexer.Read(markup); //// OUTPUT //foreach ( XmlToken tok in lexer.GetTokens()) { // Trace.WriteLine( string.Format(" ['{0}',{1}]", tok.lexeme, tok.type) ); //} XmlParser parser = new XmlParser(); parser.Parse(lexer.GetTokens()); //parser.TraceTree(); // ASSERT XmlDocument actual = parser.Tree; XmlDocument expected = new XmlDocument(); expected.LoadXml(markup); Assert.AreEqual(actual.OuterXml, expected.OuterXml); }
public MainWindow() { // This needs to exist prior to the InitializeComponent() call; otherwise, key binding (Ctrl-G) will not work this.GoToCommand = new RelayCommand(this.ExecuteGoTo); this.InitializeComponent(); this.viewModel = (MainWindowViewModel)this.DataContext; // Initialize find / replace / goto dialogs this.FindReplaceDialog.Scintilla = this.Editor.Scintilla; this.FindReplaceDialog.KeyPressed += this.OnEditorKeyDown; this.viewModel.ShowSettings += (o, e) => this.ShowSettings(); this.viewModel.ShowCallbacks += (o, e) => this.ShowCallbacks(e.Data); this.viewModel.ReadEditorInfo += (o, e) => e.Data = new EditorInfo { Text = this.Editor.Text, Selection = Tuple.Create(this.Editor.SelectionStart, this.Editor.SelectionEnd) }; this.viewModel.InsertRecentFile += (o, e) => this.RecentFileList.InsertFile(e.Data); this.viewModel.UpdateLexer += (o, e) => this.lexer.Update(); this.viewModel.UpdateEditor += (o, e) => { this.Editor.DeleteRange(e.Start, (e.End >= 0 ? e.End : this.Editor.TextLength) - e.Start); this.Editor.InsertText(e.Start, e.NewText); if (e.UpdateSelection) { this.Editor.SetSelection(e.Start, e.Start + e.NewText.Length); } if (e.ResetUndoHistory) { this.Editor.EmptyUndoBuffer(); } }; this.lexer = new XmlLexer { Editor = this.Editor }; }
public string OnSave(string source, byte additionalOptions) { string jsonString; Token[] tokens = XmlLexer.GetTokens(source); tokens = XmlLexer.AddArray(new List <string> { "AstronomicalObject", "UidHash" }, new List <string>() { "AstroObjects", "AstroObjectsEditors" }, tokens); XmlToJsonParser parser = new XmlToJsonParser((SerializationOptions)additionalOptions); jsonString = parser.GetJsonString(tokens); string removeString = "\"SaveInfo\": "; if (jsonString.Length > removeString.Length) { jsonString = jsonString.Substring(removeString.Length, jsonString.Length - removeString.Length); } return(jsonString); }
private void TestLexer(string source, TokenListBuilder <LexerTokenType> expected) { var actual = XmlLexer.LexTokens(source, new Position(0, 0, 0)); Assert.True(expected.SequenceEqual(actual, this.comparer)); }