本文整理汇总了C#中Parser.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Parse方法的具体用法?C# Parser.Parse怎么用?C# Parser.Parse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestComplex
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);
}
示例2: TestBasic
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);
}
示例3: run
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));
}
示例4: TestAstEquals
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);
}
示例5: repeated_parsing_yields_different_values
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());
}
示例6: RequiredArgumentsWork
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);
}
示例7: PositionedArgumentValidation
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);
}
示例8: PatternMatchingWorks
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);
}
示例9: Main
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);
}
示例10: Parser_Reads_Character_Sets_Strings
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());
}
示例11: ParseEmpty
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);
}
示例12: Main
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);
}
示例13: Functions
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[]{});
}
示例14: Stylesheet_Renders_Friendly_Format
public void Stylesheet_Renders_Friendly_Format()
{
var parser = new Parser();
var css = parser.Parse(Resources.Css3);
Assert.AreEqual(Resources.Css3Friendly, css.ToString(true));
}
示例15: Main
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");
}