Class AptParser

    • Field Detail

      • NUMBERED_LIST_ITEM

        private static final int NUMBERED_LIST_ITEM
        Numbered list event id
        See Also:
        Constant Field Values
      • DEFINITION_LIST_ITEM

        private static final int DEFINITION_LIST_ITEM
        Definition list event id
        See Also:
        Constant Field Values
      • HORIZONTAL_RULE

        private static final int HORIZONTAL_RULE
        Horizontal rule event id
        See Also:
        Constant Field Values
      • COMMENT_BLOCK

        private static final int COMMENT_BLOCK
        Comment event id.
        See Also:
        Constant Field Values
      • TYPE_NAMES

        private static final java.lang.String[] TYPE_NAMES
        String representations of event ids
      • SPACES

        protected static final char[] SPACES
        An array of 85 spaces.
      • source

        private AptSource source
        the AptSource.
      • blockFileName

        private java.lang.String blockFileName
        blockFileName.
      • blockLineNumber

        private int blockLineNumber
        blockLineNumber.
      • sourceContent

        protected java.lang.String sourceContent
        sourceContent.
      • sink

        protected Sink sink
        the sink to receive the events.
      • line

        protected java.lang.String line
        a line of AptSource.
      • warnMessages

        protected java.util.Map<java.lang.String,​java.util.Set<java.lang.String>> warnMessages
        Map of warn messages with a String as key to describe the error type and a Set as value. Using to reduce warn messages.
    • Constructor Detail

      • AptParser

        public AptParser()
    • Method Detail

      • parse

        public void parse​(java.io.Reader source,
                          Sink sink)
                   throws ParseException
        Description copied from interface: Parser
        Parses the given source model and emits Doxia events into the given sink.
        Specified by:
        parse in interface Parser
        Parameters:
        source - not null reader that provides the source document. You could use newReader methods from ReaderFactory.
        sink - A sink that consumes the Doxia events.
        Throws:
        ParseException - if the model could not be parsed.
      • parse

        public void parse​(java.io.Reader source,
                          Sink sink,
                          java.lang.String reference)
                   throws ParseException
        Description copied from interface: Parser
        Parses the given source model and emits Doxia events into the given sink.
        Specified by:
        parse in interface Parser
        Overrides:
        parse in class AbstractParser
        Parameters:
        source - not null reader that provides the source document. You could use newReader methods from ReaderFactory.
        sink - A sink that consumes the Doxia events.
        reference - the reference
        Throws:
        ParseException - if the model could not be parsed.
      • getSourceName

        public java.lang.String getSourceName()
        Returns the name of the Apt source document.
        Returns:
        the source name.
      • getSourceLineNumber

        public int getSourceLineNumber()
        Returns the current line number of the Apt source document.
        Returns:
        the line number.
      • doTraverseText

        protected void doTraverseText​(java.lang.String text,
                                      int begin,
                                      int end,
                                      Sink sink)
                               throws AptParseException
        Parse the given text.
        Parameters:
        text - the text to parse.
        begin - offset.
        end - offset.
        sink - the sink to receive the events.
        Throws:
        AptParseException - if something goes wrong.
      • charAt

        protected static char charAt​(java.lang.String string,
                                     int length,
                                     int i)
        Returns the character at position i of the given string.
        Parameters:
        string - the string.
        length - length.
        i - offset.
        Returns:
        the character, or '\0' if i > length.
      • skipSpace

        protected static int skipSpace​(java.lang.String string,
                                       int length,
                                       int i)
        Skip spaces.
        Parameters:
        string - string.
        length - length.
        i - offset.
        Returns:
        int.
      • replaceAll

        protected static java.lang.String replaceAll​(java.lang.String string,
                                                     java.lang.String oldSub,
                                                     java.lang.String newSub)
        Replace part of a string.
        Parameters:
        string - the string
        oldSub - the substring to replace
        newSub - the replacement string
        Returns:
        String
      • traverseSection

        private void traverseSection​(int level)
                              throws AptParseException
        Parse a section of the Apt source document.
        Parameters:
        level - The section level.
        Throws:
        AptParseException - if something goes wrong.
      • traverseSectionBlocks

        private void traverseSectionBlocks()
                                    throws AptParseException
        Parse the section blocks of the Apt source document.
        Throws:
        AptParseException - if something goes wrong.
      • traverseNumberedList

        private void traverseNumberedList()
                                   throws AptParseException
        Parse a numbered list of the Apt source document.
        Throws:
        AptParseException - if something goes wrong.
      • traverseDefinitionList

        private void traverseDefinitionList()
                                     throws AptParseException
        Parse a definition list of the Apt source document.
        Throws:
        AptParseException - if something goes wrong.
      • nextBlock

        private void nextBlock​(boolean firstBlock)
                        throws AptParseException
        Parse the next block of the Apt source document.
        Parameters:
        firstBlock - True if this is the first block of the Apt source document.
        Throws:
        AptParseException - if something goes wrong.
      • expectedBlock

        private void expectedBlock​(int type)
                            throws AptParseException
        Checks that the current block is of the expected type.
        Parameters:
        type - the expected type.
        Throws:
        AptParseException - if something goes wrong.
      • isOctalChar

        private static boolean isOctalChar​(char c)
        Determine if c is an octal character.
        Parameters:
        c - the character.
        Returns:
        boolean
      • isHexChar

        private static boolean isHexChar​(char c)
        Determine if c is an hex character.
        Parameters:
        c - the character.
        Returns:
        boolean
      • flushTraversed

        private static void flushTraversed​(java.lang.StringBuilder buffer,
                                           Sink sink)
        Emits the text so far parsed into the given sink.
        Parameters:
        buffer - A StringBuilder that contains the text to be flushed.
        sink - The sink to receive the text.
      • skipTraversedLinkAnchor

        private static int skipTraversedLinkAnchor​(java.lang.String text,
                                                   int begin,
                                                   int end,
                                                   java.lang.StringBuilder linkAnchor)
                                            throws AptParseException
        Parse the given text.
        Parameters:
        text - the text to parse.
        begin - offset.
        end - offset.
        linkAnchor - a StringBuilder.
        Returns:
        int
        Throws:
        AptParseException - if something goes wrong.
      • getTraversedLink

        private java.lang.String getTraversedLink​(java.lang.String text,
                                                  int begin,
                                                  int end)
                                           throws AptParseException
        Parse the given text.
        Parameters:
        text - the text to parse.
        begin - offset.
        end - offset.
        Returns:
        String
        Throws:
        AptParseException - if something goes wrong.
      • getTraversedAnchor

        private java.lang.String getTraversedAnchor​(java.lang.String text,
                                                    int begin,
                                                    int end)
                                             throws AptParseException
        Parse the given text.
        Parameters:
        text - the text to parse.
        begin - offset.
        end - offset.
        Returns:
        String
        Throws:
        AptParseException - if something goes wrong.
      • doGetTraversedLink

        private java.lang.String doGetTraversedLink​(java.lang.String text,
                                                    int begin,
                                                    int end)
                                             throws AptParseException
        Parse the given text.
        Parameters:
        text - the text to parse.
        begin - offset.
        end - offset.
        Returns:
        String
        Throws:
        AptParseException - if something goes wrong.
      • logMessage

        private void logMessage​(java.lang.String key,
                                java.lang.String msg)
        If debug mode is enabled, log the msg as is, otherwise add unique msg in warnMessages.
        Parameters:
        key - not null
        msg - not null
        Since:
        1.1.1
        See Also:
        parse(Reader, Sink)
      • logWarnings

        private void logWarnings()
        Since:
        1.1.2