Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenquotes.git

Resolve additional edge cases

AuthorDave Jarvis <email>
Date2021-06-13 22:46:53 GMT-0700
Commit247e05a3dc0b5ecf9eb72f635c607a803290ed06
Parent8b8f90c
lib/src/main/java/com/keenwrite/quotes/Parser.java
mClosingSingleQuote++;
}
+ else if( lex2.isType( QUOTE_SINGLE ) && lex1.isType( SPACE ) &&
+ lex3.anyType( HYPHEN, NUMBER ) ) {
+ consumer.accept( new Token( QUOTE_OPENING_SINGLE, lex2 ) );
+ mOpeningSingleQuote++;
+ }
else if( lex2.anyType( QUOTE_SINGLE, QUOTE_DOUBLE ) ) {
// After tokenizing, the parser will attempt to resolve ambiguities.
else if( ambiguousLeadingCount == 0 && unresolved.size() == 1 ) {
// Must be a closing quote.
- final var lex = unresolved.get( 0 );
- consumer.accept( new Token( QUOTE_CLOSING_SINGLE, lex[ 1 ] ) );
- unresolved.remove( lex );
+ final var closing = unresolved.get( 0 );
+ consumer.accept( new Token( QUOTE_CLOSING_SINGLE, closing[ 1 ] ) );
+ unresolved.remove( closing );
}
}
if( resolvedLaggingQuotes < resolvedLeadingQuotes ) {
for( final var i = unresolved.iterator(); i.hasNext(); ) {
- final var lex = i.next()[ 1 ];
- consumer.accept( new Token( QUOTE_CLOSING_SINGLE, lex ) );
+ final var closing = i.next()[ 1 ];
+ consumer.accept( new Token( QUOTE_CLOSING_SINGLE, closing ) );
+ i.remove();
+ }
+ }
+ else if( mOpeningSingleQuote - mClosingSingleQuote == unresolved.size() ) {
+ for( final var i = unresolved.iterator(); i.hasNext(); ) {
+ final var closing = i.next();
+ consumer.accept( new Token( QUOTE_CLOSING_SINGLE, closing[ 1 ] ) );
i.remove();
}
+ }
+ else if( unresolved.size() == 2 ) {
+ final var closing = unresolved.get( 0 );
+ final var opening = unresolved.get( 1 );
+ consumer.accept( new Token( QUOTE_CLOSING_SINGLE, closing[ 1 ] ) );
+ consumer.accept( new Token( QUOTE_OPENING_SINGLE, opening[ 1 ] ) );
+
+ unresolved.clear();
}
}
else if( ambiguousLeadingCount == 1 && resolvedLaggingQuotes == 1 ) {
- final var lex = ambiguousLeadingQuotes.get( 0 );
- consumer.accept( new Token( QUOTE_OPENING_SINGLE, lex[ 1 ] ) );
- unresolved.remove( lex );
+ final var opening = ambiguousLeadingQuotes.get( 0 );
+ consumer.accept( new Token( QUOTE_OPENING_SINGLE, opening[ 1 ] ) );
+ unresolved.remove( opening );
}
}
lib/src/test/java/com/keenwrite/quotes/SmartQuotesTest.java
public void test_parse_SingleLine_Parsed() {
out.println( SmartQuotes.replace(
- "What's this '-5.5''' thing?"
+ "What's this '-5.5''' and other '-10.2'' cm' and another '-7.25''' thing?"
) );
}
lib/src/test/resources/com/keenwrite/quotes/smartypants.txt
Bob&apos;s table is 5&prime;×4&prime;.
-#What's this '-5.5''' thing?
-#What&apos;s this &lsquo;-5.5&Prime;&rsquo; thing?
+What's this '-5.5''', '-10.2'' cm', and another '-7.25''' thing?
+What&apos;s this &lsquo;-5.5&Prime;&rsquo;, &lsquo;-10.2&Prime; cm&rsquo;, and another &lsquo;-7.25&Prime;&rsquo; thing?
'What's this -5.5'' thing?'
'He said, "Thinkin'."'
&lsquo;He said, &ldquo;Thinkin&apos;.&rdquo;&rsquo;
+
+''Sup, Doc?'
+&lsquo;&apos;Sup, Doc?&rsquo;
# ########################################################################
Delta34 lines added, 11 lines removed, 23-line increase