예제 #1
0
        public PainClass GetClassDefinition(CodeLine line)
        {
            CodeLine trimmedLine = new CodeLine(line.TrimStart());

            // DEF: wykrycie definicji metody
            if (trimmedLine.Count > str_class.Length &&
                StringHelper.StrEquals(trimmedLine, str_class, true) &&
                Char.IsWhiteSpace(trimmedLine[str_class.Length]))
            {
                PainClass classDefinition = new PainClass();
                classDefinition.Depth = GetDepth(line) + 1; // zwiekszamy poziom klasy

                IList <OnpMethodPart> methodParameters = MethodParser.
                                                         ExtractNames(trimmedLine.ToString().Substring(str_class.Length + 1), true);

                foreach (OnpMethodPart methodParameter in methodParameters)
                {
                    if (methodParameter.Part == EOnpMethodPart.METHOD_NAME)
                    {
                        classDefinition.Name = methodParameter.Code.ToUpper();
                    }
                    else if (methodParameter.Part == EOnpMethodPart.PARAMETER)
                    {
                        classDefinition.Parameters.Add(methodParameter.Code);
                    }
                }

                return(classDefinition);
            }
            return(null);
        }
예제 #2
0
        public PainProgram Compile(IList <Char> Code)
        {
            CodeLines lines = GetLines(Code);

            PainProgram        mainProgram = new PainProgram();
            List <PainProgram> methodStack = new List <PainProgram>();

            methodStack.Push(mainProgram);

            foreach (CodeLine line in lines)
            {
                Int32 currentDepth = -1;

                PainMethod method = null;
                method = GetMethodDefinition(line);
                if (method != null)
                {
                    currentDepth = method.Depth;
                }

                PainClass classDefinition = null;
                if (method == null)
                {
                    classDefinition = GetClassDefinition(line);
                    if (classDefinition != null)
                    {
                        currentDepth = classDefinition.Depth;
                    }
                }

                PainCodeLine codeLine = null;
                if (method == null && classDefinition == null)
                {
                    codeLine = GetCodeLine(line);
                    if (codeLine != null)
                    {
                        currentDepth = codeLine.Depth;
                    }
                }

                PainProgram currentMethod = methodStack.Peek();
                if (codeLine == null || !codeLine.IsLineEmpty)
                {
                    while (currentDepth < currentMethod.Depth ||
                           (currentDepth == currentMethod.Depth && classDefinition != null && classDefinition != currentMethod) ||
                           (currentDepth == currentMethod.Depth && method != null && method != currentMethod))
                    {
                        methodStack.Pop();
                        currentMethod = methodStack.Peek();
                    }
                }

                if (method != null)
                {
                    currentMethod.Methods.Remove_by_Name(method.Name);
                    currentMethod.Methods.Add(method);
                    methodStack.Push(method);
                    continue;
                }

                if (classDefinition != null)
                {
                    currentMethod.Classes.Remove_by_Name(classDefinition.Name);
                    currentMethod.Classes.Add(classDefinition);
                    methodStack.Push(classDefinition);
                    continue;
                }

                if (codeLine != null)
                {
                    if (codeLine.IsLineEmpty == false)
                    {
                        currentMethod.Lines.Add(codeLine);
                    }
                }
            }

            return(mainProgram);
        }