@@ -133,13 +133,17 @@ public static List<String> tokenize(String input) {
133
133
return builder .build ();
134
134
}
135
135
136
+ private static boolean matchesOneOf (String token , String ... regexp ) {
137
+ return token .matches ("\\ (\\ s*(" + String .join ("|" , regexp ) + ")[\\ S\\ s]*" );
138
+ }
139
+
136
140
/**
137
141
* Check if the token is a function or variable declaration.
138
142
*
139
143
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
140
144
*/
141
145
public static boolean isDeclarationToken (String token ) {
142
- return token . matches ( " \\ ( \\ s*( declare-const| declare-fun)[ \\ S \\ s]* " );
146
+ return matchesOneOf ( token , " declare-const" , " declare-fun" );
143
147
}
144
148
145
149
/**
@@ -148,7 +152,7 @@ public static boolean isDeclarationToken(String token) {
148
152
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
149
153
*/
150
154
public static boolean isDefinitionToken (String token ) {
151
- return token . matches ( " \\ ( \\ s* define-fun[ \\ S \\ s]* " );
155
+ return matchesOneOf ( token , " define-fun" );
152
156
}
153
157
154
158
/**
@@ -157,7 +161,7 @@ public static boolean isDefinitionToken(String token) {
157
161
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
158
162
*/
159
163
public static boolean isAssertToken (String token ) {
160
- return token . matches ( " \\ ( \\ s* assert[ \\ S \\ s]* " );
164
+ return matchesOneOf ( token , " assert" );
161
165
}
162
166
163
167
/**
@@ -166,7 +170,7 @@ public static boolean isAssertToken(String token) {
166
170
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
167
171
*/
168
172
public static boolean isSetLogicToken (String token ) {
169
- return token . matches ( " \\ ( \\ s* set-logic[ \\ S \\ s]* " );
173
+ return matchesOneOf ( token , " set-logic" );
170
174
}
171
175
172
176
/**
@@ -175,6 +179,6 @@ public static boolean isSetLogicToken(String token) {
175
179
* <p>Use {@link #tokenize(String)} to turn an SMT-LIB2 script into a string of input tokens.
176
180
*/
177
181
public static boolean isExitToken (String token ) {
178
- return token . matches ( " \\ ( \\ s* exit[ \\ S \\ s]* " );
182
+ return matchesOneOf ( token , " exit" );
179
183
}
180
184
}
0 commit comments