graphql/language/lexer.py
def read_string(source: Source, start, line, col, prev) -> Token:
    """Read a string token from the source file."""
    body = source.body
    position = start + 1
    chunk_start = position
    value: List[str] = []
    append = value.append

    while position < len(body):
        char = char_at(body, position)
        if char is None or char in "\n\r":
            break
        if char == '"':
            append(body[chunk_start:position])
            return Token(
                TokenKind.STRING, start, position + 1, line, col, prev, "".join(value)
            )
        if char < " " and char != "\t":
            raise GraphQLSyntaxError(
                source,
                position,
                f"Invalid character within String: {print_char(char)}.",
            )
        position += 1
        if char == "\\":
            append(body[chunk_start : position - 1])
            char = char_at(body, position)
            escaped = _ESCAPED_CHARS.get(char)
            if escaped:
                value.append(escaped)
            elif char == "u":
                code = uni_char_code(
                    char_at(body, position + 1),
                    char_at(body, position + 2),
                    char_at(body, position + 3),
                    char_at(body, position + 4),
                )
                if code < 0:
                    escape = repr(body[position : position + 5])
                    escape = escape[:1] + "\\" + escape[1:]
                    raise GraphQLSyntaxError(
                        source,
                        position,
                        f"Invalid character escape sequence: {escape}.",
                    )
                append(chr(code))
                position += 4
            else:
                escape = repr(char)
                escape = escape[:1] + "\\" + escape[1:]
                raise GraphQLSyntaxError(
                    source, position, f"Invalid character escape sequence: {escape}."
                )
            position += 1
            chunk_start = position

    raise GraphQLSyntaxError(source, position, "Unterminated string.")
Read a string token from the source file.
Read a string token from the source file.
Read a string token from the source file .
def read_string(source: Source, start, line, col, prev) -> Token:
    body = source.body
    position = start + 1
    chunk_start = position
    value: List[str] = []
    append = value.append
    while position < len(body):
        char = char_at(body, position)
        if char is None or char in "\n\r":
            break
        if char == '"':
            append(body[chunk_start:position])
            return Token(
                TokenKind.STRING, start, position + 1, line, col, prev, "".join(value)
            )
        if char < " " and char != "\t":
            raise GraphQLSyntaxError(
                source,
                position,
                f"Invalid character within String: {print_char(char)}.",
            )
        position += 1
        if char == "\\":
            append(body[chunk_start : position - 1])
            char = char_at(body, position)
            escaped = _ESCAPED_CHARS.get(char)
            if escaped:
                value.append(escaped)
            elif char == "u":
                code = uni_char_code(
                    char_at(body, position + 1),
                    char_at(body, position + 2),
                    char_at(body, position + 3),
                    char_at(body, position + 4),
                )
                if code < 0:
                    escape = repr(body[position : position + 5])
                    escape = escape[:1] + "\\" + escape[1:]
                    raise GraphQLSyntaxError(
                        source,
                        position,
                        f"Invalid character escape sequence: {escape}.",
                    )
                append(chr(code))
                position += 4
            else:
                escape = repr(char)
                escape = escape[:1] + "\\" + escape[1:]
                raise GraphQLSyntaxError(
                    source, position, f"Invalid character escape sequence: {escape}."
                )
            position += 1
            chunk_start = position
    raise GraphQLSyntaxError(source, position, "Unterminated string.")
def read_string ( source : Source , start , line , col , prev ) -> Token : body = source . body position = start + 1 chunk_start = position value : List [ str ] = [ ] append = value . append while position < len ( body ) : char = char_at ( body , position ) if char is None or char in "\n\r" : break if char == '"' : append ( body [ chunk_start : position ] ) return Token ( TokenKind . STRING , start , position + 1 , line , col , prev , "" . join ( value ) ) if char < " " and char != "\t" : raise GraphQLSyntaxError ( source , position , f"Invalid character within String: {print_char(char)}." , ) position += 1 if char == "\\" : append ( body [ chunk_start : position - 1 ] ) char = char_at ( body , position ) escaped = _ESCAPED_CHARS . get ( char ) if escaped : value . append ( escaped ) elif char == "u" : code = uni_char_code ( char_at ( body , position + 1 ) , char_at ( body , position + 2 ) , char_at ( body , position + 3 ) , char_at ( body , position + 4 ) , ) if code < 0 : escape = repr ( body [ position : position + 5 ] ) escape = escape [ : 1 ] + "\\" + escape [ 1 : ] raise GraphQLSyntaxError ( source , position , f"Invalid character escape sequence: {escape}." , ) append ( chr ( code ) ) position += 4 else : escape = repr ( char ) escape = escape [ : 1 ] + "\\" + escape [ 1 : ] raise GraphQLSyntaxError ( source , position , f"Invalid character escape sequence: {escape}." ) position += 1 chunk_start = position raise GraphQLSyntaxError ( source , position , "Unterminated string." )
Read a string token from the source file.
Read a string token from the source file .
"""Read a string token from the source file."""
source
Source
start
line
col
prev