codegen: Support resize and concatenation on the same array
[vala-lang.git] / vala / valaregexliteral.vala
blob8e4cdc62bc5db63b1ceb0cb667201b3a060b7413
1 /* valaregexliteral.vala
3 * Copyright (C) 2010 Jukka-Pekka Iivonen
4 * Copyright (C) 2010 Jürg Billeter
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * Author:
21 * Jukka-Pekka Iivonen <jp0409@jippii.fi>
24 using GLib;
26 /**
27 * Represents a regular expression literal in the source code.
29 public class Vala.RegexLiteral : Literal {
30 /**
31 * The literal value.
33 public string value { get; set; }
35 /**
36 * Creates a new regular expression literal.
38 * @param s the literal value
39 * @param source reference to source code
40 * @return newly created string literal
42 public RegexLiteral (string value, SourceReference? source_reference = null) {
43 this.value = value;
44 this.source_reference = source_reference;
47 public override void accept (CodeVisitor visitor) {
48 visitor.visit_regex_literal (this);
50 visitor.visit_expression (this);
53 public override bool is_pure () {
54 return true;
57 public override bool is_non_null () {
58 return true;
61 public override string to_string () {
62 return value;
65 public override bool check (SemanticAnalyzer analyzer) {
66 if (checked) {
67 return !error;
70 checked = true;
72 if (!analyzer.context.experimental) {
73 Report.warning (source_reference, "regular expression literals are experimental");
76 try {
77 var regex = new GLib.Regex (value);
78 if (regex != null) { /* Regex is valid. */ }
79 } catch (RegexError err) {
80 error = true;
81 Report.error (source_reference, "Invalid regular expression `%s'.".printf (value));
82 return false;
85 value_type = analyzer.regex_type.copy ();
87 return !error;
90 public override void emit (CodeGenerator codegen) {
91 codegen.visit_regex_literal (this);
93 codegen.visit_expression (this);