/// <summary>
        /// Visits a group level declaration.
        /// </summary>
        private void VisitGroupLevelDeclaration(StateGroupDeclaration parentNode, TokenRange tokenRange)
        {
            ModifierSet modSet = ModifierSet.CreateDefault();

            while (!this.TokenStream.Done &&
                   this.TokenStream.Peek().Type != TokenType.StateDecl &&
                   this.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                   this.TokenStream.Peek().Type != TokenType.MachineDecl)
            {
                new ModifierVisitor(this.TokenStream).Visit(modSet);

                this.TokenStream.Index++;
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (this.TokenStream.Done ||
                (this.TokenStream.Peek().Type != TokenType.StateDecl &&
                 this.TokenStream.Peek().Type != TokenType.StateGroupDecl))
            {
                throw new ParsingException("Expected state or group declaration.", this.TokenStream.Peek(), TokenType.StateDecl, TokenType.StateGroupDecl);
            }

            if (this.TokenStream.Peek().Type == TokenType.StateDecl)
            {
                new StateDeclarationVisitor(this.TokenStream).Visit(parentNode.Machine, parentNode, modSet, tokenRange.Start());
            }
            else if (this.TokenStream.Peek().Type == TokenType.StateGroupDecl)
            {
                new StateGroupDeclarationVisitor(this.TokenStream).Visit(parentNode.Machine, parentNode, modSet, tokenRange.Start());
            }
        }
Exemplo n.º 2
0
        private IEnumerable <CreoleRichTextElementNodeData> _GetRootNodesFrom(TokenRange <CreoleTokenCode> tokens, IEnumerable <CreoleRichTextElementData> elementsData)
        {
            var rootNodes           = new List <CreoleRichTextElementNodeData>();
            var visitedElementTypes = new List <CreoleRichTextElementType>(10);

            foreach (var elementData in elementsData)
            {
                var node = new CreoleRichTextElementNodeData(elementData);

                IList <CreoleRichTextElementNodeData> siblingNodes = rootNodes;
                while (siblingNodes.Count > 0 && _Contains(siblingNodes[siblingNodes.Count - 1], node))
                {
                    var parentNode = siblingNodes[siblingNodes.Count - 1];
                    siblingNodes = parentNode.ChildNodes;
                    visitedElementTypes.Add(parentNode.ElementType);
                }

                if (node.ElementType == CreoleRichTextElementType.Hyperlink)
                {
                    var contentRange = tokens.SubRange(node.ContentStartIndex, (node.ContentEndIndex - node.ContentStartIndex));
                    foreach (var hyperlinkContentElementNodeData in _GetHyperlinkContentElementNodesData(contentRange, visitedElementTypes))
                    {
                        node.ChildNodes.Add(_AddIndexOffset(node.ContentStartIndex, hyperlinkContentElementNodeData));
                    }
                }

                siblingNodes.Add(node);
                visitedElementTypes.Clear();
            }

            return(rootNodes);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        internal void Visit(StateDeclaration parentNode, TokenRange tokenRange, bool isAsync = false)
        {
            if (parentNode.EntryDeclaration != null)
            {
                throw new ParsingException("Duplicate entry declaration.", this.TokenStream.Peek());
            }

            var node = new EntryDeclaration(this.TokenStream.Program, parentNode, isAsync);

            node.EntryKeyword     = this.TokenStream.Peek();
            node.HeaderTokenRange = tokenRange.FinishAndClone();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".", this.TokenStream.Peek(), TokenType.LeftCurlyBracket);
            }

            var blockNode = new BlockSyntax(this.TokenStream.Program, parentNode.Machine, parentNode);

            new BlockSyntaxVisitor(this.TokenStream).Visit(blockNode);
            node.StatementBlock = blockNode;

            parentNode.EntryDeclaration = node;
        }
Exemplo n.º 4
0
        private string _GetContentFrom(TokenRange <CreoleTokenCode> tokens, CreoleRichTextElementNodeData richTextElementData)
        {
            var contentStartIndex = richTextElementData.ContentStartIndex;
            var contentEndIdnex   = richTextElementData.ContentEndIndex;
            var contentRange      = tokens.SubRange(contentStartIndex, (contentEndIdnex - contentStartIndex));

            return(TokenRangeHelper.GetPlainText(contentRange));
        }
Exemplo n.º 5
0
        private string _GetUrlFrom(TokenRange <CreoleTokenCode> tokens, CreoleRichTextElementNodeData richTextElementData)
        {
            var urlStartIndex = richTextElementData.UrlStartIndex;
            var urlEndIdnex   = richTextElementData.UrlEndIndex;
            var urlRange      = tokens.SubRange(urlStartIndex, (urlEndIdnex - urlStartIndex));

            return(TokenRangeHelper.GetPlainText(urlRange));
        }
Exemplo n.º 6
0
        protected CreoleElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens)
        {
            Context = context;
            _tokens = tokens;

            _token         = tokens.GetEnumerator();
            _tokenHasValue = _token.MoveNext();
        }
 private CreoleRichTextElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens, ICreoleRichTextElementDataIterator elementIterator)
 {
     _tokens  = tokens;
     Context  = context;
     _element = elementIterator;
     if (_element != null && _element.MoveNext())
     {
         _token      = _tokens.SubRange(_startIndex, (_element.Current.StartIndex - _startIndex)).GetEnumerator();
         _startIndex = _element.Current.EndIndex;
     }
     else
     {
         _element?.Dispose();
         _element    = null;
         _token      = _tokens.GetEnumerator();
         _startIndex = _tokens.Count;
     }
 }
Exemplo n.º 8
0
        internal IEnumerable <Element> Process(TokenRange <CreoleTokenCode> tokens)
        {
            var baseElementsData = new List <CreoleRichTextElementData>();

            using (var baseElementProcessor = _GetBaseElementProcessor(_context, tokens))
                while (baseElementProcessor.MoveNext())
                {
                    baseElementsData.Add(baseElementProcessor.Current);
                }

            var elementsData = new List <CreoleRichTextElementData>();

            using (var elementDataIterator = new MergeElementDataIterator(_GetStyleElementIterator(_context, tokens, baseElementsData), new ElementDataCollectionIteratorAdapter(baseElementsData)))
                while (elementDataIterator.MoveNext())
                {
                    elementsData.Add(elementDataIterator.Current);
                }

            return(_GetCreoleElements(tokens, elementsData));
        }
Exemplo n.º 9
0
        private IEnumerable <Element> _GetCreoleElements(TokenRange <CreoleTokenCode> tokens, int startIndex, int endIndex, IEnumerable <CreoleRichTextElementNodeData> nodesData)
        {
            var elements           = new List <Element>();
            var subRangeStartIndex = startIndex;

            foreach (var nodeData in nodesData)
            {
                if (subRangeStartIndex < nodeData.StartIndex)
                {
                    elements.Add(new TextElement(TokenRangeHelper.GetPlainText(tokens.SubRange(subRangeStartIndex, (nodeData.StartIndex - subRangeStartIndex)))));
                }

                elements.Add(_GetCreoleElementFrom(tokens, nodeData));
                subRangeStartIndex = nodeData.EndIndex;
            }
            if (subRangeStartIndex < endIndex)
            {
                var subRange = tokens.SubRange(subRangeStartIndex, (endIndex - subRangeStartIndex));
                elements.Add(new TextElement(TokenRangeHelper.GetPlainText(subRange)));
            }

            return(elements);
        }
Exemplo n.º 10
0
        private string _GetCodeBlockTextFrom(TokenRange <CreoleTokenCode> tokens)
        {
            var builder = new StringBuilder();

            using (var token = tokens.GetEnumerator())
                if (token.MoveNext())
                {
                    var startIndex = (token.Current.Text.IndexOf('\n') + 1);
                    builder.Append(token.Current.Text, startIndex, token.Current.Text.Length - startIndex);

                    if (token.MoveNext())
                    {
                        var previousToken = token.Current;
                        while (token.MoveNext())
                        {
                            builder.Append(previousToken.Text);
                            previousToken = token.Current;
                        }

                        startIndex = previousToken.Text.LastIndexOf('\n');
                        if (startIndex >= 0)
                        {
                            if (startIndex > 0 && previousToken.Text[startIndex - 1] == '\r')
                            {
                                startIndex--;
                            }
                            builder.Append(previousToken.Text, 0, startIndex);
                        }
                        else
                        {
                            builder.Append(previousToken.Text);
                        }
                    }
                }

            return(builder.ToString());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        internal void Visit(NamespaceDeclaration parentNode, bool isMonitor, ModifierSet modSet, TokenRange tokenRange)
        {
            if (isMonitor)
            {
                this.CheckMonitorModifierSet(modSet);
            }
            else
            {
                this.CheckMachineModifierSet(modSet);
            }

            var node = new MachineDeclaration(this.TokenStream.Program, parentNode, isMonitor, modSet);

            node.MachineKeyword = this.TokenStream.Peek();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected machine identifier.", this.TokenStream.Peek(), TokenType.Identifier);
            }

            this.TokenStream.Swap(TokenType.MachineIdentifier);

            node.Identifier       = this.TokenStream.Peek();
            node.HeaderTokenRange = tokenRange.FinishAndClone();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            var nameVisitor = new NameVisitor(this.TokenStream);

            node.TemplateParameters = nameVisitor.ConsumeTemplateParams();

            if (this.TokenStream.Program is PSharpProgram)
            {
                if (this.TokenStream.Done ||
                    (this.TokenStream.Peek().Type != TokenType.Colon &&
                     this.TokenStream.Peek().Type != TokenType.LeftCurlyBracket))
                {
                    throw new ParsingException("Expected \":\" or \"{\".", this.TokenStream.Peek(), TokenType.Colon, TokenType.LeftCurlyBracket);
                }

                if (this.TokenStream.Peek().Type == TokenType.Colon)
                {
                    node.ColonToken = this.TokenStream.Peek();

                    this.TokenStream.Index++;
                    this.TokenStream.SkipWhiteSpaceAndCommentTokens();

                    var baseNameTokensVisitor = new NameVisitor(this.TokenStream, node.HeaderTokenRange);
                    node.BaseNameTokens = baseNameTokensVisitor.ConsumeGenericName(TokenType.MachineIdentifier);
                }
            }

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".", this.TokenStream.Peek(), TokenType.LeftCurlyBracket);
            }

            this.TokenStream.Swap(TokenType.MachineLeftCurlyBracket);

            node.LeftCurlyBracketToken = this.TokenStream.Peek();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            this.VisitNextPSharpIntraMachineDeclaration(node);
            parentNode.MachineDeclarations.Add(node);

            var stateDeclarations = node.GetAllStateDeclarations();

            if (stateDeclarations.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare at least one state.", this.TokenStream.Peek());
            }

            var startStates = stateDeclarations.FindAll(s => s.IsStart);

            if (startStates.Count == 0 && node.BaseNameTokens.Count == 0)
            {
                throw new ParsingException("A machine must declare a start state.", this.TokenStream.Peek());
            }
            else if (startStates.Count > 1)
            {
                throw new ParsingException("A machine can declare only a single start state.", this.TokenStream.Peek());
            }
        }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NameVisitor"/> class.
 /// </summary>
 internal NameVisitor(TokenStream tokenStream, TokenRange headerTokenRange = null)
     : base(tokenStream)
     => this.headerTokenRange = headerTokenRange;
Exemplo n.º 13
0
        /// <summary>
        /// Visits the next intra-machine declaration.
        /// </summary>
        private void VisitNextPSharpIntraMachineDeclaration(MachineDeclaration node)
        {
            bool fixpoint   = false;
            var  tokenRange = new TokenRange(this.TokenStream);

            while (!fixpoint)
            {
                if (!this.TokenStream.Done)
                {
                    var token = this.TokenStream.Peek();
                    switch (token.Type)
                    {
                    case TokenType.WhiteSpace:
                    case TokenType.QuotedString:
                    case TokenType.Comment:
                    case TokenType.NewLine:
                        this.TokenStream.Index++;
                        break;

                    case TokenType.CommentLine:
                    case TokenType.Region:
                        this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        break;

                    case TokenType.CommentStart:
                        this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        break;

                    case TokenType.ExternDecl:
                        new EventDeclarationVisitor(this.TokenStream).VisitExternDeclaration(node.Namespace, node);
                        this.TokenStream.Index++;
                        break;

                    case TokenType.Abstract:
                    case TokenType.StartState:
                    case TokenType.HotState:
                    case TokenType.ColdState:
                    case TokenType.EventDecl:
                    case TokenType.StateDecl:
                    case TokenType.StateGroupDecl:
                    case TokenType.Void:
                    case TokenType.MachineDecl:
                    case TokenType.Object:
                    case TokenType.String:
                    case TokenType.Sbyte:
                    case TokenType.Byte:
                    case TokenType.Short:
                    case TokenType.Ushort:
                    case TokenType.Int:
                    case TokenType.Uint:
                    case TokenType.Long:
                    case TokenType.Ulong:
                    case TokenType.Char:
                    case TokenType.Bool:
                    case TokenType.Decimal:
                    case TokenType.Float:
                    case TokenType.Double:
                    case TokenType.Identifier:
                    case TokenType.Private:
                    case TokenType.Protected:
                    case TokenType.Internal:
                    case TokenType.Public:
                    case TokenType.Async:
                    case TokenType.Partial:
                        this.VisitMachineLevelDeclaration(node, tokenRange.Start());
                        this.TokenStream.Index++;
                        break;

                    case TokenType.LeftSquareBracket:
                        this.TokenStream.Index++;
                        this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        new AttributeListVisitor(this.TokenStream).Visit();
                        this.TokenStream.Index++;
                        break;

                    case TokenType.RightCurlyBracket:
                        this.TokenStream.Swap(TokenType.MachineRightCurlyBracket);
                        node.RightCurlyBracketToken = this.TokenStream.Peek();
                        fixpoint = true;
                        break;

                    default:
                        throw new ParsingException($"Unexpected token '{this.TokenStream.Peek().TextUnit.Text}'.", this.TokenStream.Peek());
                    }
                }

                if (this.TokenStream.Done)
                {
                    throw new ParsingException("Expected \"}\".", this.TokenStream.Peek(),
                                               TokenType.Private,
                                               TokenType.Protected,
                                               TokenType.StartState,
                                               TokenType.HotState,
                                               TokenType.ColdState,
                                               TokenType.StateDecl,
                                               TokenType.StateGroupDecl,
                                               TokenType.LeftSquareBracket,
                                               TokenType.RightCurlyBracket);
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Visits a machine level declaration.
        /// </summary>
        private void VisitMachineLevelDeclaration(MachineDeclaration parentNode, TokenRange tokenRange)
        {
            var modSet = ModifierSet.CreateDefault();

            while (!this.TokenStream.Done &&
                   this.TokenStream.Peek().Type != TokenType.EventDecl &&
                   this.TokenStream.Peek().Type != TokenType.StateDecl &&
                   this.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                   this.TokenStream.Peek().Type != TokenType.MachineDecl &&
                   this.TokenStream.Peek().Type != TokenType.Void &&
                   this.TokenStream.Peek().Type != TokenType.Object &&
                   this.TokenStream.Peek().Type != TokenType.String &&
                   this.TokenStream.Peek().Type != TokenType.Sbyte &&
                   this.TokenStream.Peek().Type != TokenType.Byte &&
                   this.TokenStream.Peek().Type != TokenType.Short &&
                   this.TokenStream.Peek().Type != TokenType.Ushort &&
                   this.TokenStream.Peek().Type != TokenType.Int &&
                   this.TokenStream.Peek().Type != TokenType.Uint &&
                   this.TokenStream.Peek().Type != TokenType.Long &&
                   this.TokenStream.Peek().Type != TokenType.Ulong &&
                   this.TokenStream.Peek().Type != TokenType.Char &&
                   this.TokenStream.Peek().Type != TokenType.Bool &&
                   this.TokenStream.Peek().Type != TokenType.Decimal &&
                   this.TokenStream.Peek().Type != TokenType.Float &&
                   this.TokenStream.Peek().Type != TokenType.Double &&
                   this.TokenStream.Peek().Type != TokenType.Identifier)
            {
                new ModifierVisitor(this.TokenStream).Visit(modSet);

                this.TokenStream.Index++;
                this.TokenStream.SkipWhiteSpaceAndCommentTokens();
            }

            if (this.TokenStream.Done ||
                (this.TokenStream.Peek().Type != TokenType.EventDecl &&
                 this.TokenStream.Peek().Type != TokenType.StateDecl &&
                 this.TokenStream.Peek().Type != TokenType.StateGroupDecl &&
                 this.TokenStream.Peek().Type != TokenType.MachineDecl &&
                 this.TokenStream.Peek().Type != TokenType.Void &&
                 this.TokenStream.Peek().Type != TokenType.Object &&
                 this.TokenStream.Peek().Type != TokenType.String &&
                 this.TokenStream.Peek().Type != TokenType.Sbyte &&
                 this.TokenStream.Peek().Type != TokenType.Byte &&
                 this.TokenStream.Peek().Type != TokenType.Short &&
                 this.TokenStream.Peek().Type != TokenType.Ushort &&
                 this.TokenStream.Peek().Type != TokenType.Int &&
                 this.TokenStream.Peek().Type != TokenType.Uint &&
                 this.TokenStream.Peek().Type != TokenType.Long &&
                 this.TokenStream.Peek().Type != TokenType.Ulong &&
                 this.TokenStream.Peek().Type != TokenType.Char &&
                 this.TokenStream.Peek().Type != TokenType.Bool &&
                 this.TokenStream.Peek().Type != TokenType.Decimal &&
                 this.TokenStream.Peek().Type != TokenType.Float &&
                 this.TokenStream.Peek().Type != TokenType.Double &&
                 this.TokenStream.Peek().Type != TokenType.Identifier))
            {
                throw new ParsingException("Expected event, state, group or method declaration.", this.TokenStream.Peek(),
                                           TokenType.EventDecl,
                                           TokenType.StateDecl,
                                           TokenType.StateGroupDecl,
                                           TokenType.MachineDecl,
                                           TokenType.Void,
                                           TokenType.Object,
                                           TokenType.String,
                                           TokenType.Sbyte,
                                           TokenType.Byte,
                                           TokenType.Short,
                                           TokenType.Ushort,
                                           TokenType.Int,
                                           TokenType.Uint,
                                           TokenType.Long,
                                           TokenType.Ulong,
                                           TokenType.Char,
                                           TokenType.Bool,
                                           TokenType.Decimal,
                                           TokenType.Float,
                                           TokenType.Double,
                                           TokenType.Identifier);
            }

            if (this.TokenStream.Peek().Type == TokenType.EventDecl)
            {
                new EventDeclarationVisitor(this.TokenStream).Visit(parentNode.Namespace, parentNode, modSet);
            }
            else if (this.TokenStream.Peek().Type == TokenType.StateDecl)
            {
                new StateDeclarationVisitor(this.TokenStream).Visit(parentNode, null, modSet, tokenRange.Start());
            }
            else if (this.TokenStream.Peek().Type == TokenType.StateGroupDecl)
            {
                new StateGroupDeclarationVisitor(this.TokenStream).Visit(parentNode, null, modSet, tokenRange.Start());
            }
            else
            {
                new MachineMemberDeclarationVisitor(this.TokenStream).Visit(parentNode, modSet);
            }
        }
 internal CreoleRichTextElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens, IEnumerable <CreoleRichTextElementData> elements)
     : this(context, tokens, (elements != null ? new CreoleRichTextElementDataCollectionAdapter(elements) : null))
 {
 }
Exemplo n.º 16
0
 private IElementDataIterator _GetStyleElementIterator(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens, IEnumerable <CreoleRichTextElementData> baseElementsData)
 => _GetStyleElementIterator(context, tokens, baseElementsData, null);
 internal CreoleRichTextElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens)
     : this(context, tokens, elementIterator : null)
 {
 }
Exemplo n.º 18
0
 private IEnumerable <Element> _GetCreoleElements(TokenRange <CreoleTokenCode> tokens, IEnumerable <CreoleRichTextElementData> elementsData)
 => _GetCreoleElements(tokens, _GetRootNodesFrom(tokens, elementsData));
Exemplo n.º 19
0
        private IElementDataIterator _GetStyleElementIterator(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens, IEnumerable <CreoleRichTextElementData> baseElementsData, IEnumerable <CreoleRichTextElementType> excludedElementTypes)
        {
            var processors = new List <IElementDataIterator>();

            if (excludedElementTypes == null)
            {
                foreach (var styleElementFactory in _styleElementFactories)
                {
                    var elementType = styleElementFactory.Key;
                    processors.Add(new ElementProcessorFilterIterator(styleElementFactory.Value(_context, tokens, baseElementsData), elementType));
                }
            }
            else
            {
                foreach (var styleElementFactory in _styleElementFactories)
                {
                    var elementType = styleElementFactory.Key;
                    if (!_Contains(excludedElementTypes, elementType))
                    {
                        processors.Add(new ElementProcessorFilterIterator(styleElementFactory.Value(_context, tokens, baseElementsData), elementType));
                    }
                }
            }

            IElementDataIterator styleElementIterator = null;

            using (var processor = processors.GetEnumerator())
                if (processor.MoveNext())
                {
                    styleElementIterator = processor.Current;
                    while (processor.MoveNext())
                    {
                        styleElementIterator = new MergeElementDataIterator(styleElementIterator, processor.Current);
                    }
                }
            return(styleElementIterator);
        }
Exemplo n.º 20
0
 internal CreoleHorizontalRuleElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens)
     : base(context, tokens)
 {
 }
Exemplo n.º 21
0
 public CreoleListElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens)
     : base(context, tokens)
 {
 }
Exemplo n.º 22
0
        /// <summary>
        /// Visits the next intra-group declaration.
        /// </summary>
        private void VisitNextPSharpIntraGroupDeclaration(StateGroupDeclaration node)
        {
            bool fixpoint   = false;
            var  tokenRange = new TokenRange(this.TokenStream);

            while (!fixpoint)
            {
                if (!this.TokenStream.Done)
                {
                    var token = this.TokenStream.Peek();
                    switch (token.Type)
                    {
                    case TokenType.WhiteSpace:
                    case TokenType.QuotedString:
                    case TokenType.Comment:
                    case TokenType.NewLine:
                        this.TokenStream.Index++;
                        break;

                    case TokenType.CommentLine:
                    case TokenType.Region:
                        this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        break;

                    case TokenType.CommentStart:
                        this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        break;

                    case TokenType.StartState:
                    case TokenType.HotState:
                    case TokenType.ColdState:
                    case TokenType.StateDecl:
                    case TokenType.StateGroupDecl:
                    case TokenType.Private:
                    case TokenType.Protected:
                    case TokenType.Internal:
                    case TokenType.Public:
                        this.VisitGroupLevelDeclaration(node, tokenRange.Start());
                        this.TokenStream.Index++;
                        break;

                    case TokenType.LeftSquareBracket:
                        this.TokenStream.Index++;
                        this.TokenStream.SkipWhiteSpaceAndCommentTokens();
                        new AttributeListVisitor(this.TokenStream).Visit();
                        this.TokenStream.Index++;
                        break;

                    case TokenType.RightCurlyBracket:
                        this.TokenStream.Swap(TokenType.MachineRightCurlyBracket);
                        node.RightCurlyBracketToken = this.TokenStream.Peek();
                        fixpoint = true;
                        break;

                    default:
                        throw new ParsingException("Unexpected token '" + this.TokenStream.Peek().TextUnit.Text + "'.", this.TokenStream.Peek());
                    }
                }

                if (this.TokenStream.Done)
                {
                    throw new ParsingException("Expected \"}\".", this.TokenStream.Peek(),
                                               TokenType.Private,
                                               TokenType.Protected,
                                               TokenType.StartState,
                                               TokenType.HotState,
                                               TokenType.ColdState,
                                               TokenType.StateDecl,
                                               TokenType.StateGroupDecl,
                                               TokenType.LeftSquareBracket,
                                               TokenType.RightCurlyBracket);
                }
            }
        }
Exemplo n.º 23
0
 private IEnumerable <Element> _GetCreoleElements(TokenRange <CreoleTokenCode> tokens, IEnumerable <CreoleRichTextElementNodeData> nodesData)
 => _GetCreoleElements(tokens, 0, tokens.Count, nodesData);
Exemplo n.º 24
0
        private Element _GetCreoleElementFrom(TokenRange <CreoleTokenCode> tokens, CreoleRichTextElementNodeData nodeData)
        {
            Element result = null;

            switch (nodeData.ElementType)
            {
            case CreoleRichTextElementType.Code:
                result = new CodeElement(
                    _GetContentFrom(tokens, nodeData)
                    );
                break;

            case CreoleRichTextElementType.Hyperlink:
                result = new HyperlinkElement(
                    _GetUrlFrom(tokens, nodeData),
                    _GetCreoleElements(tokens, nodeData.ContentStartIndex, nodeData.ContentEndIndex, nodeData.ChildNodes)
                    );
                break;

            case CreoleRichTextElementType.Image:
                if (nodeData.UrlEndIndex < nodeData.ContentStartIndex)
                {
                    result = new ImageElement(
                        _GetUrlFrom(tokens, nodeData),
                        _GetContentFrom(tokens, nodeData)
                        );
                }
                else
                {
                    result = new ImageElement(
                        _GetUrlFrom(tokens, nodeData)
                        );
                }
                break;

            case CreoleRichTextElementType.Plugin:
                result = new PluginElement(
                    _GetContentFrom(tokens, nodeData)
                    );
                break;

            case CreoleRichTextElementType.LineBreak:
                result = _creoleLineBreakElement;
                break;

            case CreoleRichTextElementType.InlineHyperlink:
                var url = _GetUrlFrom(tokens, nodeData);
                result = new HyperlinkElement(url, new[] { new TextElement(url) });
                break;

            case CreoleRichTextElementType.EscapedInlineHyperlink:
                result = new TextElement(
                    _GetUrlFrom(tokens, nodeData)
                    );
                break;

            case CreoleRichTextElementType.Emphasis:
                result = new EmphasisElement(
                    _GetCreoleElements(tokens, nodeData.ContentStartIndex, nodeData.ContentEndIndex, nodeData.ChildNodes)
                    );
                break;

            case CreoleRichTextElementType.Strong:
                result = new StrongElement(
                    _GetCreoleElements(tokens, nodeData.ContentStartIndex, nodeData.ContentEndIndex, nodeData.ChildNodes)
                    );
                break;
            }

            return(result);
        }
 internal CreoleRichTextElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens, CreoleRichTextElementProcessor elementProcessor)
     : this(context, tokens, (elementProcessor != null ? new CreoleRichTextElementProcessorIteratorAdapter(elementProcessor) : null))
 {
 }
Exemplo n.º 26
0
        /// <summary>
        /// Visits the syntax node.
        /// </summary>
        internal void Visit(MachineDeclaration parentNode, StateGroupDeclaration groupNode, ModifierSet modSet, TokenRange tokenRange)
        {
            this.CheckStateGroupModifierSet(modSet);

            var node = new StateGroupDeclaration(this.TokenStream.Program, parentNode, groupNode);

            node.AccessModifier    = modSet.AccessModifier;
            node.StateGroupKeyword = this.TokenStream.Peek();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.Identifier)
            {
                throw new ParsingException("Expected state group identifier.", this.TokenStream.Peek(), TokenType.Identifier);
            }

            this.TokenStream.Swap(TokenType.StateGroupIdentifier);
            node.Identifier       = this.TokenStream.Peek();
            node.HeaderTokenRange = tokenRange.FinishAndClone();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            if (this.TokenStream.Done ||
                this.TokenStream.Peek().Type != TokenType.LeftCurlyBracket)
            {
                throw new ParsingException("Expected \"{\".", this.TokenStream.Peek(), TokenType.LeftCurlyBracket);
            }

            this.TokenStream.Swap(TokenType.StateGroupLeftCurlyBracket);

            node.LeftCurlyBracketToken = this.TokenStream.Peek();

            this.TokenStream.Index++;
            this.TokenStream.SkipWhiteSpaceAndCommentTokens();

            this.VisitNextPSharpIntraGroupDeclaration(node);

            if (groupNode is null)
            {
                parentNode.StateGroupDeclarations.Add(node);
            }
            else
            {
                groupNode.StateGroupDeclarations.Add(node);
            }

            var stateDeclarations = node.GetAllStateDeclarations();

            if (stateDeclarations.Count == 0)
            {
                throw new ParsingException("A state group must declare at least one state.", this.TokenStream.Peek());
            }
        }
Exemplo n.º 27
0
 private CreoleRichTextElementProcessor _GetHyperlinkBaseElementProcessor(CreoleParserContext contenxt, TokenRange <CreoleTokenCode> tokens)
 => new CreoleLineBreakElementProcessor(
     _context,
     tokens,
     new CreoleImageElementProcessor(
         _context,
         tokens,
         new CreoleCodeElementProcessor(
             _context,
             tokens)
         )
     );
Exemplo n.º 28
0
 internal CreolePluginElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens, CreoleRichTextElementProcessor baseElementProcessor)
     : base(context, tokens, baseElementProcessor)
 {
 }
Exemplo n.º 29
0
        //public List<Comment> trailingComments { get; set; }

        //public bool tail { get; set; }

        public Token2()
        {
            range = new TokenRange();
        }
Exemplo n.º 30
0
 internal CreoleHeadingElementProcessor(CreoleParserContext context, TokenRange <CreoleTokenCode> tokens)
     : base(context, tokens)
 {
 }
Exemplo n.º 31
0
 public Token()
 {
     range = new TokenRange(); 
 }