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
21 * Jukka-Pekka Iivonen <jp0409@jippii.fi>
27 * Represents a regular expression literal in the source code.
29 public class Vala
.RegexLiteral
: Literal
{
33 public string value
{ get; set; }
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) {
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 () {
57 public override bool is_non_null () {
61 public override string to_string () {
65 public override bool check (CodeContext context
) {
72 if (!context
.experimental
) {
73 Report
.warning (source_reference
, "regular expression literals are experimental");
77 var regex
= new GLib
.Regex (value
);
78 if (regex
!= null) { /* Regex is valid. */ }
79 } catch (RegexError err
) {
81 Report
.error (source_reference
, "Invalid regular expression `%s'.".printf (value
));
85 value_type
= context
.analyzer
.regex_type
.copy ();
90 public override void emit (CodeGenerator codegen
) {
91 codegen
.visit_regex_literal (this
);
93 codegen
.visit_expression (this
);