Search in sources :

Example 1 with PartitionTokenScanner

use of org.eclipse.xtext.ui.editor.model.PartitionTokenScanner in project xtext-eclipse by eclipse.

the class DocumentPartitionerTest method getDocument.

public XtextDocument getDocument(String s) {
    TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {

        {
            setTokenDefProvider(new AntlrTokenDefProvider() {

                {
                    setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
                }
            });
        }
    };
    PartitionTokenScanner scanner = new PartitionTokenScanner();
    scanner.setMapper(mapper);
    DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
    DocumentTokenSource tokenSource = new DocumentTokenSource();
    tokenSource.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
        }
    });
    XtextDocument document = new XtextDocument(tokenSource, null, new OutdatedStateManager(), new OperationCanceledManager());
    document.setDocumentPartitioner(partitioner);
    partitioner.connect(document);
    document.set(s);
    return document;
}
Also used : OutdatedStateManager(org.eclipse.xtext.resource.OutdatedStateManager) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) TerminalsTokenTypeToPartitionMapper(org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper) OperationCanceledManager(org.eclipse.xtext.service.OperationCanceledManager) AntlrTokenDefProvider(org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider) XtextAntlrTokenFileProvider(org.eclipse.xtext.parser.antlr.XtextAntlrTokenFileProvider) Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) PartitionTokenScanner(org.eclipse.xtext.ui.editor.model.PartitionTokenScanner) DocumentPartitioner(org.eclipse.xtext.ui.editor.model.DocumentPartitioner)

Example 2 with PartitionTokenScanner

use of org.eclipse.xtext.ui.editor.model.PartitionTokenScanner in project xtext-eclipse by eclipse.

the class PartitionTokenScannerTest method testWholePart.

@Test
public void testWholePart() throws Exception {
    PartitionTokenScanner scanner = getPartitionTokenScanner(t(2, 3), t(4, 3), t(2, 1), t(34, 3));
    scanner.setPartialRange(null, 0, 42, "3", 0);
    assertEquals("3", scanner.nextToken().getData());
    assertEquals(0, scanner.getTokenOffset());
    assertEquals(6, scanner.getTokenLength());
    assertEquals("1", scanner.nextToken().getData());
    assertEquals(6, scanner.getTokenOffset());
    assertEquals(2, scanner.getTokenLength());
    assertEquals("3", scanner.nextToken().getData());
    assertEquals(8, scanner.getTokenOffset());
    assertEquals(34, scanner.getTokenLength());
    assertSame(Token.EOF, scanner.nextToken());
}
Also used : PartitionTokenScanner(org.eclipse.xtext.ui.editor.model.PartitionTokenScanner) Test(org.junit.Test)

Example 3 with PartitionTokenScanner

use of org.eclipse.xtext.ui.editor.model.PartitionTokenScanner in project xtext-eclipse by eclipse.

the class PartitionTokenScannerTest method getPartitionTokenScanner.

public PartitionTokenScanner getPartitionTokenScanner(ILexerTokenRegion... tokenDescs) throws Exception {
    final List<ILexerTokenRegion> tokens = Arrays.asList(tokenDescs);
    int offset = 0;
    for (ILexerTokenRegion token : tokens) {
        ((LexerTokenRegion) token).setOffset(offset);
        offset += token.getLength();
    }
    PartitionTokenScanner tokenScanner = new PartitionTokenScanner() {

        @Override
        protected Iterable<ILexerTokenRegion> getTokens(IDocument document) {
            return tokens;
        }

        @Override
        protected boolean shouldMergePartitions(String contentType) {
            return "3".equals(contentType);
        }
    };
    tokenScanner.setMapper(new ITokenTypeToPartitionTypeMapper() {

        @Override
        public String[] getSupportedPartitionTypes() {
            throw new UnsupportedOperationException();
        }

        @Override
        public String getPartitionType(int antlrTokenType) {
            return "" + antlrTokenType;
        }
    });
    return tokenScanner;
}
Also used : ILexerTokenRegion(org.eclipse.xtext.ui.editor.model.ILexerTokenRegion) PartitionTokenScanner(org.eclipse.xtext.ui.editor.model.PartitionTokenScanner) ITokenTypeToPartitionTypeMapper(org.eclipse.xtext.ui.editor.model.ITokenTypeToPartitionTypeMapper) ILexerTokenRegion(org.eclipse.xtext.ui.editor.model.ILexerTokenRegion) IDocument(org.eclipse.jface.text.IDocument)

Example 4 with PartitionTokenScanner

use of org.eclipse.xtext.ui.editor.model.PartitionTokenScanner in project xtext-eclipse by eclipse.

the class PartitionTokenScannerTest method testMiddlePart.

@Test
public void testMiddlePart() throws Exception {
    PartitionTokenScanner scanner = getPartitionTokenScanner(t(2, 3), t(4, 3), t(2, 1), t(34, 3));
    scanner.setPartialRange(null, 6, 2, "1", 6);
    assertEquals("1", scanner.nextToken().getData());
    assertEquals(6, scanner.getTokenOffset());
    assertEquals(2, scanner.getTokenLength());
    assertSame(Token.EOF, scanner.nextToken());
}
Also used : PartitionTokenScanner(org.eclipse.xtext.ui.editor.model.PartitionTokenScanner) Test(org.junit.Test)

Example 5 with PartitionTokenScanner

use of org.eclipse.xtext.ui.editor.model.PartitionTokenScanner in project xtext-eclipse by eclipse.

the class AbstractXtextDocumentTest method getDocument.

public XtextDocument getDocument(String s) {
    TerminalsTokenTypeToPartitionMapper mapper = new TerminalsTokenTypeToPartitionMapper() {

        {
            setTokenDefProvider(new AntlrTokenDefProvider() {

                {
                    setAntlrTokenFileProvider(new XtextAntlrTokenFileProvider());
                }
            });
        }
    };
    PartitionTokenScanner scanner = new PartitionTokenScanner();
    scanner.setMapper(mapper);
    DocumentPartitioner partitioner = new DocumentPartitioner(scanner, mapper);
    DocumentTokenSource tokenSource = new DocumentTokenSource();
    tokenSource.setLexer(new Provider<Lexer>() {

        @Override
        public Lexer get() {
            return new org.eclipse.xtext.parser.antlr.internal.InternalXtextLexer();
        }
    });
    XtextDocument document = new XtextDocument(tokenSource, null, outdatedStateManager, operationCanceledManager);
    document.setDocumentPartitioner(partitioner);
    partitioner.connect(document);
    document.set(s);
    return document;
}
Also used : XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) TerminalsTokenTypeToPartitionMapper(org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper) AntlrTokenDefProvider(org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider) XtextAntlrTokenFileProvider(org.eclipse.xtext.parser.antlr.XtextAntlrTokenFileProvider) Lexer(org.eclipse.xtext.parser.antlr.Lexer) DocumentTokenSource(org.eclipse.xtext.ui.editor.model.DocumentTokenSource) PartitionTokenScanner(org.eclipse.xtext.ui.editor.model.PartitionTokenScanner) DocumentPartitioner(org.eclipse.xtext.ui.editor.model.DocumentPartitioner)

Aggregations

PartitionTokenScanner (org.eclipse.xtext.ui.editor.model.PartitionTokenScanner)5 AntlrTokenDefProvider (org.eclipse.xtext.parser.antlr.AntlrTokenDefProvider)2 Lexer (org.eclipse.xtext.parser.antlr.Lexer)2 XtextAntlrTokenFileProvider (org.eclipse.xtext.parser.antlr.XtextAntlrTokenFileProvider)2 DocumentPartitioner (org.eclipse.xtext.ui.editor.model.DocumentPartitioner)2 DocumentTokenSource (org.eclipse.xtext.ui.editor.model.DocumentTokenSource)2 TerminalsTokenTypeToPartitionMapper (org.eclipse.xtext.ui.editor.model.TerminalsTokenTypeToPartitionMapper)2 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)2 Test (org.junit.Test)2 IDocument (org.eclipse.jface.text.IDocument)1 OutdatedStateManager (org.eclipse.xtext.resource.OutdatedStateManager)1 OperationCanceledManager (org.eclipse.xtext.service.OperationCanceledManager)1 ILexerTokenRegion (org.eclipse.xtext.ui.editor.model.ILexerTokenRegion)1 ITokenTypeToPartitionTypeMapper (org.eclipse.xtext.ui.editor.model.ITokenTypeToPartitionTypeMapper)1