summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-07-31 15:05:30 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2017-07-31 15:05:30 +0200
commit067f596822b80b2786ce2bb895a593d479516cad (patch)
tree52c7fed0824edd09545f9577e5f08f206ee7b628 /instr-to-kodkod/parser
parent05fbf26dbb1b1f19e3ef76a0d0789806fa7be12c (diff)
First shot at the handling of regular expressions.
Diffstat (limited to 'instr-to-kodkod/parser')
-rw-r--r--instr-to-kodkod/parser/PropertyLexer.g44
-rw-r--r--instr-to-kodkod/parser/PropertyParser.g444
2 files changed, 47 insertions, 1 deletions
diff --git a/instr-to-kodkod/parser/PropertyLexer.g4 b/instr-to-kodkod/parser/PropertyLexer.g4
index 64fccb0..ec01c88 100644
--- a/instr-to-kodkod/parser/PropertyLexer.g4
+++ b/instr-to-kodkod/parser/PropertyLexer.g4
@@ -12,7 +12,9 @@ TAG_EXISTING_KW: '(tag_existing' SEP;
AND_OPERATOR_KW: '(and' SEP;
OR_OPERATOR_KW: '(or' SEP;
NOT_OPERATOR_KW: '(not' SEP ;
-IMPLIES_OPERATOR_KW: '(implies' SEP ;
+IMPLIES_OPERATOR_KW: '(implies' SEP;
+
+REGEX_SPECIAL_PREDICATE_KW: '(string_matches' SEP;
EXISTS_OPERATOR_KW: '(exists' SEP;
FORALL_OPERATOR_KW: '(forall' SEP;
diff --git a/instr-to-kodkod/parser/PropertyParser.g4 b/instr-to-kodkod/parser/PropertyParser.g4
index 986ad3b..3e5634f 100644
--- a/instr-to-kodkod/parser/PropertyParser.g4
+++ b/instr-to-kodkod/parser/PropertyParser.g4
@@ -318,6 +318,50 @@ function [Variable current_node]
}
;
+regex_special_predicate [Variable current_node]
+ returns [Formula result]:
+
+ (WS)* REGEX_SPECIAL_PREDICATE_KW
+ id_or_string_or_fun[current_node]
+ STRING
+ (WS)* R_PAREN
+
+ {
+ try
+ {
+ $result =
+ ($id_or_string_or_fun.value).product
+ (
+ Main.get_string_manager().get_regex_as_relation
+ (
+ ($STRING.text)
+ )
+ ).in
+ (
+ Main.get_model().get_predicate_as_relation
+ (
+ "is_start_node"
+ ).transpose()
+ );
+ }
+ catch (final Exception e)
+ {
+ System.err.println
+ (
+ "[F] A problem occured while handling a regex related predicate in"
+ + " the property (l."
+ + ($REGEX_SPECIAL_PREDICATE_KW.getLine())
+ + " c."
+ + ($REGEX_SPECIAL_PREDICATE_KW.getCharPositionInLine())
+ + "):"
+ + e.getMessage()
+ );
+
+ System.exit(-1);
+ }
+ }
+;
+
non_empty_formula_list [Variable current_node]
returns [List<Formula> list]