Пример #1
0
 internal static AbstractParsecError raiseExpecting(int at, string s,
                                                    AbstractParsecError err)
 {
     return(new ParsecErrorExpecting(false, at,
                                     myPrecedence(err.Precedence, s), err.Exception,
                                     err, s));
 }
Пример #2
0
 internal MergedParsecError(int ind, int pred,
                            AbstractParsecError err1, AbstractParsecError err2)
     : base(false, ind, pred, mergeObj(err1.Exception, err2.Exception))
 {
     this.err1 = err1;
     this.err2 = err2;
 }
Пример #3
0
 internal ParsecErrorExpecting(bool nomerge, int at, int pred, object exception,
                               AbstractParsecError err, string s)
     : base(nomerge, at, pred, exception)
 {
     this.err = err;
     this.s   = s;
 }
Пример #4
0
 internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
 {
     if (ctxt.isEof())
     {
         return(Scanners.setErrorExpecting(out err, expected_name, ctxt));
     }
     ctxt.next();
     return(true);
 }
Пример #5
0
 internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
 {
     if (ctxt.isEof())
     {
         return Scanners.setErrorExpecting(out err, expected_name, ctxt);
     }
     ctxt.next();
     return true;
 }
Пример #6
0
        internal static AbstractParsecError mergeError(AbstractParsecError e1,
                                                       AbstractParsecError e2)
        {
            if (e1 == null)
            {
                return(e2);
            }
            if (e2 == null)
            {
                return(e1);
            }
            if (e1 == e2)
            {
                return(e1);
            }
            int pred  = e1.precedence;
            int pred2 = e2.precedence;
            int at    = e1.at;
            int at2   = e2.at;

            if (at == at2)
            {
                if (pred2 > pred)
                {
                    return(e2);
                }
                else if (pred > pred2)
                {
                    return(e1);
                }
                //else return e1;
            }
            else if (at > at2)
            {
                /*if(pred < pred2){
                 * return e2;
                 * }
                 * else */
                return(e1);
            }
            else if (at < at2)
            {
                /*if(pred > pred2){
                 * return e1;
                 * }
                 * else */
                return(e2);
            }
            if (e1.nomerge && e2.nomerge)
            {
                return(e1);
            }
            return(new MergedParsecError(at, pred, e1, e2));
        }
Пример #7
0
 internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
 {
     int at = ctxt.getAt();
     string src = ctxt.getSource();
     int mlen = pp.Match(src, at, src.Length);
     if (mlen < 0)
     {
         return Scanners.setErrorExpecting(out err, expected_name, ctxt);
     }
     ctxt.next(mlen);
     return true;
 }
Пример #8
0
            internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
            {
                int from = ctxt.getAt();

                if (!outer_scanner.parse(ctxt, ref result, ref err))
                {
                    return(false);
                }
                ScannerState inner_ctxt = new ScannerState(ctxt.getSource(), from, module, ctxt.getPositionMap(),
                                                           ctxt.getAt() - from);

                return(ParserChores.cont(ctxt, inner_ctxt, nested, ref result, ref err));
            }
Пример #9
0
            internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
            {
                int    at   = ctxt.getAt();
                string src  = ctxt.getSource();
                int    mlen = pp.Match(src, at, src.Length);

                if (mlen < 0)
                {
                    return(Scanners.setErrorExpecting(out err, expected_name, ctxt));
                }
                ctxt.next(mlen);
                return(true);
            }
Пример #10
0
 internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
 {
     if (!open.parse(ctxt, ref result, ref err))
     {
         return(false);
     }
     for (int level = 1; level > 0;)
     {
         int at = ctxt.getAt();
         if (close.parse(ctxt, ref result, ref err))
         {
             if (at == ctxt.getAt())
             {
                 throw new IllegalParserStateException("closing comment scanner not consuming input.");
             }
             level--;
             continue;
         }
         if (at != ctxt.getAt())
         {
             return(false);
         }
         if (open.parse(ctxt, ref result, ref err))
         {
             if (at == ctxt.getAt())
             {
                 throw new IllegalParserStateException("opening comment scanner not consuming input.");
             }
             level++;
             continue;
         }
         if (at != ctxt.getAt())
         {
             return(false);
         }
         if (commented.parse(ctxt, ref result, ref err))
         {
             if (at == ctxt.getAt())
             {
                 throw new IllegalParserStateException("commented scanner not consuming input.");
             }
             continue;
         }
         return(false);
     }
     return(true);
 }
Пример #11
0
 internal static AbstractParsecError mergeError(AbstractParsecError e1,
     AbstractParsecError e2)
 {
     if (e1 == null) return e2;
     if (e2 == null) return e1;
     if (e1 == e2) return e1;
     int pred = e1.precedence;
     int pred2 = e2.precedence;
     int at = e1.at;
     int at2 = e2.at;
     if (at == at2)
     {
         if (pred2 > pred)
         {
             return e2;
         }
         else if (pred > pred2)
         {
             return e1;
         }
         //else return e1;
     }
     else if (at > at2)
     {
         /*if(pred < pred2){
           return e2;
         }
         else */
         return e1;
     }
     else if (at < at2)
     {
         /*if(pred > pred2){
           return e1;
         }
         else */
         return e2;
     }
     if (e1.nomerge && e2.nomerge)
     {
         return e1;
     }
     return new MergedParsecError(at, pred, e1, e2);
 }
Пример #12
0
        internal override bool apply(ParseContext ctxt, ref Tok result, ref AbstractParsecError err)
        {
            int original_step = ctxt.getStep();
            int original_at   = ctxt.getAt();
            S   tmp           = default(S);

            if (!scanner.parse(ctxt, ref tmp, ref err))
            {
                return(false);
            }
            int    cur = ctxt.getAt();
            int    len = cur - original_at;
            object tok = tn(ctxt.getSource(), original_at, len);

            //The java version uses null to indicate a failure. It doesn't not seem to be used though. So we keep it simple.
            result = new Tok(original_at, len, tok);
            ctxt.setStep(original_step + 1);
            return(true);
        }
Пример #13
0
 private static bool setErrorExpecting(out AbstractParsecError err, string msg, ParseContext ctxt)
 {
     err = ParserChores.raiseExpecting(msg, ctxt);
     return false;
 }
Пример #14
0
 internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
 {
     int from = ctxt.getAt();
     if (!outer_scanner.parse(ctxt, ref result, ref err))
         return false;
     ScannerState inner_ctxt = new ScannerState(ctxt.getSource(), from, module, ctxt.getPositionMap(),
       ctxt.getAt() - from);
     return ParserChores.cont(ctxt, inner_ctxt, nested, ref result, ref err);
 }
Пример #15
0
 private static bool setErrorExpecting(out AbstractParsecError err, string msg, ParseContext ctxt)
 {
     err = ParserChores.raiseExpecting(msg, ctxt);
     return(false);
 }
Пример #16
0
 internal override bool apply(ParseContext ctxt, ref D_ result, ref AbstractParsecError err)
 {
     if (!open.parse(ctxt, ref result, ref err))
     {
         return false;
     }
     for (int level = 1; level > 0; )
     {
         int at = ctxt.getAt();
         if (close.parse(ctxt, ref result, ref err))
         {
             if (at == ctxt.getAt())
             {
                 throw new IllegalParserStateException("closing comment scanner not consuming input.");
             }
             level--;
             continue;
         }
         if (at != ctxt.getAt())
         {
             return false;
         }
         if (open.parse(ctxt, ref result, ref err))
         {
             if (at == ctxt.getAt())
                 throw new IllegalParserStateException("opening comment scanner not consuming input.");
             level++;
             continue;
         }
         if (at != ctxt.getAt())
         {
             return false;
         }
         if (commented.parse(ctxt, ref result, ref err))
         {
             if (at == ctxt.getAt())
                 throw new IllegalParserStateException("commented scanner not consuming input.");
             continue;
         }
         return false;
     }
     return true;
 }
Пример #17
0
 internal ParsecErrorExpecting(bool nomerge, int at, int pred, object exception,
     AbstractParsecError err, string s)
     : base(nomerge, at, pred, exception)
 {
     this.err = err;
     this.s = s;
 }
Пример #18
0
 internal MergedParsecError(int ind, int pred,
     AbstractParsecError err1, AbstractParsecError err2)
     : base(false, ind, pred, mergeObj(err1.Exception, err2.Exception))
 {
     this.err1 = err1;
     this.err2 = err2;
 }
Пример #19
0
 internal static AbstractParsecError raiseExpecting(int at, string s,
     AbstractParsecError err)
 {
     return new ParsecErrorExpecting(false, at,
         myPrecedence(err.Precedence, s), err.Exception,
         err, s);
 }