Actual support fo backticks.

This commit is contained in:
Dave Halter
2017-08-28 18:32:48 +02:00
parent b921e280b0
commit db1079a7fe
3 changed files with 23 additions and 22 deletions

View File

@@ -1,39 +1,36 @@
from __future__ import absolute_import from __future__ import absolute_import
from itertools import count
from parso._compatibility import py_version
from token import * from token import *
from parso._compatibility import py_version
COMMENT = N_TOKENS
_counter = count(N_TOKENS)
# Never want to see this thing again.
del N_TOKENS
COMMENT = next(_counter)
tok_name[COMMENT] = 'COMMENT' tok_name[COMMENT] = 'COMMENT'
N_TOKENS += 1
NL = N_TOKENS NL = next(_counter)
tok_name[NL] = 'NL' tok_name[NL] = 'NL'
N_TOKENS += 1
# Sets the attributes that don't exist in these tok_name versions.
if py_version >= 30: if py_version >= 30:
BACKQUOTE = N_TOKENS BACKQUOTE = next(_counter)
tok_name[BACKQUOTE] = 'BACKQUOTE' tok_name[BACKQUOTE] = 'BACKQUOTE'
N_TOKENS += 1
else: else:
RARROW = N_TOKENS RARROW = next(_counter)
tok_name[RARROW] = 'RARROW' tok_name[RARROW] = 'RARROW'
N_TOKENS += 1 ELLIPSIS = next(_counter)
ELLIPSIS = N_TOKENS
tok_name[ELLIPSIS] = 'ELLIPSIS' tok_name[ELLIPSIS] = 'ELLIPSIS'
N_TOKENS += 1
if not py_version >= 35: if py_version < 35:
ATEQUAL = N_TOKENS ATEQUAL = next(_counter)
tok_name[ATEQUAL] = 'ATEQUAL' tok_name[ATEQUAL] = 'ATEQUAL'
N_TOKENS += 1
ERROR_DEDENT = N_TOKENS ERROR_DEDENT = next(_counter)
tok_name[ERROR_DEDENT] = 'ERROR_DEDENT' tok_name[ERROR_DEDENT] = 'ERROR_DEDENT'
N_TOKENS += 1
# Map from operator to number (since tokenize doesn't do this) # Map from operator to number (since tokenize doesn't do this)

View File

@@ -18,8 +18,8 @@ from collections import namedtuple
import itertools as _itertools import itertools as _itertools
from codecs import BOM_UTF8 from codecs import BOM_UTF8
from parso.python.token import (tok_name, N_TOKENS, ENDMARKER, STRING, NUMBER, opmap, from parso.python.token import (tok_name, ENDMARKER, STRING, NUMBER, opmap,
NAME, OP, ERRORTOKEN, NEWLINE, INDENT, DEDENT, NAME, ERRORTOKEN, NEWLINE, INDENT, DEDENT,
ERROR_DEDENT) ERROR_DEDENT)
from parso._compatibility import py_version from parso._compatibility import py_version
from parso.utils import split_lines from parso.utils import split_lines
@@ -153,7 +153,7 @@ def _create_token_collection(version_info):
# recognized as two instances of =). # recognized as two instances of =).
Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"!=", Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"!=",
r"//=?", r"->", r"//=?", r"->",
r"[+\-*/%&@|^=<>]=?", r"[+\-*/%&@`|^=<>]=?",
r"~") r"~")
Bracket = '[][(){}]' Bracket = '[][(){}]'

View File

@@ -250,3 +250,7 @@ def test_multiline_str_literals(each_version):
"6f630fad67cda0ee1fb1f562db3aa53e") "6f630fad67cda0ee1fb1f562db3aa53e")
""" """
_parse(s, each_version) _parse(s, each_version)
def test_py2_backticks(works_in_py2):
works_in_py2.parse("`1`")