@@ -72,33 +72,33 @@ function buildUnaryNode(node: UnaryNode): TreeNodeDisplay {
7272/**
7373 * Parses a node string to extract the rule and the content.
7474 *
75- * A node string is usually of the form "A(B) ", where a is the rule applied
75+ * A node string is usually of the form "A[B] ", where a is the rule applied
7676 * and B is the resulting category. The rule is anything everything before
77- * the first parenthesis . Everything within it is the content. For example,
78- * in "fa( s:ng-np) ", "fa" is the rule and "s:ng-np" is the content.
77+ * the first bracket . Everything within it is the content. For example,
78+ * in "fa[ s:ng-np] ", "fa" is the rule and "s:ng-np" is the content.
7979 *
80- * Due to a bug in the CCG parser, sometimes the node string can have
81- * multiple layers of parentheses, e.g. fa(((s:ng-np)-(s:ng-np))).
82- * function only strips off the first .
80+ * If there are more brackets, we ignore them.
81+ *
82+ * The rule symbolised by '@' is trivial and all too common, so it is ignored .
8383 *
8484 */
85- function extractRule ( nodeString : string ) : { rule : string , content : string ; } {
86- const firstParen = nodeString . indexOf ( '( ' ) ;
87- const lastParen = nodeString . lastIndexOf ( ') ' ) ;
85+ export function extractRule ( nodeString : string ) : { rule : string , content : string ; } {
86+ const firstBracket = nodeString . indexOf ( '[ ' ) ;
87+ const lastBracket = nodeString . lastIndexOf ( '] ' ) ;
8888
8989 // Return a fallback value if the string is not what we expect.
90- if ( firstParen === - 1 || lastParen === - 1 || lastParen < firstParen ) {
90+ if ( firstBracket === - 1 || lastBracket === - 1 || lastBracket < firstBracket ) {
9191 return {
9292 rule : "" ,
9393 content : nodeString
9494 } ;
9595 }
9696
97- const rule = nodeString . slice ( 0 , firstParen ) ;
98- // Strip off any remaining parentheses due to the CCG parser bug .
99- const content = nodeString . slice ( firstParen + 1 , lastParen ) . replaceAll ( '( ' , '' ) . replaceAll ( ') ' , '' ) ;
97+ const rule = nodeString . slice ( 0 , firstBracket ) ;
98+ // Strip off any remaining brackets .
99+ const content = nodeString . slice ( firstBracket + 1 , lastBracket ) . replaceAll ( '[ ' , '' ) . replaceAll ( '] ' , '' ) ;
100100
101- return { rule, content } ;
101+ return { rule : rule === '@' ? "" : rule , content } ;
102102}
103103
104104@Component ( {
0 commit comments