# Path: pydsl/encoding.py

# 
# Path: pydsl/lex.py
# def lexer_factory(alphabet, base, force_lexer = None):
#     if force_lexer is None:
#         if alphabet == ascii_encoding:
#             force_lexer = "lexer"
#         elif isinstance(alphabet, Choice) and alphabet.alphabet == base:
#             force_lexer = "brute_force"
#         else:
#             force_lexer = "general"
#         
#     if force_lexer == "lexer":
#         return ChoiceLexer(alphabet)
#     elif force_lexer == "brute_force":
#         return ChoiceBruteForceLexer(alphabet)
#     elif force_lexer == "general":
#         return GeneralLexer(alphabet, base)
#     else:
#         raise ValueError
# 
# Path: pydsl/parser/LL.py
# class LL1RecursiveDescentParser(TopDownParser):
#     def get_trees(self, data, showerrors = False): # -> list:
#         """ returns a list of trees with valid guesses """
#         if showerrors:
#             raise NotImplementedError("This parser doesn't implement errors")
#         self.data = data
#         self.index = 0
#         try:
#             return [self.__aux_parser(self._productionset.initialsymbol)]
#         except (IndexError, ParseError):
#             return []
# 
#     def __aux_parser(self, symbol):
#         from pydsl.grammar.symbol import TerminalSymbol
#         if isinstance(symbol, TerminalSymbol):
#             LOG.debug("matching symbol %s, data:%s, index:%s" % (symbol,self.data,self.index ))
#             result= self.match(symbol)
#             LOG.debug("symbol matched %s" % result)
#             return result
#         productions = self._productionset.getProductionsBySide(symbol)
#         valid_firsts = []
#         for production in productions:
#             first_of_production = self._productionset.first_lookup(production.rightside[0])
#             if check(first_of_production, [self.current]):
#                 valid_firsts.append(production)
#         if len(valid_firsts) != 1:
#             raise ParseError("Expected only one valid production, found %s" % len(valid_firsts), 0)
#         childlist = [self.__aux_parser(x) for x in valid_firsts[0].rightside]
#         left = childlist[0].left
#         right = childlist[-1].right
#         content = [x.content for x in childlist]
#         return ParseTree(left, right, symbol, content, childlist=childlist)
# 
# 
#     def consume(self):
#         self.index +=1
#         if self.index > len(self.data):
#             raise IndexError("Attempted to consume index %s of data %s" % (self.index, self.data))
# 
#     @property
#     def current(self):
#         return self.data[self.index]
# 
#     def match(self, symbol):
#         if symbol.check([self.current]):
#             current = self.current
#             self.consume()
#             return ParseTree(self.index-1, self.index, symbol, current)
#         raise Exception("Not matched")


import unittest
from pydsl.encoding import ascii_encoding
from pydsl.lex import lexer_factory
from pydsl.parser.LL import LL1RecursiveDescentParser
        from pydsl.file.BNF import strlist_to_production_set
        from pydsl.parser.backtracing import BacktracingErrorRecursiveDescentParser
        from pydsl.grammar.symbol import NonTerminalSymbol
        from pydsl.file.BNF import strlist_to_production_set
        from pydsl.grammar import RegularExpression
            from pydsl.grammar.symbol import NonTerminalSymbol
        from pydsl.grammar.PEG import Choice
        from pydsl.grammar.definition import String, RegularExpression
        from pydsl.encoding import ascii_encoding
        from pydsl.lex import lex
#!/usr/bin/python
# -*- coding: utf-8 -*-
#This file is part of pydsl.
#
#pydsl is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#pydsl is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with pydsl.  If not, see <http://www.gnu.org/licenses/>.

__author__ = "Nestor Arocha"
__copyright__ = "Copyright 2008-2014, Nestor Arocha"
__email__ = "nesaro@gmail.com"


class TestCase(unittest.TestCase):
    def test_main_case(self):
        input_data = "1+2"

# Path: pydsl/encoding.py

# 
# Path: pydsl/lex.py
# def lexer_factory(alphabet, base, force_lexer = None):
#     if force_lexer is None:
#         if alphabet == ascii_encoding:
#             force_lexer = "lexer"
#         elif isinstance(alphabet, Choice) and alphabet.alphabet == base:
#             force_lexer = "brute_force"
#         else:
#             force_lexer = "general"
#         
#     if force_lexer == "lexer":
#         return ChoiceLexer(alphabet)
#     elif force_lexer == "brute_force":
#         return ChoiceBruteForceLexer(alphabet)
#     elif force_lexer == "general":
#         return GeneralLexer(alphabet, base)
#     else:
#         raise ValueError
# 
# Path: pydsl/parser/LL.py
# class LL1RecursiveDescentParser(TopDownParser):
#     def get_trees(self, data, showerrors = False): # -> list:
#         """ returns a list of trees with valid guesses """
#         if showerrors:
#             raise NotImplementedError("This parser doesn't implement errors")
#         self.data = data
#         self.index = 0
#         try:
#             return [self.__aux_parser(self._productionset.initialsymbol)]
#         except (IndexError, ParseError):
#             return []
# 
#     def __aux_parser(self, symbol):
#         from pydsl.grammar.symbol import TerminalSymbol
#         if isinstance(symbol, TerminalSymbol):
#             LOG.debug("matching symbol %s, data:%s, index:%s" % (symbol,self.data,self.index ))
#             result= self.match(symbol)
#             LOG.debug("symbol matched %s" % result)
#             return result
#         productions = self._productionset.getProductionsBySide(symbol)
#         valid_firsts = []
#         for production in productions:
#             first_of_production = self._productionset.first_lookup(production.rightside[0])
#             if check(first_of_production, [self.current]):
#                 valid_firsts.append(production)
#         if len(valid_firsts) != 1:
#             raise ParseError("Expected only one valid production, found %s" % len(valid_firsts), 0)
#         childlist = [self.__aux_parser(x) for x in valid_firsts[0].rightside]
#         left = childlist[0].left
#         right = childlist[-1].right
#         content = [x.content for x in childlist]
#         return ParseTree(left, right, symbol, content, childlist=childlist)
# 
# 
#     def consume(self):
#         self.index +=1
#         if self.index > len(self.data):
#             raise IndexError("Attempted to consume index %s of data %s" % (self.index, self.data))
# 
#     @property
#     def current(self):
#         return self.data[self.index]
# 
#     def match(self, symbol):
#         if symbol.check([self.current]):
#             current = self.current
#             self.consume()
#             return ParseTree(self.index-1, self.index, symbol, current)
#         raise Exception("Not matched")


# Path: tests/functional/test_Case.py
import unittest
from pydsl.encoding import ascii_encoding
from pydsl.lex import lexer_factory
from pydsl.parser.LL import LL1RecursiveDescentParser
        from pydsl.file.BNF import strlist_to_production_set
        from pydsl.parser.backtracing import BacktracingErrorRecursiveDescentParser
        from pydsl.grammar.symbol import NonTerminalSymbol
        from pydsl.file.BNF import strlist_to_production_set
        from pydsl.grammar import RegularExpression
            from pydsl.grammar.symbol import NonTerminalSymbol
        from pydsl.grammar.PEG import Choice
        from pydsl.grammar.definition import String, RegularExpression
        from pydsl.encoding import ascii_encoding
        from pydsl.lex import lex

#!/usr/bin/python
# -*- coding: utf-8 -*-
#This file is part of pydsl.
#
#pydsl is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#pydsl is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with pydsl.  If not, see <http://www.gnu.org/licenses/>.

__author__ = "Nestor Arocha"
__copyright__ = "Copyright 2008-2014, Nestor Arocha"
__email__ = "nesaro@gmail.com"


class TestCase(unittest.TestCase):
    def test_main_case(self):
        input_data = "1+2"

        ascii_lexer = lexer_factory(ascii_encoding, None)