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 parso._compatibility import py_version
from itertools import count
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'
N_TOKENS += 1
NL = N_TOKENS
NL = next(_counter)
tok_name[NL] = 'NL'
N_TOKENS += 1
# Sets the attributes that don't exist in these tok_name versions.
if py_version >= 30:
BACKQUOTE = N_TOKENS
BACKQUOTE = next(_counter)
tok_name[BACKQUOTE] = 'BACKQUOTE'
N_TOKENS += 1
else:
RARROW = N_TOKENS
RARROW = next(_counter)
tok_name[RARROW] = 'RARROW'
N_TOKENS += 1
ELLIPSIS = N_TOKENS
ELLIPSIS = next(_counter)
tok_name[ELLIPSIS] = 'ELLIPSIS'
N_TOKENS += 1
if not py_version >= 35:
ATEQUAL = N_TOKENS
if py_version < 35:
ATEQUAL = next(_counter)
tok_name[ATEQUAL] = 'ATEQUAL'
N_TOKENS += 1
ERROR_DEDENT = N_TOKENS
ERROR_DEDENT = next(_counter)
tok_name[ERROR_DEDENT] = 'ERROR_DEDENT'
N_TOKENS += 1
# 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
from codecs import BOM_UTF8
from parso.python.token import (tok_name, N_TOKENS, ENDMARKER, STRING, NUMBER, opmap,
NAME, OP, ERRORTOKEN, NEWLINE, INDENT, DEDENT,
from parso.python.token import (tok_name, ENDMARKER, STRING, NUMBER, opmap,
NAME, ERRORTOKEN, NEWLINE, INDENT, DEDENT,
ERROR_DEDENT)
from parso._compatibility import py_version
from parso.utils import split_lines
@@ -153,7 +153,7 @@ def _create_token_collection(version_info):
# recognized as two instances of =).
Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"!=",
r"//=?", r"->",
r"[+\-*/%&@|^=<>]=?",
r"[+\-*/%&@`|^=<>]=?",
r"~")
Bracket = '[][(){}]'

View File

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