package com.dwarfartisan.parsec;

import java.io.EOFException;

/**
 * Created by Mars Liu on 2016-01-03.
 */
public class Between<T, E, O, C> implements Parsec<T, E> {
    private Parsec<O, E> open;
    private Parsec<C, E> close;
    private Parsec<T, E> parsec;

    @Override
    public T parse(State<E> s) throws EOFException, ParsecException {
        open.parse(s);
        T re = parsec.parse(s);
        close.parse(s);
        return re;
    }

    public Between(Parsec<O, E> open, Parsec<C, E> close, Parsec<T, E> parsec) {
        this.open = open;
        this.close = close;
        this.parsec = parsec;
    }


    public class In {
        private Parsec<O, E> open;
        private Parsec<C, E> close;
        public In(Parsec<O, E> open, Parsec<C, E> close) {
            this.open = open;
            this.close = close;
        }
        public Parsec<T, E> pack(Parsec<T, E> parser) {
            return new Between<>(this.open, this.close, parser);
        }
    }
}

@@ -621,24 +621,31 @@
     %7D%0A%0A%0A    
+static 
 public class
@@ -647,16 +647,28 @@
 class In
+%3CT, E, O, C%3E
  %7B%0A     

make between in advance use a static curry subclass