Ejemplo n.º 1
0
        public static void GenerateNode(JSContext context, TextWriter textWriter, AstNode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node is IJSBasicNode)
            {
                IJSBasicNode jsBasicNode = (IJSBasicNode)node;
                jsBasicNode.GenerateJavaScript(context, textWriter);
            }
            else if (node is Token)
            {
                Token t = (Token)node;
                switch (t.Terminal.Name)
                {
                case "VARIABLE":
                    if (t.Text.EndsWith("$"))
                    {
                        textWriter.Write("s_" + t.Text.Substring(0, t.Text.Length - 1));
                    }
                    else
                    {
                        throw new BasicSyntaxErrorException("Invalid variable name: " + t.Text);
                    }
                    break;

                case "BOOLEAN_OP":
                {
                    switch (t.Text.ToLowerInvariant())
                    {
                    case "and":
                        textWriter.Write("&&");
                        break;

                    case "or":
                        textWriter.Write("||");
                        break;

                    default:
                        textWriter.Write(t.Text);
                        break;
                    }
                }
                break;

                default:
                    textWriter.Write(ConvertToJavascript(t.Text));
                    break;
                }
                textWriter.Write(" ");
            }
            else
            {
                throw new ApplicationException("Unhandled statement type: " + node.GetType().FullName);
            }
        }
Ejemplo n.º 2
0
 public IfElseStmtNode(AstNodeArgs args)
     : base(args)
 {
     _condition = (IJSBasicNode)args.ChildNodes[1];
     _thenExpression = (IJSBasicNode)args.ChildNodes[3];
     //Child #4 is ELSE_CLAUSE
     AstNode elseClause = args.ChildNodes[4];
     if (elseClause.ChildNodes.Count > 0)
     {
         _elseExpression = (IJSBasicNode)elseClause.ChildNodes[1];
     }
 }
Ejemplo n.º 3
0
        public IfElseStmtNode(AstNodeArgs args)
            : base(args)
        {
            _condition      = (IJSBasicNode)args.ChildNodes[1];
            _thenExpression = (IJSBasicNode)args.ChildNodes[3];
            //Child #4 is ELSE_CLAUSE
            AstNode elseClause = args.ChildNodes[4];

            if (elseClause.ChildNodes.Count > 0)
            {
                _elseExpression = (IJSBasicNode)elseClause.ChildNodes[1];
            }
        }