text:
package com.reason.lang.reason;

import com.intellij.lang.*;
import com.intellij.psi.tree.*;
import com.reason.lang.*;
import org.jetbrains.annotations.*;

import static com.intellij.codeInsight.completion.CompletionUtilCore.*;

public class RmlParser extends CommonPsiParser {
    RmlParser(boolean isSafe) {
        super(isSafe);
    }

    @Override
    protected ORParser<RmlTypes> getORParser(@NotNull PsiBuilder builder) {
        return new RmlParserState(builder, myIsSafe);
    }

    static class RmlParserState extends ORLanguageParser<RmlTypes> {
        public RmlParserState(@NotNull PsiBuilder builder, boolean isSafe) {
            super(RmlTypes.INSTANCE, builder, isSafe);
        }

        @Override
        public void parse() {
            IElementType tokenType;

            long parseStart = System.currentTimeMillis();
            int parseCount = 0;

            while (!myBuilder.eof()) {
                parseCount++;
                if (parseCount > 100) {
                    parseCount = 0;
                    long parseTime = System.currentTimeMillis();
                    if (PARSE_MAX_TIME < parseTime - parseStart) {
                        if (myIsSafe) { // Don't do that in tests
                            error("Parsing cancelled, you should create a github issue with the source code");
                            break;
                        }
                    }
                }

                tokenType = myBuilder.getTokenType();

                if (in(myTypes.C_INTERPOLATION_EXPR)) {
                    // special analysis when inside an interpolation string
                    if (tokenType == myTypes.JS_STRING_CLOSE) {
                        parseJsStringClose();
                    } else if (tokenType == myTypes.DOLLAR) {
                        if (is(myTypes.C_INTERPOLATION_PART)) {
                            popEnd();
                            advance().mark(myTypes.C_INTERPOLATION_REF);
                        } else if (is(myTypes.C_INTERPOLATION_EXPR)) {
                            // first element
                            advance().mark(myTypes.C_INTERPOLATION_REF);
                        }
                    } else if (is(myTypes.C_INTERPOLATION_REF)) {
                        advance().popEnd();
                    } else if (!is(myTypes.C_INTERPOLATION_PART)) {
                        mark(myTypes.C_INTERPOLATION_PART);
                    }
                } else {
                    if (tokenType == myTypes.SEMI) {
                        parseSemi();
                    } else if (tokenType == myTypes.EQ) {
                        parseEq();
                    } else if (tokenType == myTypes.ARROW) {
                        parseArrow();
                    } else if (tokenType == myTypes.REF) {
                        parseRef();
                    } else if (tokenType == myTypes.OPTION) {
                        parseOption();
                    } else if (tokenType == myTypes.MATCH) {
                        parseMatch();
                    } else if (tokenType == myTypes.TRY) {
                        parseTry();
                    } else if (tokenType == myTypes.SWITCH) {
                        parseSwitch();
                    } else if (tokenType == myTypes.LIDENT) {
                        parseLIdent();
                    } else if (tokenType == myTypes.UIDENT) {
                        parseUIdent();
                    } else if (tokenType == myTypes.POLY_VARIANT) {
                        parsePolyVariant();
                    } else if (tokenType == myTypes.ARROBASE) {
                        parseArrobase();
                    } else if (tokenType == myTypes.PERCENT) {
                        parsePercent();
                    } else if (tokenType == myTypes.COLON) {
                        parseColon();
                    } else if (tokenType == myTypes.RAW) {
                        parseRaw();
                    } else if (tokenType == myTypes.STRING_VALUE) {
                        parseStringValue();
                    } else if (tokenType == myTypes.PIPE) {
                        parsePipe();
                    } else if (tokenType == myTypes.COMMA) {
                        parseComma();
                    } else if (tokenType == myTypes.AND) {
                        parseAnd();
                    } else if (tokenType == myTypes.FUN) {
                        parseFun();
                    } else if (tokenType == myTypes.ASSERT) {
                        parseAssert();
                    } else if (tokenType == myTypes.IF) {
                        parseIf();
                    } else if (tokenType == myTypes.ELSE) {
                        parseElse();
                    } else if (tokenType == myTypes.THEN) {
                        parseThen();
                    } else if (tokenType == myTypes.DOT) {
                        parseDot();
                    } else if (tokenType == myTypes.DOTDOTDOT) {
                        parseDotDotDot();
                    } else if (tokenType == myTypes.WITH) {
                        parseWith();
                    } else if (tokenType == myTypes.TILDE) {
                        parseTilde();
                    } else if (tokenType == myTypes.QUESTION_MARK) {
                        parseQuestionMark();
                    } else if (tokenType == myTypes.UNDERSCORE) {
                        parseUnderscore();
                    }
                    // ( ... )
                    else if (tokenType == myTypes.LPAREN) {
                        parseLParen();
                    } else if (tokenType == myTypes.RPAREN) {
                        parseRParen();
                    }
                    // { ... }
                    else if (tokenType == myTypes.LBRACE) {
                        parseLBrace();
                    } else if (tokenType == myTypes.RBRACE) {
                        parseRBrace();
                    }
                    // [| ... |]
                    else if (tokenType == myTypes.LARRAY) {
                        parseLArray();
                    } else if (tokenType == myTypes.RARRAY) {
                        parseRArray();
                    }
                    // [ ... ]
                    // [> ... ]
                    else if (tokenType == myTypes.LBRACKET) {
                        parseLBracket();
                    } else if (tokenType == myTypes.BRACKET_GT) {
                        parseBracketGt();
                    } else if (tokenType == myTypes.RBRACKET) {
                        parseRBracket();
                    }
                    // < ... >
                    else if (tokenType == myTypes.LT) {
                        parseLt();
                    } else if (tokenType == myTypes.TAG_LT_SLASH) {
                        parseLtSlash();
                    } else if (tokenType == myTypes.GT) {
                        parseGt();
                    } else if (tokenType == myTypes.TAG_AUTO_CLOSE) {
                        parseGtAutoClose();
                    }
                    // {| ... |}
                    else if (tokenType == myTypes.ML_STRING_OPEN) {
                        parseMlStringOpen();
                    } else if (tokenType == myTypes.ML_STRING_CLOSE) {
                        parseMlStringClose();
                    }
                    // {j| ... |j}
                    else if (tokenType == myTypes.JS_STRING_OPEN) {
                        parseJsStringOpen();
                    }
                    // Starts an expression
                    else if (tokenType == myTypes.OPEN) {
                        parseOpen();
                    } else if (tokenType == myTypes.INCLUDE) {
                        parseInclude();
                    } else if (tokenType == myTypes.EXTERNAL) {
                        parseExternal();
                    } else if (tokenType == myTypes.TYPE) {
                        parseType();
                    } else if (tokenType == myTypes.MODULE) {
                        parseModule();
                    } else if (tokenType == myTypes.CLASS) {
                        parseClass();
                    } else if (tokenType == myTypes.LET) {
                        parseLet();
                    } else if (tokenType == myTypes.VAL) {
                        parseVal();
                    } else if (tokenType == myTypes.PUB) {
                        parsePub();
                    } else if (tokenType == myTypes.EXCEPTION) {
                        parseException();
                    }
                }

                if (dontMove) {
                    dontMove = false;
                } else {
                    myBuilder.advanceLexer();
                }
            }
        }

        private void parsePolyVariant() {
            if (isRawParent(myTypes.C_TYPE_BINDING)) {
                // type t = [ |>`xxx<| ...
                mark(myTypes.C_VARIANT_DECLARATION);
            }
            advance();
            markParenthesisScope(false);
        }

        private void parseUnderscore() {
            if (is(myTypes.C_PARAMETERS) && isRawParent(myTypes.C_FUNCTION_EXPR)) {
                // ( |>_<| ...
                mark(myTypes.C_PARAM_DECLARATION);
            } else {
                IElementType nextElementType = lookAhead(1);
                if (nextElementType == myTypes.ARROW && strictlyInAny(myTypes.C_LET_BINDING, myTypes.C_DEFAULT_VALUE, myTypes.C_PARAM, myTypes.C_FIELD_VALUE)) {
                    // A paren-less function definition ::  |>_<| =>
                    mark(myTypes.C_FUNCTION_EXPR)
                            .mark(myTypes.C_PARAMETERS)
                            .mark(myTypes.C_PARAM_DECLARATION)
                            .wrapAtom(myTypes.CA_LOWER_SYMBOL);
                }
            }
        }

        private void parseTilde() {
            IElementType nextType = rawLookup(1);
            if (nextType == myTypes.LIDENT) {
                if (isCurrent(myTypes.C_PARAM_DECLARATION)) {
                    markBefore(0, myTypes.C_PARAM_DECLARATION)
                            .updateComposite(myTypes.H_NAMED_PARAM_DECLARATION).updateToHolder()
                            .advance().wrapAtom(myTypes.CA_LOWER_SYMBOL);
                } else if (isCurrent(myTypes.C_SIG_ITEM)) {
                    mark(myTypes.C_PARAM_DECLARATION)
                            .markHolder(myTypes.H_NAMED_PARAM_DECLARATION)
                            .advance().wrapAtom(myTypes.CA_LOWER_SYMBOL);
                } else {
                    if (isCurrent(myTypes.C_PARAMETERS) && in(myTypes.C_FUNCTION_EXPR)) {
                        mark(myTypes.C_PARAM_DECLARATION).markHolder(myTypes.H_NAMED_PARAM_DECLARATION);
                    } else if (isCurrent(myTypes.C_PARAM)) {
                        updateComposite(myTypes.C_NAMED_PARAM);
                    } else {
                        mark(myTypes.C_NAMED_PARAM);
                    }
                    advance().wrapAtom(myTypes.CA_LOWER_SYMBOL);
                }
            }
        }

        private void parseQuestionMark() {
            if (is(myTypes.C_TAG_START)) {
                // <jsx |>?<|prop ...
                mark(myTypes.C_TAG_PROPERTY)
                        .setWhitespaceSkippedCallback(endJsxPropertyIfWhitespace())
                        .advance()
                        .remapCurrentToken(myTypes.PROPERTY_NAME);
            } else if (strictlyIn(myTypes.C_IF_THEN_SCOPE)) {
                // if_then_scope can be inside a ternary
                parseTernary();
            } else if (!strictlyInAny(myTypes.C_TERNARY) && previousElementType(1) != myTypes.EQ /*default optional value*/) {
                if (inScopeOrAny(myTypes.C_LET_BINDING, myTypes.C_FIELD_VALUE, myTypes.C_PARAM_DECLARATION, myTypes.C_PARAM,
                        myTypes.C_PATTERN_MATCH_BODY, myTypes.C_IF_THEN_SCOPE, myTypes.C_FUNCTION_BODY, myTypes.H_COLLECTION_ITEM,
                        myTypes.C_DEFAULT_VALUE)) {
                    // a new ternary
                    parseTernary();
                }
            }
        }

        private void parseTernary() {
            // «placeHolder» ... |>?<| ...
            int foundPos = getIndex();
            int nextPos = foundPos - 1;
            if (isAtIndex(nextPos, myTypes.H_PLACE_HOLDER)) {
                markBefore(nextPos, myTypes.C_TERNARY)
                        .updateCompositeAt(nextPos, myTypes.C_BINARY_CONDITION)
                        .popEndUntilIndex(nextPos).end()
                        .advance().mark(myTypes.C_IF_THEN_SCOPE);
                markHolder(myTypes.H_PLACE_HOLDER);
            } else if (isAtIndex(foundPos, myTypes.H_COLLECTION_ITEM)) {
                markHolderBefore(foundPos, myTypes.H_COLLECTION_ITEM);
                markBefore(foundPos, myTypes.C_TERNARY)
                        .updateCompositeAt(foundPos, myTypes.C_BINARY_CONDITION)
                        .popEndUntilIndex(foundPos).end()
                        .advance().mark(myTypes.C_IF_THEN_SCOPE);
            }
        }

        private void parseRef() {
            if (strictlyIn(myTypes.C_TAG_START)) {
                remapCurrentToken(myTypes.PROPERTY_NAME)
                        .mark(myTypes.C_TAG_PROPERTY);
            }
        }

        private void generateJsxPropertyName() {
            remapCurrentToken(myTypes.PROPERTY_NAME)
                    .mark(myTypes.C_TAG_PROPERTY)
                    .setWhitespaceSkippedCallback(endJsxPropertyIfWhitespace());
        }

        private void parseOption() {
            if (strictlyIn(myTypes.C_TAG_START)) {
                generateJsxPropertyName();
            } else {
                mark(myTypes.C_OPTION);
            }
        }

        private void parseMatch() {
            if (strictlyIn(myTypes.C_TAG_START)) {
                generateJsxPropertyName();
            }
        }

        private void parseRaw() {
            if (is(myTypes.C_MACRO_NAME)) {
                // % |>raw<| ...
                advance().popEnd();
            }
        }

        private void parseIf() {
            mark(myTypes.C_IF);
        }

        private void parseThen() {
            // if ... |>then<| ...
            popEndUntil(myTypes.C_IF).advance()
                    .mark(myTypes.C_IF_THEN_SCOPE);
        }

        private void parseElse() {
            // if ... then ... |>else<| ...
            popEndUntil(myTypes.C_IF).advance()
                    .mark(myTypes.C_IF_THEN_SCOPE);
        }

        private void parseDot() {
            if (previousElementType(1) == myTypes.LBRACE && (is(myTypes.C_JS_OBJECT))) { // Js object definition
                // ... { |>.<| ... }
                advance().mark(myTypes.C_OBJECT_FIELD);
            }
        }

        private void parseDotDotDot() {
            if (previousElementType(1) == myTypes.LBRACE) { // Mixin, always first element in a record
                // { |>...<| x ...
                if (isCurrent(myTypes.C_FUNCTION_BODY)) {
                    markBefore(0, myTypes.C_FUNCTION_BODY)
                            .updateLatestComposite(myTypes.C_RECORD_EXPR)
                            .mark(myTypes.C_MIXIN_FIELD);
                } else {
                    popIfHold()
                            .updateComposite(myTypes.C_RECORD_EXPR)
                            .mark(myTypes.C_MIXIN_FIELD);
                }
            }
        }

        private void parseWith() {
            if (strictlyInAny(myTypes.C_FUNCTOR_RESULT, myTypes.C_MODULE_TYPE)) {
                // module M (X) : ( S |>with<| ... ) = ...
                popEndUntilFoundIndex().popEnd()
                        .advance().mark(myTypes.C_CONSTRAINTS);
            }
        }

        private void parseAssert() {
            mark(myTypes.C_ASSERT_STMT).advance();
        }

        private void parseFun() {
            if (isCurrent(myTypes.C_LET_BINDING) && isHold()) { // fun keyword is equivalent to a switch body
                // let x = |>fun<| | ...
                updateLatestComposite(myTypes.C_FUN_EXPR);
            }
        }

        private void parseAnd() {
            if (in(myTypes.C_TYPE_CONSTRAINT)) {
                // module M = (X) : ( S with ... |>and<| ... ) = ...
                popEndUntilFoundIndex().popEnd();
            } else {
                Marker scope = popEndUntilScope();
                if (scope != null) {
                    if (scope.isCompositeType(myTypes.C_TYPE_DECLARATION)) {
                        advance().mark(myTypes.C_TYPE_DECLARATION).setStart();
                    } else if (scope.isCompositeType(myTypes.C_LET_DECLARATION)) {
                        advance().mark(myTypes.C_LET_DECLARATION).setStart();
                    } else if (scope.isCompositeType(myTypes.C_MODULE_DECLARATION) || scope.isCompositeType(myTypes.C_MODULE_TYPE)) {
                        advance().mark(myTypes.C_MODULE_DECLARATION).setStart();
                    }
                }
            }
        }

        private void parseComma() {
            if (inScopeOrAny(
                    myTypes.C_RECORD_FIELD, myTypes.C_OBJECT_FIELD, myTypes.C_MIXIN_FIELD,
                    myTypes.C_VARIANT_CONSTRUCTOR, myTypes.C_SIG_EXPR, myTypes.C_SIG_ITEM, myTypes.H_COLLECTION_ITEM,
                    myTypes.C_PARAMETERS, myTypes.C_PARAM_DECLARATION, myTypes.C_NAMED_PARAM, myTypes.C_PARAM
            )) {

                if (isFound(myTypes.H_COLLECTION_ITEM)) {
                    popEndUntilFoundIndex().popEnd().advance();
                    markHolder(myTypes.H_COLLECTION_ITEM);
                    return;
                }
                if (isFound(myTypes.C_SCOPED_EXPR) && isAtIndex(getIndex() + 1, myTypes.C_LET_DECLARATION)) { // It must be a deconstruction
                    // let ( a |>,<| b ) = ...
                    // We need to do it again because lower symbols must be wrapped with identifiers
                    rollbackToFoundIndex()
                            .updateComposite(myTypes.C_DECONSTRUCTION);
                    return;
                }
                if (isFound(myTypes.C_SCOPED_EXPR) && isFoundScope(myTypes.LBRACE) && isAtIndex(getIndex() + 1, myTypes.C_PARAM_DECLARATION)) { // It must be a deconstruction in parameters
                    // { a |>,<| b } => ...
                    // We need to do it again because lower symbols must be wrapped with identifiers
                    rollbackToFoundIndex()
                            .updateComposite(myTypes.C_DECONSTRUCTION);
                    return;
                }

                if (isFound(myTypes.C_SIG_ITEM) || (isFound(myTypes.C_PARAM_DECLARATION) && isAtIndex(getIndex() + 1, myTypes.C_SIG_ITEM))) {
                    popEndUntilFoundIndex();
                    if (isRawParent(myTypes.H_COLLECTION_ITEM)) {
                        // ( ... |>,<|
                        popEnd().popEnd().advance()
                                .markHolder(myTypes.H_COLLECTION_ITEM)
                                .mark(myTypes.C_SIG_ITEM);
                        return;
                    }

                    // double sig ? ~x:int,
                    if (in(myTypes.C_PARAM_DECLARATION, /*not*/myTypes.C_SCOPED_EXPR)) {
                        popEndUntilFoundIndex().popEnd();
                    }
                    popEnd();
                }

                if (isScope(myTypes.LPAREN) && isRawParent(myTypes.C_SIG_EXPR)) {
                    // type t = ( ... |>,<|
                    advance().mark(myTypes.C_SIG_ITEM);
                } else if (strictlyInAny(myTypes.C_RECORD_FIELD, myTypes.C_OBJECT_FIELD)) {
                    boolean isRecord = isFound(myTypes.C_RECORD_FIELD);
                    popEndUntilFoundIndex().popEnd().advance();

                    IElementType tokenType = getTokenType();
                    if (tokenType != myTypes.RBRACE && tokenType != myTypes.LBRACKET) {
                        mark(isRecord ? myTypes.C_RECORD_FIELD : myTypes.C_OBJECT_FIELD);
                    }
                } else if (strictlyIn(myTypes.C_MIXIN_FIELD)) {
                    popEndUntilFoundIndex().popEnd().advance();
                } else if (strictlyIn(myTypes.C_DECONSTRUCTION)) {
                    popEndUntilScope();
                } else if (strictlyInAny(myTypes.C_PARAM_DECLARATION)) {
                    popEndUntilFoundIndex().popEnd().advance();
                    if (getTokenType() != myTypes.RPAREN) {
                        // not at the end of a list: ie not => (p1, p2<,> )
                        mark(myTypes.C_PARAM_DECLARATION);
                        markHolder(myTypes.H_PLACE_HOLDER);
                    }
                } else if (strictlyInAny(myTypes.C_NAMED_PARAM, myTypes.C_PARAM)) {
                    popEndUntilFoundIndex().popEnd().advance();
                    if (getTokenType() != myTypes.RPAREN) {
                        // not at the end of a list: ie not => (p1, p2<,> )
                        mark(myTypes.C_PARAM);
                        markHolder(myTypes.H_PLACE_HOLDER);
                    }
                } else if (strictlyInAny(myTypes.C_VARIANT_CONSTRUCTOR, myTypes.C_PARAMETERS)) {
                    popEndUntilFoundIndex().advance();
                    if (getTokenType() != myTypes.RPAREN) {
                        // not at the end of a list: ie not => (p1, p2<,> )
                        markHolder(myTypes.H_COLLECTION_ITEM);
                        mark(myTypes.C_PARAM_DECLARATION);
                        markHolder(myTypes.H_PLACE_HOLDER);
                    }
                } else if (strictlyIn(myTypes.C_SCOPED_EXPR)) {
                    popEndUntilFoundIndex();
                }
            }

        }

        private void parsePipe() {
            if (is(myTypes.C_TRY_HANDLERS)) {
                // try (...) { |>|<| ...
                mark(myTypes.C_TRY_HANDLER);
            } else if (is(myTypes.C_TYPE_BINDING)) {
                // type t = |>|<| ...
                popEndUntil(myTypes.C_TYPE_BINDING).advance()
                        .mark(myTypes.C_VARIANT_DECLARATION);
            } else if (in(myTypes.C_VARIANT_DECLARATION)) {
                // type t = | X |>|<| Y ...
                popEndUntilFoundIndex().popEnd().advance()
                        .mark(myTypes.C_VARIANT_DECLARATION);
            } else if (in(myTypes.C_PATTERN_MATCH_BODY)) {
                // can be a switchBody or a 'fun'
                if (!is(myTypes.C_SWITCH_BODY)) {
                    popEndUntil(myTypes.C_PATTERN_MATCH_EXPR).popEnd().advance();
                }
                mark(myTypes.C_PATTERN_MATCH_EXPR);
            } else {
                if (!is(myTypes.C_SWITCH_BODY) && in(myTypes.C_PATTERN_MATCH_EXPR, /*not*/myTypes.C_PATTERN_MATCH_BODY)) { // pattern grouping
                    // | X |>|<| Y => ...
                    popEndUntilIndex(getIndex()).popEnd();
                }

                if (isScope(myTypes.LBRACKET) && isRawParent(myTypes.C_TYPE_BINDING)) {
                    // type t = [ |>|<| ...
                    advance().mark(myTypes.C_VARIANT_DECLARATION);
                } else { // By default, a pattern match
                    advance().mark(myTypes.C_PATTERN_MATCH_EXPR);
                }
            }
        }

        private void parseStringValue() {
            if (is(myTypes.C_MACRO_EXPR)) {
                // [%raw |>"x"<| ...
                wrapWith(myTypes.C_MACRO_BODY);
            } else if (in(myTypes.C_MACRO_NAME)) {
                // [@bs |>"x<| ...
                popEndUntilScope();
            } else if (is(myTypes.C_JS_OBJECT)) {
                mark(myTypes.C_OBJECT_FIELD).wrapAtom(myTypes.CA_LOWER_SYMBOL);
            } else if (is(myTypes.C_OBJECT_FIELD)) {
                wrapAtom(myTypes.CA_LOWER_SYMBOL);
            }
        }

        private void parseMlStringOpen() {
            if (is(myTypes.C_MACRO_EXPR)) {
                mark(myTypes.C_MACRO_BODY);
            }

            markScope(myTypes.C_ML_INTERPOLATOR, myTypes.ML_STRING_OPEN);
        }

        private void parseMlStringClose() {
            Marker scope = popEndUntilScopeToken(myTypes.ML_STRING_OPEN);
            advance();

            if (scope != null) {
                popEnd();
            }
        }

        private void parseJsStringOpen() {
            markScope(myTypes.C_INTERPOLATION_EXPR, myTypes.JS_STRING_OPEN);
        }

        private void parseJsStringClose() {
            Marker scope = popEndUntilScopeToken(myTypes.JS_STRING_OPEN);
            advance();

            if (scope != null) {
                popEnd();
            }
        }

        private void parseLet() {
            mark(myTypes.C_LET_DECLARATION).setStart();
        }

        private void parseVal() {
            if (!in(myTypes.C_MACRO_NAME)) {
                popEndUntilScope();
                if (is(myTypes.C_OBJECT)) {
                    mark(myTypes.C_CLASS_FIELD);
                }
            }
        }

        private void parsePub() {
            if (in(myTypes.C_OBJECT)) {
                popEndUntil(myTypes.C_OBJECT).
                        mark(myTypes.C_CLASS_METHOD);
            }
        }

        private void parseModule() {
            if (is(myTypes.C_SIG_ITEM)) {
                // let fn = (~x : ( |>module<| ... ) ...
                mark(myTypes.C_MODULE_VALUE);
            } else if (in(myTypes.C_DEFAULT_VALUE)) {
                // let fn = (~x:(module X)= ( |>module<| ... ) ...
                popIfHold()
                        .updateLatestComposite(myTypes.H_PLACE_HOLDER).dropLatest()
                        .mark(myTypes.C_MODULE_VALUE);
            } else if (!in(myTypes.C_MACRO_NAME)) {
                popEndUntilScope();
                mark(myTypes.C_MODULE_DECLARATION).setStart();
            }
        }

        private void parseException() {
            popEndUntilScope();
            mark(myTypes.C_EXCEPTION_DECLARATION).setStart();
        }

        private void parseClass() {
            popEndUntilScope();
            mark(myTypes.C_CLASS_DECLARATION).setStart();
        }

        private void parseType() {
            if (is(myTypes.C_CONSTRAINTS)) {
                // module M = (X) : ( S with |>type<| ... ) = ...
                mark(myTypes.C_TYPE_CONSTRAINT);
            } else if (!is(myTypes.C_MODULE_DECLARATION) && !is(myTypes.C_CLASS_DECLARATION)) {
                popEndUntilScope();
                mark(myTypes.C_TYPE_DECLARATION).setStart();
            }
        }

        private void parseExternal() {
            popEndUntilScope();
            mark(myTypes.C_EXTERNAL_DECLARATION).setStart();
        }

        private void parseOpen() {
            popEndUntilScope();
            mark(myTypes.C_OPEN);
        }

        private void parseInclude() {
            popEndUntilScope();
            mark(myTypes.C_INCLUDE);
        }

        private void parsePercent() {
            if (is(myTypes.C_MACRO_EXPR)) {
                mark(myTypes.C_MACRO_NAME);
            } else if (in(myTypes.C_LET_DECLARATION)) {
                // let name|>%<|private = ...
                mark(myTypes.C_LET_ATTR);
            } else {
                IElementType nextTokenType = rawLookup(1);
                if (nextTokenType == myTypes.RAW) {
                    // |>%<| raw ...
                    mark(myTypes.C_MACRO_EXPR).
                            mark(myTypes.C_MACRO_NAME);
                }
            }
        }

        private void parseColon() {
            if (isCurrent(myTypes.C_MODULE_DECLARATION)) {
                // module M |> :<| ...
                advance();
                boolean isParen = getTokenType() == myTypes.LPAREN;
                if (isParen) {
                    // module M : |>(<| ...
                    advance();
                }
                mark(myTypes.C_MODULE_TYPE).updateScopeToken(isParen ? myTypes.LPAREN : null);
            } else if (isRawParent(myTypes.C_EXTERNAL_DECLARATION) || isRawParent(myTypes.C_LET_DECLARATION)) {
                // external/let e |> :<| ...
                advance().mark(myTypes.C_SIG_EXPR);
                if (getTokenType() == myTypes.LPAREN) {
                    // external/let e : |>(<| ...
                    markDummyScope(myTypes.C_SCOPED_EXPR, myTypes.LPAREN).advance();
                    if (getTokenType() == myTypes.DOT) {
                        // external/let e : ( |>.<| ...
                        advance();
                    }
                }
                mark(myTypes.C_SIG_ITEM);
            }
            //
            else if (inScopeOrAny(
                    myTypes.H_NAMED_PARAM_DECLARATION, myTypes.C_PARAM_DECLARATION, myTypes.C_NAMED_PARAM,
                    myTypes.C_RECORD_FIELD, myTypes.C_OBJECT_FIELD, myTypes.C_TERNARY
            )) {

                if (isFound(myTypes.H_NAMED_PARAM_DECLARATION) || isFound(myTypes.C_PARAM_DECLARATION) || isFound(myTypes.C_NAMED_PARAM)) {
                    // let x = (~y |> : <| ...
                    advance().mark(myTypes.C_SIG_EXPR);
                    markParenthesisScope(true).
                            mark(myTypes.C_SIG_ITEM);
                } else if (isFound(myTypes.C_RECORD_FIELD) || isFound(myTypes.C_OBJECT_FIELD)) {
                    advance();
                    if (in(myTypes.C_TYPE_BINDING)) {
                        mark(myTypes.C_SIG_EXPR)
                                .mark(myTypes.C_SIG_ITEM);
                    } else {
                        mark(myTypes.C_FIELD_VALUE);
                    }
                } else if (isFound(myTypes.C_TERNARY)) {
                    // x ? y |> :<| ...
                    popEndUntilFoundIndex()
                            .advance().mark(myTypes.C_IF_THEN_SCOPE);
                    markHolder(myTypes.H_PLACE_HOLDER);
                }

            }
        }

        private void parseArrobase() {
            if (is(myTypes.C_ANNOTATION)) {
                mark(myTypes.C_MACRO_NAME);
            }
        }

        private void parseLt() {
            // Can be a symbol or a JSX tag
            IElementType nextTokenType = rawLookup(1);
            // Note that option is a ReasonML keyword but also a JSX keyword !
            if (nextTokenType == myTypes.LIDENT || nextTokenType == myTypes.UIDENT || nextTokenType == myTypes.OPTION) {
                // Surely a tag
                mark(myTypes.C_TAG)
                        .markScope(myTypes.C_TAG_START, myTypes.LT)
                        .advance()
                        .remapCurrentToken(nextTokenType == myTypes.UIDENT ? myTypes.A_UPPER_TAG_NAME : myTypes.A_LOWER_TAG_NAME)
                        .wrapAtom(nextTokenType == myTypes.UIDENT ? myTypes.CA_UPPER_SYMBOL : myTypes.CA_LOWER_SYMBOL)
                        .popEnd();
            } else if (nextTokenType == myTypes.GT) {
                // a React fragment start
                mark(myTypes.C_TAG)
                        .mark(myTypes.C_TAG_START)
                        .advance().advance().popEnd();
            }
        }

        private void parseLtSlash() {
            IElementType nextTokenType = rawLookup(1);
            // Note that option is a ReasonML keyword but also a JSX keyword !
            if (nextTokenType == myTypes.LIDENT || nextTokenType == myTypes.UIDENT || nextTokenType == myTypes.OPTION) {
                // A closing tag
                if (in(myTypes.C_TAG_BODY)) {
                    popEndUntil(myTypes.C_TAG);
                }

                mark(myTypes.C_TAG_CLOSE)
                        .advance()
                        .remapCurrentToken(nextTokenType == myTypes.UIDENT ? myTypes.A_UPPER_TAG_NAME : myTypes.A_LOWER_TAG_NAME)
                        .wrapAtom(nextTokenType == myTypes.UIDENT ? myTypes.CA_UPPER_SYMBOL : myTypes.CA_LOWER_SYMBOL);
            } else if (nextTokenType == myTypes.GT) {
                // a React fragment end
                mark(myTypes.C_TAG_CLOSE)
                        .advance().advance().popEnd();
            }
        }

        private void parseGt() {
            if (isCurrent(myTypes.C_TAG_PROP_VALUE)) {
                // ?prop=value |> > <| ...
                popEndUntil(myTypes.C_TAG_PROP_VALUE).popEnd().popEnd();
            } else if (is(myTypes.C_TAG_PROPERTY)) {
                // ?prop |> > <| ...
                popEnd();
            }

            if (in(myTypes.C_TAG)) {
                if (inScopeOrAny(myTypes.C_TAG_PROP_VALUE, myTypes.C_TAG_START, myTypes.C_TAG_CLOSE)) {
                    advance().popEndUntilFoundIndex();
                    if (is(myTypes.C_TAG_START)) {
                        popEnd().mark(myTypes.C_TAG_BODY);
                    } else if (is(myTypes.C_TAG_CLOSE)) {
                        // end the tag
                        popEndUntil(myTypes.C_TAG).popEnd();
                    }
                }
            }
        }

        private void parseGtAutoClose() {
            popEndUntilScope();
            advance().popEnd(/*tag_start*/).popEnd(/*tag*/);
        }

        private void parseLIdent() {
            if (is(myTypes.C_LET_DECLARATION)) {
                // let |>x<| ...
                wrapAtom(myTypes.CA_LOWER_SYMBOL);
            } else if (is(myTypes.C_TYPE_DECLARATION)) {
                // type |>x<| ...
                wrapAtom(myTypes.CA_LOWER_SYMBOL);
            } else if (is(myTypes.C_EXTERNAL_DECLARATION)) {
                // external |>x<| ...
                wrapAtom(myTypes.CA_LOWER_SYMBOL);
            } else if (is(myTypes.C_CLASS_DECLARATION)) {
                // class |>x<| ...
                wrapAtom(myTypes.CA_LOWER_SYMBOL);
            } else if (is(myTypes.C_RECORD_EXPR)) {
                // let x = { |>y<| ...
                mark(myTypes.C_RECORD_FIELD).wrapAtom(myTypes.CA_LOWER_SYMBOL);
            } else if (is(myTypes.C_RECORD_FIELD)) {
                // let x = { y, |>z<| ...
                wrapAtom(myTypes.CA_LOWER_SYMBOL);
            } else if ((isCurrent(myTypes.C_PARAMETERS)) || isCurrent(myTypes.C_VARIANT_CONSTRUCTOR)) {
                // ( x , |>y<| ...
                mark(myTypes.C_PARAM_DECLARATION);
                markHolder(myTypes.H_PLACE_HOLDER);
                wrapAtom(myTypes.CA_LOWER_SYMBOL);
            } else if (strictlyInAny(myTypes.C_TAG_START, myTypes.C_TAG_PROP_VALUE)) {
                if (previousElementType(1) != myTypes.LT && isFound(myTypes.C_TAG_START)) {
                    // This is a property
                    popEndUntilScope();
                    generateJsxPropertyName();
                }
            } else {
                IElementType nextElementType = lookAhead(1);

                if (isCurrent(myTypes.C_SCOPED_EXPR) && isCurrentScope(myTypes.LBRACE) && nextElementType == myTypes.COLON) {
                    // this is a record usage ::  { |>x<| : ...
                    popIfHold()
                            .updateComposite(myTypes.C_RECORD_EXPR)
                            .mark(myTypes.C_RECORD_FIELD)
                            .wrapAtom(myTypes.CA_LOWER_SYMBOL);
                } else if (nextElementType == myTypes.LPAREN && !inAny(myTypes.C_TYPE_BINDING, myTypes.C_TYPE_CONSTRAINT, myTypes.C_SIG_ITEM)) {
                    mark(myTypes.C_FUNCTION_CALL)
                            .wrapAtom(myTypes.CA_LOWER_SYMBOL);
                } else if (is(myTypes.C_DECONSTRUCTION)) {
                    wrapAtom(myTypes.CA_LOWER_SYMBOL);
                } else if (nextElementType == myTypes.ARROW && strictlyInAny(
                        myTypes.C_LET_BINDING, myTypes.C_DEFAULT_VALUE, myTypes.C_PARAM, myTypes.C_FIELD_VALUE, myTypes.C_SCOPED_EXPR
                )) {
                    // A paren-less function definition ::  |>x<| =>
                    mark(myTypes.C_FUNCTION_EXPR)
                            .mark(myTypes.C_PARAMETERS)
                            .mark(myTypes.C_PARAM_DECLARATION)
                            .wrapAtom(myTypes.CA_LOWER_SYMBOL);
                } else {
                    wrapAtom(myTypes.CA_LOWER_SYMBOL);
                }
            }
        }

        private void parseLArray() {
            markScope(myTypes.C_SCOPED_EXPR, myTypes.LARRAY).advance();
            markHolder(myTypes.H_COLLECTION_ITEM);
        }

        private void parseRArray() {
            Marker scope = popEndUntilScopeToken(myTypes.LARRAY);
            advance();

            if (scope != null) {
                popEnd();
            }
        }

        private void parseLBracket() {
            IElementType nextType = rawLookup(1);

            if (nextType == myTypes.ARROBASE) {
                // |>[ <| @ ...
                markScope(myTypes.C_ANNOTATION, myTypes.LBRACKET);
            } else if (nextType == myTypes.PERCENT) {
                // |>[ <| % ...
                markScope(myTypes.C_MACRO_EXPR, myTypes.LBRACKET);
            } else if (previousElementType(2) == myTypes.A_MODULE_NAME && previousElementType(1) == myTypes.DOT) { // Local open
                // M.|>(<| ...
                markScope(myTypes.C_LOCAL_OPEN, myTypes.LBRACKET);
            } else if (nextType == myTypes.GT) {
                // |> [ <| > ... ]
                markScope(myTypes.C_OPEN_VARIANT, myTypes.LBRACKET).advance().advance();
                if (getTokenType() != myTypes.RBRACKET) {
                    mark(myTypes.C_VARIANT_DECLARATION).advance();
                }
            } else if (nextType == myTypes.LT) {
                // |> [ <| < ... ]
                markScope(myTypes.C_CLOSED_VARIANT, myTypes.LBRACKET).advance().advance();
                if (getTokenType() != myTypes.RBRACKET) {
                    mark(myTypes.C_VARIANT_DECLARATION).advance();
                }
            } else {
                markScope(myTypes.C_SCOPED_EXPR, myTypes.LBRACKET).advance();
                if (getTokenType() != myTypes.PIPE) {
                    markHolder(myTypes.H_COLLECTION_ITEM);
                }
            }
        }

        private void parseRBracket() {
            Marker scope = popEndUntilScopeToken(myTypes.LBRACKET);
            advance();

            if (scope != null) {
                popEnd();
            }
        }

        private void parseBracketGt() {
            markScope(myTypes.C_SCOPED_EXPR, myTypes.LBRACKET);
        }

        private void parseLBrace() {
            if (previousElementType(2) == myTypes.A_MODULE_NAME && previousElementType(1) == myTypes.DOT) { // Local open a js object or a record
                // Xxx.|>{<| ... }
                mark(myTypes.C_LOCAL_OPEN);
                IElementType nextElementType = lookAhead(1);
                if (nextElementType == myTypes.LIDENT) {
                    markScope(myTypes.C_RECORD_EXPR, myTypes.LBRACE);
                } else {
                    markScope(myTypes.C_JS_OBJECT, myTypes.LBRACE);
                }
            } else if (is(myTypes.C_TYPE_BINDING)) {
                boolean isJsObject = lookAhead(1) == myTypes.DOT;
                markScope(isJsObject ? myTypes.C_JS_OBJECT : myTypes.C_RECORD_EXPR, myTypes.LBRACE);
            } else if (is(myTypes.C_TRY_EXPR)) { // A try expression
                // try (..) |>{<| .. }
                markScope(myTypes.C_TRY_HANDLERS, myTypes.LBRACE);
            } else if (is(myTypes.C_MODULE_BINDING)) {
                // module M = |>{<| ...
                updateScopeToken(myTypes.LBRACE);
            } else if (is(myTypes.C_FUNCTOR_BINDING)) {
                // module M = (...) => |>{<| ...
                updateScopeToken(myTypes.LBRACE);
            } else if (isCurrent(myTypes.C_IF)) {
                markScope(myTypes.C_IF_THEN_SCOPE, myTypes.LBRACE);
            } else if (is(myTypes.C_MODULE_TYPE)) {
                // module M : |>{<| ...
                updateScopeToken(myTypes.LBRACE);
            } else if (in(myTypes.C_CLASS_DECLARATION)) {
                // class x = |>{<| ... }
                markScope(myTypes.C_OBJECT, myTypes.LBRACE);
            } else if (is(myTypes.C_SWITCH_EXPR)) {
                markScope(myTypes.C_SWITCH_BODY, myTypes.LBRACE);
            } else {
                // it might be a js object
                IElementType nextElement = lookAhead(1);
                if (nextElement == myTypes.STRING_VALUE || nextElement == myTypes.DOT) { // js object detected (in usage)
                    // |>{<| "x" ... }
                    markScope(myTypes.C_JS_OBJECT, myTypes.LBRACE);
                } else if (is(myTypes.C_FUNCTION_BODY) && !isScope(myTypes.LBRACE) && nextElement != myTypes.LIDENT) { // function body
                    // x => |>{<| ... }
                    updateScopeToken(myTypes.LBRACE);
                } else {
                    if (isHold()) {
                        popEnd();
                    }
                    markScope(myTypes.C_SCOPED_EXPR, myTypes.LBRACE)
                            .advance().markHolder(myTypes.H_PLACE_HOLDER);
                }
            }
        }

        private void parseRBrace() {
            Marker scope = popEndUntilOneOfElementType(myTypes.LBRACE, myTypes.RECORD, myTypes.SWITCH);
            advance();

            if (scope != null) {
                popEnd();

                if (is(myTypes.C_LOCAL_OPEN) && !rawHasScope()) {
                    // X.{ ... |>}<|
                    popEnd();
                } else if (is(myTypes.C_TAG_PROP_VALUE)) {
                    popEndUntil(myTypes.C_TAG_PROPERTY).popEnd();
                }
            }
        }

        private void parseLParen() {
            if (isCurrent(myTypes.C_PARAM_DECLARATION)) {
                markScope(myTypes.C_SCOPED_EXPR, myTypes.LPAREN).advance();
                markHolder(myTypes.H_PLACE_HOLDER);
            } else if (isCurrent(myTypes.C_PARAMETERS)) {
                if (!currentHasScope()) {
                    // |>(<| ... ) => ...
                    updateScopeToken(myTypes.LPAREN);
                    markHolder(myTypes.H_COLLECTION_ITEM);
                } else {
                    // ( |>(<| ... ) , ... ) => ...
                    mark(myTypes.C_PARAM_DECLARATION)
                            .markScope(myTypes.C_SCOPED_EXPR, myTypes.LPAREN).advance()
                            .markHolder(myTypes.H_COLLECTION_ITEM);
                }
            } else if (is(myTypes.C_ASSERT_STMT)) {
                // assert |>(<| ...
                markScope(myTypes.C_BINARY_CONDITION, myTypes.LPAREN);
            } else if (is(myTypes.C_TRY_EXPR)) {
                // try |>(<| ...
                markScope(myTypes.C_TRY_BODY, myTypes.LPAREN);
            } else if (is(myTypes.C_IF) || is(myTypes.C_SWITCH_EXPR)) {
                // if |>(<| ...  OR  switch |>(<| ...
                markScope(myTypes.C_BINARY_CONDITION, myTypes.LPAREN);
            } else if (is(myTypes.C_LET_DECLARATION)) { // Overloading operator OR deconstructing a term
                //  let |>(<| + ) =
                //  let |>(<| a, b ) =
                markScope(myTypes.C_SCOPED_EXPR, myTypes.LPAREN);
            } else if (previousElementType(2) == myTypes.A_MODULE_NAME && previousElementType(1) == myTypes.DOT) { // Local open
                // M.|>(<| ...
                markScope(myTypes.C_LOCAL_OPEN, myTypes.LPAREN);
            } else if (is(myTypes.C_MODULE_BINDING) && !in(myTypes.C_FUNCTOR_DECLARATION)) {
                if (myBuilder.lookAhead(1) == myTypes.VAL) {
                    markDummyParenthesisScope();
                } else if (in(myTypes.C_MODULE_DECLARATION)) {
                    // This is a functor ::  module M = |>(<| .. )
                    updateCompositeAt(getIndex(), myTypes.C_FUNCTOR_DECLARATION)
                            .updateComposite(myTypes.C_PARAMETERS).updateScopeToken(myTypes.LPAREN).advance()
                            .markHolder(myTypes.H_COLLECTION_ITEM)
                            .mark(myTypes.C_PARAM_DECLARATION)
                            .markHolder(myTypes.H_PLACE_HOLDER);
                }
            } else if (is(myTypes.C_DECONSTRUCTION) && isRawParent(myTypes.C_LET_DECLARATION)) {
                // let ((x |>,<| ...
                markScope(myTypes.C_DECONSTRUCTION, myTypes.LPAREN);
            } else if (previousElementType(1) == myTypes.SOME) {
                // Some |>(<|
                markScope(myTypes.C_SCOPED_EXPR, myTypes.LPAREN)
                        .advance().markHolder(myTypes.H_PLACE_HOLDER);
            } else if (in(myTypes.C_FUNCTION_CALL)
                    && !(is(myTypes.C_TYPE_DECLARATION) || isCurrent(myTypes.C_PARAM)
                    || inAny(myTypes.C_TYPE_BINDING, myTypes.C_SIG_ITEM))) { // calling a function
                markScope(myTypes.C_PARAMETERS, myTypes.LPAREN).advance();
                IElementType nextTokenType = getTokenType();
                if (nextTokenType == myTypes.RPAREN) {
                    markHolder(myTypes.H_COLLECTION_ITEM);
                } else {
                    mark(myTypes.C_PARAM);
                    markHolder(myTypes.H_PLACE_HOLDER);
                }
            } else if (inAny(myTypes.C_FUNCTOR_CALL, myTypes.C_FUNCTOR_RESULT)) {
                // module M = ( ... ) : |>(<| ...
                if (isFound(myTypes.C_FUNCTOR_CALL)) {
                    markScope(myTypes.C_PARAMETERS, myTypes.LPAREN).advance()
                            .mark(myTypes.C_PARAM)
                            .markHolder(myTypes.H_PLACE_HOLDER);
                }
            } else if (in(myTypes.C_VARIANT_DECLARATION)) { // Variant params
                // type t = | Variant |>(<| .. )
                markScope(myTypes.C_VARIANT_CONSTRUCTOR, myTypes.LPAREN).advance();
                markHolder(myTypes.H_COLLECTION_ITEM);
                mark(myTypes.C_PARAM_DECLARATION);
            } else if (inAny(myTypes.C_CLASS_DECLARATION, myTypes.C_OBJECT)) {
                if (isFound(myTypes.C_CLASS_DECLARATION)) {
                    popEndUntil(myTypes.C_CLASS_DECLARATION).
                            markScope(myTypes.C_CLASS_CONSTR, myTypes.LPAREN);
                }
            } else {
                markScope(myTypes.C_SCOPED_EXPR, myTypes.LPAREN).advance();
                markHolder(myTypes.H_COLLECTION_ITEM);
            }
        }

        private void parseRParen() {
            // Removing intermediate resolutions
            Marker lParen = popEndUntilScopeToken(myTypes.LPAREN);
            advance();

            if (is(myTypes.C_BINARY_CONDITION) && isRawParent(myTypes.C_IF)) {
                // if ( x |>)<| ...
                end();
                if (getTokenType() != myTypes.LBRACE) {
                    mark(myTypes.C_IF_THEN_SCOPE);
                }
            } else if (lParen != null) {
                IElementType nextTokenType = getTokenType();

                if (nextTokenType == myTypes.ARROW && !isParent(myTypes.C_FUNCTION_EXPR) && !inAny(myTypes.C_SIG_EXPR, myTypes.C_PATTERN_MATCH_EXPR, myTypes.C_FUNCTOR_DECLARATION)) {
                    // a missed function expression
                    rollbackToIndex(0)
                            .markBefore(0, myTypes.C_FUNCTION_EXPR)
                            .updateComposite(myTypes.C_PARAMETERS)
                            .markHolder(myTypes.H_COLLECTION_ITEM);
                } else {
                    popEnd();

                    if (isRawParent(myTypes.C_FUNCTION_CALL)) {
                        popEnd().popEnd();
                    } else if (isCurrent(myTypes.C_FUNCTOR_DECLARATION)) {
                        if (nextTokenType == myTypes.COLON) {
                            // module M = (P) |> :<| R ...
                            advance();
                            if (getTokenType() == myTypes.LPAREN) {
                                markScope(myTypes.C_SCOPED_EXPR, myTypes.LPAREN).advance();
                            }
                            mark(myTypes.C_FUNCTOR_RESULT);
                        } else if (nextTokenType == myTypes.ARROW) {
                            // module M = (P) |>=><| ...
                            advance().mark(myTypes.C_FUNCTOR_BINDING);
                        }
                    } else if (isCurrent(myTypes.C_TAG_PROP_VALUE)) {
                        popEndUntil(myTypes.C_TAG_PROP_VALUE).popEnd();
                    }
                }
            }
        }

        private void parseEq() {
            if (is(myTypes.C_TAG_PROPERTY)) {
                // <X p|> =<| ...
                advance().mark(myTypes.C_TAG_PROP_VALUE);
            } else if (isCurrent(myTypes.C_MODULE_DECLARATION) || isRawParent(myTypes.C_MODULE_DECLARATION)) {
                // module M |> =<| ...
                advance().mark(myTypes.C_MODULE_BINDING);
            } else if (isParent(myTypes.C_PARAM_DECLARATION) || isParent(myTypes.C_NAMED_PARAM)) {
                // ( ~x |> =<| ...
                popEndUntilFoundIndex()
                        .advance().mark(myTypes.C_DEFAULT_VALUE)
                        .markHolder(myTypes.H_PLACE_HOLDER);
            } else if (strictlyIn(myTypes.C_TYPE_BINDING) && strictlyIn(myTypes.C_CONSTRAINTS)) {
                // .. with type .. = .. |> =<| ..
                popEndUntilFoundIndex().popEnd();
                if (strictlyIn(myTypes.C_MODULE_DECLARATION)) {
                    popEndUntilFoundIndex()
                            .advance().mark(myTypes.C_MODULE_BINDING);
                }
            } else if (strictlyInAny(myTypes.C_TYPE_DECLARATION, myTypes.C_TYPE_CONSTRAINT)) {
                // type t |> =<| ...
                advance().mark(myTypes.C_TYPE_BINDING);
            } else if (inScopeOrAny(myTypes.C_LET_DECLARATION, myTypes.C_MODULE_TYPE, myTypes.C_SIG_EXPR)) {

                if (isFound(myTypes.C_SIG_EXPR)) {
                    popEndUntil(myTypes.C_SIG_EXPR).popEnd();
                    if (inAny(myTypes.H_NAMED_PARAM_DECLARATION, myTypes.C_NAMED_PARAM)) {
                        advance().mark(myTypes.C_DEFAULT_VALUE);
                    } else if (in(myTypes.C_LET_DECLARATION)) {
                        parseLetBinding();
                    }
                } else if (isFound(myTypes.C_MODULE_TYPE)) {
                    // module M : T |> =<| ...
                    popEndUntilIndex(getIndex()).popEnd()
                            .advance().mark(myTypes.C_MODULE_BINDING);
                } else if (!isFound(myTypes.C_SCOPED_EXPR) && in(myTypes.C_LET_DECLARATION)) {
                    if (!isAtIndex(getIndex() - 1, myTypes.C_LET_BINDING)) { // already parsed
                        parseLetBinding();
                    }
                }

            }
        }

        // let ... |> =<| ...
        private void parseLetBinding() {
            popEndUntil(myTypes.C_LET_DECLARATION).advance()
                    .mark(myTypes.C_LET_BINDING);
            markHolder(myTypes.H_PLACE_HOLDER);
        }

        private void parseSemi() {
            if (in(myTypes.C_PATTERN_MATCH_BODY)) {
                if (in(myTypes.C_FUN_EXPR)) { // Special case for the `fun` keyword
                    popEndUntilScope();
                }
            } else {
                popEndUntilScope();
            }

            if (is(myTypes.C_LET_BINDING) || rawHasScope()) {
                // let x = ... |>;<|
                // { ... |>;<|
                advance().markHolder(myTypes.H_PLACE_HOLDER);
            }
        }

        private void parseUIdent() {
            if (DUMMY_IDENTIFIER_TRIMMED.equals(getTokenText())) {
                return;
            }

            if (is(myTypes.C_MODULE_DECLARATION) || is(myTypes.C_FUNCTOR_DECLARATION) || is(myTypes.C_MODULE_VALUE)) {
                // module |>M<| ...
                remapCurrentToken(myTypes.A_MODULE_NAME).wrapAtom(myTypes.CA_UPPER_SYMBOL);
            } else if (is(myTypes.C_VARIANT_DECLARATION)) {
                // type t = | |>X<| ..
                remapCurrentToken(myTypes.A_VARIANT_NAME).wrapAtom(myTypes.CA_UPPER_SYMBOL);
            } else if (is(myTypes.C_EXCEPTION_DECLARATION)) {
                // exception |>E<| ..
                wrapAtom(myTypes.CA_UPPER_SYMBOL);
            } else if ((in(myTypes.C_TAG_START, /*not*/myTypes.C_TAG_PROP_VALUE) || in(myTypes.C_TAG_CLOSE)) && previousElementType(1) == myTypes.DOT) { // a namespaced custom component
                // <X.|>Y<| ...
                remapCurrentToken(myTypes.A_UPPER_TAG_NAME).wrapAtom(myTypes.CA_UPPER_SYMBOL);
            } else {
                IElementType nextToken = lookAhead(1);

                if (is(myTypes.C_TYPE_BINDING) && nextToken != myTypes.DOT) {
                    // We are declaring a variant without a pipe before ::  type t = |>X<| | ...
                    mark(myTypes.C_VARIANT_DECLARATION)
                            .remapCurrentToken(myTypes.A_VARIANT_NAME).wrapAtom(myTypes.CA_UPPER_SYMBOL);
                } else if (nextToken == myTypes.LPAREN && (isCurrent(myTypes.C_MODULE_BINDING) || isCurrent(myTypes.C_OPEN) || isCurrent(myTypes.C_INCLUDE))) {
                    // functor call ::  |>X<| ( ...
                    // functor call with path :: A.B.|>X<| ( ...
                    mark(myTypes.C_FUNCTOR_CALL)
                            .remapCurrentToken(myTypes.A_MODULE_NAME).wrapAtom(myTypes.CA_UPPER_SYMBOL);
                } else if (((isCurrent(myTypes.C_PATTERN_MATCH_EXPR) || isCurrent(myTypes.C_LET_BINDING))) && nextToken != myTypes.DOT) { // Pattern matching a variant or using it
                    // switch (c) { | |>X<| ... / let x = |>X<| ...
                    remapCurrentToken(myTypes.A_VARIANT_NAME).wrapAtom(myTypes.CA_UPPER_SYMBOL);
                } else {
                    remapCurrentToken(nextToken == myTypes.DOT || isCurrent(myTypes.C_MODULE_BINDING) || isCurrent(myTypes.C_MODULE_TYPE)
                            || isCurrent(myTypes.C_OPEN) || isCurrent(myTypes.C_INCLUDE)
                            ? myTypes.A_MODULE_NAME : myTypes.A_VARIANT_NAME);
                    wrapAtom(myTypes.CA_UPPER_SYMBOL);
                }
            }
        }

        private void parseSwitch() {
            mark(myTypes.C_SWITCH_EXPR);
        }

        private void parseTry() {
            mark(myTypes.C_TRY_EXPR);
        }

        private void parseArrow() {
            if (inScopeOrAny(
                    myTypes.C_SIG_EXPR, myTypes.C_SIG_ITEM, myTypes.C_FUNCTOR_RESULT, myTypes.C_PATTERN_MATCH_EXPR,
                    myTypes.C_FUNCTION_EXPR, myTypes.C_PARAMETERS, myTypes.C_PARAM_DECLARATION
            )) {
                if (isFound(myTypes.C_SIG_EXPR)) {
                    advance().mark(myTypes.C_SIG_ITEM);
                } else if (isFound(myTypes.C_SIG_ITEM)) {
                    popEndUntil(myTypes.C_SIG_ITEM).popEnd()
                            .advance().mark(myTypes.C_SIG_ITEM);
                } else if (isFound(myTypes.C_FUNCTOR_RESULT)) {
                    // module Make = (M) : R |>=><| ...
                    popEndUntilFoundIndex().popEnd()
                            .advance().mark(myTypes.C_FUNCTOR_BINDING);
                } else if (isFound(myTypes.C_PARAM_DECLARATION)) {
                    // x |>=><| ...
                    popEndUntil(myTypes.C_FUNCTION_EXPR).advance()
                            .mark(myTypes.C_FUNCTION_BODY);
                    markHolder(myTypes.H_PLACE_HOLDER);
                } else if (isFound(myTypes.C_PARAMETERS) || isFound(myTypes.C_FUNCTION_EXPR)) {
                    popEndUntilOneOf(myTypes.C_PARAMETERS, myTypes.C_FUNCTION_EXPR);
                    if (isRawParent(myTypes.C_FUNCTION_EXPR) || isRawParent(myTypes.C_FUNCTION_CALL)) {
                        popEnd();
                    }
                    advance().mark(myTypes.C_FUNCTION_BODY);
                } else if (isFound(myTypes.C_PATTERN_MATCH_EXPR)) {
                    advance().mark(myTypes.C_PATTERN_MATCH_BODY);
                    markHolder(myTypes.H_PLACE_HOLDER);
                }
            }
        }
    }
}


text:
using Microsoft.OData.Edm;
using Microsoft.OData.UriParser;
using Microsoft.OData.UriParser.Aggregation;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;

namespace OdataToEntity.Parsers
{
    public sealed class OeExpressionBuilder
    {
        private OeEntryFactoryFactory? _entryFactoryFactory;
        private readonly Translators.OeJoinBuilder _joinBuilder;

        public OeExpressionBuilder(Translators.OeJoinBuilder joinBuilder)
        {
            _joinBuilder = joinBuilder;
            Visitor = joinBuilder.Visitor;
        }
        public OeExpressionBuilder(Translators.OeJoinBuilder joinBuilder, OeQueryNodeVisitor visitor)
        {
            _joinBuilder = joinBuilder;
            Visitor = visitor;
        }

        public Expression ApplyAggregation(Expression source, ApplyClause applyClause)
        {
            if (applyClause == null)
                return source;

            var aggTranslator = new Translators.OeAggregationTranslator(Visitor);
            Expression aggExpression = aggTranslator.Build(source, applyClause, out _entryFactoryFactory);

            ChangeParameterType(aggExpression);
            Visitor.TuplePropertyByAliasName = aggTranslator.GetTuplePropertyByAliasName;

            return aggExpression;
        }
        public Expression ApplyCount(Expression source, bool? queryCount)
        {
            if (!queryCount.GetValueOrDefault())
                return source;

            MethodInfo countMethodInfo = OeMethodInfoHelper.GetCountMethodInfo(ParameterType);
            return Expression.Call(countMethodInfo, source);
        }
        public Expression ApplyFilter(Expression source, FilterClause filterClause)
        {
            if (filterClause == null)
                return source;

            Expression e = Visitor.TranslateNode(filterClause.Expression);
            LambdaExpression lambda = Expression.Lambda(e, Visitor.Parameter);

            MethodInfo whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(ParameterType);
            return Expression.Call(whereMethodInfo, source, lambda);
        }
        public Expression ApplyNavigation(Expression source, IReadOnlyList<OeParseNavigationSegment> parseNavigationSegments)
        {
            if (parseNavigationSegments == null)
                return source;

            Type sourceItemType = OeExpressionHelper.GetCollectionItemType(source.Type);
            foreach (OeParseNavigationSegment parseNavigationSegment in parseNavigationSegments)
            {
                Type selectType;
                ParameterExpression parameter;
                Expression e;
                if (parseNavigationSegment.NavigationSegment == null) //EntitySetSegment, KeySegment
                {
                    parameter = Visitor.Parameter;
                    e = source;
                    selectType = sourceItemType;
                }
                else
                {
                    parameter = Expression.Parameter(sourceItemType);
                    PropertyInfo navigationClrProperty = sourceItemType.GetPropertyIgnoreCase(parseNavigationSegment.NavigationSegment.NavigationProperty);
                    e = Expression.MakeMemberAccess(parameter, navigationClrProperty);

                    MethodInfo selectMethodInfo;
                    selectType = OeExpressionHelper.GetCollectionItemTypeOrNull(e.Type) ?? e.Type;
                    if (selectType == e.Type)
                        selectMethodInfo = OeMethodInfoHelper.GetSelectMethodInfo(sourceItemType, selectType);
                    else
                        selectMethodInfo = OeMethodInfoHelper.GetSelectManyMethodInfo(sourceItemType, selectType);

                    LambdaExpression lambda = Expression.Lambda(e, parameter);
                    source = Expression.Call(selectMethodInfo, source, lambda);
                }

                if (parseNavigationSegment.Filter != null)
                {
                    var visitor = new OeQueryNodeVisitor(Visitor, Expression.Parameter(selectType));
                    e = visitor.TranslateNode(parseNavigationSegment.Filter.Expression);
                    LambdaExpression lambda = Expression.Lambda(e, visitor.Parameter);

                    MethodInfo whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(selectType);
                    source = Expression.Call(whereMethodInfo, source, lambda);
                }

                sourceItemType = selectType;
            }

            Visitor.ChangeParameterType(Expression.Parameter(sourceItemType));
            return source;
        }
        public Expression ApplyOrderBy(Expression source, OrderByClause? orderByClause)
        {
            if (orderByClause == null)
                return source;

            return Translators.OeOrderByTranslator.Build(_joinBuilder, source, Visitor.Parameter, orderByClause);
        }
        public Expression ApplySelect(Expression source, OeQueryContext queryContext)
        {
            if (queryContext.ODataUri.Path.LastSegment is CountSegment)
                return source;

            var selectTranslator = new Translators.OeSelectTranslator(queryContext.EdmModel, _joinBuilder, queryContext.ODataUri);
            var selectTranslatorParameters = new Translators.OeSelectTranslatorParameters()
            {
                IsDatabaseNullHighestValue = queryContext.IsDatabaseNullHighestValue,
                MetadataLevel = queryContext.MetadataLevel,
                SkipTokenNameValues = queryContext.SkipTokenNameValues
            };
            source = selectTranslator.Build(source, in selectTranslatorParameters, out _entryFactoryFactory);

            ChangeParameterType(source);
            return source;
        }
        public Expression ApplySkip(Expression source, long? skip, ODataPath path)
        {
            if (skip == null)
                return source;

            ConstantExpression skipConstant = Visitor.AddSkipConstant((int)skip.Value, path);
            MethodInfo skipMethodInfo = OeMethodInfoHelper.GetSkipMethodInfo(ParameterType);
            return Expression.Call(skipMethodInfo, source, skipConstant);
        }
        public Expression ApplySkipToken(Expression source, OeSkipTokenNameValue[] skipTokenNameValues, OrderByClause uniqueOrderBy, bool isDatabaseNullHighestValue)
        {
            if (skipTokenNameValues == null || skipTokenNameValues.Length == 0)
                return source;

            var skipTokenTranslator = new Translators.OeSkipTokenTranslator(Visitor, _joinBuilder, isDatabaseNullHighestValue);
            source = skipTokenTranslator.Build(source, skipTokenNameValues, uniqueOrderBy);

            Visitor.ChangeParameterType(source);
            return source;
        }
        public Expression ApplyTake(Expression source, long? top, ODataPath path)
        {
            if (top == null)
                return source;

            ConstantExpression topConstant = Visitor.AddTopConstant((int)top.Value, path);
            MethodInfo takeMethodInfo = OeMethodInfoHelper.GetTakeMethodInfo(ParameterType);
            return Expression.Call(takeMethodInfo, source, topConstant);
        }
        private void ChangeParameterType(Expression source)
        {
            _joinBuilder.Visitor.ChangeParameterType(source);
        }
        public OeEntryFactory CreateEntryFactory(IEdmEntitySet entitySet, OePropertyAccessor[]? skipTokenAccessors)
        {
            if (_entryFactoryFactory != null)
                return _entryFactoryFactory.CreateEntryFactory(entitySet, ParameterType, skipTokenAccessors);

            OePropertyAccessor[] accessors = OePropertyAccessor.CreateFromType(ParameterType, entitySet);
            return new OeEntryFactory(entitySet, accessors, skipTokenAccessors);
        }

        public IReadOnlyDictionary<ConstantExpression, ConstantNode> Constants => Visitor.Constans;
        internal Translators.OeJoinBuilder JoinBuilder => _joinBuilder;
        private Type ParameterType => Visitor.Parameter.Type;
        private OeQueryNodeVisitor Visitor { get; }
    }
}

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Diagnostics;
using System.IO;

namespace EarTrumpet.Interop.Helpers
{
    class LegacyControlPanelHelper
    {
        public static void Open(string panel)
        {
            try
            {
                var rundllPath = Path.Combine(
                    Environment.GetEnvironmentVariable("SystemRoot"),
                    (Environment.Is64BitOperatingSystem ? @"sysnative\rundll32.exe" : @"system32\rundll32.exe"));

                using (Process.Start(rundllPath, $"shell32.dll,Control_RunDLL mmsys.cpl,,{panel}"))
                { }
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"LegacyControlPanelHelper Open Failed: {ex}");
            }
        }

        public static void StartLegacyAudioMixer()
        {
            try
            {
                var pos = System.Windows.Forms.Cursor.Position;
                using (Process.Start("sndvol.exe", $"-a {User32.MAKEWPARAM((ushort)pos.X, (ushort)pos.Y)}"))
                { }
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"LegacyControlPanelHelper StartLegacyAudioMixer Failed: {ex}");
            }
        }
    }
}


text:
package main

import (
	"flag"
	"fmt"
	"net/http"
	"strings"
	"time"

	"github.com/aws/aws-sdk-go/service/s3/s3manager"
)

type Config struct {
	Bucket         string
	Size           int64
	Key            string
	LogVerbose     bool
	UploadPartSize int64

	SDK      SDKConfig
	Client   ClientConfig
	Profiler Profiler
}

func (c *Config) SetupFlags(prefix string, flagset *flag.FlagSet) {
	flagset.StringVar(&c.Bucket, "bucket", "",
		"The S3 bucket `name` to download the object from.")
	flagset.Int64Var(&c.Size, "size", 0,
		"The S3 object size in bytes to be first uploaded then downloaded")
	flagset.StringVar(&c.Key, "key", "", "The S3 object key to download")
	flagset.BoolVar(&c.LogVerbose, "verbose", false,
		"The output log will include verbose request information")
	flagset.Int64Var(&c.UploadPartSize, "upload-part-size", 0, "the upload part size when uploading a file to s3")

	c.SDK.SetupFlags(prefix, flagset)
	c.Client.SetupFlags(prefix, flagset)
	c.Profiler.SetupFlags(prefix, flagset)
}

func (c *Config) Validate() error {
	var errs Errors

	if len(c.Bucket) == 0 || (c.Size <= 0 && len(c.Key) == 0) {
		errs = append(errs, fmt.Errorf("bucket and filename/size are required"))
	}

	if err := c.SDK.Validate(); err != nil {
		errs = append(errs, err)
	}
	if err := c.Client.Validate(); err != nil {
		errs = append(errs, err)
	}

	if len(errs) != 0 {
		return errs
	}

	return nil
}

type SDKConfig struct {
	PartSize       int64
	Concurrency    int
	BufferProvider s3manager.WriterReadFromProvider
}

func (c *SDKConfig) SetupFlags(prefix string, flagset *flag.FlagSet) {
	prefix += "sdk."

	flagset.Int64Var(&c.PartSize, prefix+"part-size", s3manager.DefaultDownloadPartSize,
		"Specifies the `size` of parts of the object to download.")
	flagset.IntVar(&c.Concurrency, prefix+"concurrency", s3manager.DefaultDownloadConcurrency,
		"Specifies the number of parts to download `at once`.")
}

func (c *SDKConfig) Validate() error {
	return nil
}

type ClientConfig struct {
	KeepAlive bool
	Timeouts  Timeouts

	MaxIdleConns        int
	MaxIdleConnsPerHost int

	// Go 1.13
	ReadBufferSize  int
	WriteBufferSize int
}

func (c *ClientConfig) SetupFlags(prefix string, flagset *flag.FlagSet) {
	prefix += "client."

	flagset.BoolVar(&c.KeepAlive, prefix+"http-keep-alive", true,
		"Specifies if HTTP keep alive is enabled.")

	defTR := http.DefaultTransport.(*http.Transport)

	flagset.IntVar(&c.MaxIdleConns, prefix+"idle-conns", defTR.MaxIdleConns,
		"Specifies max idle connection pool size.")

	flagset.IntVar(&c.MaxIdleConnsPerHost, prefix+"idle-conns-host", http.DefaultMaxIdleConnsPerHost,
		"Specifies max idle connection pool per host, will be truncated by idle-conns.")

	flagset.IntVar(&c.ReadBufferSize, prefix+"read-buffer", defTR.ReadBufferSize, "size of the transport read buffer used")
	flagset.IntVar(&c.WriteBufferSize, prefix+"writer-buffer", defTR.WriteBufferSize, "size of the transport write buffer used")

	c.Timeouts.SetupFlags(prefix, flagset)
}

func (c *ClientConfig) Validate() error {
	var errs Errors

	if err := c.Timeouts.Validate(); err != nil {
		errs = append(errs, err)
	}

	if len(errs) != 0 {
		return errs
	}
	return nil
}

type Timeouts struct {
	Connect        time.Duration
	TLSHandshake   time.Duration
	ExpectContinue time.Duration
	ResponseHeader time.Duration
}

func (c *Timeouts) SetupFlags(prefix string, flagset *flag.FlagSet) {
	prefix += "timeout."

	flagset.DurationVar(&c.Connect, prefix+"connect", 30*time.Second,
		"The `timeout` connecting to the remote host.")

	defTR := http.DefaultTransport.(*http.Transport)

	flagset.DurationVar(&c.TLSHandshake, prefix+"tls", defTR.TLSHandshakeTimeout,
		"The `timeout` waiting for the TLS handshake to complete.")

	flagset.DurationVar(&c.ExpectContinue, prefix+"expect-continue", defTR.ExpectContinueTimeout,
		"The `timeout` waiting for the TLS handshake to complete.")

	flagset.DurationVar(&c.ResponseHeader, prefix+"response-header", defTR.ResponseHeaderTimeout,
		"The `timeout` waiting for the TLS handshake to complete.")
}

func (c *Timeouts) Validate() error {
	return nil
}

type Errors []error

func (es Errors) Error() string {
	var buf strings.Builder
	for _, e := range es {
		buf.WriteString(e.Error())
	}

	return buf.String()
}


text:
<?php

namespace Jose;

use Assert\Assertion;
use Base64Url\Base64Url;

final class Encrypter implements EncrypterInterface
{
    use Behaviour\HasKeyChecker;
    use Behaviour\HasJWAManager;
    use Behaviour\HasCompressionManager;
    use Behaviour\CommonCipheringMethods;
    use Behaviour\EncrypterTrait;

    /**
     * {@inheritdoc}
     */
    public static function createEncrypter(array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods = ['DEF', 'ZLIB', 'GZ'])
    {
        $encrypter = new self($key_encryption_algorithms, $content_encryption_algorithms, $compression_methods);

        return $encrypter;
    }

    /**
     * Decrypter constructor.
     *
     * @param string[]|\Jose\Algorithm\KeyEncryptionAlgorithmInterface[]     $key_encryption_algorithms
     * @param string[]|\Jose\Algorithm\ContentEncryptionAlgorithmInterface[] $content_encryption_algorithms
     * @param string[]|\Jose\Compression\CompressionInterface[]              $compression_methods
     */
    public function __construct(array $key_encryption_algorithms, array $content_encryption_algorithms, array $compression_methods)
    {
        $this->setKeyEncryptionAlgorithms($key_encryption_algorithms);
        $this->setContentEncryptionAlgorithms($content_encryption_algorithms);
        $this->setCompressionMethods($compression_methods);
        $this->setJWAManager(Factory\AlgorithmManagerFactory::createAlgorithmManager(array_merge($key_encryption_algorithms, $content_encryption_algorithms)));
        $this->setCompressionManager(Factory\CompressionManagerFactory::createCompressionManager($compression_methods));
    }

    /**
     * {@inheritdoc}
     */
    public function encrypt(Object\JWEInterface &$jwe)
    {
        Assertion::false($jwe->isEncrypted(), 'The JWE is already encrypted.');
        Assertion::greaterThan($jwe->countRecipients(), 0, 'The JWE does not contain recipient.');
        $additional_headers = [];
        $nb_recipients = $jwe->countRecipients();
        $content_encryption_algorithm = $this->getContentEncryptionAlgorithm($jwe);
        $compression_method = $this->getCompressionMethod($jwe);
        $key_management_mode = $this->getKeyManagementMode($jwe);
        $cek = $this->determineCEK($jwe, $content_encryption_algorithm, $key_management_mode, $additional_headers);

        for ($i = 0; $i < $nb_recipients; ++$i) {
            $this->processRecipient($jwe, $jwe->getRecipient($i), $cek, $content_encryption_algorithm, $additional_headers);
        }

        if (!empty($additional_headers) && 1 === $jwe->countRecipients()) {
            $jwe = $jwe->withSharedProtectedHeaders(array_merge($jwe->getSharedProtectedHeaders(), $additional_headers));
        }

        $iv_size = $content_encryption_algorithm->getIVSize();
        $iv = $this->createIV($iv_size);

        $this->encryptJWE($jwe, $content_encryption_algorithm, $cek, $iv, $compression_method);
    }

    /**
     * @param \Jose\Object\JWEInterface                           $jwe
     * @param \Jose\Object\RecipientInterface                     $recipient
     * @param string                                              $cek
     * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm
     * @param array                                               $additional_headers
     */
    private function processRecipient(Object\JWEInterface $jwe, Object\RecipientInterface &$recipient, $cek, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array &$additional_headers)
    {
        if (null === $recipient->getRecipientKey()) {
            return;
        }
        $complete_headers = array_merge($jwe->getSharedProtectedHeaders(), $jwe->getSharedHeaders(), $recipient->getHeaders());
        $key_encryption_algorithm = $this->findKeyEncryptionAlgorithm($complete_headers);
        $this->checkKeys($key_encryption_algorithm, $content_encryption_algorithm, $recipient->getRecipientKey());
        $encrypted_content_encryption_key = $this->getEncryptedKey($complete_headers, $cek, $key_encryption_algorithm, $content_encryption_algorithm, $additional_headers, $recipient->getRecipientKey());
        $recipient_headers = $recipient->getHeaders();
        if (!empty($additional_headers) && 1 !== $jwe->countRecipients()) {
            $recipient_headers = array_merge($recipient_headers, $additional_headers);
            $additional_headers = [];
        }

        $recipient = Object\Recipient::createRecipientFromLoadedJWE($recipient_headers, $encrypted_content_encryption_key);
    }

    /**
     * @param \Jose\Object\JWEInterface                           $jwe
     * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm
     * @param string                                              $cek
     * @param string                                              $iv
     * @param \Jose\Compression\CompressionInterface|null         $compression_method
     */
    private function encryptJWE(Object\JWEInterface &$jwe, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, $cek, $iv, Compression\CompressionInterface $compression_method = null)
    {
        if (!empty($jwe->getSharedProtectedHeaders())) {
            $jwe = $jwe->withEncodedSharedProtectedHeaders(Base64Url::encode(json_encode($jwe->getSharedProtectedHeaders())));
        }

        $tag = null;
        $payload = $this->preparePayload($jwe->getPayload(), $compression_method);
        $aad = null === $jwe->getAAD() ? null : Base64Url::encode($jwe->getAAD());
        $ciphertext = $content_encryption_algorithm->encryptContent($payload, $cek, $iv, $aad, $jwe->getEncodedSharedProtectedHeaders(), $tag);
        $jwe = $jwe->withCiphertext($ciphertext);
        $jwe = $jwe->withIV($iv);

        if (null !== $tag) {
            $jwe = $jwe->withTag($tag);
        }
    }

    /**
     * @param string                                      $payload
     * @param \Jose\Compression\CompressionInterface|null $compression_method
     *
     * @return string
     */
    private function preparePayload($payload, Compression\CompressionInterface $compression_method = null)
    {
        $prepared = is_string($payload) ? $payload : json_encode($payload);
        Assertion::notNull($prepared, 'The payload is empty or cannot encoded into JSON.');

        if (null === $compression_method) {
            return $prepared;
        }
        $compressed_payload = $compression_method->compress($prepared);
        Assertion::string($compressed_payload, 'Compression failed.');

        return $compressed_payload;
    }

    /**
     * @param array                                               $complete_headers
     * @param string                                              $cek
     * @param \Jose\Algorithm\KeyEncryptionAlgorithmInterface     $key_encryption_algorithm
     * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm
     * @param \Jose\Object\JWKInterface                           $recipient_key
     * @param array                                               $additional_headers
     *
     * @return string|null
     */
    private function getEncryptedKey(array $complete_headers, $cek, Algorithm\KeyEncryptionAlgorithmInterface $key_encryption_algorithm, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array &$additional_headers, Object\JWKInterface $recipient_key)
    {
        if ($key_encryption_algorithm instanceof Algorithm\KeyEncryption\KeyEncryptionInterface) {
            return $this->getEncryptedKeyFromKeyEncryptionAlgorithm($complete_headers, $cek, $key_encryption_algorithm, $recipient_key, $additional_headers);
        } elseif ($key_encryption_algorithm instanceof Algorithm\KeyEncryption\KeyWrappingInterface) {
            return $this->getEncryptedKeyFromKeyWrappingAlgorithm($complete_headers, $cek, $key_encryption_algorithm, $recipient_key, $additional_headers);
        } elseif ($key_encryption_algorithm instanceof Algorithm\KeyEncryption\KeyAgreementWrappingInterface) {
            return $this->getEncryptedKeyFromKeyAgreementAndKeyWrappingAlgorithm($complete_headers, $cek, $key_encryption_algorithm, $content_encryption_algorithm, $additional_headers, $recipient_key);
        }
    }

    /**
     * @param array                                                       $complete_headers
     * @param string                                                      $cek
     * @param \Jose\Algorithm\KeyEncryption\KeyAgreementWrappingInterface $key_encryption_algorithm
     * @param \Jose\Algorithm\ContentEncryptionAlgorithmInterface         $content_encryption_algorithm
     * @param array                                                       $additional_headers
     * @param \Jose\Object\JWKInterface                                   $recipient_key
     *
     * @return string
     */
    private function getEncryptedKeyFromKeyAgreementAndKeyWrappingAlgorithm(array $complete_headers, $cek, Algorithm\KeyEncryption\KeyAgreementWrappingInterface $key_encryption_algorithm, Algorithm\ContentEncryptionAlgorithmInterface $content_encryption_algorithm, array &$additional_headers, Object\JWKInterface $recipient_key)
    {
        $jwt_cek = $key_encryption_algorithm->wrapAgreementKey($recipient_key, $cek, $content_encryption_algorithm->getCEKSize(), $complete_headers, $additional_headers);

        return $jwt_cek;
    }

    /**
     * @param array                                                $complete_headers
     * @param string                                               $cek
     * @param \Jose\Algorithm\KeyEncryption\KeyEncryptionInterface $key_encryption_algorithm
     * @param \Jose\Object\JWKInterface                            $recipient_key
     * @param array                                                $additional_headers
     *
     * @return string
     */
    private function getEncryptedKeyFromKeyEncryptionAlgorithm(array $complete_headers, $cek, Algorithm\KeyEncryption\KeyEncryptionInterface $key_encryption_algorithm, Object\JWKInterface $recipient_key, array &$additional_headers)
    {
        return $key_encryption_algorithm->encryptKey($recipient_key, $cek, $complete_headers, $additional_headers);
    }

    /**
     * @param array                                              $complete_headers
     * @param string                                             $cek
     * @param \Jose\Algorithm\KeyEncryption\KeyWrappingInterface $key_encryption_algorithm
     * @param \Jose\Object\JWKInterface                          $recipient_key
     * @param array                                              $additional_headers
     *
     * @return string
     */
    private function getEncryptedKeyFromKeyWrappingAlgorithm(array $complete_headers, $cek, Algorithm\KeyEncryption\KeyWrappingInterface $key_encryption_algorithm, Object\JWKInterface $recipient_key, &$additional_headers)
    {
        return $key_encryption_algorithm->wrapKey($recipient_key, $cek, $complete_headers, $additional_headers);
    }
}


text:
var gulp = require('gulp'),
    concat = require('gulp-concat'),
    rename = require('gulp-rename'),
    uglify = require('gulp-uglify'),
    coffee = require('gulp-coffee');

var paths = {
  core: [ 'src/**/*.coffee' ]
};

gulp.task('build', function() {
  gulp.src(paths.core)
    .pipe(coffee())
    .pipe(concat('backbone.flux.js'))
    .pipe(gulp.dest('dist'))
    .pipe(uglify())
    .pipe(rename('backbone.flux.min.js'))
    .pipe(gulp.dest('dist'))
});

gulp.task('watch', function() {
  gulp.watch(paths.core, ['build']);
});

gulp.task('default', ['build', 'watch']);


text:
<?php

/* SonataAdminBundle:CRUD:list__action_delete.html.twig */
class __TwigTemplate_50fd77083a64165b5c32cfcbcdecf5a3c9b9e43a0b895fa633f83348405440c5 extends Sonata\CacheBundle\Twig\TwigTemplate14
{
    public function __construct(Twig_Environment $env)
    {
        parent::__construct($env);

        $this->parent = false;

        $this->blocks = array(
        );
    }

    protected function doDisplay(array $context, array $blocks = array())
    {
        // line 11
        echo "
";
        // line 12
        if (($this->getAttribute((isset($context["admin"]) ? $context["admin"] : $this->getContext($context, "admin")), "isGranted", array(0 => "DELETE", 1 => (isset($context["object"]) ? $context["object"] : $this->getContext($context, "object"))), "method") && $this->getAttribute((isset($context["admin"]) ? $context["admin"] : $this->getContext($context, "admin")), "hasRoute", array(0 => "delete"), "method"))) {
            // line 13
            echo "    env, $this->getAttribute((isset($context["admin"]) ? $context["admin"] : $this->getContext($context, "admin")), "generateObjectUrl", array(0 => "delete", 1 => (isset($context["object"]) ? $context["object"] : $this->getContext($context, "object"))), "method"), "html", null, true);
            echo "\" class=\"btn btn-sm btn-default delete_link\" title=\"";
            echo twig_escape_filter($this->env, $this->env->getExtension('translator')->trans("action_delete", array(), "SonataAdminBundle"), "html", null, true);
            echo "\">

        ";
            // line 15
            echo twig_escape_filter($this->env, $this->env->getExtension('translator')->trans("action_delete", array(), "SonataAdminBundle"), "html", null, true);
            echo "

";
        }
    }

    public function getTemplateName()
    {
        return "SonataAdminBundle:CRUD:list__action_delete.html.twig";
    }

    public function isTraitable()
    {
        return false;
    }

    public function getDebugInfo()
    {
        return array (  32 => 15,  24 => 13,  22 => 12,  19 => 11,);
    }
}