public RootScopePopulateScope ParseFile(FileToken file) { IOrType <EntryPointDefinitionPopulateScope, IError> defaultEntryPoint = OrType.Make <EntryPointDefinitionPopulateScope, IError>( new EntryPointDefinitionPopulateScope( new TypeReferancePopulateScope(new NameKey("empty")), Array.Empty <IOrType <EntryPointDefinitionPopulateScope, IError> >(), new TypeReferancePopulateScope(new NameKey("empty")), "unused")); var entryToReturn = defaultEntryPoint; var assignments = new List <IOrType <WeakAssignOperationPopulateScope, IError> >(); var types = new List <IOrType <TypeDefinitionPopulateScope, IError> >(); var genericTypes = new List <IOrType <GenericTypeDefinitionPopulateScope, IError> >(); foreach (var element in file.Tokens.Select(line => ParseLine(line.CastTo <LineToken>().Tokens))) { element.Switch(setup => { if (setup.SafeIs(out WeakAssignOperationPopulateScope assign)) { assignments.Add(OrType.Make <WeakAssignOperationPopulateScope, IError>(assign)); } else if (setup.SafeIs(out GenericTypeDefinitionPopulateScope genericType)) { genericTypes.Add(OrType.Make <GenericTypeDefinitionPopulateScope, IError>(genericType)); } else if (setup.SafeIs(out TypeDefinitionPopulateScope type)) { types.Add(OrType.Make <TypeDefinitionPopulateScope, IError>(type)); } else if (setup.SafeIs(out EntryPointDefinitionPopulateScope entry)) { if (entryToReturn == defaultEntryPoint) { entryToReturn = OrType.Make <EntryPointDefinitionPopulateScope, IError>(entry); } else { entryToReturn = OrType.Make <EntryPointDefinitionPopulateScope, IError>(Error.Other("you can't have more than one entry point")); } } else { assignments.Add(OrType.Make <WeakAssignOperationPopulateScope, IError>(Error.Other($"unexpected type {setup.GetType().Name}"))); } } , error => { assignments.Add(OrType.Make <WeakAssignOperationPopulateScope, IError>(error)); }); } return(new RootScopePopulateScope(assignments.ToArray(), entryToReturn, types, genericTypes)); }
public IPopulateScope <IFrontendCodeElement, ISetUpSideNode>[] ParseFile(FileToken file) { return(file.Tokens.Select(x => ParseLine(x.Cast <LineToken>().Tokens)).ToArray()); }