<commit_before># Based on PLY calc.py example:
# -----------------------------------------------------------------------------
#
# A simple calculator with variables.   This is from O'Reilly's
# "Lex and Yacc", p. 63.
#
# Class-based example contributed to PLY by <NAME>.
#
# Modified to use new-style classes.   Test case.
# -----------------------------------------------------------------------------





import ply.lex as lex
import ply.yacc as yacc
import os

import math_namespace


class NineMLMathParseError(ValueError):
    pass


def call_expr_func(expr_func, ns):
    args = []
    for var in expr_func.func_code.co_varnames:
        try:
            args.append(ns[var])
        except KeyError:
            raise KeyError, "call_expr_func: namespace missing variable '%s'" % var
    return expr_func(*args)


class Parser(object):
    """
    Base class for a lexer/parser that has the rules defined as methods
    """
    tokens = ()
    precedence = ()


    def __init__(self, **kw):
        self.debug = kw.get('debug', 0)
        self.names = { }
        try:
            modname = os.path.split(os.path.splitext(__file__)[0])[1] + "_" + self.__class__.__name__
        except:
            modname = "parser"+"_"+self.__class__.__name__
        self.debugfile = modname + ".dbg"
        self.tabmodule = modname + "_" + "parsetab"
        #print self.debugfile, self.tabmodule
<commit_msg>Parser files are now generated in Location specified in LocationMgr<commit_after># Based on PLY calc.py example:
# -----------------------------------------------------------------------------
#
# A simple calculator with variables.   This is from O'Reilly's
# "Lex and Yacc", p. 63.
#
# Class-based example contributed to PLY by <NAME>.
#
# Modified to use new-style classes.   Test case.
# -----------------------------------------------------------------------------





import ply.lex as lex
import ply.yacc as yacc
import os

import math_namespace


class NineMLMathParseError(ValueError):
    pass


def call_expr_func(expr_func, ns):
    args = []
    for var in expr_func.func_code.co_varnames:
        try:
            args.append(ns[var])
        except KeyError:
            raise KeyError, "call_expr_func: namespace missing variable '%s'" % var
    return expr_func(*args)


class Parser(object):
    """
    Base class for a lexer/parser that has the rules defined as methods
    """
    tokens = ()
    precedence = ()


    def __init__(self, **kw):
        self.debug = kw.get('debug', 0)
        self.names = { }
        try:
            modname = os.path.split(os.path.splitext(__file__)[0])[1] + "_" + self.__class__.__name__
        except:
            modname = "parser"+"_"+self.__class__.__name__

        from nineml.utility import LocationMgr
        self.debugfile = LocationMgr.getTmpDir() + modname + ".dbg"
        self.tabmodule = LocationMgr.getTmpDir() + modname + "_" + "parsetab"

        #print self.debugfile, self.tabmodule

{'fraction_non_alphanumeric': 0.20430831369909122, 'fraction_numerical': 0.003365870077415012, 'mean_word_length': 1.8385864374403056, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5388509', 'n_tokens_mistral': 885, 'n_tokens_neox': 845, 'n_words': 235}