mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-29 00:16:52 +08:00
The driver file is now empty.
This commit is contained in:
@@ -19,7 +19,8 @@ import os
|
||||
|
||||
from jedi.parser import tree as pt
|
||||
from jedi.parser import tokenize
|
||||
from jedi.parser import pgen2
|
||||
from jedi.parser.pgen2 import grammar
|
||||
from jedi.parser.pgen2.pgen import generate_grammar
|
||||
from jedi.parser.pgen2.parse import PgenParser
|
||||
|
||||
OPERATOR_KEYWORDS = 'and', 'for', 'if', 'else', 'in', 'is', 'lambda', 'not', 'or'
|
||||
@@ -37,7 +38,7 @@ def load_grammar(file='grammar3.4'):
|
||||
try:
|
||||
return _loaded_grammars[path]
|
||||
except KeyError:
|
||||
return _loaded_grammars.setdefault(path, pgen2.load_grammar(path))
|
||||
return _loaded_grammars.setdefault(path, generate_grammar(path))
|
||||
|
||||
|
||||
class ErrorStatement(object):
|
||||
@@ -295,7 +296,7 @@ class Parser(object):
|
||||
typ = token.type
|
||||
value = token.value
|
||||
if typ == tokenize.OP:
|
||||
typ = pgen2.grammar.opmap[value]
|
||||
typ = grammar.opmap[value]
|
||||
yield typ, value, token.prefix, token.start_pos
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@@ -4,50 +4,5 @@
|
||||
# Modifications:
|
||||
# Copyright 2006 Google, Inc. All Rights Reserved.
|
||||
# Licensed to PSF under a Contributor Agreement.
|
||||
|
||||
__all__ = ["load_grammar"]
|
||||
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
|
||||
from . import pgen
|
||||
from . import grammar
|
||||
|
||||
|
||||
def load_grammar(grammar_path="grammar.txt", pickle_path=None,
|
||||
save=True, force=False, logger=None):
|
||||
"""Load the grammar (maybe from a pickle)."""
|
||||
if logger is None:
|
||||
logger = logging.getLogger()
|
||||
if pickle_path is None:
|
||||
head, tail = os.path.splitext(grammar_path)
|
||||
if tail == ".txt":
|
||||
tail = ""
|
||||
pickle_path = head + tail + ".".join(map(str, sys.version_info)) + ".pickle"
|
||||
if force or not _newer(pickle_path, grammar_path):
|
||||
logger.info("Generating grammar tables from %s", grammar_path)
|
||||
g = pgen.generate_grammar(grammar_path)
|
||||
# the pickle files mismatch, when built on different architectures.
|
||||
# don't save these for now. An alternative solution might be to
|
||||
# include the multiarch triplet into the file name
|
||||
if False:
|
||||
logger.info("Writing grammar tables to %s", pickle_path)
|
||||
try:
|
||||
g.dump(pickle_path)
|
||||
except OSError as e:
|
||||
logger.info("Writing failed:" + str(e))
|
||||
else:
|
||||
g = grammar.Grammar()
|
||||
g.load(pickle_path)
|
||||
return g
|
||||
|
||||
|
||||
def _newer(a, b):
|
||||
"""Inquire whether file a was written since file b."""
|
||||
if not os.path.exists(a):
|
||||
return False
|
||||
if not os.path.exists(b):
|
||||
return True
|
||||
return os.path.getmtime(a) >= os.path.getmtime(b)
|
||||
# Copyright 2014 David Halter. Integration into Jedi.
|
||||
# Modifications are dual-licensed: MIT and PSF.
|
||||
|
||||
Reference in New Issue
Block a user