File tree Expand file tree Collapse file tree 2 files changed +24
-7
lines changed
Expand file tree Collapse file tree 2 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -63,16 +63,32 @@ var atomRegex = {
6363 open : / ^ \{ / ,
6464 close : / ^ \} / ,
6565 ordinary : / ^ [ ^ \\ { } $ & # % _ \s ] + / ,
66- math : mathPattern ///^\$.*\$/
66+ math : mathPattern ///^\$.*\$/,
6767} ;
68- var whitespaceRegex = / ^ \s * / ;
68+ var commentRegex = / ^ % .* /
69+ var whitespaceRegex = / ^ \s + / ;
70+
71+ Lexer . prototype . _skip = function ( len ) {
72+ this . _pos += len ;
73+ this . _remain = this . _remain . slice ( len ) ;
74+ }
6975
7076/* Get the next atom */
7177Lexer . prototype . _next = function ( ) {
72- // Skip whitespace (zero or more)
73- var whitespaceLen = whitespaceRegex . exec ( this . _remain ) [ 0 ] . length ;
74- this . _pos += whitespaceLen ;
75- this . _remain = this . _remain . slice ( whitespaceLen ) ;
78+ while ( 1 ) {
79+ // Skip whitespace (one or more)
80+ var whitespaceMatch = whitespaceRegex . exec ( this . _remain ) ;
81+ if ( whitespaceMatch ) {
82+ var whitespaceLen = whitespaceMatch [ 0 ] . length ;
83+ this . _skip ( whitespaceLen ) ;
84+ }
85+
86+ // Skip comment
87+ var commentMatch = commentRegex . exec ( this . _remain ) ;
88+ if ( ! commentMatch ) break ;
89+ var commentLen = commentMatch [ 0 ] . length ;
90+ this . _skip ( commentLen ) ;
91+ }
7692
7793 // Remember the current atom
7894 this . _currentAtom = this . _nextAtom ;
Original file line number Diff line number Diff line change 104104 \end{algorithmic}
105105 \end{algorithm}
106106 </ pre >
107- <!-- Chapter 7, Introduction to Algorithms (3rd edition)-->
108107 < pre id ="test-examples " style ="display:none ">
108+ % This quicksort algorithm is extracted from Chapter 7, Introduction
109+ % to Algorithms (3rd edition)
109110 \begin{algorithm}
110111 \caption{Quicksort}
111112 \begin{algorithmic}
You can’t perform that action at this time.
0 commit comments