mirror of
https://github.com/davidhalter/parso.git
synced 2026-01-20 01:53:08 +08:00
Add a more API focused grammar.
This makes it so we don't have to expose all the details of a pgen grammar to the user.
This commit is contained in:
@@ -8,7 +8,7 @@ import pytest
|
||||
|
||||
from parso.cache import _NodeCacheItem, save_module, load_module, \
|
||||
_get_hashed_path, parser_cache, _load_from_file_system, _save_to_file_system
|
||||
from parso.python import load_grammar
|
||||
from parso import load_python_grammar
|
||||
from parso import cache
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ def test_modulepickling_change_cache_dir(tmpdir):
|
||||
path_1 = 'fake path 1'
|
||||
path_2 = 'fake path 2'
|
||||
|
||||
grammar = load_grammar()
|
||||
grammar = load_python_grammar()
|
||||
_save_to_file_system(grammar, path_1, item_1, cache_path=dir_1)
|
||||
parser_cache.clear()
|
||||
cached = load_stored_item(grammar, path_1, item_1, cache_path=dir_1)
|
||||
@@ -69,7 +69,7 @@ def test_modulepickling_simulate_deleted_cache(tmpdir):
|
||||
|
||||
__ https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
|
||||
"""
|
||||
grammar = load_grammar()
|
||||
grammar = load_python_grammar()
|
||||
module = 'fake parser'
|
||||
|
||||
# Create the file
|
||||
|
||||
@@ -5,7 +5,7 @@ import pytest
|
||||
|
||||
from parso.utils import splitlines
|
||||
from parso import cache
|
||||
from parso.python import load_grammar
|
||||
from parso import load_python_grammar
|
||||
from parso.python.diff import DiffParser
|
||||
from parso.python import parse
|
||||
|
||||
@@ -40,7 +40,7 @@ def _assert_valid_graph(node):
|
||||
|
||||
|
||||
class Differ(object):
|
||||
grammar = load_grammar()
|
||||
grammar = load_python_grammar()
|
||||
|
||||
def initialize(self, code):
|
||||
logging.debug('differ: initialize')
|
||||
@@ -52,7 +52,7 @@ class Differ(object):
|
||||
def parse(self, code, copies=0, parsers=0, expect_error_leaves=False):
|
||||
logging.debug('differ: parse copies=%s parsers=%s', copies, parsers)
|
||||
lines = splitlines(code, keepends=True)
|
||||
diff_parser = DiffParser(self.grammar, self.module)
|
||||
diff_parser = DiffParser(self.grammar._pgen_grammar, self.module)
|
||||
new_module = diff_parser.update(self.lines, lines)
|
||||
self.lines = lines
|
||||
assert code == new_module.get_code()
|
||||
|
||||
@@ -5,7 +5,8 @@ from textwrap import dedent
|
||||
import pytest
|
||||
|
||||
from parso._compatibility import u, py_version
|
||||
from parso.python import parse, load_grammar
|
||||
from parso.python import parse
|
||||
from parso import load_python_grammar
|
||||
from parso.python import tree
|
||||
from parso.utils import splitlines
|
||||
|
||||
@@ -112,7 +113,7 @@ def test_param_splitting():
|
||||
"""
|
||||
def check(src, result):
|
||||
# Python 2 tuple params should be ignored for now.
|
||||
grammar = load_grammar('%s.%s' % sys.version_info[:2])
|
||||
grammar = load_python_grammar('%s.%s' % sys.version_info[:2])
|
||||
m = parse(src, grammar=grammar)
|
||||
if py_version >= 30:
|
||||
assert not list(m.iter_funcdefs())
|
||||
@@ -160,10 +161,10 @@ def test_python3_octal():
|
||||
def test_load_newer_grammar():
|
||||
# This version shouldn't be out for a while, but if we somehow get this it
|
||||
# should just take the latest Python grammar.
|
||||
load_grammar('15.8')
|
||||
load_python_grammar('15.8')
|
||||
# The same is true for very old grammars (even though this is probably not
|
||||
# going to be an issue.
|
||||
load_grammar('1.5')
|
||||
load_python_grammar('1.5')
|
||||
|
||||
|
||||
@pytest.mark.parametrize('code', ['foo "', 'foo """\n', 'foo """\nbar'])
|
||||
|
||||
@@ -9,14 +9,15 @@ test_grammar.py files from both Python 2 and Python 3.
|
||||
from textwrap import dedent
|
||||
|
||||
from parso._compatibility import py_version
|
||||
from parso.python import parse as _parse, load_grammar
|
||||
from parso import load_python_grammar
|
||||
from parso.python import parse as _parse
|
||||
from parso import ParserSyntaxError
|
||||
import pytest
|
||||
|
||||
|
||||
def parse(code, version='3.4'):
|
||||
code = dedent(code) + "\n\n"
|
||||
grammar = load_grammar(version=version)
|
||||
grammar = load_python_grammar(version=version)
|
||||
return _parse(code, grammar=grammar, error_recovery=False)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user