package net.ranides.assira.grammar.impl;

import lombok.experimental.UtilityClass;
import net.ranides.assira.grammar.G4ErrorHandler;
import org.antlr.v4.runtime.BaseErrorListener;
import org.antlr.v4.runtime.DiagnosticErrorListener;
import org.antlr.v4.runtime.Parser;
import org.antlr.v4.runtime.RecognitionException;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.atn.ATNConfigSet;
import org.antlr.v4.runtime.dfa.DFA;

import java.util.BitSet;
import java.util.regex.Pattern;

@UtilityClass
class NodeSupport  {

    public static final String QUALIFIER_NAME = "#";
    public static final String QUALIFIER_INDEX = "$";
    public static final String QUALIFIER_INDEX_DEFAULT = "$1";

    public static final String PARENT_SELECTOR = "..";
    public static final String LABEL_SELECTOR = "@";
    public static final Pattern INDEX_SELECTOR = Pattern.compile("([^\\[]+)\\[(0-9+)\\]");
    public static final String INDEX_SUFFIX = "]";
    public static final Pattern POSITION_SELECTOR = Pattern.compile("[0-9]+");

    public static class DelegateListener extends BaseErrorListener {

        private final G4ErrorHandler handler;

        public DelegateListener(G4ErrorHandler handler) {
            this.handler = handler;
        }

        @Override
        public void syntaxError(Recognizer<?, ?> recognizer,
            Object offendingSymbol,
            int line,
            int charPositionInLine,
            String msg,
            RecognitionException e
        ) {
            handler.onError(msg, e);
        }

    }



}
