3 * Copyright (C) 2006-2007 Jürg Billeter
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Jürg Billeter <j@bitron.ch>
26 * Code visitor parsing all Vala source files.
28 public class Vala
.Parser
: CodeVisitor
{
29 private string comment
;
30 private string _file_comment
;
33 * Parse all source files in the specified code context and build a
36 * @param context a code context
38 public void parse (CodeContext
! context
) {
39 context
.accept (this
);
42 public override void visit_source_file (SourceFile
! source_file
) {
43 if (source_file
.filename
.has_suffix (".vala")) {
44 parse_file (source_file
);
45 source_file
.comment
= _file_comment
;
52 * Adds the specified comment to the comment stack.
54 * @param comment_item a comment string
55 * @param file_comment true if file header comment, false otherwise
57 public void push_comment (string! comment_item
, bool file_comment
) {
58 if (comment
== null) {
59 comment
= comment_item
;
61 comment
= "%s\n%s".printf (comment
, comment_item
);
64 _file_comment
= comment
;
70 * Clears and returns the content of the comment stack.
72 * @return saved comment
74 public string pop_comment () {
75 if (comment
== null) {
79 String result
= new
String (comment
);
83 while ((index
= result
.str
.chr (-1, '\t')) != null) {
84 result
.erase (result
.str
.pointer_to_offset (index
), 1);
91 public void parse_file (SourceFile
! source_file
);