FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Refactor Parser and Parser.Builder by ani28-bit · Pull Request #452 · commonmark/commonmark-java · GitHub

Repository navigation

Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public static Builder builder() {
return new Builder();
}

private Node processParsedDocument(Node document) {
return postProcess(document);
}

/**
* Parse the specified input text into a tree of nodes.
* <p>
Expand All @@ -74,11 +78,12 @@ public static Builder builder() {
* @param input the text to parse - must not be null
* @return the root node
*/

public Node parse(String input) {
Objects.requireNonNull(input, "input must not be null");
DocumentParser documentParser = createDocumentParser();
Node document = documentParser.parse(input);
return postProcess(document);
Objects.requireNonNull(input);
DocumentParser documentParser = createDocumentParser();

return processParsedDocument(documentParser.parse(input));
}

/**
Expand All @@ -100,10 +105,10 @@ public Node parse(String input) {
* @throws IOException when reading throws an exception
*/
public Node parseReader(Reader input) throws IOException {
Objects.requireNonNull(input, "input must not be null");
Objects.requireNonNull(input);
DocumentParser documentParser = createDocumentParser();
Node document = documentParser.parse(input);
return postProcess(document);
return processParsedDocument(documentParser.parse(input));

}

private DocumentParser createDocumentParser() {
Expand Down Expand Up @@ -147,13 +152,18 @@ public Parser build() {
public Builder extensions(Iterable<? extends Extension> extensions) {
Objects.requireNonNull(extensions, "extensions must not be null");
for (Extension extension : extensions) {
applyExtension(extension);
}
return this;
}
private void applyExtension(Extension extension){
if (extension instanceof ParserExtension) {
ParserExtension parserExtension = (ParserExtension) extension;
parserExtension.extend(this);
}
}
return this;
}



/**
* Describe the list of markdown features the parser will recognize and parse.
Expand Down Expand Up @@ -217,12 +227,15 @@ public Builder includeSourceSpans(IncludeSourceSpans includeSourceSpans) {
* @return {@code this}
*/
public Builder maxOpenBlockParsers(int maxOpenBlockParsers) {
if (maxOpenBlockParsers < 0) {
throw new IllegalArgumentException("maxOpenBlockParsers must be >= 0");
}
validateMaxOpenBlockParsers(maxOpenBlockParsers);
this.maxOpenBlockParsers = maxOpenBlockParsers;
return this;
}
private void validateMaxOpenBlockParsers(int value){
if (value < 0) {
throw new IllegalArgumentException("maxOpenBlockParsers must be >= 0");
}
}

/**
* Add a custom block parser factory.
Expand Down Expand Up @@ -335,11 +348,10 @@ public Builder inlineParserFactory(InlineParserFactory inlineParserFactory) {
}

private InlineParserFactory getInlineParserFactory() {
if (inlineParserFactory != null) {
return inlineParserFactory;
} else {
return InlineParserImpl::new;
}
return inlineParserFactory != null
? inlineParserFactory :
InlineParserImpl::new;

}
}

Expand Down

Back | FazBrowse Home | New Git URL