ZenCodeLang / ZenCode

The ZenCode project.
MIT License
12 stars 8 forks source link

Define Syntax for Iterator Definition #154

Open kindlich opened 3 months ago

kindlich commented 3 months ago

Currently, StdLib's Iterable.zs defines the Iterator-Member like so:

for(item as T) as Iterator<T> => iterate();

However, the parser expects:

for(T) {
    // What to do in here?
}

Defined in ParsedDefinitionMember:

            case K_FOR: {
                tokens.next();

                tokens.required(T_BROPEN, "( expected");

                List<IParsedType> loopVariableTypes = new ArrayList<>();
                if (tokens.optional(T_BRCLOSE) == null) {
                    do {
                        loopVariableTypes.add(IParsedType.parse(tokens));
                    } while (tokens.optional(T_COMMA) != null);
                    tokens.required(T_BRCLOSE, ") expected");
                }

                ParsedFunctionBody body = ParsedStatement.parseFunctionBody(tokens);
                return new ParsedIterator(start, modifiers, annotations, loopVariableTypes, body);
            }

We need to define how the iterator members should look like and how it should behave.

Acceptance Criteria: