KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > PHPTagger


1 /*
2  * PHPTagger.java
3  *
4  * Copyright (C) 2002-2003 Peter Graves
5  * $Id: PHPTagger.java,v 1.2 2003/03/20 17:21:25 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * 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 JavaDoc;
28
29 public final class PHPTagger extends Tagger
30 {
31     // We trim before matching, so "function" will appear without any preceding
32
// whitespace.
33
private static final RE functionRE =
34         new UncheckedRE("^function\\s+&?([a-zA-Z_\u007f-\u00ff][a-zA-Z0-9_\u007f-\u00ff]*)\\s*\\(");
35
36     public PHPTagger(SystemBuffer buffer)
37     {
38         super(buffer);
39     }
40
41     public void run()
42     {
43         ArrayList JavaDoc tags = new ArrayList JavaDoc();
44         Line line = buffer.getFirstLine();
45         while (line != null) {
46             String JavaDoc s = line.trim();
47             if (s != null && s.startsWith("function")) {
48                 REMatch match = functionRE.getMatch(s);
49                 if (match != null) {
50                     String JavaDoc token = s.substring(match.getSubStartIndex(1),
51                         match.getSubEndIndex(1));
52                     tags.add(new LocalTag(token, line));
53                 }
54             }
55             line = line.next();
56         }
57         buffer.setTags(tags);
58     }
59 }
60
Popular Tags