Changeset 161


Ignore:
Timestamp:
10/18/02 21:35:47 (21 years ago)
Author:
piso
Message:

Handle multi-line quoted strings correctly.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/j/LispSyntaxIterator.java

    r2 r161  
    33 *
    44 * Copyright (C) 1998-2002 Peter Graves
    5  * $Id: LispSyntaxIterator.java,v 1.1.1.1 2002-09-24 16:09:30 piso Exp $
     5 * $Id: LispSyntaxIterator.java,v 1.2 2002-10-18 21:35:47 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    2525// i.e. skipping whitespace and comments.
    2626public final class LispSyntaxIterator extends DefaultSyntaxIterator
     27    implements Constants
    2728{
    2829    public LispSyntaxIterator(Position pos)
     
    3132    }
    3233
     34    // Caller must make sure parseBuffer() has been called so flags will be
     35    // correct.
     36    public char[] hideSyntacticWhitespace(Line line)
     37    {
     38        if (line.flags() == STATE_QUOTE)
     39            return hideSyntacticWhitespace(line.getText(), STATE_QUOTE);
     40        else
     41            return hideSyntacticWhitespace(line.getText(), STATE_NEUTRAL);
     42    }
     43
     44    public char[] hideSyntacticWhitespace(String s)
     45    {
     46        return hideSyntacticWhitespace(s, STATE_NEUTRAL);
     47    }
     48
    3349    // Returns char array with syntactic whitespace (quotes and comments)
    3450    // replaced with actual space characters.
    35     public char[] hideSyntacticWhitespace(String s)
     51    public char[] hideSyntacticWhitespace(String s, int initialState)
    3652    {
    3753        char[] chars = s.toCharArray();
    38         boolean inQuote = false;
     54        int state = initialState;
    3955        int length = chars.length;
    4056        for (int i = 0; i < length; i++) {
    4157            char c = chars[i];
    42             if (inQuote) {
     58            if (c == '\\' && i < length-1) {
     59                // Escape character.
     60                chars[i++] = ' ';
    4361                chars[i] = ' ';
    44                 if (c == '\\' && i < length-1) {
    45                     // Handle escape char.
    46                     chars[++i] = ' ';
    47                 } else if (c == '"')
    48                     inQuote = false;
     62                continue;
     63            }
     64            if (state == STATE_QUOTE) {
     65                chars[i] = ' ';
     66                if (c == '"')
     67                    state = STATE_NEUTRAL;
    4968            } else if (c == '"') {
    50                 inQuote = true;
     69                state = STATE_QUOTE;
    5170                chars[i] = ' ';
    5271            }
     
    5574        int index = -1;
    5675        for (int i = 0; i < length-1; i++) {
    57             if (chars[i] == ';') {
     76            if (chars[i] == '\\')
     77                ++i; // Escape character.
     78            else if (chars[i] == ';') {
    5879                index = i;
    5980                break;
Note: See TracChangeset for help on using the changeset viewer.