<commit_before>import ceylon.ast.core {
    BaseType,
    ClassBody,
    ClassDefinition,
    CompilationUnit,
    FunctionDefinition,
    InterfaceDefinition,
    IntersectionType,
    LIdentifier,
    ObjectDefinition,
    OutModifier,
    Return,
    TypeAliasDefinition,
    TypeConstraint,
    TypeParameter,
    TypeSpecifier,
    UIdentifier,
    UnionType,
    ValueDeclaration,
    ValueParameter
}
import ceylon.ast.create {
    annotations,
    baseExpression,
    baseType,
    caseTypes,
    classDefinition,
    extendedType,
    functionDefinition,
    interfaceDefinition,
    satisfiedTypes
}
import ceylon.collection {
    SingletonSet
}

shared abstract class Movement(shared actual String string)
        of left | none | right {}
shared object left extends Movement("left") {}
shared object none extends Movement("none") {}
shared object right extends Movement("right") {}

"Creates the components of the type system Turing machine."
shared class TuringMachineCreator(
    states,
    symbols,
    inputSymbols,
    initialState,
    acceptingStates,
    "Optionally: Descriptions for the states."
    String? stateDescription(String state) => null,
    "Optionally: Descriptions for the symbols."
    String? symbolDescription(Character symbol) => null) {
    
    "The set of states in which the turing machine can be."
    Set<String> states;
    "The set of symbols that can be written onto the tape (excluding the blank symbol)."
    Set<Character> symbols;
    "The set of symbols that can be on the tape initially. Must be a subset of [[symbols]]."
    Set<Character> inputSymbols;
    "The initial state. Must be an element of [[states]]."
    String initialState;
    "The accepting states. Must be a subset of [[states]]."
    Set<String> acceptingStates;
    
    "Must have at least one accepting state"
    assert (nonempty acceptingStates_seq = acceptingStates.sequence());
    
    "Input symbols must be valid symsols"
    assert (inputSymbols.subset(symbols));
    "Initial state must be a valid state"
    assert (initialState in states);
    "Accepting states must be valid states"
    assert (acceptingStates.subset(states));
    
    Boolean identifierPart(Character character) => character.letter || character.digit || character == '_';
    "State names must be composed of valid identifier parts"
    assert (states.every((String state) => state.every(identifierPart)));
    "Alphabet must be valid identifier parts"
    assert (symbols.every(identifierPart));
    
    value blank = '_';
    "`_` symbol is reserved for blank symbol"
    assert (!blank in symbols);
    value allSymbols = symbols | SingletonSet(blank);
    
    /*
     toplevel declarations can’t end with underscore,
     so we terminate all names explicitly.
     */
    String symbolTypeName(Character symbol)
            => "Symbol_``symbol``_T";
    String inputTypeName(Character symbol)
            => "Input_``symbol``_T";
    String inputInstanceName(Character symbol)
            => "input_``symbol``_T";
    String stateTypeName(String state)
            => "State_``state``_T";
    
    "The definitions for the data tape:
     One enumerated `Symbol` interface,
     with one case type `Symbol_${symbol}` per [[symbol|symbols]],
     along with the definitions of those tape symbol interfaces."
    shared {InterfaceDefinition*} symbolDefinitions
            => {
        interfaceDefinition {
            name = "Symbol";
            caseTypes = { for (symbol in allSymbols) symbolTypeName(symbol) };
            annotations = annotations { "shared" };
        },
        for (symbol in allSymbols)
            interfaceDefinition {
                name = symbolTypeName(symbol);
                satisfiedTypes = { "Symbol" };
                annotations = annotations { "shared" };
            }
    };
    
    "The definitions for the input:
     One enumerated class `Input_${symbol}`
     satisfying `Symbol_${symbol}` (see [[symbolDefinitions]])
     and one object `input_${symbol}`
     per [[input symbol|inputSymbols]]."
    shared {ClassDefinition|ObjectDefinition*} inputDefinitions
            => expand {
        for (symbol in inputSymbols)
            {
                classDefinition {
                    name = inputTypeName(symbol);
                    caseTypes = { inputInstanceName(symbol) };
                    satisfiedTypes = { symbolTypeName(symbol) };
                    annotations = annotations {
                        doc = symbolDescription(symbol);
                        "shared", "abstract"
                    };<commit_msg>Fix type system Turing machine<commit_after>import ceylon.ast.core {
    BaseType,
    ClassBody,
    ClassDefinition,
    CompilationUnit,
    FunctionDefinition,
    InterfaceDefinition,
    IntersectionType,
    LIdentifier,
    ObjectDefinition,
    OutModifier,
    Return,
    TypeAliasDefinition,
    TypeConstraint,
    TypeParameter,
    TypeSpecifier,
    UIdentifier,
    UnionType,
    ValueDeclaration,
    ValueParameter
}
import ceylon.ast.create {
    annotations,
    baseExpression,
    baseType,
    caseTypes,
    classDefinition,
    extendedType,
    functionDefinition,
    interfaceDefinition,
    satisfiedTypes
}
import ceylon.collection {
    SingletonSet
}

shared abstract class Movement(shared actual String string)
        of left | none | right {}
shared object left extends Movement("left") {}
shared object none extends Movement("none") {}
shared object right extends Movement("right") {}

"Creates the components of the type system Turing machine."
shared class TuringMachineCreator(
    states,
    symbols,
    inputSymbols,
    initialState,
    acceptingStates,
    "Optionally: Descriptions for the states."
    String? stateDescription(String state) => null,
    "Optionally: Descriptions for the symbols."
    String? symbolDescription(Character symbol) => null) {
    
    "The set of states in which the turing machine can be."
    Set<String> states;
    "The set of symbols that can be written onto the tape (excluding the blank symbol)."
    Set<Character> symbols;
    "The set of symbols that can be on the tape initially. Must be a subset of [[symbols]]."
    Set<Character> inputSymbols;
    "The initial state. Must be an element of [[states]]."
    String initialState;
    "The accepting states. Must be a subset of [[states]]."
    Set<String> acceptingStates;
    
    "Must have at least one accepting state"
    assert (nonempty acceptingStates_seq = acceptingStates.sequence());
    
    "Input symbols must be valid symsols"
    assert (inputSymbols.subset(symbols));
    "Initial state must be a valid state"
    assert (initialState in states);
    "Accepting states must be valid states"
    assert (acceptingStates.subset(states));
    
    Boolean identifierPart(Character character) => character.letter || character.digit || character == '_';
    "State names must be composed of valid identifier parts"
    assert (states.every((String state) => state.every(identifierPart)));
    "Alphabet must be valid identifier parts"
    assert (symbols.every(identifierPart));
    
    value blank = '_';
    "`_` symbol is reserved for blank symbol"
    assert (!blank in symbols);
    value allSymbols = symbols | SingletonSet(blank);
    
    /*
     toplevel declarations can’t end with underscore,
     so we terminate all names explicitly.
     */
    String symbolTypeName(Character symbol)
            => "Symbol_``symbol``_T";
    String inputTypeName(Character symbol)
            => "Input_``symbol``_T";
    String inputInstanceName(Character symbol)
            => "input_``symbol``_T";
    String stateTypeName(String state)
            => "State_``state``_T";
    
    "The definitions for the data tape:
     One enumerated `Symbol` interface,
     with one case type `Symbol_${symbol}` per [[symbol|symbols]],
     along with the definitions of those tape symbol interfaces."
    shared {InterfaceDefinition*} symbolDefinitions
            => {
        interfaceDefinition {
            name = "Symbol";
            caseTypes = { for (symbol in allSymbols) symbolTypeName(symbol) };
            annotations = annotations { "shared" };
        },
        for (symbol in allSymbols)
            interfaceDefinition {
                name = symbolTypeName(symbol);
                satisfiedTypes = { "Symbol" };
                annotations = annotations { "shared" };
            }
    };
    
    "The definitions for the input:
     One enumerated class `Input_${symbol}`
     satisfying `Symbol_${symbol}` (see [[symbolDefinitions]])
     and one object `input_${symbol}`
     per [[input symbol|inputSymbols]]."
    shared {ClassDefinition|ObjectDefinition*} inputDefinitions
            => expand {
        for (symbol in inputSymbols)
            {
                classDefinition {
                    name = inputTypeName(symbol);
                    satisfiedTypes = { symbolTypeName(symbol) };
                    annotations = annotations {
                        doc = symbolDescription(symbol);
                        "shared", "abstract"
                    };
{'fraction_non_alphanumeric': 0.08949671772428884, 'fraction_numerical': 0.0, 'mean_word_length': 2.6710843373493978, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3014377', 'n_tokens_mistral': 2320, 'n_tokens_neox': 2278, 'n_words': 742}