Search in sources :

Example 1 with ComposedContent

use of org.eclipse.n4js.jsdoc.dom.ComposedContent in project n4js by eclipse.

the class DescriptionParser method parse.

/**
 * Returns Text if descriptions contains only text. If it contains any inline Tags, than returned composedContent
 * will contain multiple nodes, one for each inline tag and one for each text before/after/in between inline tags.
 * Order of data is preserved. Stops scanning for text when reaches end of comment or LineTag.
 *
 * InlineTags are identified based on dictionary provided with method call.
 */
public ContentNode parse(JSDocCharScanner scanner, TagDictionary<AbstractInlineTagDefinition> inlineTagsDictinary) {
    ComposedContent description = DomFactory.eINSTANCE.createComposedContent();
    if (!scanner.hasNext()) {
        return null;
    }
    if (nextIsTagTitle(scanner)) {
        return null;
    }
    int start = scanner.nextOffset();
    int end = start;
    StringBuilder strb = new StringBuilder();
    while (scanner.hasNext()) {
        char c = scanner.peek();
        if (regionStart(c)) {
            ScannerState st = scanner.saveState();
            InlineTag tag = (InlineTag) parseRegion(scanner, inlineTagsDictinary);
            if (tag != null) {
                saveTextTokens(description, start, end, strb);
                strb = new StringBuilder();
                start = end;
                description.getContents().add(tag);
                continue;
            } else {
                scanner.restoreState(st);
                if (start == end) {
                    assert false;
                }
            /*
					 * On unkown region just continue with text parsing
					 */
            // saveTextTokens(description, start, end, strb);
            // break;
            }
        }
        // consume c
        scanner.next();
        if (JSDocCharScanner.isNL(c)) {
            if (scanner.hasNext() && !nextIsTagTitle(scanner)) {
                end = scanner.offset();
            } else {
                break;
            }
        }
        strb.append(c);
        end = scanner.offset();
    }
    String pendingData = strb.toString();
    if (pendingData.isEmpty() == false) {
        saveTextTokens(description, start, end, strb);
    }
    switch(description.getContents().size()) {
        case 0:
            return null;
        case 1:
            return description.getContents().get(0);
        default:
            return description;
    }
}
Also used : InlineTag(org.eclipse.n4js.jsdoc.dom.InlineTag) ComposedContent(org.eclipse.n4js.jsdoc.dom.ComposedContent) ScannerState(org.eclipse.n4js.jsdoc.JSDocCharScanner.ScannerState)

Aggregations

ScannerState (org.eclipse.n4js.jsdoc.JSDocCharScanner.ScannerState)1 ComposedContent (org.eclipse.n4js.jsdoc.dom.ComposedContent)1 InlineTag (org.eclipse.n4js.jsdoc.dom.InlineTag)1