# Path: pydsl/exceptions.py
# class ParseError(Exception):
# 
#     def __init__(self, msg, offset):
#         self.msg = msg
#         self.offset = offset
# 
#     def __repr__(self):
#         return "ParseError(%r, %r)" % (self.msg, self.offset)
# 
#     def __str__(self):
#         return "%s at position %s" % (self.msg, self.offset + 1)


from ply.lex import TOKEN
from pydsl.exceptions import ParseError

##### Define the grammar

# The molecular weight of "" is 0.0
def p_mw_empty(p):
    "mw : "
    p[0] = 0.0

def p_mw_formula(p):
    "mw : formula"
    p[0] = p[1]
    

def p_first_species_term(p):
    "formula : species"
    p[0] = p[1]

def p_species_list(p):
    "formula : formula species"
    p[0] = p[1] + p[2]

def p_species(p):
    "species : ATOM DIGITS"
    p[0] = p[1] * p[2]

def p_species_default(p):
    "species : ATOM"
    p[0] = p[1]

def p_error(p):

# Path: pydsl/exceptions.py
# class ParseError(Exception):
# 
#     def __init__(self, msg, offset):
#         self.msg = msg
#         self.offset = offset
# 
#     def __repr__(self):
#         return "ParseError(%r, %r)" % (self.msg, self.offset)
# 
#     def __str__(self):
#         return "%s at position %s" % (self.msg, self.offset + 1)


# Path: pydsl/contrib/grammar/example_ply.py
from ply.lex import TOKEN
from pydsl.exceptions import ParseError


##### Define the grammar

# The molecular weight of "" is 0.0
def p_mw_empty(p):
    "mw : "
    p[0] = 0.0

def p_mw_formula(p):
    "mw : formula"
    p[0] = p[1]
    

def p_first_species_term(p):
    "formula : species"
    p[0] = p[1]

def p_species_list(p):
    "formula : formula species"
    p[0] = p[1] + p[2]

def p_species(p):
    "species : ATOM DIGITS"
    p[0] = p[1] * p[2]

def p_species_default(p):
    "species : ATOM"
    p[0] = p[1]

def p_error(p):

    raise ParseError("unexpected character", p.lexpos)