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 booleanprivate final booleanprivate final List<BlockParserFactory> private final List<List<BlockPreProcessorFactory>> private final ClassifyingBlockTrackerprivate intcurrent column of input line (tab causes column to go to next 4-space tab stop) (0-based)private booleanif 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 ParserPhaseprivate final DocumentBlockParserprivate intprivate intcurrent index (offset) in input line (0-based)static final InlineParserFactoryprivate final InlineParserprivate booleanprivate BasedSequenceprivate intcurrent end of line offset in the input including EOLprivate intcurrent lines EOL sequenceprivate intcurrent line number in the inputprivate final List<BasedSequence> private intcurrent start of line offset in the inputprivate BasedSequenceprivate final Parsingprivate intprivate intprivate final DataHolderprivate 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 voidactivateBlockParser(BlockParser blockParser) private <T extends BlockParser>
TaddChild(T blockParser) Add block parser of type T as a child of the currently active parsers.private voidaddLine()Add line content to the active block parser.private voidadvance()voidblockAdded(@NotNull Block node) voidblockAddedWithChildren(@NotNull Block node) voidblockAddedWithDescendants(@NotNull Block node) voidblockParserAdded(BlockParser blockParser) voidblockParserRemoved(BlockParser blockParser) voidblockRemoved(@NotNull Block node) voidblockRemovedWithChildren(@NotNull Block node) voidblockRemovedWithDescendants(@NotNull Block node) private voidbreakOutOfLists(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 voidbooleanendsWithBlankLine(Node block) Test the block to see if it ends in a blank line.private voidfinalize(BlockParser blockParser) Finalize a block.private Documentprivate booleanfinalizeBlocks(List<BlockParser> blockParsers) Finalize blocks of previous line.private BlockStartImplfindBlockStart(BlockParser blockParser) private voidgetActiveBlockParser(Block node) intThe column is the position within the line after tab characters have been processed as 4-space tab stops.intintgetIndex()getLine()intintintReturns a list of document lines encountered this far in the parsing processintintGet the current parser phaseprivate voidAnalyze a line of text and update the document appropriately.booleanisBlank()booleanbooleanisLastLineBlank(Node node) Test a block to see if the last line of the block is blank.parse(CharSequence source) The main parsing function.private voidprivate voidpreProcessParagraph(Paragraph block, List<ParagraphPreProcessorFactory> stage, DocumentParser.ParagraphPreProcessorCache processorMap) pre-process a paragraph blockprivate voidprivate voidWalk through a block invalid input: '&' children recursively, parsing string content into inline content where appropriate.private voidpropagateLastLineBlank(BlockParser blockParser, BlockParser lastMatchedBlockParser) private voidprivate voidsetLastLineBlank(Node node, boolean value) private voidsetNewColumn(int newColumn) private voidsetNewIndex(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:ParserStateReturns a list of document lines encountered this far in the parsing process- Specified by:
getLineSegmentsin interfaceParserState- Returns:
- list of line sequences (including EOLs)
-
blockParserAdded
- Specified by:
blockParserAddedin interfaceBlockParserTracker
-
blockParserRemoved
- Specified by:
blockParserRemovedin interfaceBlockParserTracker
-
blockAdded
- Specified by:
blockAddedin interfaceBlockTracker
-
blockAddedWithChildren
- Specified by:
blockAddedWithChildrenin interfaceBlockTracker
-
blockAddedWithDescendants
- Specified by:
blockAddedWithDescendantsin interfaceBlockTracker
-
blockRemoved
- Specified by:
blockRemovedin interfaceBlockTracker
-
blockRemovedWithChildren
- Specified by:
blockRemovedWithChildrenin interfaceBlockTracker
-
blockRemovedWithDescendants
- Specified by:
blockRemovedWithDescendantsin interfaceBlockTracker
-
getParserPhase
Description copied from interface:ParserStateGet the current parser phase- Specified by:
getParserPhasein interfaceParserState- Returns:
- the current parser phase
ParserPhase
-
getParsing
- Specified by:
getParsingin interfaceParserState- Returns:
- strings and patterns class adjusted for options
Parsing
-
getProperties
- Specified by:
getPropertiesin 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:
getInlineParserin 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:
getLineNumberin interfaceParserState- Returns:
- The 0 based current line number within the input
-
getLineStart
public int getLineStart()- Specified by:
getLineStartin interfaceParserState- Returns:
- the start of line offset into the input stream corresponding to current index into the line
-
getLineEndIndex
public int getLineEndIndex()- Specified by:
getLineEndIndexin interfaceParserState- Returns:
- the end of line offset into the input stream corresponding to current index into the line, including the EOL
-
getLine
- Specified by:
getLinein interfaceParserState- Returns:
- the current line
-
getLineWithEOL
- Specified by:
getLineWithEOLin interfaceParserState- Returns:
- the current line with EOL
-
getLineEolLength
public int getLineEolLength()- Specified by:
getLineEolLengthin interfaceParserState- Returns:
- the EOL offset into the input stream corresponding to current index into the line
-
getIndex
public int getIndex()- Specified by:
getIndexin interfaceParserState- Returns:
- the current index within the line (0-based)
-
getNextNonSpaceIndex
public int getNextNonSpaceIndex()- Specified by:
getNextNonSpaceIndexin 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:ParserStateThe 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:
getColumnin interfaceParserState- Returns:
- the current column within the line (0-based)
-
getIndent
public int getIndent()- Specified by:
getIndentin interfaceParserState- Returns:
- the indentation in columns (either by spaces or tab stop of 4), starting from
ParserState.getColumn()
-
isBlank
public boolean isBlank()- Specified by:
isBlankin interfaceParserState- Returns:
- true if the current line is blank starting from the index
-
isBlankLine
public boolean isBlankLine()- Specified by:
isBlankLinein interfaceParserState- Returns:
- true if the current line is blank starting from the index
-
getActiveBlockParser
- Specified by:
getActiveBlockParserin interfaceParserState- Returns:
- the deepest open block parser
-
getActiveBlockParser
- Specified by:
getActiveBlockParserin 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:
getActiveBlockParsersin 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:ParserStateTest 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:
endsWithBlankLinein 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:ParserStateTest a block to see if the last line of the block is blank. Children not tested.- Specified by:
isLastLineBlankin 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
-