File tree 4 files changed +13
-2
lines changed
src/edu/stanford/nlp/trees/tregex
4 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ class TregexParser implements TregexParserConstants {
28
28
// keep track of which variables we've seen, so that we can reject
29
29
// some nonsense patterns such as ones that reset variables or link
30
30
// to variables that haven't been set
31
- private Set <String > knownVariables = Generics .newHashSet ();
31
+ Set <String > knownVariables = Generics .newHashSet ();
32
32
33
33
public TregexParser (java .io .Reader stream ,
34
34
Function <String , String > basicCatFunction ,
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ class TregexParser {
33
33
// keep track of which variables we've seen, so that we can reject
34
34
// some nonsense patterns such as ones that reset variables or link
35
35
// to variables that haven't been set
36
- private Set<String> knownVariables = Generics.newHashSet();
36
+ Set<String> knownVariables = Generics.newHashSet();
37
37
38
38
public TregexParser(java.io.Reader stream,
39
39
Function<String, String> basicCatFunction,
Original file line number Diff line number Diff line change @@ -361,6 +361,7 @@ public abstract class TregexPattern implements Serializable {
361
361
private boolean neg ; // = false;
362
362
private boolean opt ; // = false;
363
363
private String patternString ;
364
+ private Set <String > knownVariables ;
364
365
365
366
void negate () {
366
367
neg = true ;
@@ -484,6 +485,15 @@ void setPatternString(String patternString) {
484
485
this .patternString = patternString ;
485
486
}
486
487
488
+ /** Only used by the TregexPatternCompiler to track the known variables in the tregex (and only at the root). Pseudo-final. */
489
+ void setKnownVariables (Set <String > knownVariables ) {
490
+ this .knownVariables = knownVariables ;
491
+ }
492
+
493
+ public Set <String > knownVariables () {
494
+ return Collections .unmodifiableSet (knownVariables );
495
+ }
496
+
487
497
/**
488
498
* @return A single-line string representation of the pattern
489
499
*/
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ public TregexPattern compile(String tregex) {
138
138
TregexParser parser = new TregexParser (new StringReader (tregex + '\n' ),
139
139
basicCatFunction , headFinder );
140
140
pattern = parser .Root ();
141
+ pattern .setKnownVariables (parser .knownVariables );
141
142
} catch (TokenMgrError tme ) {
142
143
throw new TregexParseException ("Could not parse " + tregex , tme );
143
144
} catch (ParseException e ) {
You can’t perform that action at this time.
0 commit comments