Пример #1
0
        /// <summary>
        ///     Validates the format of a string is acceptable for assigning to <see cref="ValueString" /> when <see cref="Type" />
        ///     is equal to <see cref="LSLType.Float" />.
        /// </summary>
        /// <param name="value">The value string to validate.</param>
        /// <param name="valueString">The re-formated version of <paramref name="valueString" /> if the parse was successful.</param>
        /// <param name="errMessage">An error message describing why the parse failed if this function returns <c>false</c>.</param>
        /// <returns><c>true</c> if <paramref name="valueString" /> can successfully be parsed for <see cref="LSLType.Float" />.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="value" /> is <c>null</c>.</exception>
        public static bool TryParseFloatValueString(string value, out string valueString, out string errMessage)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value", "value cannot be null.");
            }

            valueString = null;

            string stripSpecifiers = value.TrimEnd('f', 'F');

            try
            {
                valueString = LSLFormatTools.FormatFloatString(stripSpecifiers);
            }
            catch (FormatException)
            {
                errMessage =
                    string.Format("Float Constant ValueString:  Given string '{0}' is not a valid LSL float value.",
                                  value);

                return(false);
            }

            errMessage = null;
            return(true);
        }
Пример #2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="LSLListFloatExpr" /> class.
 /// </summary>
 /// <param name="val">The value.</param>
 /// <param name="hex">if set to <c>true</c> val is parsed from hexadecimal notation.</param>
 public LSLListFloatExpr(string val, bool hex = false)
 {
     if (hex)
     {
         Value = Convert.ToInt32(val, 16);
     }
     else
     {
         var v = LSLFormatTools.FormatFloatString(val.TrimEnd('f', 'F'));
         Value = float.Parse(v);
     }
 }
Пример #3
0
        /// <summary>
        ///     Validates the format of a string is acceptable for assigning to <see cref="ValueString" /> when <see cref="Type" />
        ///     is equal to <see cref="LSLType.Vector" />.
        /// </summary>
        /// <param name="value">The value string to validate.</param>
        /// <param name="valueString">The re-formated version of <paramref name="valueString" /> if the parse was successful.</param>
        /// <param name="errMessage">An error message describing why the parse failed if this function returns <c>false</c>.</param>
        /// <returns><c>true</c> if <paramref name="valueString" /> can successfully be parsed for <see cref="LSLType.Vector" />.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="value" /> is <c>null</c>.</exception>
        public static bool TryParseVectorValueString(string value, out string valueString, out string errMessage)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value", "value cannot be null.");
            }

            valueString = null;

            string s = value.Trim(' ');


            if (string.IsNullOrWhiteSpace(s))
            {
                errMessage =
                    "Vector Constant ValueString Invalid: May not be null or whitespace.";

                return(false);
            }

            char firstChar = s[0];
            char lastChar  = s[s.Length - 1];

            if ((firstChar == '<' || lastChar == '>') &&
                (firstChar != '<' || lastChar != '>'))
            {
                errMessage =
                    "Vector Constant ValueString '{0}' Invalid: If vector quotes are used for a Vector value string, both '<' and '>' must be present.";
                return(false);
            }

            if (firstChar == '<')
            {
                s = s.Substring(1, s.Length - 2);
            }


            var match = VectorValidationRegex.Match(s);

            if (!match.Success)
            {
                errMessage =
                    string.Format("Vector Constant ValueString: '{0}' could not be parsed and formated.", value);

                return(false);
            }

            valueString = string.Join(", ", s.Split(',').Select(x => LSLFormatTools.FormatFloatString(x.TrimEnd('f', 'F'))));

            errMessage = null;
            return(true);
        }
        /// <summary>
        ///     Determines whether the float literal node is a literal value that overflows/underflows a 32 bit float.
        /// </summary>
        /// <param name="node">The float literal node to test.</param>
        /// <returns><see cref="LSLLiteralOverflowType"/>.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="node"/> is <c>null</c>.</exception>
        public static LSLLiteralOverflowType CheckForOverflow(this ILSLFloatLiteralNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }


            var formatedFloatString = LSLFormatTools.FormatFloatString(node.RawText.TrimEnd('f', 'F'));

            bool nonZero = formatedFloatString.TakeWhile(c => c != 'e').Any(c => c != '0' && c != '.' && c != 'f');

            if (!nonZero)
            {
                return(LSLLiteralOverflowType.None);
            }

            double val;

            try
            {
                val = double.Parse(formatedFloatString);
            }
            catch (OverflowException)
            {
                return(LSLLiteralOverflowType.Overflow);
            }


            if (val > 3.402823466E+38)
            {
                return(LSLLiteralOverflowType.Overflow);
            }
            if (val < 1.401298464E-45)
            {
                return(LSLLiteralOverflowType.Underflow);
            }

            return(LSLLiteralOverflowType.None);
        }
Пример #5
0
        public void Complete(TextArea textArea, ISegment completionSegment, EventArgs insertionRequestEventArgs)
        {
            var prep          = string.IsNullOrEmpty(PrependOnInsert) ? "" : PrependOnInsert;
            var app           = string.IsNullOrEmpty(AppendOnInsert) ? "" : AppendOnInsert;
            var insertionText = string.IsNullOrWhiteSpace(CaretOffsetInsertionText) ? "" : CaretOffsetInsertionText;

            //AvalonEdit apparently MODFIES segment descriptions passed to Document.Replace. wtf.exe
            //this took me a long time to debug.
            var completionOffset = completionSegment.Offset;

            var text = prep + Text + app;

            int offsetFromBegining = CaretOffsetAfterInsert;

            bool lineBroken = false;

            if (ForceIndent)
            {
                var indent = LSLFormatTools.CreateTabsString(IndentLevel);

                int i;
                int length = 0;
                for (i = completionSegment.Offset - 1;
                     i >= 0 &&
                     textArea.Document.Text[i] != '\n';
                     i--)
                {
                    if (MatchOneOfBackwards(IndentBreakCharacters, textArea.Document.Text, i))
                    {
                        lineBroken = true;
                    }

                    length++;
                }

                text = "\n" + IndentString(text, indent, true, offsetFromBegining, out offsetFromBegining);

                if (!lineBroken)
                {
                    textArea.Document.Replace(i, length + completionSegment.Length + 1, text);
                    completionOffset = i + IndentLevel + 1;
                }
                else
                {
                    textArea.Document.Replace(completionOffset, completionSegment.Length, text);
                    completionOffset += IndentLevel + 1;
                }
            }
            else
            {
                textArea.Document.Replace(completionOffset, completionSegment.Length, text);
            }

            if (!OffsetCaretAfterInsert)
            {
                return;
            }

            if (OffsetCaretFromBegining)
            {
                textArea.Caret.Offset = Clamp(completionOffset + offsetFromBegining, 0, textArea.Document.TextLength);
            }
            else if (OffsetCaretRelativeToDocument)
            {
                textArea.Caret.Offset = Clamp(CaretOffsetAfterInsert, 0, textArea.Document.TextLength);
            }
            else
            {
                textArea.Caret.Offset = Clamp(textArea.Caret.Offset + CaretOffsetAfterInsert, 0, textArea.Document.TextLength);
            }

            if (InsertTextAtCaretAfterOffset)
            {
                textArea.Document.Insert(textArea.Caret.Offset, insertionText);
            }
        }
Пример #6
0
        private void Initialize(bool newInstance, string[] args)
        {
            ShowEndOfLine = AppSettings.Settings.ShowEndOfLine;
            ShowSpaces    = AppSettings.Settings.ShowSpaces;
            ShowTabs      = AppSettings.Settings.ShowTabs;


            var entryAssembly = Assembly.GetEntryAssembly();

            Title = "LSLCCEditor v" + entryAssembly.GetName().Version;


            var assembly = entryAssembly.Location;

            var appDirectory = Path.GetDirectoryName(assembly);


            _libraryDataProvider = new LSLXmlLibraryDataProvider(new[] { "lsl" });


            try
            {
                _libraryDataProvider.FillFromXmlDirectory(Path.Combine(appDirectory, "library_data"));
            }
            catch (LSLLibraryDataXmlSyntaxException err)
            {
                MessageBox.Show(this,
                                "There is a syntax error in one of your XML library data files and the application must close."
                                + LSLFormatTools.CreateNewLinesString(2) + err.Message,
                                "Library Data Syntax Error", MessageBoxButton.OK, MessageBoxImage.Error);

                Application.Current.Shutdown();
            }


            _codeValidatorStrategies = new LSLCodeValidatorStrategies
            {
                ExpressionValidator       = new LSLDefaultExpressionValidator(),
                StringLiteralPreProcessor = new LSLDefaultStringPreProcessor(),
                SyntaxErrorListener       = new WindowSyntaxErrorListener(this),
                SyntaxWarningListener     = new WindowSyntaxWarningListener(this),
                LibraryDataProvider       = _libraryDataProvider
            };


            foreach (var dataMenuItem in _libraryDataProvider.SubsetDescriptions.Select(subset => new MenuItem
            {
                StaysOpenOnClick = true,
                IsCheckable = true,
                Header = subset.Value.FriendlyName,
                Tag = subset.Value.Subset,
                ToolTip = new ToolTip {
                    Content = new TextBlock {
                        Text = subset.Value.Description
                    }
                }
            }))
            {
                dataMenuItem.Checked   += DataMenuItemOnChecked;
                dataMenuItem.Unchecked += DataMenuItemOnUnChecked;
                TabLibraryDataMenu.Items.Add(dataMenuItem);
            }


            FindDialogManager = new FindReplaceMgr
            {
                OwnerWindow        = this,
                InterfaceConverter = new IEditorConverter(),
                ShowSearchIn       = false
            };

            if (args.Length > 0)
            {
                foreach (string arg in args)
                {
                    var tab = CreateEditorTab();
                    if (tab.OpenFileInteractive(arg))
                    {
                        EditorTabs.Add(tab);
                    }
                }
            }
            else
            {
                EditorTabs.Add(CreateEditorTab());
            }

            if (!newInstance)
            {
                StartOpenTabPipeServer();
            }


            _selectingStartupTabDuringWindowLoad = true;

            TabControl.SelectedIndex = 0;

            var initialTab = (EditorTab)TabControl.SelectedItem;

            initialTab.IsSelected = true;

            SetLibraryMenuFromTab(initialTab);


            FindDialogManager.CurrentEditor = initialTab.Content.EditControl.Editor;


            initialTab.Content.EditControl.Editor.TextChanged += Editor_OnTextChanged;

            EditRedoMenuItem.IsEnabled = initialTab.Content.EditControl.Editor.CanRedo;
            EditUndoMenuItem.IsEnabled = initialTab.Content.EditControl.Editor.CanUndo;


            _selectingStartupTabDuringWindowLoad = false;
        }