public Verb Generate() { var fieldBuilder = new CodeBuilder(); fieldBuilder.CreateField(VAR_STATE, false, Private); fieldBuilder.CreateField(VAR_SOURCE, false, Private); var resetBuilder = new CodeBuilder(); resetBuilder.AssignToField(VAR_STATE, 0, 0); var blocks = getBlocks(body, fieldBuilder, resetBuilder); var matchBlock = getMatch(blocks); fieldBuilder.Function("reset", resetBuilder); fieldBuilder.Function("next", new Lambda(new Region(), matchBlock, new Parameters(), false)); var objectBlock = fieldBuilder.Block; var cls = new Class(parameters, objectBlock); CompilerState.RegisterClass(functionName, cls); return(new CreateClass(functionName, cls)); }
public override Verb CreateVerb(string[] tokens) { var isAbstract = tokens[2].IsNotEmpty(); var type = tokens[3].Trim(); var className = tokens[4]; var parameterBegin = tokens[5]; ClassName = className; EnumerationValue = -1; CurrentVisibility = Object.VisibilityType.Public; Color(position, tokens[1].Length, Whitespaces); Color(tokens[2].Length, KeyWords); Color(tokens[3].Length, KeyWords); Color(className.Length, Types); Color(parameterBegin.Length, Structures); Parameters parameters; int index; if (parameterBegin == "(" && type != "module") { Color(parameterBegin.Length, Structures); index = position + length; var parametersParser = new ParametersParser(); var parsed = parametersParser.Parse(source, index); if (!parsed.If(out parameters, out index)) { return(null); } if (type == "enum") { parameters.Unshift(new Parameter("name")); parameters.Unshift(new Parameter("value")); } } else if (type == "enum") { parameters = new Parameters(new[] { new Parameter("value"), new Parameter("name") }); index = position + length; } else { parameters = new Parameters(); index = position + length; } (var superClass, var superParameters, var traits, var newIndex) = Ancestors(source, index); index = newIndex; var endParser = new EndParser(); if (endParser.Scan(source, index)) { index = endParser.Position; } Block objectBlock; InClassDefinition = true; EnumerationMappingCode = new CodeBuilder(); try { if (type == "enum") { addEnumerationSupport(className); } LockedDown = type == "view"; if (GetBlock(source, index, true, InClass).If(out var block, out newIndex)) { objectBlock = block; index = newIndex; if (type == "enum") { addEnumerationInstanceSupport(ref objectBlock); } } else { objectBlock = new Block(); } } finally { InClassDefinition = false; if (EnumerationMappingCode != null) { AddStaticBlock(EnumerationMappingCode.Block); } EnumerationMappingCode = null; LockedDown = false; } var checker = new InheritanceChecker(className, objectBlock, parameters, superClass, isAbstract, traits); var passes = checker.Passes(); Assert(passes.IsSuccessful, LOCATION, () => passes.Exception.Message); var cls = new Class(parameters, objectBlock, GetStaticBlock(), superClass, traits, superParameters, type == "view"); CompilerState.RegisterClass(ClassName, cls); result.Value = cls; overridePosition = index; ClassName = ""; switch (type) { case "module": return(new CreateModule(className, cls, true) { Index = position }); case "extend": return(new CreateExtender(className, cls)); default: var verb = new CreateClass(className, cls) { HelperFunctions = HelperFunctions, HelperBlock = HelperBlock, Index = position }; HelperFunctions = null; HelperBlock = null; return(verb); } }