Package org.commonmark.internal
Class DocumentParser
- java.lang.Object
-
- org.commonmark.internal.DocumentParser
-
- All Implemented Interfaces:
ParserState
public class DocumentParser extends java.lang.Object implements ParserState
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DocumentParser.MatchedBlockParserImpl
private static class
DocumentParser.OpenBlockParser
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<BlockParser>
allBlockParsers
private boolean
blank
private java.util.List<BlockParserFactory>
blockParserFactories
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 java.util.Set<java.lang.Class<? extends Block>>
CORE_FACTORY_TYPES
private LinkReferenceDefinitions
definitions
private java.util.List<DelimiterProcessor>
delimiterProcessors
private DocumentBlockParser
documentBlockParser
private IncludeSourceSpans
includeSourceSpans
private int
indent
private int
index
current index (offset) in input line (0-based)private InlineParserFactory
inlineParserFactory
private SourceLine
line
private int
lineIndex
Line index (0-based)private int
nextNonSpace
private int
nextNonSpaceColumn
private static java.util.Map<java.lang.Class<? extends Block>,BlockParserFactory>
NODES_TO_CORE_FACTORIES
private java.util.List<DocumentParser.OpenBlockParser>
openBlockParsers
-
Constructor Summary
Constructors Constructor Description DocumentParser(java.util.List<BlockParserFactory> blockParserFactories, InlineParserFactory inlineParserFactory, java.util.List<DelimiterProcessor> delimiterProcessors, IncludeSourceSpans includeSourceSpans)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
activateBlockParser(DocumentParser.OpenBlockParser openBlockParser)
private void
addChild(DocumentParser.OpenBlockParser openBlockParser)
Add block of type tag as a child of the tip.private void
addDefinitionsFrom(ParagraphParser paragraphParser)
private void
addLine()
Add line content to the active block parser.private void
addSourceSpans()
private void
advance()
static java.util.List<BlockParserFactory>
calculateBlockParserFactories(java.util.List<BlockParserFactory> customBlockParserFactories, java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes)
static void
checkEnabledBlockTypes(java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes)
private void
closeBlockParsers(int count)
private DocumentParser.OpenBlockParser
deactivateBlockParser()
private void
finalize(BlockParser blockParser)
Finalize a block.private Document
finalizeAndProcess()
private BlockStartImpl
findBlockStart(BlockParser blockParser)
private void
findNextNonSpace()
BlockParser
getActiveBlockParser()
int
getColumn()
The column is the position within the line after tab characters have been processed as 4-space tab stops.static java.util.Set<java.lang.Class<? extends Block>>
getDefaultBlockParserTypes()
int
getIndent()
int
getIndex()
SourceLine
getLine()
int
getNextNonSpaceIndex()
boolean
isBlank()
Document
parse(java.io.Reader input)
Document
parse(java.lang.String input)
The main parsing function.private void
parseLine(java.lang.CharSequence ln)
Analyze a line of text and update the document appropriately.private Block
prepareActiveBlockParserForReplacement()
private static java.lang.CharSequence
prepareLine(java.lang.CharSequence line)
Prepares the input line replacing\0
private void
processInlines()
Walk through a block & children recursively, parsing string content into inline content where appropriate.private void
setLine(java.lang.CharSequence ln)
private void
setNewColumn(int newColumn)
private void
setNewIndex(int newIndex)
-
-
-
Field Detail
-
CORE_FACTORY_TYPES
private static final java.util.Set<java.lang.Class<? extends Block>> CORE_FACTORY_TYPES
-
NODES_TO_CORE_FACTORIES
private static final java.util.Map<java.lang.Class<? extends Block>,BlockParserFactory> NODES_TO_CORE_FACTORIES
-
line
private SourceLine line
-
lineIndex
private int lineIndex
Line index (0-based)
-
index
private int index
current index (offset) in input line (0-based)
-
column
private int column
current column of input line (tab causes column to go to next 4-space tab stop) (0-based)
-
columnIsInTab
private boolean columnIsInTab
if 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
-
blockParserFactories
private final java.util.List<BlockParserFactory> blockParserFactories
-
inlineParserFactory
private final InlineParserFactory inlineParserFactory
-
delimiterProcessors
private final java.util.List<DelimiterProcessor> delimiterProcessors
-
includeSourceSpans
private final IncludeSourceSpans includeSourceSpans
-
documentBlockParser
private final DocumentBlockParser documentBlockParser
-
definitions
private final LinkReferenceDefinitions definitions
-
openBlockParsers
private final java.util.List<DocumentParser.OpenBlockParser> openBlockParsers
-
allBlockParsers
private final java.util.List<BlockParser> allBlockParsers
-
-
Constructor Detail
-
DocumentParser
public DocumentParser(java.util.List<BlockParserFactory> blockParserFactories, InlineParserFactory inlineParserFactory, java.util.List<DelimiterProcessor> delimiterProcessors, IncludeSourceSpans includeSourceSpans)
-
-
Method Detail
-
getDefaultBlockParserTypes
public static java.util.Set<java.lang.Class<? extends Block>> getDefaultBlockParserTypes()
-
calculateBlockParserFactories
public static java.util.List<BlockParserFactory> calculateBlockParserFactories(java.util.List<BlockParserFactory> customBlockParserFactories, java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes)
-
checkEnabledBlockTypes
public static void checkEnabledBlockTypes(java.util.Set<java.lang.Class<? extends Block>> enabledBlockTypes)
-
parse
public Document parse(java.lang.String input)
The main parsing function. Returns a parsed document AST.
-
parse
public Document parse(java.io.Reader input) throws java.io.IOException
- Throws:
java.io.IOException
-
getLine
public SourceLine getLine()
- Specified by:
getLine
in interfaceParserState
- Returns:
- the current source line being parsed (full 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
-
getActiveBlockParser
public BlockParser getActiveBlockParser()
- Specified by:
getActiveBlockParser
in interfaceParserState
- Returns:
- the deepest open block parser
-
parseLine
private void parseLine(java.lang.CharSequence 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.
-
setLine
private void setLine(java.lang.CharSequence ln)
-
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.
-
addSourceSpans
private void addSourceSpans()
-
findBlockStart
private BlockStartImpl findBlockStart(BlockParser blockParser)
-
finalize
private void finalize(BlockParser blockParser)
Finalize a block. Close it and do any necessary postprocessing, e.g. setting the content of blocks and collecting link reference definitions from paragraphs.
-
addDefinitionsFrom
private void addDefinitionsFrom(ParagraphParser paragraphParser)
-
processInlines
private void processInlines()
Walk through a block & children recursively, parsing string content into inline content where appropriate.
-
addChild
private void addChild(DocumentParser.OpenBlockParser openBlockParser)
Add block of type tag as a child of the tip. If the tip can't accept children, close and finalize it and try its parent, and so on until we find a block that can accept children.
-
activateBlockParser
private void activateBlockParser(DocumentParser.OpenBlockParser openBlockParser)
-
deactivateBlockParser
private DocumentParser.OpenBlockParser deactivateBlockParser()
-
prepareActiveBlockParserForReplacement
private Block prepareActiveBlockParserForReplacement()
-
finalizeAndProcess
private Document finalizeAndProcess()
-
closeBlockParsers
private void closeBlockParsers(int count)
-
prepareLine
private static java.lang.CharSequence prepareLine(java.lang.CharSequence line)
Prepares the input line replacing\0
-
-