本文整理汇总了C#中Irony.Parsing.ParseTree类的典型用法代码示例。如果您正苦于以下问题:C# ParseTree类的具体用法?C# ParseTree怎么用?C# ParseTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParseTree类属于Irony.Parsing命名空间,在下文中一共展示了ParseTree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryParse
public bool TryParse(string sourceText, out MarkupExtension graph)
{
graph = null;
try
{
ParseTree tree = _parser.Parse(sourceText);
#if DEBUG
// Save result tree for debugging purposes
LastParseTree = tree;
LastException = null;
#endif
if (tree.Status == ParseTreeStatus.Parsed)
{
graph = MarkupExtension.Create(tree.Root);
return true;
}
}
#if DEBUG
catch (Exception ex)
{
LastParseTree = null;
LastException = ex;
}
#else
catch
{
// ignored
}
#endif
return false;
}
示例2: BuildAst
public override void BuildAst(LanguageData language, ParseTree parseTree) {
var opHandler = new OperatorHandler(language.Grammar.CaseSensitive);
Util.Check(!parseTree.HasErrors(), "ParseTree has errors, cannot build AST.");
var astContext = new InterpreterAstContext(language, opHandler);
var astBuilder = new AstBuilder(astContext);
astBuilder.BuildAst(parseTree);
}
示例3: BuildAst
public virtual void BuildAst(LanguageData language, ParseTree parseTree)
{
if (!LanguageFlags.IsSet(LanguageFlags.CreateAst))
return;
var astContext = new AstContext(language);
var astBuilder = new AstBuilder(astContext);
astBuilder.BuildAst(parseTree);
}
示例4: NormalizeParseTree
private string NormalizeParseTree(ParseTree tree) {
StringBuilder fullString = new StringBuilder();
foreach (ParseTreeNode node in tree.Root.ChildNodes) {
fullString.Append(node.Token.Value);
}
fullString = fullString.Replace("\r\n", "\\n");
fullString = fullString.Replace("\n", "\\n");
return fullString.ToString();
}
示例5: BuildAst
public virtual void BuildAst(ParseTree parseTree) {
if (parseTree.Root == null)
return;
Context.Messages = parseTree.ParserMessages;
if (!Context.Language.AstDataVerified)
VerifyLanguageData();
if (Context.Language.ErrorLevel == GrammarErrorLevel.Error)
return;
BuildAst(parseTree.Root);
}
示例6: ParseString
public Block ParseString(string Chunk)
{
var parseTree = parser.Parse(Chunk);
curParseTree = parseTree;
var root = parseTree.Root;
if (root == null)
{
var msg = parseTree.ParserMessages[0];
throw new LuaException("", msg.Location.Line, msg.Location.Column, msg.Message);
}
return (ParseBlock(root));
}
示例7: GetParserMessages
private string GetParserMessages(ParseTree parseTree)
{
var sb = new StringBuilder();
foreach (var message in parseTree.ParserMessages)
{
sb.AppendFormat("{0} at line {1}, column {2}", message.Message, message.Location.Line, message.Location.Column);
}
sb.AppendLine();
sb.AppendLine("Source Code:");
sb.AppendLine();
sb.Append(parseTree.SourceText);
return sb.ToString();
}
示例8: ParseFile
public Block ParseFile(string Filename)
{
var source = File.ReadAllText(Filename);
var parseTree = parser.Parse(source, Filename);
curParseTree = parseTree;
var root = parseTree.Root;
if (root == null)
{
var msg = parseTree.ParserMessages[0];
throw new LuaException(Filename, msg.Location.Line, msg.Location.Column, msg.Message);
}
return (ParseBlock(root));
}
示例9: Refresh
public void Refresh(ParseTree tree)
{
var root = tree.Root;
if (root != null)
{
File = new LuaFile(FileManager.Instance.CurrentFile.File, tree.Tokens); ;
RefreshTree(root);
FileManager.Instance.CurrentFile = File;
System.Diagnostics.Debug.Print("file refreshed.");
}
}
示例10: Analyze
private Expression Analyze(ParseTree tree, CompilerState state)
{
if (tree == null)
{
throw new ArgumentNullException("tree");
}
if (tree.Status != ParseTreeStatus.Parsed)
{
throw new ArgumentException("Cannot build expression on incomplete tree");
}
var root = tree.Root;
return Analyze(root, state);
}
示例11: Read
/// <summary>
/// Reads a Dql query into an abstract syntax tree.
/// </summary>
/// <param name="query">Dql query.</param>
/// <param name="node">The current abstract syntax tree to construct.</param>
/// <returns>Time taken to build the abstract syntax tree in milliseconds.</returns>
public long Read(string query, out ParseTree node)
{
var parser = new Parser(language);
var tree = parser.Parse(query);
if (tree.HasErrors())
{
// TODO: Throw LQL errors.
throw new InvalidOperationException();
}
#if DEBUG
this.DisplayTree(tree.Root, 0);
#endif
node = tree;
return tree.ParseTimeMilliseconds;
}
示例12: ParseSample
public void ParseSample(string code)
{
if (parser == null || !parser.Language.CanParse()) return;
ParseTree = null;
GC.Collect(); //to avoid disruption of perf times with occasional collections
parser.Context.TracingEnabled = false;//parsetrace not needed for us
try {
parser.Parse(code, "<source>");
}
catch (Exception ex) {
Console.WriteLine(ex.Message);
throw;
}
finally {
ParseTree = parser.Context.CurrentParseTree;
}
}
示例13: GenerateCode
public CodeCompileUnit GenerateCode(ParseTree tree)
{
var generator = new RuleCodeGenerator();
var unit = new CodeCompileUnit();
var ns = new CodeNamespace(GetType().Namespace);
ns.Imports.Add(new CodeNamespaceImport(GetType().Namespace));
var rules = tree.Root.ChildNodes[0].ChildNodes;
var count = 1;
foreach (var rule in rules)
{
ns.Types.Add(generator.GenerateRuleClass("Rule" + count, rule));
count++;
}
unit.Namespaces.Add(ns);
return unit;
}
示例14: ConvertParseTreeToModel
public static LPModel ConvertParseTreeToModel(ParseTree tree)
{
string modelName = "";
var lpGoal = new LPGoal();
var lpConstraints = new List<LPConstraint>();
if (tree.Root.ToString() == "lpApp")
{
foreach (ParseTreeNode node in tree.Root.ChildNodes)
{
switch (node.ToString())
{
case "lpAppName":
modelName = ParseModelName(node);
break;
case "lpModel":
foreach (ParseTreeNode subNodes in node.ChildNodes)
{
switch (subNodes.ToString())
{
case "lpGoal":
lpGoal = ParseGoal(subNodes);
break;
case "lpConstraints":
lpConstraints = ParseConstraints(subNodes);
break;
}
}
break;
}
}
}
else
{
throw new Exception("The Root element is not Correct");
}
return new LPModel(modelName.Replace("(appIdentifier)", "").Replace(" ", ""), lpGoal, lpConstraints);
}
示例15: Generate
public void Generate(ParseTree parseTree) {
if (parseTree == null) return;
GeneratedOK = true;
defaultClass = ag.Public.Class("Default");
typeTable.Add("Default", defaultClass);
mainMethod = defaultClass.Public.Static.Method(typeof(void), "Main");
//generator stack
typeStack.Push(defaultClass);
funcStack.Push(mainMethod);
//InitIO();
InitRequiredType();
PushScope();
var ioOperand = mainMethod.Local(exp.New(typeTable["IO"]));
ParseNode(parseTree.Root);
if (GeneratedOK) {
ag.Save();
AppDomain.CurrentDomain.ExecuteAssembly(name + ".exe");
}
}