public void TestComplex() { Parser p = new Parser(); var cplx = new Ast.ComplexNumberNode() { Real = 4.2, Imaginary = 3.2 }; var cplx2 = new Ast.ComplexNumberNode() { Real = 4.2, Imaginary = 99 }; Assert.AreNotEqual(cplx, cplx2); cplx2.Imaginary = 3.2; Assert.AreEqual(cplx, cplx2); Assert.AreEqual(cplx, p.Parse("(4.2+3.2j)").Root); cplx.Real = 0; Assert.AreEqual(cplx, p.Parse("(0+3.2j)").Root); Assert.AreEqual(cplx, p.Parse("3.2j").Root); Assert.AreEqual(cplx, p.Parse("+3.2j").Root); cplx.Imaginary = -3.2; Assert.AreEqual(cplx, p.Parse("-3.2j").Root); cplx.Real = -9.9; Assert.AreEqual(cplx, p.Parse("(-9.9-3.2j)").Root); cplx.Real = 2; cplx.Imaginary = 3; Assert.AreEqual(cplx, p.Parse("(2+3j)").Root); cplx.Imaginary = -3; Assert.AreEqual(cplx, p.Parse("(2-3j)").Root); cplx.Real = 0; Assert.AreEqual(cplx, p.Parse("-3j").Root); }
public void TestBasic() { Parser p = new Parser(); Assert.IsNull(p.Parse((string)null).Root); Assert.IsNull(p.Parse("").Root); Assert.IsNotNull(p.Parse("# comment\n42\n").Root); }
static void run(IEnumerable<String> filePaths) { var p = new Parser(); var modules = new Dictionary<String, IReadOnlyList<IClassItem>>(); foreach (var path in filePaths.Reverse()) { Contract.Assume(path != null); var txt = File.ReadAllText(path); var items = p.Parse(txt, ValidationList); modules.Add(Path.GetFileNameWithoutExtension(path), items.Cast<IClassItem>().ToList()); } var preludeTxt = File.ReadAllText(libPath + "prelude.ef"); var preludeTxtItems = p.Parse(preludeTxt, ValidationList); var rw = new Rewriter(); var prog = rw.MakeProgram(preludeTxtItems.Cast<Declr>().ToList(), modules); var n = new Namer(); n.Name(prog, ValidationList); var ti = new TypeInferer(); ti.VisitDeclr(prog.GlobalModule); var i = new Interpreter(); var res = i.Run(prog, ValidationList); Console.Write("Result: "); Console.WriteLine(res.Accept(DefaultPrinter)); }
public void TestAstEquals() { Parser p = new Parser (); byte[] ser = File.ReadAllBytes ("testserpent.utf8.bin"); Ast ast = p.Parse(ser); Ast ast2 = p.Parse(ser); Assert.AreEqual(ast.Root, ast2.Root); }
public void repeated_parsing_yields_different_values() { var parser = new Parser(); var result1 = parser.Parse("now"); Thread.Sleep(100); var result2 = parser.Parse("now"); Assert.NotEqual(result1.ToTime(), result2.ToTime()); }
public void RequiredArgumentsWork() { var strategy = new Parser(); strategy.AddDescription(new NamedArgumentDescription<string>("required") { IsRequired = true }); var actual = strategy.Parse("--notrequired=mmmm"); Assert.That(actual.IsValid, Is.False); var actual2 = strategy.Parse("--required=aaa"); Assert.That(actual2.IsValid); }
public void PositionedArgumentValidation() { var strategy = new Parser(); strategy.AddDescription(new PositionedArgumentDescription<string>(0) { MatchPattern = "^\\d+$" }); var actual = strategy.Parse("ab112d", "111333442"); Assert.That(actual.IsValid, Is.False); var actual2 = strategy.Parse("111333442", "ab112d"); Assert.That(actual2.IsValid); }
public void PatternMatchingWorks() { var strategy = new Parser(); strategy.AddDescription(new NamedArgumentDescription<string>("numbers") { MatchPattern = "^\\d+$" }); var actual = strategy.Parse("--numbers=ab112d"); Assert.That(actual.IsValid, Is.False); var actual2 = strategy.Parse("--numbers=12345"); Assert.That(actual2.IsValid); }
public static void Main(string[] args) { var parser = new Parser(new Worm.WormFactory()); string workingDir = Directory.GetCurrentDirectory(); DirectoryInfo libRoot = Directory.GetParent(workingDir).Parent.Parent.GetDirectories("fullflow-lib")[0]; string modelProjectFile = String.Format("{0}/fullflow-lib.csproj", libRoot.FullName); PocoModel model = parser.Parse(modelProjectFile); foreach (PocoEntity entity in model.Entities) { Console.WriteLine("DbFactory: {0}", entity.DbFactory.GetType().Name); Console.WriteLine("PocoClassName: {0}", entity.PocoClassName); Console.WriteLine("PocoFilename: {0}", entity.PocoFilename); Console.WriteLine("PocoNamespace: {0}", entity.PocoNamespace); Console.WriteLine("TableName: {0}", entity.TableName); Console.WriteLine(); foreach (PocoField field in entity.Fields) { Console.WriteLine("AccessModifier: {0}", field.AccessModifier); Console.WriteLine("AllowNull: {0}", field.AllowNull); Console.WriteLine("ColumnName: {0}", field.ColumnName); Console.WriteLine("HasGetter: {0}", field.HasGetter); Console.WriteLine("HasSetter: {0}", field.HasSetter); Console.WriteLine("IdGenerator: {0}", field.IdGenerator); Console.WriteLine("IsEnum: {0}", field.IsEnum); Console.WriteLine("IsPrimaryKey: {0}", field.IsPrimaryKey); Console.WriteLine("Name: {0}", field.Name); Console.WriteLine("StorageType: {0}", field.StorageType); Console.WriteLine("Type: {0}", field.Type); Console.WriteLine(); } Console.WriteLine(); } Engine eng = new Engine(); Project proj = new Project(eng); proj.Load(modelProjectFile); BuildItemGroup compileBuildItemGroup = GetCompileIncludeBuildItemGroup(proj); var writer = new DbClassWriter(new WormFactory()); foreach (PocoEntity entity in model.Entities) { CodeFile cf = writer.Generate(entity); //cf.Filename = cf.Filename.Replace("fullflowlib", "fullflow-lib"); WriteCodeFile(libRoot, cf); AddFileToProject(compileBuildItemGroup, cf); } proj.Save(modelProjectFile); // compile the project again parser.Parse(modelProjectFile); }
public void Parser_Reads_Character_Sets_Strings() { var parser = new Parser(); var css = parser.Parse("@charset 'utf-8';"); var charset = css.CharsetDirectives; Assert.AreEqual("@charset 'utf-8';", charset[0].ToString()); css = parser.Parse("@charset \"utf-8\";"); charset = css.CharsetDirectives; Assert.AreEqual("@charset 'utf-8';", charset[0].ToString()); }
public void ParseEmpty() { Parser parser = new Parser(); ExpressionQueue result = parser.Parse(null); Assert.IsNotNull(result); Assert.AreEqual(0, result.Count); result = parser.Parse(string.Empty); Assert.IsNotNull(result); Assert.AreEqual(0, result.Count); result = parser.Parse(" \t"); Assert.IsNotNull(result); Assert.AreEqual(0, result.Count); }
public static void Main(string[] args) { while (true) { try { string s = Console.ReadLine(); Lexer l = new Lexer(); Parser p = new Parser(l.Lex(s)); Ast.Chunk c = p.Parse(); Compiler.Compiler cplr = new SharpLua.Compiler.Compiler(); LuaFile proto = cplr.Compile(c, "<stdin>"); Console.WriteLine("compiled!"); FileStream fs = File.Open("out.sluac", FileMode.Create); foreach (char ch in proto.Compile()) { //Console.WriteLine(ch + " " + (int)ch); fs.WriteByte((byte)ch); } fs.Close(); Console.WriteLine("written to out.sluac!"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } Console.Write("Press any key to continue . . . "); Console.ReadKey(true); }
public void Functions() { var parser = new Parser(new Scanner("../../sources/for_unit_tests/functions.exs")); parser.DoPostParseProcessing = true; parser.Parse(); var ast = parser.TopmostAst; var options = new ExpressoCompilerOptions{ LibraryPaths = new List<string>{""}, OutputPath = "../../test_executable", BuildType = BuildType.Debug | BuildType.Executable }; var emitter = new CSharpEmitter(parser, options); ast.AcceptWalker(emitter, null); var asm = emitter.AssemblyBuilder; var main_method = asm.GetModule("main.exe") .GetType("ExsMain") .GetMethod("Main", BindingFlags.NonPublic | BindingFlags.Static); Assert.AreEqual(main_method.Name, "Main"); Assert.IsTrue(main_method.IsStatic); Assert.AreEqual(typeof(int), main_method.ReturnType); Assert.AreEqual(0, main_method.GetParameters().Length); //Assert.IsTrue(main_method.GetParameters().SequenceEqual(new []{typeof(string[])})); Console.Out.WriteLine("テスト実行"); Console.Out.WriteLine(main_method.ToString()); //main_method.Invoke(null, new object[]{}); }
public void Stylesheet_Renders_Friendly_Format() { var parser = new Parser(); var css = parser.Parse(Resources.Css3); Assert.AreEqual(Resources.Css3Friendly, css.ToString(true)); }
public static void Main(string[] arg) { Scanner scanner = new Scanner(arg[0]); Parser parser = new Parser(scanner); parser.Parse(); Console.Write(parser.errors.count + " errors detected"); }
public EvoQLExpression(string query, IEnumerable<GetTypes> defaultTypes) { MemoryStream stream = new MemoryStream(); String errorString; StreamWriter writer = new StreamWriter(stream); writer.Write(query); writer.Flush(); Scanner scanner = new Scanner(stream); Parser parser = new Parser(scanner); MemoryStream errorStream = new MemoryStream(); StreamWriter errorWriter = new StreamWriter(errorStream); parser.errors.errorStream = errorWriter; parser.Parse(); errorWriter.Flush(); errorStream.Seek(0, SeekOrigin.Begin); errorString = new StreamReader(errorStream).ReadToEnd(); errorStream.Close(); stream.Close(); if (parser.errors.count > 0) { Errors = errorString.Split('\n'); HadErrors = true; } else { Tree = parser.RootTree; } }
public void It_handles_nested_sections() { var parser = new Parser(); var template = new Template(); parser.Parse(template, new Part[] { new LiteralText("before foo"), new Block("foo"), new LiteralText("before bar"), new Block("bar"), new LiteralText("inside bar"), new EndSection("bar"), new LiteralText("after bar"), new EndSection("foo"), new LiteralText("after foo") }); template.Parts.IsEqualTo(new LiteralText("before foo"), new Block("foo", new LiteralText("before bar"), new Block("bar", new LiteralText("inside bar"), new EndSection("bar")), new LiteralText("after bar"), new EndSection("foo")), new LiteralText("after foo")); }
static void Main(string[] args) { String uaString = "";//Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30"; Stopwatch sw = new Stopwatch(); sw.Start(); Parser uaParser = new Parser(); Client c = uaParser.Parse(uaString); sw.Stop(); Console.WriteLine("Parsing the user agent string took " + sw.ElapsedMilliseconds + "ms\n"); Console.WriteLine("Browser"); Console.WriteLine(c.userAgent.family); Console.WriteLine(c.userAgent.major); Console.WriteLine(c.userAgent.minor); Console.WriteLine(); Console.WriteLine("OS"); Console.WriteLine(c.os.family); Console.WriteLine(c.os.major); Console.WriteLine(c.os.minor); Console.WriteLine(); Console.WriteLine("device family: " + c.device.family); Console.WriteLine("isMobile? " + c.device.isMobile); Console.ReadLine(); }
public void Should_Parse_Simple_Name_And_Array_Value() { var simpleTemplatStream = File.OpenRead(AppDomain.CurrentDomain.BaseDirectory + "/templates/simple template.xls"); IParser parser = new Parser(); try { var parserResult = parser.Parse(simpleTemplatStream, ExcelExtension.XLS); Assert.AreEqual(3, parserResult.Count); Assert.AreEqual("Name", parserResult[0].Name); Assert.AreEqual(0, parserResult[0].RowIndex); Assert.AreEqual(1, parserResult[0].ColumnIndex); Assert.IsFalse(parserResult[0].IsArray); Assert.AreEqual("Owner", parserResult[1].Name); Assert.AreEqual(3, parserResult[1].RowIndex); Assert.AreEqual(0, parserResult[1].ColumnIndex); Assert.IsTrue(parserResult[1].IsArray); Assert.AreEqual("Price", parserResult[2].Name); Assert.AreEqual(3, parserResult[2].RowIndex); Assert.AreEqual(1, parserResult[2].ColumnIndex); Assert.IsTrue(parserResult[2].IsArray); } finally { simpleTemplatStream.Close(); } }
public void TestLoopbackSimpleRTFTableGetsTable() { using (Stream sIn = new FileStream(TESTFILE_DIR + "SimpleRTFTable_document.xml", FileMode.Open)) { FcsToRtfWriter writerOut = new FcsToRtfWriter(); writerOut.RememberElementsWritten = true; ParsingContext context = new ParsingContext(); context.SetDefaultStartContext(); context.ParsingBody = true; Parser pft = new Parser(sIn, new BodyConsumer(context), writerOut); pft.Parse(); List<DocElement> elemsBefore = writerOut.ListOfWrittenElements(); Workshare.Compositor.FCSFilters.Reader readBack = new Workshare.Compositor.FCSFilters.Reader(); readBack.ExtractRTFFileCollectionFromWriter(writerOut); List<DocElement> elemsAfter = readBack.ReadBackAllElementsFromFileCollection(); int iCountBefore = elemsBefore.Count; int iCountAfter = elemsAfter.Count; Assert.IsTrue(iCountAfter <= iCountBefore, "Seem to have invented extra elements in teh loop back"); } }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //GridView1.DataSource = bll.GetScrollMatchList(); //GridView1.DataBind(); WebClient web = WebClientBLL.getWebClient(); string s = web.DownloadString("http://data.nowscore.com/detail/403052.html"); Lexer lexer = new Lexer(s); Parser parser = new Parser(lexer); INode tableNode = parser.Parse(new TagNameFilter("HTML"))[0].Children.ExtractAllNodesThatMatch(new TagNameFilter("BODY"))[0].Children[0]; TableTag tt = tableNode as TableTag; Response.Write(tt.GetRow(0).Columns[0].Children[0].Children[0].ToPlainTextString()); Response.Write(tt.GetRow(0).Columns[1].Children[0].Children[0].ToPlainTextString()); Response.Write(tt.GetRow(0).Columns[2].Children[0].Children[0].ToPlainTextString()); //ITag divNode = bodyNodes.ExtractAllNodesThatMatch(new TagNameFilter("FORM"))[0].Children.ExtractAllNodesThatMatch(new TagNameFilter("DIV"))[0] as ITag; //if (divNode.Attributes["ID"].Equals("PageBody")) //{ // NodeList dataDivList = divNode.Children.SearchFor(typeof(Winista.Text.HtmlParser.Tags.Div)); //} } }
static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("No file passed in"); return; } if (!File.Exists(args[0])) { Console.WriteLine("File Doesn't exist"); } Lexical lex = new Lexical(args[0]); Parser pars = new Parser(lex); if (pars.Parse()) { StreamWriter writer = new StreamWriter("Icode.txt"); foreach (Quad q in pars.Icode) { writer.WriteLine(q.ToString()); } writer.Close(); IcodeParser iParser = new IcodeParser(pars.SymbolTb, pars.Icode); iParser.Parse(); writer = new StreamWriter("Tcode.asm"); foreach (Quad q in iParser.GetTcode()) { writer.WriteLine(q.ToString()); } writer.Close(); } }
public override ParsedDocument Parse (ProjectDom dom, string fileName, string fileContent) { XmlParsedDocument doc = new XmlParsedDocument (fileName); doc.Flags |= ParsedDocumentFlags.NonSerializable; TextReader tr = new StringReader (fileContent); try { Parser xmlParser = new Parser (new XmlFreeState (), true); xmlParser.Parse (tr); doc.XDocument = xmlParser.Nodes.GetRoot (); doc.Add (xmlParser.Errors); if (doc.XDocument != null && doc.XDocument.RootElement != null) { if (!doc.XDocument.RootElement.IsEnded) doc.XDocument.RootElement.End (xmlParser.Location); } } catch (Exception ex) { MonoDevelop.Core.LoggingService.LogError ("Unhandled error parsing xml document", ex); } finally { if (tr != null) tr.Dispose (); } return doc; }
public void DuplicateMethod() { string text = @" define Run() for method in Methods do method.InsertProlog(text) end end define property Methods return Globals.Methods end define Run() return Globals.Methods end "; var parser = new Parser(text); try { parser.Parse(); Assert.Fail("expected an exception"); } catch (ParserException e) { if (!e.Message.Contains("method was defined more than once")) Assert.Fail(e.ToString()); } }
private static void Main(string[] args) { /* if (args.Length != 1) exit("Usage: Simplecalc.exe filename"); */ using (StreamReader sr = new StreamReader(File.Open("test", FileMode.Open))) { // Read source Lexer lexer = new Lexer(sr); // Parse source Parser parser = new Parser(lexer); Start ast = null; try { ast = parser.Parse(); } catch (Exception ex) { exit(ex.ToString()); } // Print tree SimplePrinter printer = new SimplePrinter(true, ConsoleColor.White, ConsoleColor.Gray, ConsoleColor.Red, ConsoleColor.Blue); ast.Apply(printer); } exit("Done"); }
public void ParseFailure() { Parser parser = new Parser(); List<Context> context = parser.Parse("2U5X6EE"); Assert.AreEqual(0, context.Count); }
public static CombatLog CreateCombatLog(string combatLog) { string hash = ComputeHash(combatLog); var logParser = new Parser(); var log = logParser.Parse(new StringReader(combatLog)); return CreateCombatLog(hash, log); }
public void ParseSuccess() { Parser parser = new Parser(); List<Context> context = parser.Parse("F2U5L6"); Assert.AreNotEqual(0, context.Count); }
private static void DoGenerate(string pegFile) { // Parse the file. if (Program.Verbosity >= 1) Console.WriteLine("parsing '{0}'", pegFile); var parser = new Parser(); string input = File.ReadAllText(pegFile, System.Text.Encoding.UTF8); parser.Parse(input, pegFile); // Check for errors. parser.Grammar.Validate(); // Delete the old parser. if (File.Exists(ms_outFile)) File.Delete(ms_outFile); // Write the new parser. if (Program.Verbosity >= 1) Console.WriteLine("writing '{0}'", ms_outFile); using (var stream = new StreamWriter(ms_outFile, false, System.Text.Encoding.UTF8)) { using (var writer = new Writer(stream, parser.Grammar)) { writer.Write(pegFile); stream.Flush(); } } }
// Protected/Private methods -------------------------------------------------------- protected override void Init(Stream streamHRF, string uriHRF, FileAccess mode) { tempfileName = null; if (mode == FileAccess.Read) { MemoryStream ms = new MemoryStream(); Scanner s = new Scanner(); if (streamHRF != null) s.Init(streamHRF); else s.Init(uriHRF); Parser p = new Parser(s); p.Parse(ms); if (p.ParserErrors.List.Count >0) throw new BREException(p.ParserErrors.List.Count + " HRF Parser error(s), top one is: " + p.ParserErrors.List[0]); ms.Seek(0, SeekOrigin.Begin); base.Init(ms, null, FileAccess.Read); } else { if (streamHRF != null) resultStream = streamHRF; else resultStream = new FileStream(uriHRF, FileMode.Create); tempfileName = Path.GetTempFileName(); base.Init(null, tempfileName, FileAccess.Write); } }