py-tree-sitter icon indicating copy to clipboard operation
py-tree-sitter copied to clipboard

Value Error: Parsing failed

Open fredmarkus opened this issue 3 years ago • 0 comments

I am getting a value error when trying to parse a piece of C code. I have built the grammar as instructed and instantiated the parser. The issue is similar to the ones mentioned in #3 and #100 but these didn't resolve my issue.

` from tree_sitter import Language, Parser

Language.build_library('build/my-languages.so', [ 'vendor/tree-sitter-c'] )

C_LANGUAGE = Language('build/my-languages.so', 'c')

parser = Parser() parser.set_language(C_LANGUAGE) ` The code that I am trying to parse looks as follows:

` #include <limits.h> #include <stdlib.h>

#include "libavutil/avstring.h" #include "libavutil/mathematics.h"

static const char *check_nan_suffix(const char *s) { const char *start = s;

if (*s++ != '(')
    return start;

while ((*s >= 'a' && *s <= 'z') || (*s >= 'A' && *s <= 'Z') ||
       (*s >= '0' && *s <= '9') ||  *s == '_')
    s++;

return *s == ')' ? s + 1 : start;

}

#undef strtod double strtod(const char *, char **);

double avpriv_strtod(const char *nptr, char **endptr) { const char *end; double res;

/* Skip leading spaces */
while (av_isspace(*nptr))
    nptr++;

if (!av_strncasecmp(nptr, "infinity", 8)) {
    end = nptr + 8;
    res = INFINITY;
} else if (!av_strncasecmp(nptr, "inf", 3)) {
    end = nptr + 3;
    res = INFINITY;
} else if (!av_strncasecmp(nptr, "+infinity", 9)) {
    end = nptr + 9;
    res = INFINITY;
} else if (!av_strncasecmp(nptr, "+inf", 4)) {
    end = nptr + 4;
    res = INFINITY;
} else if (!av_strncasecmp(nptr, "-infinity", 9)) {
    end = nptr + 9;
    res = -INFINITY;
} else if (!av_strncasecmp(nptr, "-inf", 4)) {
    end = nptr + 4;
    res = -INFINITY;
} else if (!av_strncasecmp(nptr, "nan", 3)) {
    end = check_nan_suffix(nptr + 3);
    res = NAN;
} else if (!av_strncasecmp(nptr, "+nan", 4) ||
           !av_strncasecmp(nptr, "-nan", 4)) {
    end = check_nan_suffix(nptr + 4);
    res = NAN;
} else if (!av_strncasecmp(nptr, "0x", 2) ||
           !av_strncasecmp(nptr, "-0x", 3) ||
           !av_strncasecmp(nptr, "+0x", 3)) {
    /* FIXME this doesn't handle exponents, non-integers (float/double)
     * and numbers too large for long long */
    res = strtoll(nptr, (char **)&end, 16);
} else {
    res = strtod(nptr, (char **)&end);
}

if (endptr)
    *endptr = (char *)end;

return res;

} `

fredmarkus avatar Jun 22 '22 12:06 fredmarkus