Search in sources :

Example 1 with JSDocToken

use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.

the class DefaultInlineTagDefinition method parse.

@Override
public Tag parse(TagTitle title, JSDocCharScanner scanner) {
    Tag tag = createInlineTag(title);
    scanner.skipWS();
    JSDocToken description = InlineTagTokenizer.INSTANCE.nextToken(scanner);
    if (description != null) {
        String raw = convertToText(description).getText();
        int titleOff = raw.indexOf(title.getTitle());
        int titleLen = title.getTitle().length();
        int fix = titleOff + titleLen;
        raw = raw.substring(fix);
        Text text = DOM.createText();
        text.setText(raw);
        text.setBegin(description.start + fix);
        text.setEnd(description.end);
        addValue(tag, VALUE, text);
    }
    return tag;
}
Also used : Text(org.eclipse.n4js.jsdoc.dom.Text) Tag(org.eclipse.n4js.jsdoc.dom.Tag) InlineTag(org.eclipse.n4js.jsdoc.dom.InlineTag) JSDocToken(org.eclipse.n4js.jsdoc.JSDocToken)

Example 2 with JSDocToken

use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.

the class RegionTokenizer method nextToken.

@Override
public JSDocToken nextToken(JSDocCharScanner scanner) {
    int start = scanner.nextOffset();
    if (!findMarker(scanner, startMarker)) {
        return null;
    }
    StringBuilder strb = new StringBuilder();
    if (includeMarkers) {
        strb.append(startMarker);
    } else {
        start = scanner.nextOffset();
    }
    int nestedRegions = 0;
    int end = start;
    while (scanner.hasNext() && (allowLinebreaks || !scanner.skipped())) {
        if (scanner.peek() == escapeChar) {
            strb.append(scanner.next());
            if (scanner.hasNext() && (allowLinebreaks || !scanner.skipped())) {
                strb.append(scanner.next());
                end = scanner.offset();
            }
            continue;
        }
        if (findMarker(scanner, startMarker)) {
            if (nested) {
                nestedRegions++;
            }
            strb.append(startMarker);
        } else if (findMarker(scanner, endMarker)) {
            if (nestedRegions == 0) {
                if (includeMarkers) {
                    strb.append(endMarker);
                    end = scanner.offset();
                }
                return new JSDocToken(strb.toString(), start, end);
            }
            strb.append(endMarker);
            nestedRegions--;
        } else {
            strb.append(scanner.next());
            end = scanner.offset();
        }
    }
    return null;
}
Also used : JSDocToken(org.eclipse.n4js.jsdoc.JSDocToken)

Example 3 with JSDocToken

use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.

the class TagTitleTokenizerTest method test.

@SuppressWarnings("javadoc")
@Test
public void test() {
    TagTitleTokenizer tokenizer = new TagTitleTokenizer();
    assertEquals(new JSDocToken("Test", 1, 4), tokenizer.nextToken(new JSDocCharScanner("@Test Hello World")));
    assertEquals(new JSDocToken("Test", 1, 4), tokenizer.nextToken(new JSDocCharScanner("@Test\nHello World")));
    assertEquals(new JSDocToken("Test", 1, 4), tokenizer.nextToken(new JSDocCharScanner("@Test\n * Hello World")));
    assertNull(tokenizer.nextToken(new JSDocCharScanner("@ Hello World")));
    assertNull(tokenizer.nextToken(new JSDocCharScanner("Test Hello World")));
    assertNull(tokenizer.nextToken(new JSDocCharScanner("Test @Hello World")));
}
Also used : JSDocCharScanner(org.eclipse.n4js.jsdoc.JSDocCharScanner) JSDocToken(org.eclipse.n4js.jsdoc.JSDocToken) Test(org.junit.Test)

Example 4 with JSDocToken

use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.

the class TextTokenizerTest method testLinebreak.

@SuppressWarnings("javadoc")
@Test
public void testLinebreak() {
    TextTokenizer TEXT = TextTokenizer.INSTANCE;
    assertEquals(new JSDocToken("Hello World\n", 7, 18), TEXT.nextToken(new JSDocCharScanner("/**\n * Hello World\n * Skipped */")));
    assertEquals(new JSDocToken("Hello World", 7, 17), TEXT.nextToken(new JSDocCharScanner("/**\n * Hello World\n * @tag Skipped */")));
    assertEquals(new JSDocToken("Hello World", 7, 17), TEXT.nextToken(new JSDocCharScanner("/**\n * Hello World\n */")));
}
Also used : JSDocCharScanner(org.eclipse.n4js.jsdoc.JSDocCharScanner) JSDocToken(org.eclipse.n4js.jsdoc.JSDocToken) Test(org.junit.Test)

Example 5 with JSDocToken

use of org.eclipse.n4js.jsdoc.JSDocToken in project n4js by eclipse.

the class TextTokenizerTest method testEmpty.

@SuppressWarnings("javadoc")
@Test
public void testEmpty() {
    TextTokenizer TEXT = TextTokenizer.INSTANCE;
    assertEquals(new JSDocToken("\n", 1, 1), TEXT.nextToken(new JSDocCharScanner("x\n cont", 1)));
    assertNull(TEXT.nextToken(new JSDocCharScanner("x*/", 1)));
}
Also used : JSDocCharScanner(org.eclipse.n4js.jsdoc.JSDocCharScanner) JSDocToken(org.eclipse.n4js.jsdoc.JSDocToken) Test(org.junit.Test)

Aggregations

JSDocToken (org.eclipse.n4js.jsdoc.JSDocToken)8 JSDocCharScanner (org.eclipse.n4js.jsdoc.JSDocCharScanner)4 Test (org.junit.Test)4 Tag (org.eclipse.n4js.jsdoc.dom.Tag)3 Text (org.eclipse.n4js.jsdoc.dom.Text)2 TagDictionary (org.eclipse.n4js.jsdoc.TagDictionary)1 ContentNode (org.eclipse.n4js.jsdoc.dom.ContentNode)1 InlineTag (org.eclipse.n4js.jsdoc.dom.InlineTag)1