Skip to content

Commit 3063b26

Browse files
committed
Fix the semgrex parser usage of includes
1 parent 33de4e1 commit 3063b26

File tree

3 files changed

+34
-30
lines changed

3 files changed

+34
-30
lines changed

src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.java

+15-15
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,11 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
530530
Token value = null;
531531
Token attrType = null;
532532
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
533-
case ALIGNRELN:
534533
case IDENTIFIER:{
534+
attr = jj_consume_token(IDENTIFIER);
535535
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
536-
case IDENTIFIER:{
537-
attr = jj_consume_token(IDENTIFIER);
536+
case 10:
537+
case 22:{
538538
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
539539
case 10:{
540540
attrType = jj_consume_token(10);
@@ -563,6 +563,10 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
563563
jj_consume_token(-1);
564564
throw new ParseException();
565565
}
566+
if (attr != null && value != null) {
567+
boolean negated = attrType.image.equals("!:");
568+
attributes.setAttribute(attr.image, value.image, negated);
569+
}
566570
break;
567571
}
568572
case ALIGNRELN:{
@@ -583,23 +587,20 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
583587
jj_consume_token(-1);
584588
throw new ParseException();
585589
}
590+
if (attrType.image.equals("@")) {
591+
if (attr == null || key == null || value == null) {
592+
{if (true) throw new SemgrexParseException("null while parsing semgrex expression: attr=" + attr +
593+
" key=" + key + " value=" + value);}
594+
}
595+
attributes.addContains(attr.image, key.image, value.image);
596+
}
586597
break;
587598
}
588599
default:
589600
jj_la1[26] = jj_gen;
590601
jj_consume_token(-1);
591602
throw new ParseException();
592603
}
593-
if (attrType.image.equals("@")) {
594-
if (attr == null || key == null || value == null) {
595-
{if (true) throw new SemgrexParseException("null while parsing semgrex expression: attr=" + attr +
596-
" key=" + key + " value=" + value);}
597-
}
598-
attributes.addContains(attr.image, key.image, value.image);
599-
} else if (attr != null && value != null) {
600-
boolean negated = attrType.image.equals("!:");
601-
attributes.setAttribute(attr.image, value.image, negated);
602-
}
603604
break;
604605
}
605606
case ROOT:{
@@ -625,7 +626,6 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
625626
NodePattern pat;
626627
jj_consume_token(23);
627628
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
628-
case ALIGNRELN:
629629
case IDENTIFIER:
630630
case EMPTY:
631631
case ROOT:{
@@ -690,7 +690,7 @@ final public SemgrexPattern Root() throws ParseException {// Root pattern for th
690690
jj_la1_init_0();
691691
}
692692
private static void jj_la1_init_0() {
693-
jj_la1_0 = new int[] {0x400,0x828808,0x3801c,0x3801c,0x828800,0x2000,0x3c01c,0x4000,0x3801c,0x2001c,0x80000,0x10,0x110,0x110,0x100000,0x200000,0x1c,0x828800,0x2000,0x82c000,0x4000,0x828000,0x820000,0x400400,0x110,0x110,0x18,0xd8,0x1000000,0xd8,0x200000,};
693+
jj_la1_0 = new int[] {0x400,0x828808,0x3801c,0x3801c,0x828800,0x2000,0x3c01c,0x4000,0x3801c,0x2001c,0x80000,0x10,0x110,0x110,0x100000,0x200000,0x1c,0x828800,0x2000,0x82c000,0x4000,0x828000,0x820000,0x400400,0x110,0x110,0x400408,0xd0,0x1000000,0xd0,0x200000,};
694694
}
695695

696696
/** Constructor with InputStream. */

src/edu/stanford/nlp/semgraph/semgrex/SemgrexParser.jj

+18-14
Original file line numberDiff line numberDiff line change
@@ -275,21 +275,25 @@ void AddAttribute(NodeAttributes attributes) : {
275275
Token value = null;
276276
Token attrType = null;
277277
} {
278-
((attr = <IDENTIFIER>
279-
( (attrType = ":" | attrType = "!:") (value = <IDENTIFIER> | value = <REGEX>) ) |
280-
( (attrType = "@") (key = <IDENTIFIER>) "=" (value = <IDENTIFIER> | value = <REGEX>) ) )
281-
{
282-
if (attrType.image.equals("@")) {
283-
if (attr == null || key == null || value == null) {
284-
throw new SemgrexParseException("null while parsing semgrex expression: attr=" + attr +
285-
" key=" + key + " value=" + value);
278+
(attr = <IDENTIFIER>
279+
(( (attrType = ":" | attrType = "!:") (value = <IDENTIFIER> | value = <REGEX>) {
280+
if (attr != null && value != null) {
281+
boolean negated = attrType.image.equals("!:");
282+
attributes.setAttribute(attr.image, value.image, negated);
286283
}
287-
attributes.addContains(attr.image, key.image, value.image);
288-
} else if (attr != null && value != null) {
289-
boolean negated = attrType.image.equals("!:");
290-
attributes.setAttribute(attr.image, value.image, negated);
291-
}
292-
})
284+
})
285+
|
286+
(attrType = "@") (key = <IDENTIFIER>) "=" (value = <IDENTIFIER> | value = <REGEX>)
287+
{
288+
if (attrType.image.equals("@")) {
289+
if (attr == null || key == null || value == null) {
290+
throw new SemgrexParseException("null while parsing semgrex expression: attr=" + attr +
291+
" key=" + key + " value=" + value);
292+
}
293+
attributes.addContains(attr.image, key.image, value.image);
294+
}
295+
})
296+
)
293297
|
294298
( attr = <ROOT> { attributes.setRoot(true); } )
295299
|

test/src/edu/stanford/nlp/semgraph/semgrex/SemgrexTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public void testBrokenContainsExpression() {
234234

235235
public void testContainsExpression() {
236236
// morphofeatures is a Map, so this should work
237-
//SemgrexPattern pattern = SemgrexPattern.compile("{morphofeatures@foo=bar}");
237+
SemgrexPattern pattern = SemgrexPattern.compile("{morphofeatures@foo=bar}");
238238
}
239239

240240
public void testReferencedRegex() {

0 commit comments

Comments
 (0)