Top Inners Fields Constructors Methods
com.vladsch.flexmark.parser.internal

public Class DocumentParser

extends Object
implements ParserState
Class Inheritance
All Implemented Interfaces
com.vladsch.flexmark.parser.block.ParserState, com.vladsch.flexmark.parser.block.BlockParserTracker, com.vladsch.flexmark.util.ast.BlockTracker
Imports
com.vladsch.flexmark.ast.Paragraph, com.vladsch.flexmark.ast.util.ClassifyingBlockTracker, .Parsing, com.vladsch.flexmark.parser.InlineParser, .InlineParserFactory, .Parser, com.vladsch.flexmark.parser.block.*, com.vladsch.flexmark.parser.core.*, com.vladsch.flexmark.util.ast.*, com.vladsch.flexmark.util.collection.ItemFactoryMap, com.vladsch.flexmark.util.collection.iteration.ReversibleIterable, com.vladsch.flexmark.util.data.DataHolder, .DataKey, .MutableDataHolder, com.vladsch.flexmark.util.dependency.DependencyResolver, com.vladsch.flexmark.util.misc.CharPredicate, com.vladsch.flexmark.util.sequence.BasedSequence, .PrefixedSubSequence, org.jetbrains.annotations.NotNull, java.io.BufferedReader, .IOException, .Reader, java.util.*

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final List<BlockParser>
private boolean
private final boolean
private final List<BlockParserFactory>
private final List<List<BlockPreProcessorFactory>>
private final ClassifyingBlockTracker
private int
column

current column of input line (tab causes column to go to next 4-space tab stop) (0-based)

private boolean
columnIsInTab

if the current column is within a tab character (partially consumed tab)

private static final HashMap<CustomBlockParserFactory, DataKey<Boolean>>
private static final HashMap<DataKey<Boolean>, ParagraphPreProcessorFactory>
private ParserPhase
private final DocumentBlockParser
private int
private int
index

current index (offset) in input line (0-based)

public static final InlineParserFactory
private final InlineParser
private boolean
private final Map<Node, Boolean>
private BasedSequence
private int
lineEndIndex

current end of line offset in the input including EOL

private int
lineEOLIndex

current lines EOL sequence

private int
lineNumber

current line number in the input

private final List<BasedSequence>
private int
lineStart

current start of line offset in the input

private BasedSequence
private final Parsing
private int
private int
private final DataHolder
private final List<List<ParagraphPreProcessorFactory>>
private final boolean

Constructor Summary

AccessConstructor and Description
public
DocumentParser(DataHolder options, List<CustomBlockParserFactory> customBlockParserFactories, List<List<ParagraphPreProcessorFactory>> paragraphPreProcessorDependencies, List<List<BlockPreProcessorFactory>> blockPreProcessorDependencies, InlineParser inlineParser)

Method Summary

Modifier and TypeMethod and Description
private void
private <
block parser type
T extends BlockParser
>
T

Returns:

block parser instance added as a child.
addChild
(T
new block parser to add as a child
blockParser
)

Add block parser of type T as a child of the currently active parsers.

private void
addLine()

Add line content to the active block parser.

private void
public void
public void
public void
public void
public void
public void
public void
public void
private void
breakOutOfLists(List<BlockParser>
list of block parsers to break out on double blank line
blockParsers
)

Break out of all containing lists, resetting the tip of the document to the parent of the highest list, and finalizing all the lists.

public static List<CustomBlockParserFactory>
public static List<List<BlockPreProcessorFactory>>
public static List<List<ParagraphPreProcessorFactory>>
private void
public boolean
endsWithBlankLine(Node
block to be tested
block
)

Implements com.vladsch.flexmark.parser.block.ParserState.endsWithBlankLine.

Test the block to see if it ends in a blank line.

private void
finalize(BlockParser
block parser instance to finalize
blockParser
)

Finalize a block.

private Document
private boolean

Returns:

true.
finalizeBlocks
(List<BlockParser> blockParsers)

Finalize blocks of previous line.

private BlockStartImpl
private void
public BlockParser
public BlockParser
getActiveBlockParser(Block
block node for which to get the active block parser
node
)

Implements com.vladsch.flexmark.parser.block.ParserState.getActiveBlockParser.

public List<BlockParser>
public int
getColumn()

Implements com.vladsch.flexmark.parser.block.ParserState.getColumn.

The column is the position within the line after tab characters have been processed as 4-space tab stops.

public int
public int
public InlineParser
public BasedSequence
public int
public int
public int
public List<BasedSequence>
getLineSegments()

Implements com.vladsch.flexmark.parser.block.ParserState.getLineSegments.

Returns a list of document lines encountered this far in the parsing process

public int
public BasedSequence
public int
public ParserPhase
public Parsing
public MutableDataHolder
private void
incorporateLine(BasedSequence
sequence of the current line
ln
)

Analyze a line of text and update the document appropriately.

public boolean
public boolean
public boolean
isLastLineBlank(Node
block instance to test
node
)

Implements com.vladsch.flexmark.parser.block.ParserState.isLastLineBlank.

Test a block to see if the last line of the block is blank.

public Document

Returns:

Document node of the resulting AST
parse
(CharSequence
source sequence to parse
source
)

The main parsing function.

public Document
parse(Reader input)

private void
private void
preProcessParagraph(Paragraph
paragraph block to pre-process
block
,
List<ParagraphPreProcessorFactory>
paragraph pre-processor dependency stage
stage
,
DocumentParser.ParagraphPreProcessorCache
paragraph pre-processor cache
processorMap
)

pre-process a paragraph block

private void
private void
processInlines()

Walk through a block & children recursively, parsing string content into inline content where appropriate.

private void
propagateLastLineBlank(BlockParser blockParser, BlockParser lastMatchedBlockParser)

private void
private void
setLastLineBlank(Node node, boolean value)

private void
setNewColumn(int newColumn)

private void
setNewIndex(int newIndex)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

activeBlockParsersback to summary
private final List<BlockParser> activeBlockParsers
blankback to summary
private boolean blank
blankLinesInAstback to summary
private final boolean blankLinesInAst
blockParserFactoriesback to summary
private final List<BlockParserFactory> blockParserFactories
blockPreProcessorDependenciesback to summary
private final List<List<BlockPreProcessorFactory>> blockPreProcessorDependencies
blockTrackerback to summary
private final ClassifyingBlockTracker blockTracker
columnback to summary
private int column

current column of input line (tab causes column to go to next 4-space tab stop) (0-based)

columnIsInTabback to summary
private boolean columnIsInTab

if the current column is within a tab character (partially consumed tab)

CORE_FACTORIES_DATA_KEYSback to summary
private static final HashMap<CustomBlockParserFactory, DataKey<Boolean>> CORE_FACTORIES_DATA_KEYS
CORE_PARAGRAPH_PRE_PROCESSORSback to summary
private static final HashMap<DataKey<Boolean>, ParagraphPreProcessorFactory> CORE_PARAGRAPH_PRE_PROCESSORS
currentPhaseback to summary
private ParserPhase currentPhase
documentBlockParserback to summary
private final DocumentBlockParser documentBlockParser
indentback to summary
private int indent
indexback to summary
private int index

current index (offset) in input line (0-based)

INLINE_PARSER_FACTORYback to summary
public static final InlineParserFactory INLINE_PARSER_FACTORY
inlineParserback to summary
private final InlineParser inlineParser
isBlankLineback to summary
private boolean isBlankLine
lastLineBlankback to summary
private final Map<Node, Boolean> lastLineBlank
lineback to summary
private BasedSequence line
lineEndIndexback to summary
private int lineEndIndex

current end of line offset in the input including EOL

lineEOLIndexback to summary
private int lineEOLIndex

current lines EOL sequence

lineNumberback to summary
private int lineNumber

current line number in the input

lineSegmentsback to summary
private final List<BasedSequence> lineSegments
lineStartback to summary
private int lineStart

current start of line offset in the input

lineWithEOLback to summary
private BasedSequence lineWithEOL
myParsingback to summary
private final Parsing myParsing
nextNonSpaceback to summary
private int nextNonSpace
nextNonSpaceColumnback to summary
private int nextNonSpaceColumn
optionsback to summary
private final DataHolder options
paragraphPreProcessorDependenciesback to summary
private final List<List<ParagraphPreProcessorFactory>> paragraphPreProcessorDependencies
trackDocumentLinesback to summary
private final boolean trackDocumentLines

Constructor Detail

DocumentParserback to summary
public DocumentParser(DataHolder options, List<CustomBlockParserFactory> customBlockParserFactories, List<List<ParagraphPreProcessorFactory>> paragraphPreProcessorDependencies, List<List<BlockPreProcessorFactory>> blockPreProcessorDependencies, InlineParser inlineParser)

Method Detail

activateBlockParserback to summary
private void activateBlockParser(BlockParser blockParser)
addChildback to summary
private <T extends BlockParser> T addChild(T blockParser)

Add block parser of type T as a child of the currently active parsers. If the tip can't accept children, close and finalize it and try its parent, and so on til we find a block that can accept children.

Parameters
<T>
block parser type
blockParser:T

new block parser to add as a child

Returns:T

block parser instance added as a child.

addLineback to summary
private void addLine()

Add line content to the active block parser. We assume it can accept lines -- that check should be done before calling this.

advanceback to summary
private void advance()
blockAddedback to summary
public void blockAdded(@NotNull Block node)
blockAddedWithChildrenback to summary
public void blockAddedWithChildren(@NotNull Block node)
blockAddedWithDescendantsback to summary
public void blockAddedWithDescendants(@NotNull Block node)
blockParserAddedback to summary
public void blockParserAdded(BlockParser blockParser)

Implements com.vladsch.flexmark.parser.block.BlockParserTracker.blockParserAdded.

blockParserRemovedback to summary
public void blockParserRemoved(BlockParser blockParser)

Implements com.vladsch.flexmark.parser.block.BlockParserTracker.blockParserRemoved.

blockRemovedback to summary
public void blockRemoved(@NotNull Block node)
blockRemovedWithChildrenback to summary
public void blockRemovedWithChildren(@NotNull Block node)
blockRemovedWithDescendantsback to summary
public void blockRemovedWithDescendants(@NotNull Block node)
breakOutOfListsback to summary
private void breakOutOfLists(List<BlockParser> blockParsers)

Break out of all containing lists, resetting the tip of the document to the parent of the highest list, and finalizing all the lists. (This is used to implement the "two blank lines break of of all lists" feature.)

Parameters
blockParsers:List<BlockParser>

list of block parsers to break out on double blank line

calculateBlockParserFactoriesback to summary
public static List<CustomBlockParserFactory> calculateBlockParserFactories(DataHolder options, List<CustomBlockParserFactory> customBlockParserFactories)
calculateBlockPreProcessorsback to summary
public static List<List<BlockPreProcessorFactory>> calculateBlockPreProcessors(DataHolder options, List<BlockPreProcessorFactory> blockPreProcessors)
calculateParagraphPreProcessorsback to summary
public static List<List<ParagraphPreProcessorFactory>> calculateParagraphPreProcessors(DataHolder options, List<ParagraphPreProcessorFactory> blockPreProcessors, InlineParserFactory inlineParserFactory)
deactivateBlockParserback to summary
private void deactivateBlockParser()
endsWithBlankLineback to summary
public boolean endsWithBlankLine(Node block)

Implements com.vladsch.flexmark.parser.block.ParserState.endsWithBlankLine.

Doc from com.vladsch.flexmark.parser.block.ParserState.endsWithBlankLine.

Test the block to see if it ends in a blank line. The blank line can be in the block or its last child.

Parameters
block:Node

block to be tested

Returns:boolean

true if the block ends in a blank line

Annotations
@Override
finalizeback to summary
private void finalize(BlockParser blockParser)

Finalize a block. Close it and do any necessary postprocessing, e.g. creating string_content from strings, setting the 'tight' or 'loose' status of a list, and parsing the beginnings of paragraphs for reference definitions.

Parameters
blockParser:BlockParser

block parser instance to finalize

finalizeAndProcessback to summary
private Document finalizeAndProcess()
finalizeBlocksback to summary
private boolean finalizeBlocks(List<BlockParser> blockParsers)

Finalize blocks of previous line.

Returns:boolean

true.

findBlockStartback to summary
private BlockStartImpl findBlockStart(BlockParser blockParser)
findNextNonSpaceback to summary
private void findNextNonSpace()
getActiveBlockParserback to summary
public BlockParser getActiveBlockParser()

Implements com.vladsch.flexmark.parser.block.ParserState.getActiveBlockParser.

Returns:BlockParser

Doc from com.vladsch.flexmark.parser.block.ParserState.getActiveBlockParser.

the deepest open block parser

Annotations
@Override
getActiveBlockParserback to summary
public BlockParser getActiveBlockParser(Block node)

Implements com.vladsch.flexmark.parser.block.ParserState.getActiveBlockParser.

Parameters
node:Block

Doc from com.vladsch.flexmark.parser.block.ParserState.getActiveBlockParser.

block node for which to get the active block parser

Returns:BlockParser

Doc from com.vladsch.flexmark.parser.block.ParserState.getActiveBlockParser.

an active block parser for the node or null if not found or the block is already closed.

Annotations
@Override
getActiveBlockParsersback to summary
public List<BlockParser> getActiveBlockParsers()

Implements com.vladsch.flexmark.parser.block.ParserState.getActiveBlockParsers.

Returns:List<BlockParser>

Doc from com.vladsch.flexmark.parser.block.ParserState.getActiveBlockParsers.

the current list of active block parsers, deepest is last

Annotations
@Override
getColumnback to summary
public int getColumn()

Implements com.vladsch.flexmark.parser.block.ParserState.getColumn.

Doc from com.vladsch.flexmark.parser.block.ParserState.getColumn.

The column is the position within the line after tab characters have been processed as 4-space tab stops. If the line doesn't contain any tabs, it's the same as the getIndex(). If the line starts with a tab, followed by text, then the column for the first character of the text is 4 (the index is 1).

Returns:int

the current column within the line (0-based)

Annotations
@Override
getIndentback to summary
public int getIndent()

Implements com.vladsch.flexmark.parser.block.ParserState.getIndent.

Returns:int

Doc from com.vladsch.flexmark.parser.block.ParserState.getIndent.

the indentation in columns (either by spaces or tab stop of 4), starting from getColumn()

Annotations
@Override
getIndexback to summary
public int getIndex()

Implements com.vladsch.flexmark.parser.block.ParserState.getIndex.

Returns:int

Doc from com.vladsch.flexmark.parser.block.ParserState.getIndex.

the current index within the line (0-based)

Annotations
@Override
getInlineParserback to summary
public InlineParser getInlineParser()

Implements com.vladsch.flexmark.parser.block.ParserState.getInlineParser.

Returns:InlineParser

Doc from com.vladsch.flexmark.parser.block.ParserState.getInlineParser.

inline parser instance for the parser state

Annotations
@Override
getLineback to summary
public BasedSequence getLine()

Implements com.vladsch.flexmark.parser.block.ParserState.getLine.

Returns:BasedSequence

Doc from com.vladsch.flexmark.parser.block.ParserState.getLine.

the current line

Annotations
@Override
getLineEndIndexback to summary
public int getLineEndIndex()

Implements com.vladsch.flexmark.parser.block.ParserState.getLineEndIndex.

Returns:int

Doc from com.vladsch.flexmark.parser.block.ParserState.getLineEndIndex.

the end of line offset into the input stream corresponding to current index into the line, including the EOL

getLineEolLengthback to summary
public int getLineEolLength()

Implements com.vladsch.flexmark.parser.block.ParserState.getLineEolLength.

Returns:int

Doc from com.vladsch.flexmark.parser.block.ParserState.getLineEolLength.

the EOL offset into the input stream corresponding to current index into the line

Annotations
@Override
getLineNumberback to summary
public int getLineNumber()

Implements com.vladsch.flexmark.parser.block.ParserState.getLineNumber.

Returns:int

Doc from com.vladsch.flexmark.parser.block.ParserState.getLineNumber.

The 0 based current line number within the input

Annotations
@Override
getLineSegmentsback to summary
public List<BasedSequence> getLineSegments()

Implements com.vladsch.flexmark.parser.block.ParserState.getLineSegments.

Doc from com.vladsch.flexmark.parser.block.ParserState.getLineSegments.

Returns a list of document lines encountered this far in the parsing process

Returns:List<BasedSequence>

list of line sequences (including EOLs)

Annotations
@Override
getLineStartback to summary
public int getLineStart()

Implements com.vladsch.flexmark.parser.block.ParserState.getLineStart.

Returns:int

Doc from com.vladsch.flexmark.parser.block.ParserState.getLineStart.

the start of line offset into the input stream corresponding to current index into the line

Annotations
@Override
getLineWithEOLback to summary
public BasedSequence getLineWithEOL()

Implements com.vladsch.flexmark.parser.block.ParserState.getLineWithEOL.

Returns:BasedSequence

Doc from com.vladsch.flexmark.parser.block.ParserState.getLineWithEOL.

the current line with EOL

Annotations
@Override
getNextNonSpaceIndexback to summary
public int getNextNonSpaceIndex()

Implements com.vladsch.flexmark.parser.block.ParserState.getNextNonSpaceIndex.

Returns:int

Doc from com.vladsch.flexmark.parser.block.ParserState.getNextNonSpaceIndex.

the index of the next non-space character starting from getIndex() (may be the same) (0-based)

Annotations
@Override
getParserPhaseback to summary
public ParserPhase getParserPhase()

Implements com.vladsch.flexmark.parser.block.ParserState.getParserPhase.

Doc from com.vladsch.flexmark.parser.block.ParserState.getParserPhase.

Get the current parser phase

Returns:ParserPhase

the current parser phase ParserPhase

Annotations
@Override
getParsingback to summary
public Parsing getParsing()

Implements com.vladsch.flexmark.parser.block.ParserState.getParsing.

Returns:Parsing

Doc from com.vladsch.flexmark.parser.block.ParserState.getParsing.

strings and patterns class adjusted for options Parsing

Annotations
@Override
getPropertiesback to summary
public MutableDataHolder getProperties()

Implements com.vladsch.flexmark.parser.block.ParserState.getProperties.

Returns:MutableDataHolder

Doc from com.vladsch.flexmark.parser.block.ParserState.getProperties.

document properties of the document being parsed

Annotations
@Override
incorporateLineback to summary
private void incorporateLine(BasedSequence ln)

Analyze a line of text and update the document appropriately. We parse markdown text by calling this on each line of input, then finalizing the document.

Parameters
ln:BasedSequence

sequence of the current line

isBlankback to summary
public boolean isBlank()

Implements com.vladsch.flexmark.parser.block.ParserState.isBlank.

Returns:boolean

Doc from com.vladsch.flexmark.parser.block.ParserState.isBlank.

true if the current line is blank starting from the index

Annotations
@Override
isBlankLineback to summary
public boolean isBlankLine()

Implements com.vladsch.flexmark.parser.block.ParserState.isBlankLine.

Returns:boolean

Doc from com.vladsch.flexmark.parser.block.ParserState.isBlankLine.

true if the current line is blank starting from the index

Annotations
@Override
isLastLineBlankback to summary
public boolean isLastLineBlank(Node node)

Implements com.vladsch.flexmark.parser.block.ParserState.isLastLineBlank.

Doc from com.vladsch.flexmark.parser.block.ParserState.isLastLineBlank.

Test a block to see if the last line of the block is blank. Children not tested.

Parameters
node:Node

block instance to test

Returns:boolean

true if the block's last line is blank

Annotations
@Override
parseback to summary
public Document parse(CharSequence source)

The main parsing function. Returns a parsed document AST.

Parameters
source:CharSequence

source sequence to parse

Returns:Document

Document node of the resulting AST

parseback to summary
public Document parse(Reader input) throws IOException
preProcessBlocksback to summary
private void preProcessBlocks()
preProcessParagraphback to summary
private void preProcessParagraph(Paragraph block, List<ParagraphPreProcessorFactory> stage, DocumentParser.ParagraphPreProcessorCache processorMap)

pre-process a paragraph block

Parameters
block:Paragraph

paragraph block to pre-process

stage:List<ParagraphPreProcessorFactory>

paragraph pre-processor dependency stage

processorMap:DocumentParser.ParagraphPreProcessorCache

paragraph pre-processor cache

preProcessParagraphsback to summary
private void preProcessParagraphs()
processInlinesback to summary
private void processInlines()

Walk through a block & children recursively, parsing string content into inline content where appropriate.

propagateLastLineBlankback to summary
private void propagateLastLineBlank(BlockParser blockParser, BlockParser lastMatchedBlockParser)
removeActiveBlockParserback to summary
private void removeActiveBlockParser()
setLastLineBlankback to summary
private void setLastLineBlank(Node node, boolean value)
setNewColumnback to summary
private void setNewColumn(int newColumn)
setNewIndexback to summary
private void setNewIndex(int newIndex)
com.vladsch.flexmark.parser.internal back to summary

private Class DocumentParser.ParagraphPreProcessorCache

extends ItemFactoryMap<ParagraphPreProcessor, ParserState>
Class Inheritance

Field Summary

Inherited from com.vladsch.flexmark.util.collection.ItemFactoryMap:
itemMapparam

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Inherited from com.vladsch.flexmark.util.collection.ItemFactoryMap:
clearcontainsKeycontainsValueentrySetgetgetItemisEmptykeySetputputAllremovesizevalues

Constructor Detail

ParagraphPreProcessorCacheback to summary
pack-priv ParagraphPreProcessorCache(ParserState param)