Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenquotes.git
lib/src/main/java/com/keenwrite/quotes/Parser.java
package com.keenwrite.quotes;
-import java.util.ArrayDeque;
-import java.util.Deque;
+import java.util.ArrayList;
+import java.util.List;
import java.util.function.Consumer;
import static com.keenwrite.quotes.Contractions.beginsUnambiguously;
import static com.keenwrite.quotes.Lexeme.EOT;
import static com.keenwrite.quotes.LexemeType.*;
import static com.keenwrite.quotes.TokenType.*;
+import static java.util.Comparator.comparingInt;
/**
private final Lexer mLexer;
- private final Deque<Lexeme> mQuotations = new ArrayDeque<>();
+ private final List<Lexeme[]> mQuotationMarks = new ArrayList<>();
private final CircularFifoQueue<Lexeme> mLexemes =
new CircularFifoQueue<>( 3 );
for( int i = 0; i < mLexemes.size(); i++ ) {
parse( mLexemes.get( i ), consumer );
+ }
+
+ mQuotationMarks.sort( comparingInt( lexemes -> lexemes[ 0 ].began() ) );
+
+ for( final var unparsed : mQuotationMarks ) {
+ System.out.println( "unparsed: " + unparsed[ 0 ] + " " + unparsed[ 1 ] + " " + unparsed[ 2 ] );
}
}
else if( lex1.isType( QUOTE_SINGLE ) && lex2.isType( WORD ) &&
- // E.g., 'contraction
+ // E.g., 'twas
beginsUnambiguously( lex2.toString( mText ) ) ) {
consumer.accept( new Token( QUOTE_APOSTROPHE, lex1 ) );
consumer.accept( new Token( QUOTE_STRAIGHT_DOUBLE, lex1 ) );
}
- else if( lex1.anyType( QUOTE_SINGLE, QUOTE_DOUBLE ) ) {
- mQuotations.push( lex1 );
- System.out.println( "FOUND QUOTE: " + lex1 + " " + lex1.toString( mText ) );
+ else if( lex2.anyType( QUOTE_SINGLE, QUOTE_DOUBLE ) ) {
+ mQuotationMarks.add( new Lexeme[]{lex1, lex2, lex3} );
}
}
lib/src/main/java/com/keenwrite/quotes/SmartQuotes.java
final var tokens = new ArrayList<Token>();
+ // Store all parsed quotation marks; the parser may emit them in any order.
parser.parse( tokens::add );
sort( tokens );
lib/src/test/java/com/keenwrite/quotes/SmartQuotesTest.java
public class SmartQuotesTest {
@Test
+ public void test_parse_SingleLine_Parsed() {
+ final var fixer = new SmartQuotes();
+ final var output = fixer.replace( "Didn' get th' message." );
+ System.out.println( output );
+ }
+
+ @Test
public void test_Parse_StraightQuotes_CurlyQuotes() throws IOException {
final var fixer = new SmartQuotes();

Capture lexeme triplet for quotation mark

Author Dave Jarvis <email>
Date 2021-06-02 00:12:00 GMT-0700
Commit 0583ec0bfff45423edcbcd127e7dd6e197209774
Parent 5499eb1
Delta 21 lines added, 7 lines removed, 14-line increase