{"record":{"id":"81378682326cdf93","repo":"stanfordnlp/CoreNLP","slug":"error-parsing-tsurgeon-expression-operationst","errorCode":null,"errorMessage":"Error parsing Tsurgeon expression: \" + operationString","messagePattern":"Error parsing Tsurgeon expression: \" \\+ operationString","errorType":"exception","errorClass":"TsurgeonParseException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/trees/tregex/tsurgeon/Tsurgeon.java","lineNumber":653,"sourceCode":"  /**\n   * Parses an operation string into a {@link TsurgeonPattern}.  Throws an {@link TsurgeonParseException} if\n   * the operation string is ill-formed.\n   * <p>\n   * Example of use:\n   * <p>\n   * <code>\n   * TsurgeonPattern p = Tsurgeon.parseOperation(\"prune ed\");\n   * </code>\n   * @param operationString The operation to perform, as a text string\n   * @return the operation pattern.\n   */\n  public static TsurgeonPattern parseOperation(String operationString) {\n    try {\n      TsurgeonParser parser =\n        new TsurgeonParser(new StringReader(operationString + '\\n'));\n      return parser.Root();\n    } catch (ParseException | TokenMgrError e) {\n      throw new TsurgeonParseException(\"Error parsing Tsurgeon expression: \" +\n                                       operationString, e);\n    }\n  }\n\n  /**\n   * Collects a list of operation patterns into a sequence of operations to be applied.  Required to keep track of global properties\n   * across a sequence of operations.  For example, if you want to insert a named node and then coindex it with another node,\n   * you will need to collect the insertion and coindexation operations into a single TsurgeonPattern so that tsurgeon is aware\n   * of the name of the new node and coindexation becomes possible.\n   *\n   * @param patterns a list of {@link TsurgeonPattern} operations that you want to collect together into a single compound operation\n   * @return a new {@link TsurgeonPattern} that performs all the operations in the sequence of the {@code patterns} argument\n   */\n  public static TsurgeonPattern collectOperations(List<TsurgeonPattern> patterns) {\n    return new TsurgeonPatternRoot(patterns.toArray(new TsurgeonPattern[patterns.size()]));\n  }\n\n}","sourceCodeStart":635,"sourceCodeEnd":671,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/trees/tregex/tsurgeon/Tsurgeon.java#L635-L671","documentation":"Tsurgeon.parseOperation feeds the operation string to the generated TsurgeonParser; a ParseException or TokenMgrError from the parser is rethrown as TsurgeonParseException(\"Error parsing Tsurgeon expression: ...\"). It means the tsurgeon expression is syntactically invalid.","triggerScenarios":"Calling Tsurgeon.parseOperation (directly or via getTsurgeonOperationsFromReader) with a syntactically bad operation string: misspelled operators, unbalanced parentheses, illegal tokens, or stray characters.","commonSituations":"Hand-edited tsurgeon scripts with typos; copy-paste artifacts (smart quotes, invisible characters); operations written for a different library/version that uses different syntax; a line from a paired tregex/tsurgeon script accidentally fed as an operation.","solutions":["Fix the syntax of the operation string (check operator spelling, parentheses, node names)","Test the operation with a minimal parseOperation call to isolate the offending line in a multi-line script","Strip non-ASCII/whitespace artifacts from the script file (check encoding)","Wrap parsing in try-catch for TsurgeonParseException and report the failing line to the user"],"exampleFix":"// before\nTsurgeon.parseOperation(\"excise named-node named-node1\"); // missing required arguments -> parse error\n// after\nTsurgeon.parseOperation(\"excise named-node named-node1 relabel-node\");","handlingStrategy":"try-catch","validationCode":"null","typeGuard":null,"tryCatchPattern":"try {\n  TsurgeonPattern p = Tsurgeon.parseOperation(opString);\n} catch (TsurgeonParseException e) {\n  throw new IllegalArgumentException(\"Invalid tsurgeon operation: \" + opString, e);\n}","preventionTips":["Validate every line of tsurgeon scripts with parseOperation at load time","Avoid smart quotes and non-ASCII characters in scripts","Keep script files in UTF-8 without BOM","Test scripts against a sample tree before batch runs"],"tags":["tsurgeon","parse-error","syntax","invalid-input"],"backgroundTag":"invalid-argument-format","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}