Changeset 1136


Ignore:
Timestamp:
Jul 2, 2011, 12:06:23 PM (6 years ago)
Author:
stefan
Message:

implemented math mode error detection

Location:
trunk/src/jlatexeditor/syntaxhighlighting
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/jlatexeditor/syntaxhighlighting/LatexSyntaxHighlighting.java

    r1123 r1136  
    210210            sce_char.style = stateStyles[LatexStyles.MATH];
    211211
    212             boolean doubleMath = chars[char_nr + 1].character == '$';
    213             if (doubleMath) {
     212            MathMode.Type type = row.length > char_nr+1 && chars[char_nr+1].character == '$' ? MathMode.Type.doubled : MathMode.Type.simple;
     213            if (type == MathMode.Type.doubled) {
    214214              char_nr++;
    215215              chars[char_nr].style = stateStyles[LatexStyles.MATH];
    216216            }
    217217
     218            MathMode mathMode = new MathMode(type);
     219
    218220            // if active math mode -> close; otherwise open
    219221            if (state instanceof MathMode) {
    220               stateStack.pop();
    221               state = stateStack.peek();
     222              if (state.equals(mathMode)) {
     223                stateStack.pop();
     224                state = stateStack.peek();
     225              } else {
     226                chars[char_nr].style = stateStyles[LatexStyles.ERROR];
     227              }
    222228            } else {
    223               stateStack.push(state = new MathMode(doubleMath));
     229              stateStack.push(state = mathMode);
    224230            }
    225231
  • trunk/src/jlatexeditor/syntaxhighlighting/states/MathMode.java

    r744 r1136  
    88 */
    99public class MathMode implements ParserState {
    10   private boolean doubleMath;
     10  public enum Type { simple, doubled, bracket, parenthesis }
     11
    1112  private static byte[] styles = new byte[256];
    1213
     
    1819  }
    1920
    20   public MathMode(boolean doubleMath) {
    21     this.doubleMath = doubleMath;
    22   }
     21  private Type type;
    2322
    24   @Override
     23  public MathMode(Type type) {
     24    this.type = type;
     25  }
     26
     27  @Override
    2528  public boolean equals(Object obj) {
    2629    if (obj instanceof MathMode) {
    27       MathMode mathMode = (MathMode) obj;
    28 
     30      MathMode that = (MathMode) obj;
     31      return this.type.equals(that.type);
    2932    }
    3033    return false;
     
    3235
    3336  public ParserState copy() {
    34     return new MathMode(doubleMath);
     37    return new MathMode(type);
    3538  }
    3639
     
    3841    return styles;
    3942  }
    40 
    41   public boolean isDoubleMath() {
    42     return doubleMath;
    43   }
    4443}
Note: See TracChangeset for help on using the changeset viewer.