1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 """Load a fuzzy system from FCL file, stream or string."""
19
20 __revision__ = "$Id: Reader.py,v 1.6 2013-01-09 20:10:19 rliebscher Exp $"
21
22
23 import sys
24 try:
25 sys.maxint
26 except:
27 sys.maxint = sys.maxsize
28
29 import antlr3
30
31 try:
32 from fuzzy.storage.fcl.FCLLexer import FCLLexer
33 except:
34 from fuzzy.storage.fcl.FCLLexer3 import FCLLexer
35 from fuzzy.storage.fcl.FCLParser import FCLParser
36
38 """Parses a FCL file to a fuzzy.System.System instance"""
39
40 - def __load(self, char_stream):
41 """Common part of load methods."""
42 lexer = FCLLexer(char_stream)
43 tokens = antlr3.CommonTokenStream(lexer)
44 parser = FCLParser(tokens)
45 return parser.main()
46
48 """Load a fuzzy system from FCL file."""
49 encoding = None
50 f = None
51 try:
52
53 f = open(filename)
54 line = f.readline()
55 import re
56
57 result = re.search(r'coding[=:]\s*([-\w.]+)', line)
58 if result:
59
60 encoding = result.group(1)
61 except:
62
63 pass
64 if f:
65 f.close()
66 return self.__load(antlr3.ANTLRFileStream(filename, encoding))
67
69 """Load a fuzzy system from FCL stream."""
70 return self.__load(antlr3.ANTLRInputStream(stream))
71
73 """Load a fuzzy system from FCL string."""
74 return self.__load(antlr3.ANTLRStringStream(str))
75