本文整理汇总了C#中Irony.Parsing.Parser.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.Parse方法的具体用法?C# Parser.Parse怎么用?C# Parser.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Irony.Parsing.Parser
的用法示例。
在下文中一共展示了Parser.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestConflictGrammarWithHintsOnRules
public void TestConflictGrammarWithHintsOnRules()
{
var grammar = new ConflictGrammarWithHintsInRules();
var parser = new Parser(grammar);
Assert.True(parser.Language.Errors.Count == 0);
// Field sample
var sample = FieldSample;
var tree = parser.Parse(sample);
Assert.NotNull(tree);
Assert.False(tree.HasErrors());
Assert.NotNull(tree.Root);
var term = tree.Root.Term as NonTerminal;
Assert.NotNull(term);
Assert.Equal("definition", term.Name);
Assert.Equal(1, tree.Root.ChildNodes.Count);
var modNode = tree.Root.ChildNodes[0].ChildNodes[0];
Assert.Equal("fieldModifier", modNode.Term.Name);
//Property
sample = PropertySample;
tree = parser.Parse(sample);
Assert.NotNull(tree);
Assert.False(tree.HasErrors());
Assert.NotNull(tree.Root);
term = tree.Root.Term as NonTerminal;
Assert.NotNull(term);
Assert.Equal("definition", term.Name);
Assert.Equal(1, tree.Root.ChildNodes.Count);
modNode = tree.Root.ChildNodes[0].ChildNodes[0];
Assert.Equal("propModifier", modNode.Term.Name);
}
示例2: TestErrorRecovery
public void TestErrorRecovery() {
var grammar = new ErrorRecoveryGrammar();
var parser = new Parser(grammar);
TestHelper.CheckGrammarErrors(parser);
//correct sample
var parseTree = parser.Parse("x = y; y = z + m; m = n;");
Assert.IsFalse(parseTree.HasErrors(), "Unexpected parse errors in correct source sample.");
parseTree = parser.Parse("x = y; m = = d ; y = z + m; x = z z; m = n;");
Assert.AreEqual(2, parseTree.ParserMessages.Count, "Invalid # of errors.");
}
示例3: Read
public override object Read(string path)
{
var obj = new AirfoilPropertiesData();
string text;
using (var reader = new StreamReader(path))
{
text = reader.ReadToEnd();
}
var grammar = new OpenFoamGrammar();
var parser = new Parser(grammar);
var tree = parser.Parse(text);
obj.airfoilData = new List<Vertice>();
foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
{
var id = rootEntryNode.GetEntryIdentifier();
if (id == "airfoilData")
{
var dict = rootEntryNode.GetDictContent().ChildNodes[1];
for (int i = 0; i < dict.ChildNodes.Count; i++)
{
var array_head = dict.ChildNodes[i].ChildNodes[0].ChildNodes[1].ChildNodes;
var v = new Vertice();
v.X = Convert.ToDecimal(array_head[0].ChildNodes[0].Token.Value);
v.Y = Convert.ToDecimal(array_head[1].ChildNodes[0].Token.Value);
v.Z = Convert.ToDecimal(array_head[2].ChildNodes[0].Token.Value);
obj.airfoilData.Add( v );
}
}
}
return obj;
}
示例4: Read
public override object Read(string path)
{
var rawData = new DecomposeParDictData();
string txt;
using (var reader = new StreamReader(path))
{
txt = reader.ReadToEnd();
}
var grammar = new OpenFoamGrammar();
var parser = new Parser(grammar);
var tree = parser.Parse(txt);
foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
{
var identifier = rootEntryNode.GetEntryIdentifier();
switch (identifier)
{
case "numberOfSubdomains":
rawData.numberOfSubdomains = rootEntryNode.GetBasicValInt();
break;
}
}
return rawData;
}
示例5: LoadBnfFile
private static void LoadBnfFile(string fileName, Builder mainBuilder)
{
Console.WriteLine("Parse BNF file: {0}", fileName);
var bnf = File.ReadAllText(fileName);
var metaParser = new MetaParser();
var meta = metaParser.Parse(bnf);
var oprimizedBnf = Optimize(bnf);
var parser = new Parser(new BnfGrammar(meta.Mode));
var tree = parser.Parse(oprimizedBnf, fileName);
if (tree.Status == ParseTreeStatus.Error)
{
throw new Exception((tree.ParserMessages.Count > 0)
? string.Format("{0}, in {3} file at line {1}, column {2}", tree.ParserMessages[0].Message, tree.ParserMessages[0].Location.Line, tree.ParserMessages[0].Location.Column, fileName)
: string.Format(@"Unknow error in BNF file {0}", fileName));
}
var builder = new Builder(tree, mainBuilder);
builder.BuildExpressions();
foreach (var @using in meta.Usings)
LoadBnfFile(@using, mainBuilder);
}
示例6: ShouldNotParseWithoutCases
public void ShouldNotParseWithoutCases()
{
// Arrange
var grammar = new CicodeGrammar();
var parser = new Parser(grammar);
var sourceCode =
@"
FUNCTION A()
SELECT CASE a
END SELECT
END
";
// Act
var parseTree = parser.Parse(sourceCode);
// Assert
Assert.IsNotNull(parseTree);
Assert.IsTrue(parseTree.HasErrors());
// A parser error is expected at the end of line 4 because the expected list of cases which is missing
Assert.AreEqual<int>(1, parseTree.ParserMessages
.Where(m => m.Location.Line == 4)
.Where(m => m.ParserState.ExpectedTerminals.First().Name == "CASE")
.Count());
}
示例7: ShouldNotParseCaseElseWhenNotAtTheEnd
public void ShouldNotParseCaseElseWhenNotAtTheEnd()
{
// Arrange
var grammar = new CicodeGrammar();
var parser = new Parser(grammar);
var sourceCode =
@"
FUNCTION A()
SELECT CASE a
CASE 1
A();
CASE ELSE
A();
CASE 1
A();
END SELECT
END
";
// Act
var parseTree = parser.Parse(sourceCode);
// Assert
Assert.IsNotNull(parseTree);
Assert.IsTrue(parseTree.HasErrors());
// A parser error is expected at line 7 because of the CASE ELSE clause which is not at then end of the case list
Assert.AreEqual<int>(1, parseTree.ParserMessages.Where(m => m.Location.Line == 7).Count());
}
示例8: Read
public override object Read(string path)
{
var obj = new TurbulencePropertiesData();
string text = Load(path);
var grammar = new OpenFoamGrammar();
var parser = new Parser(grammar);
var tree = parser.Parse(text);
_fileHandler = null;
foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
{
if (rootEntryNode.GetEntryIdentifier() == "simulationType")
{
obj.SimulationType = rootEntryNode.GetBasicValEnum<TurbulenceModel>();
if (obj.SimulationType == TurbulenceModel.RASModel)
{
_fileHandler = new RASPropertiesHandler();
obj.RasProperties = (RASPropertiesData) _fileHandler.Read(path);
}
else if (obj.SimulationType == TurbulenceModel.LESModel)
{
_fileHandler = new LESPropertiesHandler();
obj.LesProperties = (LESPropertiesData) _fileHandler.Read(path);
}
break;
}
}
return obj;
}
示例9: Read
public override object Read(string path)
{
var obj = new RASPropertiesData();
string text = Load(path);
var grammar = new OpenFoamGrammar();
var parser = new Parser(grammar);
var tree = parser.Parse(text);
foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
{
switch (rootEntryNode.GetEntryIdentifier())
{
case "RASModel":
obj.RasModelName = rootEntryNode.GetBasicValString();
break;
case "turbulence":
obj.Turbulence = rootEntryNode.GetBasicValEnum<OnOffValue>();
break;
case "printCoeffs":
obj.PrintCoeffs = rootEntryNode.GetBasicValEnum<OnOffValue>();
break;
}
}
return obj;
}
示例10: button1_Click
private void button1_Click(object sender, EventArgs e)
{
string programText = textBox1.Text;
CameraControlGrammar grammar = new CameraControlGrammar();
Parser parser = new Parser(grammar);
ParseTree program = parser.Parse(programText);
//var ttt=program.ToXml();
var cameraSizeNode = program.Root.ChildNodes[0];
var widthNode = cameraSizeNode.ChildNodes[0];
int width = (int)widthNode.Token.Value;
var heightNode = cameraSizeNode.ChildNodes[1];
int height = (int)heightNode.Token.Value;
// loop through the movement commands
foreach (ParseTreeNode commandNode in program.Root.ChildNodes[2].ChildNodes)
{
// get the number of pixels to move
Token pixelsToken = commandNode.ChildNodes[0].Token;
int pixelsToMove = (int)pixelsToken.Value;
// get the direction
Token directionToken =commandNode.ChildNodes[1].Token;
string directionText = directionToken.Text.ToLower();
}
int u = 0;
}
示例11: Read
public override object Read(string path)
{
var obj = new DecomposeParDictData();
string txt = Load(path);
var grammar = new OpenFoamGrammar();
var parser = new Parser(grammar);
var tree = parser.Parse(txt);
foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
{
var identifier = rootEntryNode.GetEntryIdentifier();
switch (identifier)
{
case "numberOfSubdomains":
obj.numberOfSubdomains = rootEntryNode.GetBasicValInt();
break;
case "method":
obj.method = rootEntryNode.GetBasicValEnum<DecompositionMethod>();
break;
case "hierarchicalCoeffs":
obj.hCoefs = GetHierarchicalCoeffs(rootEntryNode.GetDictContent());
break;
}
}
return obj;
}
示例12: Read
public override object Read(string path)
{
var rawData = new FvSolutionData();
string txt;
using (var reader = new StreamReader(path))
{
txt = reader.ReadToEnd();
}
var grammar = new OpenFoamGrammar();
var parser = new Parser(grammar);
var tree = parser.Parse(txt);
foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
{
var identifier = rootEntryNode.GetEntryIdentifier();
switch (identifier)
{
case "options":
ParseOptions(rootEntryNode.ChildNodes[2], rawData);
break;
case "solvers":
ParseSolvers(rootEntryNode.ChildNodes[2], rawData);
break;
}
}
return rawData;
}
示例13: Read
public override object Read(string path)
{
var obj = new FvSolutionData();
string txt = Load(path);
var grammar = new OpenFoamGrammar();
var parser = new Parser(grammar);
var tree = parser.Parse(txt);
foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
{
var identifier = rootEntryNode.GetEntryIdentifier();
switch (identifier)
{
case "solvers":
obj.Solvers = GetSolvers(rootEntryNode.GetDictContent());
break;
case "PISO":
case "SIMPLE":
case "PIMPLE":
obj.Solution = GetSolution(identifier, rootEntryNode.GetDictContent());
break;
}
}
return obj;
}
示例14: ParseTripIdl
/// <summary>
/// Build a parse tree from trip idl
/// </summary>
/// <param name="tripIdl">trip idl text</param>
/// <returns>a parse tree</returns>
public static ParseTree ParseTripIdl(string tripIdl)
{
Grammar g = new IdlGrammar();
var parser = new Parser(g);
var parseTree = parser.Parse(tripIdl);
return parseTree;
}
示例15: Read
public override object Read(string path)
{
var obj = new RefineMeshDictData();
string txt;
using (var reader = new StreamReader(path))
{
txt = reader.ReadToEnd();
}
var grammar = new OpenFoamGrammar();
var parser = new Parser(grammar);
var tree = parser.Parse(txt);
foreach (ParseTreeNode rootEntryNode in tree.Root.FindDictEntries(null))
{
var identifier = rootEntryNode.GetEntryIdentifier();
string patch;
switch ( identifier )
{
case "set":
obj.setvalue = rootEntryNode.GetBasicValString();
break;
case "coordinateSystem":
obj.coordsys = rootEntryNode.GetBasicValEnum<CoordinateSystem>();
break;
case "globalCoeffs":
{
var dict = rootEntryNode.GetDictContent();
obj.globalCoeffs = GetCoeffs(ref dict, out patch);
}
break;
case "patchLocalCoeffs":
{
var dict = rootEntryNode.GetDictContent();
obj.patchLocalCoeffs = GetCoeffs(ref dict, out patch);
obj.patch = patch;
}
break;
case "directions":
{
obj.direction = new List<DirectionType>();
var s = rootEntryNode.ChildNodes[2].ChildNodes[1].GetArrayOfString();
foreach (string t in s)
{
obj.direction.Add(t.ToEnum<DirectionType>());
}
}
break;
case "useHexTopology":
obj.useHexTopology = rootEntryNode.GetBasicValBool();
break;
case "geometricCut":
obj.geometricCut = rootEntryNode.GetBasicValBool();
break;
case "writeMesh":
obj.writeMesh = rootEntryNode.GetBasicValBool();
break;
}
}
return obj;
}