-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathdriver.py
More file actions
37 lines (27 loc) · 854 Bytes
/
driver.py
File metadata and controls
37 lines (27 loc) · 854 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
# Modifications:
# Copyright 2006 Google, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Parser driver.
This provides a high-level interface to parse a file into a syntax tree.
"""
__author__ = "Guido van Rossum <guido@python.org>"
__all__ = ["load_grammar"]
# Python imports
import os
import logging
import pkgutil
import sys
# Pgen imports
from . import grammar, pgen
if sys.version < "3":
from cStringIO import StringIO
else:
from io import StringIO
def load_grammar(package, grammar):
"""Load the grammar (maybe from a pickle)."""
data = pkgutil.get_data(package, grammar)
stream = StringIO(data.decode("utf8"))
g = pgen.generate_grammar(grammar, stream)
return g