Skip to content

Commit 90886db

Browse files
committed
Wrap all of Ssurgeon's editline processing in a try/catch so that it can report the error line no matter where the error occurs (eg, if it bubbles up from someplace that doesn't know about the editline)
1 parent 71ad47e commit 90886db

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

src/edu/stanford/nlp/semgraph/semgrex/ssurgeon/Ssurgeon.java

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -360,54 +360,55 @@ private static SsurgeonArgs parseArgsBox(String args) {
360360
* Given a string entry, converts it into a SsurgeonEdit object.
361361
*/
362362
public static SsurgeonEdit parseEditLine(String editLine) {
363-
// Extract the operation name first
364-
final String[] tuples1 = editLine.split("\\s+", 2);
365-
if (tuples1.length < 1) {
366-
throw new SsurgeonParseException("Error in SsurgeonEdit.parseEditLine: invalid number of arguments");
367-
}
368-
final String command = tuples1[0];
369-
370-
if (command.equalsIgnoreCase(SetRoots.LABEL)) {
371-
String[] names = tuples1[1].split("\\s+");
372-
List<String> newRoots = Arrays.asList(names);
373-
return new SetRoots(newRoots);
374-
} else if (command.equalsIgnoreCase(KillNonRootedNodes.LABEL)) {
375-
return new KillNonRootedNodes();
376-
}
377-
378-
// Parse the arguments based upon the type of command to execute.
379-
final SsurgeonArgs argsBox = parseArgsBox(tuples1.length == 1 ? "" : tuples1[1]);
380-
381-
SsurgeonEdit retEdit;
382-
if (command.equalsIgnoreCase(AddDep.LABEL)) {
383-
retEdit = AddDep.createEngAddDep(argsBox.govNodeName, argsBox.reln, argsBox.annotations, argsBox.position);
384-
} else if (command.equalsIgnoreCase(AddNode.LABEL)) {
385-
retEdit = AddNode.createAddNode(argsBox.nodeString, argsBox.name);
386-
} else if (command.equalsIgnoreCase(AddEdge.LABEL)) {
387-
retEdit = AddEdge.createEngAddEdge(argsBox.govNodeName, argsBox.dep, argsBox.reln, argsBox.weight);
388-
} else if (command.equalsIgnoreCase(DeleteGraphFromNode.LABEL)) {
389-
retEdit = new DeleteGraphFromNode(argsBox.node);
390-
} else if (command.equalsIgnoreCase(EditNode.LABEL)) {
391-
retEdit = new EditNode(argsBox.node, argsBox.annotations);
392-
} else if (command.equalsIgnoreCase(RelabelNamedEdge.LABEL)) {
393-
// TODO: pass around a Language (perhaps via ssurgeon argument)
394-
// rather than hardcoding English, which is probably not even true
395-
// compared to UniversalEnglish these days
396-
retEdit = RelabelNamedEdge.createEngRelabel(argsBox.edge, argsBox.reln);
397-
} else if (command.equalsIgnoreCase(RemoveEdge.LABEL)) {
398-
GrammaticalRelation reln = null;
399-
if (argsBox.reln != null) {
400-
reln = GrammaticalRelation.valueOf(argsBox.reln);
363+
try {
364+
// Extract the operation name first
365+
final String[] tuples1 = editLine.split("\\s+", 2);
366+
if (tuples1.length < 1) {
367+
throw new SsurgeonParseException("Error in SsurgeonEdit.parseEditLine: invalid number of arguments");
368+
}
369+
final String command = tuples1[0];
370+
371+
if (command.equalsIgnoreCase(SetRoots.LABEL)) {
372+
String[] names = tuples1[1].split("\\s+");
373+
List<String> newRoots = Arrays.asList(names);
374+
return new SetRoots(newRoots);
375+
} else if (command.equalsIgnoreCase(KillNonRootedNodes.LABEL)) {
376+
return new KillNonRootedNodes();
377+
}
378+
379+
// Parse the arguments based upon the type of command to execute.
380+
final SsurgeonArgs argsBox = parseArgsBox(tuples1.length == 1 ? "" : tuples1[1]);
381+
382+
if (command.equalsIgnoreCase(AddDep.LABEL)) {
383+
return AddDep.createEngAddDep(argsBox.govNodeName, argsBox.reln, argsBox.annotations, argsBox.position);
384+
} else if (command.equalsIgnoreCase(AddNode.LABEL)) {
385+
return AddNode.createAddNode(argsBox.nodeString, argsBox.name);
386+
} else if (command.equalsIgnoreCase(AddEdge.LABEL)) {
387+
return AddEdge.createEngAddEdge(argsBox.govNodeName, argsBox.dep, argsBox.reln, argsBox.weight);
388+
} else if (command.equalsIgnoreCase(DeleteGraphFromNode.LABEL)) {
389+
return new DeleteGraphFromNode(argsBox.node);
390+
} else if (command.equalsIgnoreCase(EditNode.LABEL)) {
391+
return new EditNode(argsBox.node, argsBox.annotations);
392+
} else if (command.equalsIgnoreCase(RelabelNamedEdge.LABEL)) {
393+
// TODO: pass around a Language (perhaps via ssurgeon argument)
394+
// rather than hardcoding English, which is probably not even true
395+
// compared to UniversalEnglish these days
396+
return RelabelNamedEdge.createEngRelabel(argsBox.edge, argsBox.reln);
397+
} else if (command.equalsIgnoreCase(RemoveEdge.LABEL)) {
398+
GrammaticalRelation reln = null;
399+
if (argsBox.reln != null) {
400+
reln = GrammaticalRelation.valueOf(argsBox.reln);
401+
}
402+
return new RemoveEdge(reln, argsBox.govNodeName, argsBox.dep);
403+
} else if (command.equalsIgnoreCase(RemoveNamedEdge.LABEL)) {
404+
return new RemoveNamedEdge(argsBox.edge);
405+
} else if (command.equalsIgnoreCase(KillAllIncomingEdges.LABEL)) {
406+
return new KillAllIncomingEdges(argsBox.node);
401407
}
402-
retEdit = new RemoveEdge(reln, argsBox.govNodeName, argsBox.dep);
403-
} else if (command.equalsIgnoreCase(RemoveNamedEdge.LABEL)) {
404-
retEdit = new RemoveNamedEdge(argsBox.edge);
405-
} else if (command.equalsIgnoreCase(KillAllIncomingEdges.LABEL)) {
406-
retEdit = new KillAllIncomingEdges(argsBox.node);
407-
} else {
408408
throw new SsurgeonParseException("Error in SsurgeonEdit.parseEditLine: command '"+command+"' is not supported");
409+
} catch (SsurgeonParseException e) {
410+
throw new SsurgeonParseException("Unable to process Ssurgeon edit line: " + editLine, e);
409411
}
410-
return retEdit;
411412
}
412413

413414
//public static SsurgeonPattern fromXML(String xmlString) throws Exception {

0 commit comments

Comments
 (0)