예제 #1
0
        private INode[][] PrepareSections(INode node)
        {
            bool isFancyLoop = false;

            int curSection = (int)ForeachSectionEnum.Each;

            ArrayList[] sections = new ArrayList[SectionNames.Length];

            int nodeCount = node.ChildrenCount;

            for (int i = 0; i < nodeCount; i++)
            {
                INode        childNode = node.GetChild(i);
                ASTDirective directive = childNode as ASTDirective;

                if (directive != null && Array.BinarySearch(SectionNames, directive.DirectiveName) > -1)
                {
                    isFancyLoop = true;
                    curSection  = (int)ForeachSectionEnum.Parse(
                        typeof(ForeachSectionEnum), directive.DirectiveName, true);
                }
                else
                {
                    if (sections[curSection] == null)
                    {
                        sections[curSection] = new ArrayList();
                    }
                    sections[curSection].Add(childNode);
                }
            }

            if (!isFancyLoop)
            {
                return(null);
            }
            else
            {
                INode[][] result = new INode[sections.Length][];

                for (int i = 0; i < sections.Length; i++)
                {
                    if (sections[i] != null)
                    {
                        result[i] = sections[i].ToArray(typeof(INode)) as INode[];
                    }
                }

                return(result);
            }
        }
예제 #2
0
        private INode[][] PrepareSections(INode node)
        {
            bool flag = false;
            int  num  = 0;

            ArrayList[] array         = new ArrayList[Foreach.SectionNames.Length];
            int         childrenCount = node.ChildrenCount;

            for (int i = 0; i < childrenCount; i++)
            {
                INode        child        = node.GetChild(i);
                ASTDirective aSTDirective = child as ASTDirective;
                if (aSTDirective != null && Array.BinarySearch <string>(Foreach.SectionNames, aSTDirective.DirectiveName) > -1)
                {
                    flag = true;
                    num  = (int)Enum.Parse(typeof(ForeachSectionEnum), aSTDirective.DirectiveName, true);
                }
                else
                {
                    if (array[num] == null)
                    {
                        array[num] = new ArrayList();
                    }
                    array[num].Add(child);
                }
            }
            INode[][] result;
            if (!flag)
            {
                result = null;
            }
            else
            {
                INode[][] array2 = new INode[array.Length][];
                for (int i = 0; i < array.Length; i++)
                {
                    if (array[i] != null)
                    {
                        array2[i] = (array[i].ToArray(typeof(INode)) as INode[]);
                    }
                }
                result = array2;
            }
            return(result);
        }
예제 #3
0
 public T Visit(IASTNode node)
 {
     return(node switch
     {
         ASTType n => VisitASTType(n),
         ASTTypeField n => VisitASTTypeField(n),
         ASTTypeDefinition n => VisitASTTypeDefinition(n),
         ASTRestriction n => VisitASTRestriction(n),
         ASTAlias n => VisitASTAlias(n),
         ASTData n => VisitASTData(n),
         ASTAnnotation n => VisitASTAnnotation(n),
         ASTDirective n => VisitASTDirective(n),
         ASTChoice n => VisitASTChoice(n),
         ASTOption n => VisitASTOption(n),
         ASTChapter n => VisitASTChapter(n),
         ASTParagraph n => VisitASTParagraph(n),
         _ => VisitDefault(node),
     });
예제 #4
0
        public IEnumerable <IASTNode> Parse()
        {
            List <ASTAnnotation> annotations = new List <ASTAnnotation>();
            List <ASTDirective>  directives  = new List <ASTDirective>();

            while (HasNext())
            {
                if (Current.TokenType == TokenType.KW_Type)
                {
                    var(errors, t) = ASTType.Parse(this, annotations, directives);
                    this.Errors.AddRange(errors);
                    yield return(t);
                }
                else if (Current.TokenType == TokenType.KW_Alias)
                {
                    yield return(new ASTAlias(this));
                }
                else if (Current.TokenType == TokenType.KW_Choice)
                {
                    yield return(new ASTChoice(this));
                }
                else if (Current.TokenType == TokenType.Annotation)
                {
                    annotations = ASTAnnotation.Parse(this).ToList();
                }
                else if (Current.TokenType == TokenType.Directive)
                {
                    directives = ASTDirective.Parse(this).ToList();
                }
                else
                {
                    Next();
                }
            }
            yield break;
        }
예제 #5
0
		/// <summary>   Supports the Pluggable Directives
		/// #foo( arg+ )
		/// </summary>
		public SimpleNode Directive()
		{
			ASTDirective directiveNode = new ASTDirective(this, ParserTreeConstants.DIRECTIVE);

			bool isNodeScopeOpen = true;
			nodeTree.OpenNodeScope(directiveNode);
			Token token;
			Directive directive;
			bool doItNow = false;

			try
			{
				/*
				* note that if we were escaped, that is now handled by 
				* EscapedDirective()
				*/
				token = ConsumeToken(ParserConstants.WORD);
				String directiveName = token.Image.Substring(1);

				directive = directives.Create(directiveName, directiveStack);

				Debug.Assert(directiveNode != null);

				directiveNode.Directive = directive;

				/*
				*  Velocimacro support : if the directive is macro directive
				*   then set the flag so after the block parsing, we add the VM
				*   right then. (So available if used w/in the current template )
				*/

				if (directiveName.Equals("macro"))
				{
					doItNow = true;
				}

				/*
				* set the directive name from here.  No reason for the thing to know 
				* about parser tokens
				*/

				directiveNode.DirectiveName = directiveName;

				DirectiveType directiveType;
				if (directive == null)
				{
					// if null, then not a real directive, but maybe a Velocimacro

					//d  =  (Directive) runtimeServices.getVelocimacro( directiveName, currentTemplateName );

					// TODO: adding a null check since RuntimeServices is not finished
					// since the parser can be created without RuntimeServices - this may actually be needed here and in the orgiginal source as well.
					if (runtimeServices != null)
					{
						if (!runtimeServices.IsVelocimacro(directiveName, currentTemplateName))
						{
							token_source.StateStackPop();
							token_source.inDirective = false;
							if (true)
								return directiveNode;
						}
					}

					/*
					 *  Currently, all VMs are LINE directives
					 */
					directiveType = DirectiveType.LINE;
				}
				else
				{
					directiveType = directive.Type;
				}

				/*
				*  now, switch us out of PRE_DIRECTIVE
				*/

				token_source.SwitchTo(ParserConstants.DIRECTIVE);

				ConsumeWhiteSpaces();

				if (directive != null && !directive.AcceptParams)
				{
					int curToken = GetCurrentTokenKind();

					if (curToken == ParserConstants.NEWLINE)
					{
						ConsumeToken(ParserConstants.NEWLINE);
					}
					else
					{
						throw new ParseException(
							"Foreach directives must be the only items on the line (comments or contents are not allowed)");
					}
				}

				if (directive == null || directive.AcceptParams)
				{
					ConsumeToken(ParserConstants.LPAREN);

					while(true)
					{
						switch(GetCurrentTokenKind())
						{
							case ParserConstants.LBRACKET:
							case ParserConstants.WHITESPACE:
							case ParserConstants.STRING_LITERAL:
							case ParserConstants.TRUE:
							case ParserConstants.FALSE:
							case ParserConstants.NUMBER_LITERAL:
							case ParserConstants.WORD:
							case ParserConstants.IDENTIFIER:
							case ParserConstants.LCURLY:
								;
								break;

							default:
								jj_la1[7] = jj_gen;
								//UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1012"'
								goto label_3_brk;
						}
						DirectiveArg();
					}
					//UPGRADE_NOTE: Label 'label_3_brk' was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1011"'
					label_3_brk:
					;

					ConsumeToken(ParserConstants.RPAREN);
				}

				if (directiveType == DirectiveType.LINE)
				{
					return directiveNode;
				}

				directiveStack.Push(directive);

				ASTBlock jjtn001 = new ASTBlock(this, ParserTreeConstants.BLOCK);
				bool jjtc001 = true;
				nodeTree.OpenNodeScope(jjtn001);

				try
				{
					while(true)
					{
						Statement();
						int kind = GetCurrentTokenKind();
						switch(kind)
						{
							case ParserConstants.LPAREN:
							case ParserConstants.RPAREN:
							case ParserConstants.ESCAPE_DIRECTIVE:
							case ParserConstants.SET_DIRECTIVE:
							case ParserConstants.DOUBLE_ESCAPE:
							case ParserConstants.ESCAPE:
							case ParserConstants.TEXT:
							case ParserConstants.SINGLE_LINE_COMMENT:
							case ParserConstants.FORMAL_COMMENT:
							case ParserConstants.MULTI_LINE_COMMENT:
							case ParserConstants.STRING_LITERAL:
							case ParserConstants.IF_DIRECTIVE:
							case ParserConstants.STOP_DIRECTIVE:
							case ParserConstants.NUMBER_LITERAL:
							case ParserConstants.WORD:
							case ParserConstants.IDENTIFIER:
							case ParserConstants.DOT:
							case ParserConstants.LCURLY:
							case ParserConstants.RCURLY:
								break;

							default:
								jj_la1[8] = jj_gen;
								//UPGRADE_NOTE: Labeled break statement was changed to a goto statement. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1012"'
								goto label_4_brk;
						}
					}
					//UPGRADE_NOTE: Label 'label_4_brk' was added. 'ms-help://MS.VSCC/commoner/redir/redirect.htm?keyword="jlca1011"'
					label_4_brk:
					;
				}
				catch(Exception jjte001)
				{
					nodeTree.ClearNodeScope(jjtn001);
					jjtc001 = false;
					if (jjte001 is SystemException)
					{
						throw;
					}
					if (jjte001 is ParseException)
					{
						throw;
					}
					throw (ApplicationException) jjte001;
				}
				finally
				{
					if (jjtc001)
					{
						nodeTree.CloseNodeScope(jjtn001, true);
					}

					directiveStack.Pop();
				}
				ConsumeToken(ParserConstants.END);
				nodeTree.CloseNodeScope(directiveNode, true);
				isNodeScopeOpen = false;
				/*
				 *  VM : if we are processing a #macro directive, we need to 
				 *     process the block.  In truth, I can just register the name
				 *     and do the work later when init-ing.  That would work
				 *     as long as things were always defined before use.  This way
				 *     we don't have to worry about forward references and such...
				 */

				if (doItNow)
				{
					Macro.processAndRegister(runtimeServices, directiveNode, currentTemplateName);
				}

				return directiveNode;
			}
			catch(Exception jjte000)
			{
				if (isNodeScopeOpen)
				{
					nodeTree.ClearNodeScope(directiveNode);
					isNodeScopeOpen = false;
				}
				else
				{
					nodeTree.PopNode();
				}
				if (jjte000 is SystemException)
				{
					throw;
				}
				if (jjte000 is ParseException)
				{
					throw;
				}
				throw (ApplicationException) jjte000;
			}
			finally
			{
				if (isNodeScopeOpen)
				{
					nodeTree.CloseNodeScope(directiveNode, true);
				}
			}
		}
예제 #6
0
        public IEnumerable <IASTNode> Parse()
        {
            var annotations = new List <ASTAnnotation>();
            var directives  = new List <ASTDirective>();

            while (HasNext() && Current.TokenType != TokenType.EndOfFile)
            {
                if (Current.TokenType == TokenType.KW_Type)
                {
                    var(errors, t) = ASTType.Parse(this, annotations, directives);
                    Errors.AddRange(errors);
                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                    yield return(t);
                }
                else if (Current.TokenType == TokenType.KW_Alias)
                {
                    var(errors, alias) = ASTAlias.Parse(this, annotations, directives);
                    Errors.AddRange(errors);
                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                    yield return(alias);
                }
                else if (Current.TokenType == TokenType.KW_Choice)
                {
                    var(errors, result) = ASTChoice.Parse(this);
                    Errors.AddRange(errors);
                    yield return(result);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.KW_Data)
                {
                    var(errors, data) = ASTData.Parse(this, annotations, directives);
                    Errors.AddRange(errors);
                    yield return(data);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.KW_View)
                {
                    var(errors, data) = ASTView.Parse(this, annotations, directives);
                    Errors.AddRange(errors);
                    yield return(data);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.KW_Open)
                {
                    var(errors, data) = ASTImport.Parse(this);
                    Errors.AddRange(errors);
                    yield return(data);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.KW_Flow)
                {
                    var(errors, data) = ASTFlow.Parse(this);
                    Errors.AddRange(errors);
                    yield return(data);

                    annotations = new List <ASTAnnotation>();
                    directives  = new List <ASTDirective>();
                }
                else if (Current.TokenType == TokenType.Annotation)
                {
                    annotations = ASTAnnotation.Parse(this).ToList();
                }
                else if (Current.TokenType == TokenType.Directive)
                {
                    var(errors, dirs) = ASTDirective.Parse(this);
                    Errors.AddRange(errors.ToList());
                    directives = dirs.ToList();
                }
                else if (Current.TokenType == TokenType.Chapter)
                {
                    yield return(new ASTChapter(Current.Value));

                    Next();
                }
                else if (Current.TokenType == TokenType.Paragraph)
                {
                    yield return(new ASTParagraph(Current.Value));

                    Next();
                }
                else
                {
                    Next();
                }
            }
            yield break;
        }
예제 #7
0
 public override string VisitASTDirective(ASTDirective astDirective)
 {
     return("");
 }
예제 #8
0
 public virtual Object Visit(ASTDirective node, Object data)
 {
     data = node.ChildrenAccept(this, data);
     return(data);
 }
예제 #9
0
 public override Object Visit(ASTDirective node, Object data)
 {
     return(ShowNode(node, data));
 }
예제 #10
0
 public override string VisitASTDirective(ASTDirective astDirective)
 {
     return($"% {astDirective.Key}: {astDirective.Value}");
 }
예제 #11
0
 public override T VisitASTDirective(ASTDirective astDirective) => d;
예제 #12
0
파일: NodeViewMode.cs 프로젝트: minskowl/MY
 public override System.Object visit(ASTDirective node, System.Object data)
 {
     return(showNode(node, data));
 }
예제 #13
0
 public override XmlSchemaObject?VisitASTDirective(ASTDirective astDirective)
 {
     return(null);
 }
예제 #14
0
파일: BaseVisitor.cs 프로젝트: minskowl/MY
 public virtual System.Object visit(ASTDirective node, System.Object data)
 {
     data = node.childrenAccept(this, data);
     return(data);
 }
예제 #15
0
 public override object Visit(ASTDirective node, object data)
 {
     return(this.ShowNode(node, data));
 }