Internal code reorganization.

- Separate library loading code into a new module. parser.__init__() no longer loads the library; it accepts (but does not depend on) a library as a parameter.
- Add an optional library argument to parse(). It's no longer mandatory to create a new parser for switching to a different builtins or seftable file.
- Move warning() and types from lslparse to lslcommon.
- Add .copy() to uses of base_keywords, to not rely on it being a frozen set.
- Adjust the test suite.
This commit is contained in:
Sei Lisa 2017-10-20 16:26:05 +02:00
parent 1a1531cb40
commit 3f6f8ed8ad
7 changed files with 294 additions and 238 deletions

View file

@ -15,6 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
# Classes, functions and variables for use of all modules.
import sys
# These types just wrap the Python types to make type() work on them.
# There are no ops defined on them or anything.
@ -46,6 +50,13 @@ IsCalc = False
DataPath = ''
# Language
# These are hardcoded because additions or modifications imply
# important changes to the code anyway.
types = frozenset(('integer','float','string','key','vector',
'quaternion','rotation','list'))
# Conversion of LSL types to Python types and vice versa.
PythonType2LSL = {int: 'integer', float: 'float',
@ -55,3 +66,7 @@ PythonType2LSL = {int: 'integer', float: 'float',
LSLType2Python = {'integer':int, 'float':float,
'string':unicode, 'key':Key, 'vector':Vector,
'rotation':Quaternion, 'list':list}
def warning(txt):
assert type(txt) == unicode
sys.stderr.write(u"WARNING: " + txt + u"\n")