Ejemplo n.º 1
0
        private static int my_fgets(CharPtr buf, int len, FILEPtr fp)
        {
            CharPtr p;

            for (;;)
            {
                if (PyOS_InputHook != null)
                {
                    PyOS_InputHook();
                }
                errno = 0;
                p     = fgets(buf, len, fp);
                if (p != null)
                {
                    return(0);
                }
                if (0 != feof(fp))
                {
                    return(-1);
                }
                if (errno == EINTR)
                {
                    if (0 != PyOS_InterruptOccurred())
                    {
                        return(1);
                    }
                    continue;
                }
                if (0 != PyOS_InterruptOccurred())
                {
                    return(1);
                }
                return(-2);
            }
        }
Ejemplo n.º 2
0
        private static void list1node(FILEPtr fp, node n)
        {
            if (n == null)
            {
                return;
            }
            if (ISNONTERMINAL(TYPE(n)))
            {
                int i;
                for (i = 0; i < NCH(n); i++)
                {
                    list1node(fp, CHILD(n, i));
                }
            }
            else if (ISTERMINAL(TYPE(n)))
            {
                switch (TYPE(n))
                {
                case INDENT:
                    ++level;
                    break;

                case DEDENT:
                    --level;
                    break;

                default:
                    if (atbol != 0)
                    {
                        int i;
                        for (i = 0; i < level; ++i)
                        {
                            fprintf(fp, "\t");
                        }
                        atbol = 0;
                    }
                    if (TYPE(n) == NEWLINE)
                    {
                        if (STR(n) != null)
                        {
                            fprintf(fp, "%s", STR(n));
                        }
                        fprintf(fp, "\n");
                        atbol = 1;
                    }
                    else
                    {
                        fprintf(fp, "%s ", STR(n));
                    }
                    break;
                }
            }
            else
            {
                fprintf(fp, "? ");
            }
        }
Ejemplo n.º 3
0
        public static tok_state PyTokenizer_FromFile(FILEPtr fp, CharPtr ps1, CharPtr ps2)
        {
            tok_state tok = tok_new();

            if (tok == null)
            {
                return(null);
            }
            if ((tok.buf = PyMem_NEW_char2(BUFSIZ)) == null)
            {
                PyMem_DEL(ref tok);
                return(null);
            }
            tok.cur        = new CharPtr(tok.buf);
            tok.inp        = new CharPtr(tok.buf);
            tok.end        = new CharPtr(tok.buf, BUFSIZ);
            tok.fp         = new FILEPtr(fp);
            tok.prompt     = new CharPtr(ps1);
            tok.nextprompt = new CharPtr(ps2);
            return(tok);
        }
Ejemplo n.º 4
0
        public static node PyParser_ParseFileFlags(FILEPtr fp, CharPtr filename, grammar g, int start,
                                                   CharPtr ps1, CharPtr ps2, perrdetail err_ret, int flags)
        {
            tok_state tok;

            initerr(err_ret, filename);

            if ((tok = PyTokenizer_FromFile(fp, ps1, ps2)) == null)
            {
                err_ret.error = E_NOMEM;
                return(null);
            }
            if (0 != Py_TabcheckFlag || 0 != Py_VerboseFlag)
            {
                tok.filename   = filename;
                tok.altwarning = (filename != null)?1:0;
                if (Py_TabcheckFlag >= 2)
                {
                    tok.alterror++;
                }
            }

            return(parsetok(tok, g, start, err_ret, flags));
        }
Ejemplo n.º 5
0
 public static node PyParser_ParseFile(FILEPtr fp, CharPtr filename, grammar g, int start,
                                       CharPtr ps1, CharPtr ps2, perrdetail err_ret)
 {
     return(PyParser_ParseFileFlags(fp, filename, g, start, ps1, ps2,
                                    err_ret, 0));
 }
Ejemplo n.º 6
0
 private static void listnode(FILEPtr fp, node n)
 {
     level = 0;
     atbol = 1;
     list1node(fp, n);
 }