public static CppRipper.ParseNode GenerateCppAst(string cppContent, out string status) { CppStructuralGrammar grammar = new CppStructuralGrammar(); Rule parse_rule = grammar.file; ParserState state = new ParserState(cppContent); try { if (!parse_rule.Match(state)) { status = "Failed to parse c++ content"; return(null); } else { if (state.AtEndOfInput()) { status = "Successfully parsed c++ content"; return(state.GetRoot()); } else { status = "Failed to read end of c++ content"; return(null); } } } catch (ParsingException e) { state.ForceCompletion(); status = e.Message; return(null); } }
public void ParseComment() { var grammar = new CppStructuralGrammar(); var output = new CppStructuralOutputAsXml(); var parserState = CppSourceParser.Parse("/* Comment */", output, rule: grammar.declaration_list); Assert.That(parserState.ParseException, Is.Null); Console.WriteLine(output.AsXml()); }