Skip to content

Define Syntax for Iterator Definition #154

Open
@kindlich

Description

@kindlich

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:

  • The syntax is defined
  • The header in stdlibs is adapted to whatever syntax we adopt
  • There exist tests that cover the basic iterator functionality
    • Defining an iterator
    • Calling it
    • Overloading iterators with multiple variables
    • Doing that on a generic data type like List

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentationparser

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions