grammar.py (13663:9b64aeabf9a5) grammar.py (13670:8a98db5a481f)
1# Copyright (c) 2006-2011 Nathan Binkert <nate@binkert.org>
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

--- 101 unchanged lines hidden (view full) ---

110 parser = new.instance(ply.yacc.LRParser, dict)
111 result = parser.parse(lexer=lexer, debug=debug, tracking=tracking)
112 self.lexers.pop()
113 return result
114
115 def parse_file(self, f, **kwargs):
116 if isinstance(f, basestring):
117 source = f
1# Copyright (c) 2006-2011 Nathan Binkert <nate@binkert.org>
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

--- 101 unchanged lines hidden (view full) ---

110 parser = new.instance(ply.yacc.LRParser, dict)
111 result = parser.parse(lexer=lexer, debug=debug, tracking=tracking)
112 self.lexers.pop()
113 return result
114
115 def parse_file(self, f, **kwargs):
116 if isinstance(f, basestring):
117 source = f
118 f = file(f, 'r')
118 f = open(f, 'r')
119 elif isinstance(f, file):
120 source = f.name
121 else:
122 raise AttributeError(
123 "argument must be either a string or file, was '%s'" % type(f))
124
125 return self.parse_string(f.read(), source, **kwargs)
126

--- 12 unchanged lines hidden ---
119 elif isinstance(f, file):
120 source = f.name
121 else:
122 raise AttributeError(
123 "argument must be either a string or file, was '%s'" % type(f))
124
125 return self.parse_string(f.read(), source, **kwargs)
126

--- 12 unchanged lines hidden ---