Example #1
0
        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);
        }
Example #2
0
    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();
      }
    }
Example #3
0
        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();
            }
        }
Example #4
0
        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);
            }
        }
Example #5
0
    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;
      }
    }
Example #6
0
File: Json-1.cs Project: rsdn/nitra
 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);
 }