parser.py (8452:3f2c329e9046) | parser.py (8453:82fc1267d3bb) |
---|---|
1# Copyright (c) 2009 The Hewlett-Packard Development Company 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 37 unchanged lines hidden (view full) --- 46 sm_file = sm_file.strip() 47 if not sm_file: 48 continue 49 if sm_file.startswith("#"): 50 continue 51 yield sm_file 52 53class SLICC(Grammar): | 1# Copyright (c) 2009 The Hewlett-Packard Development Company 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 37 unchanged lines hidden (view full) --- 46 sm_file = sm_file.strip() 47 if not sm_file: 48 continue 49 if sm_file.startswith("#"): 50 continue 51 yield sm_file 52 53class SLICC(Grammar): |
54 def __init__(self, protocol, **kwargs): | 54 def __init__(self, protocol, verbose=False): |
55 self.decl_list_vec = [] 56 self.protocol = protocol | 55 self.decl_list_vec = [] 56 self.protocol = protocol |
57 self.verbose = verbose |
|
57 self.symtab = SymbolTable(self) 58 | 58 self.symtab = SymbolTable(self) 59 |
60 def currentLocation(self): 61 return util.Location(self.current_source, self.current_line, 62 no_warning=not self.verbose) 63 |
|
59 def codeFormatter(self, *args, **kwargs): 60 code = code_formatter(*args, **kwargs) 61 code['protocol'] = self.protocol 62 return code 63 64 def parse(self, filename): 65 try: 66 decl_list = self.parse_file(filename) 67 except ParseError, e: 68 sys.exit(str(e)) 69 self.decl_list_vec.append(decl_list) 70 | 64 def codeFormatter(self, *args, **kwargs): 65 code = code_formatter(*args, **kwargs) 66 code['protocol'] = self.protocol 67 return code 68 69 def parse(self, filename): 70 try: 71 decl_list = self.parse_file(filename) 72 except ParseError, e: 73 sys.exit(str(e)) 74 self.decl_list_vec.append(decl_list) 75 |
71 def _load(self, *filenames): | 76 def load(self, filenames): |
72 filenames = list(filenames) 73 while filenames: 74 f = filenames.pop(0) 75 if isinstance(f, (list, tuple)): 76 filenames[0:0] = list(f) 77 continue 78 | 77 filenames = list(filenames) 78 while filenames: 79 f = filenames.pop(0) 80 if isinstance(f, (list, tuple)): 81 filenames[0:0] = list(f) 82 continue 83 |
79 yield f | |
80 if f.endswith(".slicc"): 81 dirname,basename = os.path.split(f) 82 filenames[0:0] = [ os.path.join(dirname, x) \ 83 for x in read_slicc(f)] 84 else: 85 assert f.endswith(".sm") 86 self.parse(f) 87 | 84 if f.endswith(".slicc"): 85 dirname,basename = os.path.split(f) 86 filenames[0:0] = [ os.path.join(dirname, x) \ 87 for x in read_slicc(f)] 88 else: 89 assert f.endswith(".sm") 90 self.parse(f) 91 |
88 def load(self, *filenames, **kwargs): 89 verbose = kwargs.pop("verbose", False) 90 if kwargs: 91 raise TypeError 92 93 gen = self._load(*filenames) 94 if verbose: 95 return gen 96 else: 97 # Run out the generator if we don't want the verbosity 98 for foo in gen: 99 pass 100 101 def findMachines(self): | 92 def process(self): |
102 for decl_list in self.decl_list_vec: 103 decl_list.findMachines() 104 | 93 for decl_list in self.decl_list_vec: 94 decl_list.findMachines() 95 |
105 def generate(self): | |
106 for decl_list in self.decl_list_vec: 107 decl_list.generate() 108 109 def writeCodeFiles(self, code_path): | 96 for decl_list in self.decl_list_vec: 97 decl_list.generate() 98 99 def writeCodeFiles(self, code_path): |
110 util.makeDir(code_path) | |
111 self.symtab.writeCodeFiles(code_path) 112 | 100 self.symtab.writeCodeFiles(code_path) 101 |
113 def writeHTMLFiles(self, code_path): 114 util.makeDir(code_path) 115 self.symtab.writeHTMLFiles(code_path) | 102 def writeHTMLFiles(self, html_path): 103 self.symtab.writeHTMLFiles(html_path) |
116 117 def files(self): 118 f = set([ 119 'MachineType.cc', 120 'MachineType.hh', 121 'Types.hh' ]) 122 123 for decl_list in self.decl_list_vec: --- 611 unchanged lines hidden --- | 104 105 def files(self): 106 f = set([ 107 'MachineType.cc', 108 'MachineType.hh', 109 'Types.hh' ]) 110 111 for decl_list in self.decl_list_vec: --- 611 unchanged lines hidden --- |