static void Test(string text) { var session = new ParseSession(JsonParser.Start, compilerMessages: new ConsoleCompilerMessages()); var source = new SourceSnapshot(text); var parseResult = session.Parse(source); var parseTree = parseResult.CreateParseTree(); Console.WriteLine("Pretty print: " + parseTree); }
static void Main(string[] args) { if (args.Length > 0) text = System.IO.File.ReadAllText(args[0]); var session = new ParseSession(JsonParser.Start, compilerMessages: new ConsoleCompilerMessages()); var result = session.Parse(text); if (result.IsSuccess) { var parseTree = result.CreateParseTree(); Console.WriteLine("Pretty print: " + parseTree); Console.WriteLine(); } }
static void Main(string[] args) { if (args.Length > 0) { text = System.IO.File.ReadAllText(args[0]); } var session = new ParseSession(JsonParser.Start, compilerMessages: new ConsoleCompilerMessages()); var result = session.Parse(text); if (result.IsSuccess) { var parseTree = result.CreateParseTree(); Console.WriteLine("Pretty print: " + parseTree); Console.WriteLine(); } }
public IParseResult Run([NotNull] string code, [CanBeNull] string gold = null, int completionStartPos = -1, string completionPrefix = null, RecoveryAlgorithm recoveryAlgorithm = RecoveryAlgorithm.Smart) { var source = new SourceSnapshot(code); if (Language.StartRule == null) { return(null); } try { var parseSession = new ParseSession(Language.StartRule, compositeGrammar: Language.CompositeGrammar, completionPrefix: completionPrefix, completionStartPos: completionStartPos, parseToEndOfString: true, dynamicExtensions: DynamicExtensions, statistics: Statistics); switch (recoveryAlgorithm) { case RecoveryAlgorithm.Smart: parseSession.OnRecovery = ParseSession.SmartRecovery; break; case RecoveryAlgorithm.Panic: parseSession.OnRecovery = ParseSession.PanicRecovery; break; case RecoveryAlgorithm.FirstError: parseSession.OnRecovery = ParseSession.FirsrErrorRecovery; break; } var parseResult = parseSession.Parse(source); this.Exception = null; return(parseResult); } catch (Exception ex) { this.Exception = ex; return(null); } }
public IParseResult Run([NotNull] string code, [CanBeNull] string gold = null, int completionStartPos = -1, string completionPrefix = null, RecoveryAlgorithm recoveryAlgorithm = RecoveryAlgorithm.Smart) { var source = new SourceSnapshot(code); if (Language.StartRule == null) return null; try { var parseSession = new ParseSession(Language.StartRule, compositeGrammar: Language.CompositeGrammar, completionPrefix: completionPrefix, completionStartPos: completionStartPos, parseToEndOfString: true, dynamicExtensions: DynamicExtensions, statistics: Statistics); switch (recoveryAlgorithm) { case RecoveryAlgorithm.Smart: parseSession.OnRecovery = ParseSession.SmartRecovery; break; case RecoveryAlgorithm.Panic: parseSession.OnRecovery = ParseSession.PanicRecovery; break; case RecoveryAlgorithm.FirstError: parseSession.OnRecovery = ParseSession.FirsrErrorRecovery; break; } var parseResult = parseSession.Parse(source); this.Exception = null; return parseResult; } catch (Exception ex) { this.Exception = ex; return null; } }