Removed code relevant to versions below 3.6

This commit is contained in:
Erez Sh 2021-06-28 20:19:06 +03:00
parent ff686fc89a
commit 9b77270502
6 changed files with 10 additions and 37 deletions

View File

@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.5, 3.6, 3.7, 3.8, 3.9.0-rc - 3.9, pypy3]
python-version: [3.6, 3.7, 3.8, 3.9.0-rc - 3.9, pypy3]
steps:
- uses: actions/checkout@v2

View File

@ -3,7 +3,7 @@
import re
from contextlib import suppress
from .utils import classify, get_regexp_width, Py36, Serialize
from .utils import classify, get_regexp_width, Serialize
from .exceptions import UnexpectedCharacters, LexError, UnexpectedToken
###{standalone
@ -38,19 +38,10 @@ class Pattern(Serialize):
def max_width(self):
raise NotImplementedError()
if Py36:
# Python 3.6 changed syntax for flags in regular expression
def _get_flags(self, value):
for f in self.flags:
value = ('(?%s:%s)' % (f, value))
return value
else:
def _get_flags(self, value):
for f in self.flags:
value = ('(?%s)' % f) + value
return value
def _get_flags(self, value):
for f in self.flags:
value = ('(?%s:%s)' % (f, value))
return value
class PatternStr(Pattern):

View File

@ -9,7 +9,7 @@ from ast import literal_eval
from numbers import Integral
from contextlib import suppress
from .utils import bfs, Py36, logger, classify_bool, is_id_continue, is_id_start, bfs_all_unique
from .utils import bfs, logger, classify_bool, is_id_continue, is_id_start, bfs_all_unique
from .lexer import Token, TerminalDef, PatternStr, PatternRE
from .parse_tree_builder import ParseTreeBuilder
@ -475,18 +475,7 @@ class PrepareLiterals(Transformer_InPlace):
def _make_joined_pattern(regexp, flags_set):
# In Python 3.6, a new syntax for flags was introduced, that allows us to restrict the scope
# of flags to a specific regexp group. We are already using it in `lexer.Pattern._get_flags`
# However, for prior Python versions, we still need to use global flags, so we have to make sure
# that there are no flag collisions when we merge several terminals.
flags = ()
if not Py36:
if len(flags_set) > 1:
raise GrammarError("Lark doesn't support joining terminals with conflicting flags in python <3.6!")
elif len(flags_set) == 1:
flags ,= flags_set
return PatternRE(regexp, flags)
return PatternRE(regexp, ())
class TerminalTreeToPattern(Transformer):

View File

@ -13,8 +13,6 @@ logger.addHandler(logging.StreamHandler())
logger.setLevel(logging.CRITICAL)
Py36 = (sys.version_info[:2] >= (3, 6))
NO_VALUE = object()

View File

@ -8,7 +8,7 @@ import os
import sys
from copy import copy, deepcopy
from lark.utils import Py36, isascii
from lark.utils import isascii
from lark import Token, Transformer_NonRecursive, LexError
@ -1545,7 +1545,6 @@ def _make_parser_test(LEXER, PARSER):
self.assertEqual( g.parse('"hello"').children, ['"hello"'])
self.assertEqual( g.parse("'hello'").children, ["'hello'"])
@unittest.skipIf(not Py36, "Required re syntax only exists in python3.6+")
def test_join_regex_flags(self):
g = r"""
start: A

View File

@ -1,16 +1,12 @@
[tox]
envlist = py27, py34, py35, py36, py37, py38, py39, pypy, pypy3
envlist = py36, py37, py38, py39, pypy, pypy3
skip_missing_interpreters=true
[travis]
2.7 = py27
3.4 = py34
3.5 = py35
3.6 = py36
3.7 = py37
3.8 = py38
3.9 = py39
pypy = pypy
pypy3 = pypy3
[testenv]