Beispiel #1
0
        public void SetModuleState(VBComponent component, ParserState state, SyntaxErrorException parserError = null)
        {
            if (AllUserDeclarations.Count > 0)
            {
                var projectId = component.Collection.Parent.HelpFile;

                VBProject project = null;
                foreach (var item in _projects)
                {
                    if (item.Value.HelpFile == projectId)
                    {
                        project = project != null ? null : item.Value;
                    }
                }

                if (project == null)
                {
                    // ghost component shouldn't even exist
                    ClearStateCache(component);
                    Status = EvaluateParserState();
                    return;
                }
            }
            var key = new QualifiedModuleName(component);

            _moduleStates.AddOrUpdate(key, new ModuleState(state), (c, e) => e.SetState(state));
            _moduleStates.AddOrUpdate(key, new ModuleState(parserError), (c, e) => e.SetModuleException(parserError));
            Logger.Debug("Module '{0}' state is changing to '{1}' (thread {2})", key.ComponentName, state, Thread.CurrentThread.ManagedThreadId);
            OnModuleStateChanged(component, state);
            Status = EvaluateParserState();
        }
        public static ParameterBase[] GetParameters(ParsingData parser, ParameterDefineNode[] defineNodes)
        {
            ParameterBase[] parameters = new ParameterBase[defineNodes.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                EnumData    enumData = null;
                DefinedType type     = null;
                if (defineNodes[i].Type != null)
                {
                    enumData = EnumData.GetEnum(defineNodes[i].Type);
                    type     = parser.GetDefinedType(defineNodes[i].Type, null);

                    if (enumData == null && type == null)
                    {
                        throw SyntaxErrorException.NonexistentType(defineNodes[i].Type, defineNodes[i].Location);
                    }
                }

                if (enumData != null)
                {
                    parameters[i] = new EnumParameter(defineNodes[i].VariableName, enumData.Type);
                }

                else if (type != null)
                {
                    parameters[i] = new TypeParameter(defineNodes[i].VariableName, type);
                }

                else
                {
                    parameters[i] = new Parameter(defineNodes[i].VariableName, Elements.ValueType.Any, null);
                }
            }
            return(parameters);
        }
 public ParserException(SyntaxErrorException e, string reference)
 {
     this.message     = "Error on Syntax";
     this.reference   = reference;
     this.description = e.Message;
     this.Parse(e.DecoratedMessage);
 }
        public IWorkshopTree[] ParseParameters(ScopeGroup getter, ScopeGroup scope, ParameterBase[] parameters, Node[] values, string methodName, LanguageServer.Location methodRange)
        {
            // Syntax error if there are too many parameters.
            if (values.Length > parameters.Length)
            {
                throw SyntaxErrorException.TooManyParameters(methodName, parameters.Length, values.Length, values[parameters.Length].Location);
            }

            // Parse the parameters
            List <IWorkshopTree> parsedParameters = new List <IWorkshopTree>();

            for (int i = 0; i < parameters.Length; i++)
            {
                // Get the default parameter value if there are not enough parameters.
                if (values.Length <= i)
                {
                    parsedParameters.Add(GetDefaultValue(parameters[i], methodName, methodRange));
                }
                else
                {
                    parsedParameters.Add(parameters[i].Parse(this, getter, scope, values[i]));
                }
            }
            return(parsedParameters.ToArray());
        }
        public Importer(Diagnostics diagnostics, List <string> importedFiles, string file, string referencePath, Location location)
        {
            FileName      = Path.GetFileName(file);
            FileType      = Path.GetExtension(file);
            ResultingPath = Extras.CombinePathWithDotNotation(referencePath, file);

            // Syntax error if the filename has invalid characters.
            if (ResultingPath == null)
            {
                throw SyntaxErrorException.InvalidImportPathChars(file, location);
            }

            // Syntax error if the file is importing itself.
            if (referencePath == ResultingPath)
            {
                throw SyntaxErrorException.SelfImport(location);
            }

            // Syntax error if the file does not exist.
            if (!System.IO.File.Exists(ResultingPath))
            {
                throw SyntaxErrorException.ImportFileNotFound(ResultingPath, location);
            }

            // Warning if the file was already imported.
            if (importedFiles.Contains(ResultingPath))
            {
                diagnostics.Warning(string.Format(SyntaxErrorException.alreadyImported, FileName), location);
                AlreadyImported = true;
            }
            else
            {
                AlreadyImported = false;
            }
        }
        public void SetModuleState(QualifiedModuleName module, ParserState state, SyntaxErrorException parserError = null, bool evaluateOverallState = true)
        {
            if (AllUserDeclarations.Any())
            {
                var        projectId = module.ProjectId;
                IVBProject project   = GetProject(projectId);

                if (project == null)
                {
                    // ghost component shouldn't even exist
                    ClearStateCache(module);
                    EvaluateParserState();
                    return;
                }
            }

            var oldState = GetModuleState(module);

            _moduleStates.AddOrUpdate(module, new ModuleState(state), (c, e) => e.SetState(state));
            _moduleStates.AddOrUpdate(module, new ModuleState(parserError), (c, e) => e.SetModuleException(parserError));
            Logger.Debug("Module '{0}' state is changing to '{1}' (thread {2})", module.ComponentName, state, Thread.CurrentThread.ManagedThreadId);
            OnModuleStateChanged(module, state, oldState);
            if (evaluateOverallState)
            {
                EvaluateParserState();
            }
        }
Beispiel #7
0
        /// <summary>
        /// Converts the DLR SyntaxErrorException into a Python new-style SyntaxError instance.
        /// </summary>
        private static BaseException /*!*/ SyntaxErrorToPython(SyntaxErrorException /*!*/ e)
        {
            PythonExceptions._SyntaxError se;
            if (e.GetType() == typeof(IndentationException))
            {
                se = new _SyntaxError(IndentationError);
            }
            else if (e.GetType() == typeof(TabException))
            {
                se = new _SyntaxError(TabError);
            }
            else
            {
                se = new _SyntaxError();
            }

            string sourceLine = PythonContext.GetSourceLine(e);
            string fileName   = e.GetSymbolDocumentName();
            object column     = (e.Column == 0 || e.Data[PythonContext._syntaxErrorNoCaret] != null) ? null : (object)e.Column;

            se.args = PythonTuple.MakeTuple(e.Message, PythonTuple.MakeTuple(fileName, e.Line, column, sourceLine));

            se.filename = fileName;
            se.lineno   = e.Line;
            se.offset   = column;
            se.text     = sourceLine;
            se.msg      = e.Message;

            e.SetPythonException(se);

            return(se);
        }
Beispiel #8
0
        override protected MethodResult Get()
        {
            if (((VarRef)Parameters[0]).Var is ModelVar == false)
            {
                throw SyntaxErrorException.InvalidVarRefType(((VarRef)Parameters[0]).Var.Name, VarType.Model, ParameterLocations[0]);
            }

            //throw new SyntaxErrorException("Variable must reference a model.", ParameterLocations[0]);

            ModelVar   modelVar  = (ModelVar)((VarRef)Parameters[0]).Var;
            Element    visibleTo = (Element)Parameters[1];
            Element    location  = (Element)Parameters[2];
            Element    scale     = (Element)Parameters[3];
            EnumMember effectRev = (EnumMember)Parameters[4];
            bool       getIds    = (bool)((ConstantObject)Parameters[5]).Value;

            List <Element> actions = new List <Element>();

            IndexedVar effects = null;

            if (getIds)
            {
                effects = TranslateContext.VarCollection.AssignVar(Scope, "Model Effects", TranslateContext.IsGlobal, null);
                actions.AddRange(effects.SetVariable(new V_EmptyArray()));
            }

            actions.AddRange(RenderModel(modelVar.Model, visibleTo, location, scale, effectRev, effects));

            return(new MethodResult(actions.ToArray(), effects?.GetVariable()));
        }
 public V_String(LanguageServer.Location location, string text, params Element[] stringValues) : base(NullifyEmptyValues(stringValues))
 {
     TextID = Array.IndexOf(Constants.Strings, text);
     if (TextID == -1)
     {
         throw SyntaxErrorException.InvalidString(text, location);
     }
 }
 public V_String(Range range, string text, params Element[] stringValues) : base(NullifyEmptyValues(stringValues))
 {
     TextID = Array.IndexOf(Constants.Strings, text);
     if (TextID == -1)
     {
         throw SyntaxErrorException.InvalidString(text, range);
     }
 }
Beispiel #11
0
        public Task ParseAsync(IReadOnlyList <CodeDocument> codes, IReadOnlyList <object> windows)
        {
            return(Task.Run(() =>
            {
                AlgorithmProgram = null;
                Error = null;

                _syntaxTreeBuilder = new SyntaxTreeBuilder();
                try
                {
                    foreach (var code in codes)
                    {
                        _languageParser.Reset();
                        _syntaxTreeBuilder.Reset();
                        _lexer.Initialize(code.DocumentName, code.Code);

                        var nextExpectedToken = TokenType.Unknow;
                        var previousLineNumber = 1;
                        var previousLinePosition = 0;

                        while (_lexer.Next())
                        {
                            if (nextExpectedToken != TokenType.Unknow && _lexer.CurrentTokenDefinition.Token != nextExpectedToken)
                            {
                                throw new SyntaxErrorException(code.DocumentName, _lexer.CurrentLineNumber, _lexer.CurrentLinePosition, $"A {nextExpectedToken.GetDescription()} is expected.");
                            }

                            nextExpectedToken = TokenType.Unknow;
                            if (_lexer.CurrentTokenDefinition.Evaluator != null)
                            {
                                var evaluatorResult = _lexer.CurrentTokenDefinition.Evaluator(_lexer.CurrentTokenContents, _lexer.CurrentSplittedTokenContents, new EvaluatorArgument(code.DocumentName, previousLineNumber, previousLinePosition));
                                if (evaluatorResult != null)
                                {
                                    nextExpectedToken = evaluatorResult.NextExpectedToken;
                                    _syntaxTreeBuilder.BuildSyntaxTree(new SyntaxTreeBuilderArgument(code.DocumentName, previousLineNumber, previousLinePosition, evaluatorResult));
                                }
                            }
                            previousLineNumber = _lexer.CurrentLineNumber;
                            previousLinePosition = _lexer.CurrentLinePosition;
                        }
                    }
                    AlgorithmProgram = _syntaxTreeBuilder.AlgorithmProgram;
                }
                catch (SyntaxErrorException syntaxErrorException)
                {
                    AlgorithmProgram = null;
                    Error = syntaxErrorException;
                }

                _syntaxTreeBuilder.Dispose();
                _syntaxTreeBuilder = null;

                if (ParsingCompleted != null)
                {
                    ParsingCompleted(this, new EventArgs());
                }
            }));
        }
Beispiel #12
0
            public DynamicExceptionInfo(Exception e)
            {
                ContractUtils.RequiresNotNull(e, "e");

                _exception          = e;
                _dynamicStackFrames = ScriptingRuntimeHelpers.GetDynamicStackFrames(e);

                // We can get the file name and line number from either the
                // DynamicStackFrame or from a SyntaxErrorException
                SyntaxErrorException se = e as SyntaxErrorException;

                if (null != se)
                {
                    _sourceFileName = se.GetSymbolDocumentName();
                    _sourceLine     = se.Line;
                }
                else if (_dynamicStackFrames != null && _dynamicStackFrames.Length > 0)
                {
                    _sourceFileName = _dynamicStackFrames[0].GetFileName();
                    _sourceLine     = _dynamicStackFrames[0].GetFileLineNumber();
                }

                // Try to get the ScriptEngine from the source file's extension;
                // if that fails just use the current ScriptEngine
                ScriptEngine engine = null;

                try {
                    if (_sourceFileName != null)
                    {
                        var extension = System.IO.Path.GetExtension(_sourceFileName);
                        _runtime.TryGetEngineByFileExtension(extension, out engine);
                    }
                    else
                    {
                        throw new Exception();
                    }
                } catch {
                    if (DynamicApplication.Current.Engine != null)
                    {
                        engine = DynamicApplication.Current.Engine.Engine;
                    }
                }

                // If we have the file name and the engine, use ExceptionOperations
                // to generate the exception message. Otherwise, create it by hand
                if (_sourceFileName != null && engine != null)
                {
                    ExceptionOperations es = engine.GetService <ExceptionOperations>();
                    es.GetExceptionMessage(_exception, out _message, out _errorTypeName);
                }
                else
                {
                    _errorTypeName = _exception.GetType().Name;
                    _message       = _errorTypeName + ": " + _exception.Message;
                }
            }
        public DefinedType GetDefinedType(string name, Location location)
        {
            DefinedType type = DefinedTypes.FirstOrDefault(dt => dt.Name == name);

            if (type == null && location != null)
            {
                throw SyntaxErrorException.NonexistentType(name, location);
            }
            return(type);
        }
Beispiel #14
0
        private void LogParseException(VBComponent component, SyntaxErrorException exception)
        {
            var offendingProject   = component.Collection.Parent.Name;
            var offendingComponent = component.Name;
            var offendingLine      = component.CodeModule.get_Lines(exception.LineNumber, 1);

            var message = string.Format("Parser encountered a syntax error in {0}.{1}, line {2}. Content: '{3}'", offendingProject, offendingComponent, exception.LineNumber, offendingLine);

            _logger.ErrorException(message, exception);
        }
Beispiel #15
0
        /*
         * public DefinedVar(ScopeGroup scopeGroup, DefinedNode node, VarCollection varCollection)
         *  : base(node.VariableName, node.IsGlobal, varCollection.UseVar, node.UseIndex ?? varCollection.Assign(node.IsGlobal))
         * {
         *  if (scopeGroup.IsVar(node.VariableName))
         *      throw SyntaxErrorException.AlreadyDefined(node.VariableName, node.Range);
         *
         *  scopeGroup.In(this);
         * }
         */

        public DefinedVar(ScopeGroup scopeGroup, string name, bool isGlobal, Variable variable, int index, Range range)
            : base(name, isGlobal, variable, index)
        {
            if (scopeGroup.IsVar(name))
            {
                throw SyntaxErrorException.AlreadyDefined(name, range);
            }

            scopeGroup./* we're */ In(this) /* together! */;
        }
        void IDebugger.SignalSyntaxException(SyntaxErrorException ex)
        {
            lock (m_Lock)
                if (Client == null)
                {
                    return;
                }

            Client.OnException(ex);
        }
Beispiel #17
0
        public Var GetVar(ScopeGroup getter, string name, Location location)
        {
            Var var = GetScopeable <Var>(getter, name);

            if (var == null && location != null)
            {
                throw SyntaxErrorException.VariableDoesNotExist(name, location);
            }
            return(var);
        }
 /// <summary> シンタックスエラーを処理 </summary>
 /// <param name="ex"></param>
 private void ProcessScriptSyntaxError(SyntaxErrorException ex)
 {
     ProcessScriptExceptionAndExit(
         ex,
         string.Format("\n ファイル名:\"{0}\" \n 位置: 第{1}行, 第{2}列",
                       ex.SourcePath,
                       ex.Line,
                       ex.Column
                       )
         );
 }
Beispiel #19
0
        public static NavigateCodeEventArgs GetNavigateCodeEventArgs(this SyntaxErrorException exception, Declaration declaration)
        {
            if (declaration == null)
            {
                return(null);
            }

            var selection = new Selection(exception.LineNumber, exception.Position, exception.LineNumber, exception.Position);

            return(new NavigateCodeEventArgs(declaration.QualifiedName.QualifiedModuleName, selection));
        }
Beispiel #20
0
        private LexerState SelectState()
        {
            char cs = _iterator.CurrentSymbol;

            if (Char.IsLetter(cs) || cs == SpecialChars.Underscore)
            {
                _state = _wordState;
            }
            else if (Char.IsDigit(cs))
            {
                _state = _numberState;
            }
            else if (cs == SpecialChars.DateQuote)
            {
                _state = _dateState;
            }
            else if (cs == SpecialChars.StringQuote)
            {
                _state = _stringState;
            }
            else if (SpecialChars.IsOperatorChar(cs))
            {
                _state = CommentOrOperatorState(cs);
            }
            else if (cs == SpecialChars.EndOperator)
            {
                SetFixedState(LexemType.EndOperator, Token.Semicolon);
            }
            else if (cs == SpecialChars.QuestionMark)
            {
                SetFixedState(LexemType.Operator, Token.Question);
            }
            else if (cs == SpecialChars.Preprocessor)
            {
                _state = _directiveState;
            }
            else if (cs == SpecialChars.Annotation)
            {
                _iterator.GetContents();
                _iterator.MoveNext();
                _state = _annotationState;
            }
            else
            {
                var cp  = _iterator.GetPositionInfo();
                var exc = new SyntaxErrorException(cp, string.Format("Неизвестный символ {0}", cs));
                if (!HandleError(exc))
                {
                    throw exc;
                }
            }

            return(_state);
        }
 public void RegisterParameters(ParsingData parser)
 {
     Constructors = new Constructor[ConstructorNodes.Length];
     for (int i = 0; i < Constructors.Length; i++)
     {
         if (ConstructorNodes[i].Name != Name)
         {
             throw SyntaxErrorException.ConstructorName(ConstructorNodes[i].Location);
         }
         Constructors[i] = new Constructor(parser, ConstructorNodes[i]);
     }
 }
        private IWorkshopTree GetDefaultValue(ParameterBase parameter, string methodName, Location methodRange)
        {
            IWorkshopTree defaultValue = parameter.GetDefault();

            // If there is no default value, throw a syntax error.
            if (defaultValue == null)
            {
                throw SyntaxErrorException.MissingParameter(parameter.Name, methodName, methodRange);
            }

            return(defaultValue);
        }
Beispiel #23
0
 public void In(IScopeable var)
 {
     //if (!FullVarCollection().Any(v => var.Name == v.Name))
     if (IsAlreadyDefined(var.Name) && var.Node != null)
     {
         throw SyntaxErrorException.AlreadyDefined(var.Name, var.Node.Location);
     }
     else
     {
         InScope.Add(var);
     }
 }
        protected DefinedType(TypeDefineNode node)
        {
            if (EnumData.GetEnum(node.Name) != null)
            {
                throw SyntaxErrorException.TypeNameConflict(node.Name, node.Location);
            }

            Name        = node.Name;
            DefinedVars = node.DefinedVars;
            MethodNodes = node.Methods;

            ConstructorNodes = node.Constructors;
        }
Beispiel #25
0
        private void OnParserError(SyntaxErrorException exception, VBComponent component)
        {
            if (LogManager.IsLoggingEnabled())
            {
                LogParseException(exception, component);
            }

            var handler = ParserError;

            if (handler != null)
            {
                handler(this, new ParseErrorEventArgs(exception, component));
            }
        }
Beispiel #26
0
        public ModuleState(SyntaxErrorException moduleException)
        {
            Declarations          = new ConcurrentDictionary <Declaration, byte>();
            TokenStream           = null;
            ParseTree             = null;
            State                 = ParserState.Error;
            ModuleContentHashCode = 0;
            Comments              = new List <CommentNode>();
            Annotations           = new List <IAnnotation>();
            ModuleException       = moduleException;
            ModuleAttributes      = new Dictionary <Tuple <string, DeclarationType>, Attributes>();

            IsNew = true;
        }
Beispiel #27
0
        public IMethod GetMethod(ScopeGroup getter, string name, Location location)
        {
            // Get the method by it's name.
            IMethod method = GetScopeable <UserMethod>(getter, name)
                             // If it is not found, check if its a workshop method.
                             ?? (IMethod)Element.GetElement(name)
                             // Then check if its a custom method.
                             ?? (IMethod)CustomMethodData.GetCustomMethod(name);

            // Throw if not found.
            if (method == null && location != null)
            {
                throw SyntaxErrorException.NonexistentMethod(name, location);
            }
            return(method);
        }
 public static void CheckMethodType(bool needsToBeValue, CustomMethodType type, string methodName, Location location)
 {
     if (type == CustomMethodType.Action)
     {
         if (needsToBeValue)
         {
             throw SyntaxErrorException.InvalidMethodType(true, methodName, location);
         }
     }
     else if (type == CustomMethodType.Value)
     {
         if (!needsToBeValue)
         {
             throw SyntaxErrorException.InvalidMethodType(false, methodName, location);
         }
     }
 }
Beispiel #29
0
        public ModuleState(SyntaxErrorException moduleException)
        {
            Declarations = new ConcurrentDictionary <Declaration, byte>();
            UnresolvedMemberDeclarations = new ConcurrentDictionary <UnboundMemberDeclaration, byte>();
            TokenStream           = null;
            ParseTree             = null;
            State                 = ParserState.Error;
            ModuleContentHashCode = 0;
            Comments              = new List <CommentNode>();
            Annotations           = new List <IAnnotation>();
            ModuleException       = moduleException;
            ModuleAttributes      = new Dictionary <Tuple <string, DeclarationType>, Attributes>();
            HasReferenceToModule  = new ConcurrentDictionary <QualifiedModuleName, byte>();
            IsReferencedByModule  = new HashSet <QualifiedModuleName>();

            IsNew = true;
        }
        public void SetModuleState(IVBComponent component, ParserState state, SyntaxErrorException parserError = null, bool evaluateOverallState = true)
        {
            if (AllUserDeclarations.Count > 0)
            {
                var projectId = component.Collection.Parent.HelpFile;

                IVBProject project = null;
                lock (_projects)
                {
                    foreach (var item in _projects)
                    {
                        if (item.Value.HelpFile == projectId)
                        {
                            if (project != null)
                            {
                                // ghost component detected, abort project iteration
                                project = null;
                                break;
                            }
                            project = item.Value;
                        }
                    }
                }

                if (project == null)
                {
                    // ghost component shouldn't even exist
                    ClearStateCache(component);
                    EvaluateParserState();
                    return;
                }
            }
            var key = new QualifiedModuleName(component);

            var oldState = GetModuleState(component);

            _moduleStates.AddOrUpdate(key, new ModuleState(state), (c, e) => e.SetState(state));
            _moduleStates.AddOrUpdate(key, new ModuleState(parserError), (c, e) => e.SetModuleException(parserError));
            Logger.Debug("Module '{0}' state is changing to '{1}' (thread {2})", key.ComponentName, state, Thread.CurrentThread.ManagedThreadId);
            OnModuleStateChanged(component, state, oldState);
            if (evaluateOverallState)
            {
                EvaluateParserState();
            }
        }
        //Überschreibbare Funktion, die die Formelauswertung steuert.
        protected virtual string Parse(string Formular, string OperatorRegEx)
        {
            string locTemp = null;
            Match locTerm = null;
            Match locFuncName = null;
            MatchCollection locMoreInnerTerms = null;
            List<double> locPreliminaryResult = new List<double>();
            bool locFuncFound = false;
            string locOperatorRegEx = "\\([\\d\\;" + OperatorRegEx + "]*\\)";

            FormulaEvaluatorFunction adf = null;

            locTerm = Regex.Match(Formular, locOperatorRegEx);
            if (!string.IsNullOrEmpty(locTerm.Value))
            {
                locTemp = Formular.Substring(0, locTerm.Index);

                //Befindet sich ein Funktionsname davor?
                locFuncName = Regex.Match(locTemp, "[a-zA-Z]*", RegexOptions.RightToLeft);

                //Gibt es mehrere, durch ; getrennte Parameter?
                locMoreInnerTerms = Regex.Matches(locTerm.Value, "[\\d" + OperatorRegEx + "]*[;|\\)]");

                //Jeden Parameterterm auswerten und zum Parameter-Array hinzufügen
                foreach (Match locMatch in locMoreInnerTerms)
                {
                    locTemp = locMatch.Value;
                    locTemp = locTemp.Replace(";", "").Replace(")", "");
                    locPreliminaryResult.Add(ParseSimpleTerm(locTemp));
                }

                //Möglicher Syntaxfehler: Mehrere Parameter, aber keine Funktion
                if (string.IsNullOrEmpty(locFuncName.Value) && locMoreInnerTerms.Count > 1)
                {
                    SyntaxErrorException up = new SyntaxErrorException("Fehler in Formel: Mehrere Klammerparameter aber kein Funktionsname angegeben!");
                    throw up;
                }

                if (!string.IsNullOrEmpty(locFuncName.Value))
                {
                    //Funktionsnamen suchen
                    locFuncFound = false;
                    foreach (FormulaEvaluatorFunction adfWithinLoop in myFunctions)
                    {
                        adf = adfWithinLoop;
                        if (adfWithinLoop.FunctionName.ToUpper() == locFuncName.Value.ToUpper())
                        {
                            locFuncFound = true;
                            break;
                        }
                    }

                    if (locFuncFound == false)
                    {
                        SyntaxErrorException up = new SyntaxErrorException("Fehler in Formel: Der Funktionsname wurde nicht gefunden");
                        throw up;
                    }
                    else
                    {
                        Formular = Formular.Replace(locFuncName.Value + locTerm.Value, myConstEnumCounter.ToString("000"));
                        double[] locArgs = new double[locPreliminaryResult.Count];
                        locPreliminaryResult.CopyTo(locArgs);
                        //Diese Warnung bezieht sich auf einen hypothetischen Fall,
                        //der aber nie eintreten kann! :-)
                        myConsts.Add(adf.Operate(locArgs));
                        myConstEnumCounter += 1;
                    }
                }
                else
                {
                    Formular = Formular.Replace(locTerm.Value, myConstEnumCounter.ToString("000"));
                    myConsts.Add(Convert.ToDouble(locPreliminaryResult[0]));
                    myConstEnumCounter += 1;
                }
            }
            else
            {
                return Formular;
            }
            Formular = Parse(Formular, OperatorRegEx);
            return Formular;
        }
        //Hier werden vorbereitende Arbeiten durchgeführt.
        protected virtual string PrepareFormular(string Formular, string OperatorRegEx)
        {
            int locBracketCounter = 0;

            //Klammern überprüfen
            foreach (char locChar in Formular.ToCharArray())
            {
                if (locChar == '(')
                {
                    locBracketCounter += 1;
                }

                if (locChar == ')')
                {
                    locBracketCounter -= 1;
                    if (locBracketCounter < 0)
                    {
                        SyntaxErrorException up = new SyntaxErrorException("Error in Formular: Too many closing brackets.");
                        throw up;
                    }
                }
            }
            if (locBracketCounter > 0)
            {
                SyntaxErrorException up = new SyntaxErrorException("Error in Formular: An open bracket was not closed.");
                throw up;
            }

            //White-Spaces entfernen
            Formular = Regex.Replace(Formular, "\\s", "");

            //Vorzeichen verarbeiten
            if (Formular.StartsWith("-") || Formular.StartsWith("+"))
            {
                Formular = Formular.Insert(0, "0");
            }

            //Sonderfall negative Klammer
            Formular = Regex.Replace(Formular, "\\(-\\(", "(0-(");

            return Regex.Replace(Formular, "(?<operator>[" + OperatorRegEx + "\\(])-(?<zahl>[\\d\\.\\,]*)", "${operator}((0-1)*${zahl})");
        }
Beispiel #33
0
 public SyntaxErrorException Add(SyntaxErrorException exception) {
     Add(exception.SourceUnit, exception.Message, exception.RawSpan, exception.ErrorCode, exception.Severity);
     return exception;
 }