|
19 | 19 | import sys |
20 | 20 | import os |
21 | 21 | import pathlib |
22 | | - |
23 | 22 | from ply.yacc import yacc |
24 | | -from pyverilog.vparser.plyparser import PLYParser, ParseError |
| 23 | + |
25 | 24 | from pyverilog.vparser.preprocessor import VerilogPreprocessor |
26 | 25 | from pyverilog.vparser.lexer import VerilogLexer |
27 | 26 | from pyverilog.vparser.ast import * |
28 | 27 |
|
29 | 28 |
|
30 | | -class VerilogParser(PLYParser): |
| 29 | +class VerilogParser(object): |
31 | 30 | 'Verilog HDL Parser' |
32 | 31 |
|
33 | 32 | # Expression Precedence |
@@ -64,7 +63,8 @@ def __init__(self, outputdir=".", debug=True): |
64 | 63 | ) |
65 | 64 |
|
66 | 65 | def _lexer_error_func(self, msg, line, column): |
67 | | - self._parse_error(msg, self._coord(line, column)) |
| 66 | + coord = self._coord(line, column) |
| 67 | + raise ParseError('%s: %s' % (coord, msg)) |
68 | 68 |
|
69 | 69 | def get_directives(self): |
70 | 70 | return self.lexer.get_directives() |
@@ -2265,13 +2265,29 @@ def p_empty(self, p): |
2265 | 2265 |
|
2266 | 2266 | # -------------------------------------------------------------------------- |
2267 | 2267 | def p_error(self, p): |
2268 | | - print("Syntax error") |
| 2268 | + self._raise_error(p) |
| 2269 | + |
| 2270 | + # -------------------------------------------------------------------------- |
| 2271 | + def _raise_error(self, p): |
2269 | 2272 | if p: |
2270 | | - self._parse_error( |
2271 | | - 'before: %s' % p.value, |
2272 | | - self._coord(p.lineno)) |
| 2273 | + msg = 'before: "%s"' % p.value |
| 2274 | + coord = self._coord(p.lineno) |
2273 | 2275 | else: |
2274 | | - self._parse_error('At end of input', '') |
| 2276 | + msg = 'at end of input' |
| 2277 | + coord = None |
| 2278 | + |
| 2279 | + raise ParseError("%s: %s" % (coord, msg)) |
| 2280 | + |
| 2281 | + def _coord(self, lineno, column=None): |
| 2282 | + ret = [self.lexer.filename] |
| 2283 | + ret.append('line:%s' % lineno) |
| 2284 | + if column is not None: |
| 2285 | + ret.append('column:%s' % column) |
| 2286 | + return ' '.join(ret) |
| 2287 | + |
| 2288 | + |
| 2289 | +class ParseError(Exception): |
| 2290 | + pass |
2275 | 2291 |
|
2276 | 2292 |
|
2277 | 2293 | class VerilogCodeParser(object): |
|
0 commit comments