Example #1
0
        //protected override string Read(int begin, ITextBuffer buffer) { return ""; }

        public override bool Load(List <TextElement> outElements, int level)
        {
            TextBuffer.FindNextWord(null, false);
            if (TextBuffer.IsEnd())
            {
                return(false);
            }

            TextSubString subStr = new TextSubString(TextBuffer.PointerNextChar);

            if (!AllowedCharsFirst.Contains(TextBuffer.GetChar().ToString().ToLower()))
            {
                return(false);
            }
            else
            {
                TextBuffer.IncPointer();
            }

            while (!TextBuffer.IsEnd() && AllowedCharsNext.Contains(TextBuffer.GetChar().ToString().ToLower()))
            {
                TextBuffer.IncPointer();
            }

            subStr.To = TextBuffer.PointerNextChar;

            //TextBuffer.InsertComments(outElements);
            outElements.Add(new CodeElement(this, subStr));

            //TextBuffer.FindNextWord(outElements, true);
            return(true);
        }
Example #2
0
 internal CommentElement(TextBuffer buffer, TextSubString pointer, bool multiline = false)
 {
     _multiline = multiline;
     Name       = MetaParser.Comment____;
     SubString  = pointer;
     Buffer     = buffer;
 }
Example #3
0
        public override bool ResolveErrorsForward(int level)
        {
            TextBuffer.FindNextWord(null, false);
            int           from   = TextBuffer.PointerNextChar;
            TextSubString subStr = new TextSubString(TextBuffer.PointerNextChar);

            if (TextBuffer.IsEnd(Value.Length - 1))
            {
                TextBuffer.Status.AddSyntaxError(this, TextBuffer.Length, 0, () => MessageRes.itc10, MetaParser.WordSymbol_ + " " + GetGrammar(), "EOF");
                return(SetPointerBack(subStr.From));
            }

            foreach (char ch in Value)
            {
                if ((TextBuffer.GetChar() == ch))
                {
                    TextBuffer.IncPointer();
                }
                else
                {
                    subStr.To = subStr.From + Value.Length;
                    TextBuffer.Status.AddSyntaxError(this, subStr.From, 0, () => MessageRes.itc07, Value, TextBuffer.GetSubString(subStr));
                    return(SetPointerBack(subStr.From));
                }
            }

            TextBuffer.FindNextWord(null, true);
            return(true);
        }
Example #4
0
        //internal override string Read(int begin, ITextBuffer buffer) { return ""; }

        public override bool Load(List <TextElement> outElements, int level)
        {
            TextBuffer.FindNextWord(null, false);
            if (TextBuffer.IsEnd(1) || TextBuffer.GetChar() != '\'')
            {
                return(false);
            }

            int to = TextBuffer.GetIndexAfter("'", TextBuffer.PointerNextChar + 1);

            if (to <= TextBuffer.PointerNextChar)
            {
                return(false);
            }

            TextSubString subStr = new TextSubString(TextBuffer.PointerNextChar + 1)
            {
                To = to - 1
            };

            //TextBuffer.InsertComments(outElements);
            outElements.Add(new CodeElement(this, subStr));

            TextBuffer.PointerNextChar = to;
            TextBuffer.FindNextWord(null, true);
            return(true);
        }
Example #5
0
 internal CodeElement(ParserElementBase element, TextSubString pointer)
 {
     if (element != null)
     {
         Name = element.Name;
     }
     SubString     = pointer;
     ParserElement = element;
 }
        /// <summary>
        /// Trims punctuation characters from the two ends of a word.
        /// </summary>
        /// <param name="subString">The area to trim;</param>
        /// <returns></returns>
        private static TextSubString TrimWordEndCharacters(TextSubString subString)
        {
            int frontTrimCount;
            var resultWord = TrimWordEndCharacters(subString.SubText, out frontTrimCount);

            if (frontTrimCount == 0 && resultWord.Length == subString.Length)
            {
                return(subString);
            }
            return(new TextSubString(subString.Source, subString.Offset + frontTrimCount, resultWord.Length));
        }
        public override bool Load(List <TextElement> outElements, int level)
        {
            TextSubString subStr = new TextSubString(TextBuffer.PointerNextChar);

            if (!base.Load(outElements, level))
            {
                return(false);
            }

            subStr.To = TextBuffer.PointerNextChar;
            var element = new CodeElement(this, subStr);

            outElements.Add(element);

            return(true);
        }
Example #8
0
        public bool Load(IList <TextElement> outElements, bool lineEnd)
        {
            // Read comments on form '// rest of line [cr] nl'
            const string nl = "\n";

            if (TextBuffer.IsEnd(1) || '/' != TextBuffer.GetChar() || '/' != TextBuffer.GetChar(1))
            {
                return(false);
            }

            TextSubString subStr = new TextSubString(TextBuffer.PointerNextChar + 2);

            // add comment
            int nlLenght = 1;

            TextBuffer.SetToIndexOf(subStr, nl);
            if (subStr.To < 0)
            {
                subStr.To = TextBuffer.Length;
                TextBuffer.PointerNextChar = TextBuffer.Length;
            }
            else
            {
                if ('\r' == TextBuffer.GetChar(1 + subStr.To - subStr.From))
                {
                    subStr.To--;
                    nlLenght = 2;
                }
                TextBuffer.PointerNextChar = subStr.To + nlLenght;
            }

            if (!lineEnd)
            {
                CommentBuffer.Add(new CommentElement(TextBuffer, subStr));
            }
            else if (outElements != null)
            {
                outElements.Add(new CommentElement(TextBuffer, subStr));
            }

            return(true);
        }
Example #9
0
 /// <summary>Get string representation of value from buffer.</summary>
 /// <param name="buf"></param>
 /// <param name="ptr"></param>
 /// <returns></returns>
 protected internal virtual string GetWord(TextSubString ptr)
 {
     return(ptr == null || ptr.Length() == 0 ? string.Empty : TextBuffer.GetSubString(ptr));
 }
Example #10
0
        public override bool Load(List <TextElement> outElements, int level)
        {
            TextSubString subStr = new TextSubString(TextBuffer.PointerNextChar);

            if (Collapse)
            {
                if (!LoadSet(outElements, level))
                {
                    return(false);
                }
            }
            else
            {
                var         outSubNotes = new List <TextElement>();
                TextElement element;
                if (!LoadSet(outSubNotes, level))
                {
                    return(false);
                }

                subStr.To = TextBuffer.PointerNextChar;

                // _simplify is true when a rule just contains a single word
                // The word value is inserted directly (collapsed)
                if (Comment)
                {
                    TextBuffer.InsertComments(outElements);
                }
                if (_simplify)
                {
                    element = outSubNotes.FirstOrDefault(n => n is CodeElement);
                    if (element != null)
                    {
                        element.Name = Name;
                    }
                    else
                    {
                        element = new CodeElement(this, subStr);
                    }

                    outElements.Add(element);
                }
                else
                {
                    element = new CodeElement(this, subStr);
                    element.AddRange(outSubNotes);
                    outElements.Add(element);
                }
            }

            if (Comment)
            {
                TextBuffer.FindNextWord(outElements, true);
            }

            // If this is a 'division' set unambiguous and insert comments
            if (Trust && TextBuffer.PointerNextChar > subStr.From && outElements.Count > 0)
            {
                TextBuffer.Status.ThisIsUnambiguous(this, outElements[outElements.Count - 1]);
            }

            return(true);
        }
        //public bool Complete { get; set; }

        protected internal override string GetWord(TextSubString ptr)
        {
            return(string.Empty);
        }
Example #12
0
 protected internal override string GetWord(TextSubString ptr)
 {
     return(_value);
 }