Class DocumentParser
java.lang.Object
com.vladsch.flexmark.parser.internal.DocumentParser
- All Implemented Interfaces:
BlockParserTracker
,ParserState
,BlockTracker
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final List
<BlockParser> private boolean
private final boolean
private final List
<BlockParserFactory> private final List
<List<BlockPreProcessorFactory>> private final ClassifyingBlockTracker
private int
current column of input line (tab causes column to go to next 4-space tab stop) (0-based)private boolean
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
current index (offset) in input line (0-based)static final InlineParserFactory
private final InlineParser
private boolean
private BasedSequence
private int
current end of line offset in the input including EOLprivate int
current lines EOL sequenceprivate int
current line number in the inputprivate final List
<BasedSequence> private int
current start of line offset in the inputprivate BasedSequence
private final Parsing
private int
private int
private final DataHolder
private final List
<List<ParagraphPreProcessorFactory>> private final boolean
-
Constructor Summary
ConstructorsConstructorDescriptionDocumentParser
(DataHolder options, List<CustomBlockParserFactory> customBlockParserFactories, List<List<ParagraphPreProcessorFactory>> paragraphPreProcessorDependencies, List<List<BlockPreProcessorFactory>> blockPreProcessorDependencies, InlineParser inlineParser) -
Method Summary
Modifier and TypeMethodDescriptionprivate void
activateBlockParser
(BlockParser blockParser) private <T extends BlockParser>
TaddChild
(T 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
advance()
void
blockAdded
(@NotNull Block node) void
blockAddedWithChildren
(@NotNull Block node) void
blockAddedWithDescendants
(@NotNull Block node) void
blockParserAdded
(BlockParser blockParser) void
blockParserRemoved
(BlockParser blockParser) void
blockRemoved
(@NotNull Block node) void
blockRemovedWithChildren
(@NotNull Block node) void
blockRemovedWithDescendants
(@NotNull Block node) 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.static List
<CustomBlockParserFactory> calculateBlockParserFactories
(DataHolder options, List<CustomBlockParserFactory> customBlockParserFactories) static List
<List<BlockPreProcessorFactory>> calculateBlockPreProcessors
(DataHolder options, List<BlockPreProcessorFactory> blockPreProcessors) static List
<List<ParagraphPreProcessorFactory>> calculateParagraphPreProcessors
(DataHolder options, List<ParagraphPreProcessorFactory> blockPreProcessors, InlineParserFactory inlineParserFactory) private void
boolean
endsWithBlankLine
(Node block) Test the block to see if it ends in a blank line.private void
finalize
(BlockParser blockParser) Finalize a block.private Document
private boolean
finalizeBlocks
(List<BlockParser> blockParsers) Finalize blocks of previous line.private BlockStartImpl
findBlockStart
(BlockParser blockParser) private void
getActiveBlockParser
(Block node) int
The column is the position within the line after tab characters have been processed as 4-space tab stops.int
int
getIndex()
getLine()
int
int
int
Returns a list of document lines encountered this far in the parsing processint
int
Get the current parser phaseprivate void
Analyze a line of text and update the document appropriately.boolean
isBlank()
boolean
boolean
isLastLineBlank
(Node node) Test a block to see if the last line of the block is blank.parse
(CharSequence source) The main parsing function.private void
private void
preProcessParagraph
(Paragraph block, List<ParagraphPreProcessorFactory> stage, DocumentParser.ParagraphPreProcessorCache processorMap) pre-process a paragraph blockprivate void
private void
Walk through a block invalid input: '&' 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)
-
Field Details
-
INLINE_PARSER_FACTORY
-
CORE_FACTORIES_DATA_KEYS
-
CORE_PARAGRAPH_PRE_PROCESSORS
private static final HashMap<DataKey<Boolean>,ParagraphPreProcessorFactory> CORE_PARAGRAPH_PRE_PROCESSORS -
line
-
lineWithEOL
-
lineNumber
private int lineNumbercurrent line number in the input -
lineStart
private int lineStartcurrent start of line offset in the input -
lineEOLIndex
private int lineEOLIndexcurrent lines EOL sequence -
lineEndIndex
private int lineEndIndexcurrent end of line offset in the input including EOL -
index
private int indexcurrent index (offset) in input line (0-based) -
column
private int columncurrent column of input line (tab causes column to go to next 4-space tab stop) (0-based) -
columnIsInTab
private boolean columnIsInTabif the current column is within a tab character (partially consumed tab) -
nextNonSpace
private int nextNonSpace -
nextNonSpaceColumn
private int nextNonSpaceColumn -
indent
private int indent -
blank
private boolean blank -
isBlankLine
private boolean isBlankLine -
blockParserFactories
-
paragraphPreProcessorDependencies
-
blockPreProcessorDependencies
-
inlineParser
-
documentBlockParser
-
blankLinesInAst
private final boolean blankLinesInAst -
trackDocumentLines
private final boolean trackDocumentLines -
lineSegments
-
activeBlockParsers
-
blockTracker
-
lastLineBlank
-
options
-
currentPhase
-
myParsing
-
-
Constructor Details
-
DocumentParser
public DocumentParser(DataHolder options, List<CustomBlockParserFactory> customBlockParserFactories, List<List<ParagraphPreProcessorFactory>> paragraphPreProcessorDependencies, List<List<BlockPreProcessorFactory>> blockPreProcessorDependencies, InlineParser inlineParser)
-
-
Method Details
-
getLineSegments
Description copied from interface:ParserState
Returns a list of document lines encountered this far in the parsing process- Specified by:
getLineSegments
in interfaceParserState
- Returns:
- list of line sequences (including EOLs)
-
blockParserAdded
- Specified by:
blockParserAdded
in interfaceBlockParserTracker
-
blockParserRemoved
- Specified by:
blockParserRemoved
in interfaceBlockParserTracker
-
blockAdded
- Specified by:
blockAdded
in interfaceBlockTracker
-
blockAddedWithChildren
- Specified by:
blockAddedWithChildren
in interfaceBlockTracker
-
blockAddedWithDescendants
- Specified by:
blockAddedWithDescendants
in interfaceBlockTracker
-
blockRemoved
- Specified by:
blockRemoved
in interfaceBlockTracker
-
blockRemovedWithChildren
- Specified by:
blockRemovedWithChildren
in interfaceBlockTracker
-
blockRemovedWithDescendants
- Specified by:
blockRemovedWithDescendants
in interfaceBlockTracker
-
getParserPhase
Description copied from interface:ParserState
Get the current parser phase- Specified by:
getParserPhase
in interfaceParserState
- Returns:
- the current parser phase
ParserPhase
-
getParsing
- Specified by:
getParsing
in interfaceParserState
- Returns:
- strings and patterns class adjusted for options
Parsing
-
getProperties
- Specified by:
getProperties
in interfaceParserState
- Returns:
- document properties of the document being parsed
-
calculateBlockParserFactories
public static List<CustomBlockParserFactory> calculateBlockParserFactories(DataHolder options, List<CustomBlockParserFactory> customBlockParserFactories) -
calculateParagraphPreProcessors
public static List<List<ParagraphPreProcessorFactory>> calculateParagraphPreProcessors(DataHolder options, List<ParagraphPreProcessorFactory> blockPreProcessors, InlineParserFactory inlineParserFactory) -
calculateBlockPreProcessors
public static List<List<BlockPreProcessorFactory>> calculateBlockPreProcessors(DataHolder options, List<BlockPreProcessorFactory> blockPreProcessors) -
getInlineParser
- Specified by:
getInlineParser
in interfaceParserState
- Returns:
- inline parser instance for the parser state
-
parse
The main parsing function. Returns a parsed document AST.- Parameters:
source
- source sequence to parse- Returns:
- Document node of the resulting AST
-
parse
- Throws:
IOException
-
getLineNumber
public int getLineNumber()- Specified by:
getLineNumber
in interfaceParserState
- Returns:
- The 0 based current line number within the input
-
getLineStart
public int getLineStart()- Specified by:
getLineStart
in interfaceParserState
- Returns:
- the start of line offset into the input stream corresponding to current index into the line
-
getLineEndIndex
public int getLineEndIndex()- Specified by:
getLineEndIndex
in interfaceParserState
- Returns:
- the end of line offset into the input stream corresponding to current index into the line, including the EOL
-
getLine
- Specified by:
getLine
in interfaceParserState
- Returns:
- the current line
-
getLineWithEOL
- Specified by:
getLineWithEOL
in interfaceParserState
- Returns:
- the current line with EOL
-
getLineEolLength
public int getLineEolLength()- Specified by:
getLineEolLength
in interfaceParserState
- Returns:
- the EOL offset into the input stream corresponding to current index into the line
-
getIndex
public int getIndex()- Specified by:
getIndex
in interfaceParserState
- Returns:
- the current index within the line (0-based)
-
getNextNonSpaceIndex
public int getNextNonSpaceIndex()- Specified by:
getNextNonSpaceIndex
in interfaceParserState
- Returns:
- the index of the next non-space character starting from
ParserState.getIndex()
(may be the same) (0-based)
-
getColumn
public int getColumn()Description copied from interface:ParserState
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 theParserState.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).- Specified by:
getColumn
in interfaceParserState
- Returns:
- the current column within the line (0-based)
-
getIndent
public int getIndent()- Specified by:
getIndent
in interfaceParserState
- Returns:
- the indentation in columns (either by spaces or tab stop of 4), starting from
ParserState.getColumn()
-
isBlank
public boolean isBlank()- Specified by:
isBlank
in interfaceParserState
- Returns:
- true if the current line is blank starting from the index
-
isBlankLine
public boolean isBlankLine()- Specified by:
isBlankLine
in interfaceParserState
- Returns:
- true if the current line is blank starting from the index
-
getActiveBlockParser
- Specified by:
getActiveBlockParser
in interfaceParserState
- Returns:
- the deepest open block parser
-
getActiveBlockParser
- Specified by:
getActiveBlockParser
in interfaceParserState
- Parameters:
node
- block node for which to get the active block parser- Returns:
- an active block parser for the node or null if not found or the block is already closed.
-
getActiveBlockParsers
- Specified by:
getActiveBlockParsers
in interfaceParserState
- Returns:
- the current list of active block parsers, deepest is last
-
incorporateLine
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
- sequence of the current line
-
findNextNonSpace
private void findNextNonSpace() -
setNewIndex
private void setNewIndex(int newIndex) -
setNewColumn
private void setNewColumn(int newColumn) -
advance
private void advance() -
addLine
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. -
findBlockStart
-
finalize
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
- block parser instance to finalize
-
processInlines
private void processInlines()Walk through a block invalid input: '&' children recursively, parsing string content into inline content where appropriate. -
endsWithBlankLine
Description copied from interface:ParserState
Test the block to see if it ends in a blank line. The blank line can be in the block or its last child.- Specified by:
endsWithBlankLine
in interfaceParserState
- Parameters:
block
- block to be tested- Returns:
- true if the block ends in a blank line
-
breakOutOfLists
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 of block parsers to break out on double blank line
-
addChild
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.- Type Parameters:
T
- block parser type- Parameters:
blockParser
- new block parser to add as a child- Returns:
- block parser instance added as a child.
-
activateBlockParser
-
deactivateBlockParser
private void deactivateBlockParser() -
removeActiveBlockParser
private void removeActiveBlockParser() -
propagateLastLineBlank
-
setLastLineBlank
-
isLastLineBlank
Description copied from interface:ParserState
Test a block to see if the last line of the block is blank. Children not tested.- Specified by:
isLastLineBlank
in interfaceParserState
- Parameters:
node
- block instance to test- Returns:
- true if the block's last line is blank
-
finalizeBlocks
Finalize blocks of previous line.- Returns:
- true.
-
preProcessParagraph
private void preProcessParagraph(Paragraph block, List<ParagraphPreProcessorFactory> stage, DocumentParser.ParagraphPreProcessorCache processorMap) pre-process a paragraph block- Parameters:
block
- paragraph block to pre-processstage
- paragraph pre-processor dependency stageprocessorMap
- paragraph pre-processor cache
-
preProcessParagraphs
private void preProcessParagraphs() -
preProcessBlocks
private void preProcessBlocks() -
finalizeAndProcess
-