Beispiel #1
0
        public SimpleRecResult ProcessLine(CodeString Line)
        {
            Line = Line.Trim();
            if (Line.Length > 0 && Line[0] == '#')
            {
                var MLine = Line.Substring(1).Trim();
                var Order = MLine.Word().ToString();

                if (Order == "ifdef")
                {
                    if (!DoIf(Line, MLine, PreprocConditionMode.IfDef))
                    {
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (Order == "ifndef")
                {
                    if (!DoIf(Line, MLine, PreprocConditionMode.IfNotDef))
                    {
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (Order == "if")
                {
                    if (!DoIf(Line, MLine, PreprocConditionMode.Normal))
                    {
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (Order == "elif")
                {
                    if (!DoElseIf(Line, MLine, PreprocConditionMode.Normal))
                    {
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (Order == "elifdef")
                {
                    if (!DoElseIf(Line, MLine, PreprocConditionMode.IfDef))
                    {
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (Order == "elifndef")
                {
                    if (!DoElseIf(Line, MLine, PreprocConditionMode.IfNotDef))
                    {
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (Order == "else")
                {
                    if (!DoElse(Line))
                    {
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (Order == "endif")
                {
                    if (!DoEndif(Line))
                    {
                        return(SimpleRecResult.Failed);
                    }
                }
                else if (IsInDefBlock)
                {
                    return(ProcCommands(Order, Line, MLine));
                }

                return(SimpleRecResult.Succeeded);
            }

            return(IsInDefBlock ? SimpleRecResult.Unknown : SimpleRecResult.Succeeded);
        }
Beispiel #2
0
        Macro ProcMacro(CodeString MLine)
        {
            var MacroName = MLine.Word();

            if (!MacroName.IsValidIdentifierName)
            {
                State.Messages.Add(MessageId.NotValidName, MacroName);
                return(null);
            }

            var Params   = new CodeString();
            var Handlers = State.Language.GlobalHandlers;

            if (MLine.Length > 0 && MLine[0] == '(')
            {
                var zp = MLine.GetBracketPos(false, Handlers);
                if (zp > 0)
                {
                    Params = MLine.Substring(1, zp - 1).Trim();
                    MLine  = MLine.Substring(zp + 1).Trim();
                }
            }

            List <string> ParamList = null;

            if (Params.IsValid)
            {
                var PStrList = RecognizerHelper.SplitToParameters(State, Params, ',');
                if (PStrList == null)
                {
                    return(null);
                }

                ParamList = new List <string>();
                for (var i = 0; i < PStrList.Length; i++)
                {
                    var String = PStrList[i].ToString();
                    if (!PStrList[i].IsValidIdentifierName)
                    {
                        State.Messages.Add(MessageId.WrongParamList, PStrList[i]);
                        return(null);
                    }

                    if (ParamList.Contains(String))
                    {
                        State.Messages.Add(MessageId.IdAlreadyDefined, PStrList[i]);
                        return(null);
                    }

                    ParamList.Add(String);
                }
            }

            MLine = MLine.Trim();
            if (MLine.Length > 0)
            {
                var Plugin = new PluginForDefine(Container, ParamList);
                var Node   = Expressions.CreateExpression(MLine, Plugin);

                if (Node != null)
                {
                    return(new Macro(MacroName, Node, ParamList));
                }
                else
                {
                    return(null);
                }
            }

            return(new Macro(MacroName, null, ParamList));
        }