01: /*
02: * VerilogTagger.java
03: *
04: * Copyright (C) 2002 Peter Graves
05: * $Id: VerilogTagger.java,v 1.1.1.1 2002/09/24 16:07:55 piso Exp $
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License
09: * as published by the Free Software Foundation; either version 2
10: * of the License, or (at your option) any later version.
11: *
12: * This program is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: * GNU General Public License for more details.
16: *
17: * You should have received a copy of the GNU General Public License
18: * along with this program; if not, write to the Free Software
19: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20: */
21:
22: package org.armedbear.j;
23:
24: import gnu.regexp.RE;
25: import gnu.regexp.REMatch;
26: import gnu.regexp.UncheckedRE;
27: import java.util.ArrayList;
28:
29: public final class VerilogTagger extends Tagger {
30: // We trim before matching, so "module" or "primitive" will appear without
31: // any preceding whitespace.
32: private static final RE moduleRE = new UncheckedRE(
33: "^module\\s+([a-zA-Z_][a-zA-Z0-9_$]*)");
34: private static final RE primitiveRE = new UncheckedRE(
35: "^primitive\\s+([a-zA-Z_][a-zA-Z0-9_$]*)");
36:
37: public VerilogTagger(SystemBuffer buffer) {
38: super (buffer);
39: }
40:
41: public void run() {
42: ArrayList tags = new ArrayList();
43: Line line = buffer.getFirstLine();
44: while (line != null) {
45: String s = line.trim();
46: if (s != null) {
47: REMatch match;
48: if (s.startsWith("module"))
49: match = moduleRE.getMatch(s);
50: else if (s.startsWith("primitive"))
51: match = primitiveRE.getMatch(s);
52: else
53: match = null;
54: if (match != null) {
55: String name = s.substring(
56: match.getSubStartIndex(1), match
57: .getSubEndIndex(1));
58: tags.add(new LocalTag(name, line));
59: }
60: }
61: line = line.next();
62: }
63: buffer.setTags(tags);
64: }
65: }
|