コード例 #1
0
        public static Block WriteOutCells(IEnumerable<CellDefinition> cells, bool header){
            string tagname = header ? "th" : "td";
            var onitem = new Block();
            foreach (CellDefinition cell in cells){
                var opentag = new ExpressionInterpolationExpression();
                ExpressionInterpolationExpression attrs = getAttributes(cell.Attributes);
                opentag.append("<" + tagname).append(attrs).append(">");
                onitem.add(opentag.writeOut());
                onitem.add(cell.Value.brailOutResolve());

                onitem.Add(("</" + tagname + ">").toLiteral().writeOut());
            }
            return onitem;
        }
コード例 #2
0
        private Block extractMainItemBlock(MacroStatement macro, Func<MacroStatement, Block> extract,
                                           MacroStatement onitem_macro, Expression item, string prefix, string suffix){
            Block onitem = null;
            if (onitem_macro == macro && (macro.Body == null || macro.Body.IsEmpty)){
                Expression outer = item;
                if (prefix != "" || suffix != ""){
                    outer = new ExpressionInterpolationExpression()
                        .append(prefix)
                        .append(item)
                        .append(suffix);
                }
                onitem = new Block().add(BrailBuildingHelper.WriteOut(outer));
            }
            else{
                onitem = extract(onitem_macro);
            }

            return onitem;
        }
コード例 #3
0
        override public object Clone()
        {
            ExpressionInterpolationExpression clone = (ExpressionInterpolationExpression)FormatterServices.GetUninitializedObject(typeof(ExpressionInterpolationExpression));

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }

            clone._expressionType = _expressionType;
            if (null != _expressions)
            {
                clone._expressions = _expressions.Clone() as ExpressionCollection;
                clone._expressions.InitializeParent(clone);
            }
            return(clone);
        }
コード例 #4
0
        override public object Clone()
        {
            ExpressionInterpolationExpression clone = new ExpressionInterpolationExpression();

            clone._lexicalInfo       = _lexicalInfo;
            clone._endSourceLocation = _endSourceLocation;
            clone._documentation     = _documentation;
            clone._isSynthetic       = _isSynthetic;
            clone._entity            = _entity;
            if (_annotations != null)
            {
                clone._annotations = (Hashtable)_annotations.Clone();
            }
            clone._expressionType = _expressionType;
            if (null != _expressions)
            {
                clone._expressions = _expressions.Clone() as ExpressionCollection;
                clone._expressions.InitializeParent(clone);
            }
            return(clone);
        }
コード例 #5
0
ファイル: EmitAssembly.cs プロジェクト: Bombadil77/boo
        public override void OnExpressionInterpolationExpression(ExpressionInterpolationExpression node)
        {
            Type stringBuilderType = typeof(StringBuilder);
            ConstructorInfo constructor = stringBuilderType.GetConstructor(Type.EmptyTypes);
            ConstructorInfo constructorString = stringBuilderType.GetConstructor(new Type[] { typeof(string) });

            MethodInfo appendObject = Methods.InstanceFunctionOf<StringBuilder, object, StringBuilder>(sb => sb.Append);
            MethodInfo appendString = Methods.InstanceFunctionOf<StringBuilder, string, StringBuilder>(sb => sb.Append);
            Expression arg0 = node.Expressions[0];
            IType argType = arg0.ExpressionType;

            /* if arg0 is a string, let's call StringBuilder constructor
             * directly with the string */
            if ( ( typeof(StringLiteralExpression) == arg0.GetType()
                   && ((StringLiteralExpression) arg0).Value.Length > 0 )
                || ( typeof(StringLiteralExpression) != arg0.GetType()
                     && TypeSystemServices.StringType == argType ) )
            {
                Visit(arg0);
                PopType();
                _il.Emit(OpCodes.Newobj, constructorString);
            }
            else
            {
                _il.Emit(OpCodes.Newobj, constructor);
                arg0 = null; /* arg0 is not a string so we want it to be appended below */
            }

            string formatString;
            foreach (Expression arg in node.Expressions)
            {
                /* we do not need to append literal string.Empty
                 * or arg0 if it has been handled by ctor */
                if ( ( typeof(StringLiteralExpression) == arg.GetType()
                       && ((StringLiteralExpression) arg).Value.Length == 0 )
                    || arg == arg0 )
                {
                    continue;
                }

                formatString = arg["formatString"] as string; //annotation
                if (!string.IsNullOrEmpty(formatString))
                    _il.Emit(OpCodes.Ldstr, string.Format("{{0:{0}}}", formatString));

                Visit(arg);
                argType = PopType();

                if (!string.IsNullOrEmpty(formatString))
                {
                    EmitCastIfNeeded(TypeSystemServices.ObjectType, argType);
                    _il.EmitCall(OpCodes.Call, StringFormat, null);
                }

                if (TypeSystemServices.StringType == argType || !string.IsNullOrEmpty(formatString))
                {
                    _il.EmitCall(OpCodes.Call, appendString, null);
                }
                else
                {
                    EmitCastIfNeeded(TypeSystemServices.ObjectType, argType);
                    _il.EmitCall(OpCodes.Call, appendObject, null);
                }
            }
            _il.EmitCall(OpCodes.Call, stringBuilderType.GetMethod("ToString", Type.EmptyTypes), null);
            PushType(TypeSystemServices.StringType);
        }
コード例 #6
0
ファイル: WSABooParserBase.cs プロジェクト: 0xb1dd1e/boo
        //throws RecognitionException, TokenStreamException
        protected ExpressionInterpolationExpression expression_interpolation()
        {
            ExpressionInterpolationExpression e;

            IToken  separator = null;
            IToken  format_sep = null;
            IToken  formatString = null;

                e = null;
                Expression param = null;

            try {      // for error handling
            separator = LT(1);
            match(ESEPARATOR);
            if (0==inputState.guessing)
            {

                        LexicalInfo info = SourceLocationFactory.ToLexicalInfo(separator);
                        e = new ExpressionInterpolationExpression(info);

            }
            {    // ( ... )*
                for (;;)
                {
                    if ((LA(1)==ESEPARATOR) && (tokenSet_4_.member(LA(2))))
                    {
                        match(ESEPARATOR);
                        param=expression();
                        {
                            switch ( LA(1) )
                            {
                            case ID:
                            case COLON:
                            {
                                {
                                    switch ( LA(1) )
                                    {
                                    case COLON:
                                    {
                                        format_sep = LT(1);
                                        match(COLON);
                                        break;
                                    }
                                    case ID:
                                    {
                                        break;
                                    }
                                    default:
                                    {
                                        throw new NoViableAltException(LT(1), getFilename());
                                    }
                                     }
                                }
                                formatString = LT(1);
                                match(ID);
                                break;
                            }
                            case ESEPARATOR:
                            {
                                break;
                            }
                            default:
                            {
                                throw new NoViableAltException(LT(1), getFilename());
                            }
                             }
                        }
                        if (0==inputState.guessing)
                        {

                                        if (null != param)
                                        {
                                            e.Expressions.Add(param);
                                            if (null != formatString)
                                                param.Annotate("formatString", formatString.getText());
                                        }

                        }
                        match(ESEPARATOR);
                    }
                    else
                    {
                        goto _loop556_breakloop;
                    }

                }
            _loop556_breakloop:				;
            }    // ( ... )*
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex);
                recover(ex,tokenSet_36_);
            }
            else
            {
                throw ex;
            }
            }
            return e;
        }
コード例 #7
0
            private void buildStartTag(string tagname, IEnumerable<Expression> argsource, Block innerblock) {
                IDictionary<string, string> defaults = null;
                if (DefaultAttributes.ContainsKey(tagname)){
                    defaults = DefaultAttributes[tagname];
                }
                ExpressionInterpolationExpression args = BrailBuildingHelper.getAttributes(argsource, defaults,
                                                                                           "class",
                                                                                           "id");

                if (tagname != "bmlempty"){
                    var tag = new ExpressionInterpolationExpression();
                    tag
                        .append("<" + tagname)
                        .append(args)
                        .append(">");
                    innerblock.add(BrailBuildingHelper.WriteOut(tag));
                }
            }
コード例 #8
0
        public static ExpressionInterpolationExpression getAttributes(IEnumerable<Expression> expressions,
                                                                      IEnumerable<string> skips,
                                                                      IDictionary<string, string> defaults,
                                                                      params string[] mainattributes){
            if (mainattributes == null || mainattributes.Length == 0){
                mainattributes = new[]{"class", "id"};
            }
            var dict = new Dictionary<Expression, Expression>();


            int idx = 0;
            foreach (Expression argument in expressions){
                if (argument is HashLiteralExpression){
                    foreach (ExpressionPair pair in ((HashLiteralExpression) argument).Items){
                        dict[convertToAttribute(pair.First)] = convertToAttribute(pair.Second);
                    }
                    //it MUST be last statement
                    break;
                }
                if (argument is BinaryExpression){
                    var _binexp = (BinaryExpression) argument;
                    if (skips.Contains(_binexp.Left.ToCodeString())){
                        continue;
                    }
                    
                    if (_binexp.Right is ListLiteralExpression){
                        continue;
                    }
                    if (_binexp.Right is HashLiteralExpression){
                        continue;
                    }
                    var name = convertToAttribute(_binexp.Left);
                    var value = convertToAttribute(_binexp.Right);

                    //спецобработка для атрибута checked - заколебался с ним возиться в видах
                    bool proceed = true;
                    if(name.fromLiteral()=="checked"){
                        if(value.fromLiteral().ToLower()=="true"){
                            value = "checked".toLiteral();
                        }else{
                            proceed = false;
                        }
                    }
                    if(proceed){
                        dict[name] = value;
                    }
                }
                else{
                    Expression exp = convertToAttribute(argument);
                    if (idx <= 2){
                        dict[new StringLiteralExpression(mainattributes[idx])] = exp;
                    }
                    else{
                        throw new Exception(
                            "cannot understand target of attribute, only three anonymous supported for class,id,name");
                    }
                }
                idx++;
            }
            if (null != defaults){
                foreach (var def in defaults){
                    bool proceed = true;
                    foreach (var expression in dict){
                        if (expression.Key is StringLiteralExpression){
                            if (((StringLiteralExpression) expression.Key).Value == def.Key){
                                proceed = false;
                                break;
                            }
                        }
                    }
                    if (proceed){
                        dict[def.Key.toLiteral()] = def.Value.toLiteral();
                    }
                }
            }

            var result = new ExpressionInterpolationExpression();
            foreach (var node in dict){
                result.Expressions.Add(new StringLiteralExpression(" "));
                result.Expressions.Add(node.Key);
                result.Expressions.Add(new StringLiteralExpression("='"));
                if (node.Value is StringLiteralExpression){
                    string escaped = WebUtility.HtmlEncode(((StringLiteralExpression) node.Value).Value).Replace("'",
                                                                                                                  "&apos;");
                    result.Expressions.Add(escaped.toLiteral());
                }
                else if (node.Value is IntegerLiteralExpression){
                    result.Expressions.Add(node.Value.ToCodeString().toLiteral());
                }
                else{
                    var escape = new MethodInvocationExpression(new ReferenceExpression("_escape"), node.Value);
                    result.Expressions.Add(escape);
                }
                result.Expressions.Add(new StringLiteralExpression("'"));
            }


            return result;
        }
コード例 #9
0
            public override void OnExpressionStatement(ExpressionStatement node) {

                if(isWrite(node.Expression)) {
                    var arg = get_arg(node.Expression);
                    var first = arg;
                    if (!(arg is ExpressionInterpolationExpression))
                    {
                        
                        arg = new ExpressionInterpolationExpression();
                    }
                    var block = ((Block) node.ParentNode);
                    var index = block.Statements.IndexOf(node);
                    if(index==-1) return;
                    while (true) {
                        if (index > block.Statements.Count - 2) break;
                        var next = block.Statements[index + 1];
                        if(!(next is ExpressionStatement))break;
                        if(!isWrite(((ExpressionStatement)next).Expression)) break;
                        block.Statements.Remove(next);
                        var nextarg = get_arg(((ExpressionStatement) next).Expression);
                        if (nextarg is ExpressionInterpolationExpression)
                        {
                            foreach (var e in ((ExpressionInterpolationExpression)nextarg).Expressions) {
                                ((ExpressionInterpolationExpression)arg).Expressions.Add(e);  
                            }
                        }
                        else {
                            ((ExpressionInterpolationExpression) arg).Expressions.Add(nextarg);
                        }
                    }
                    if(((ExpressionInterpolationExpression)arg).Expressions.Count>0) {
                        if (first != arg) {
                            ((ExpressionInterpolationExpression) arg).Expressions.Insert(0, first);
                        }
                        set_arg(node.Expression, arg);
                    }
                }
            }
コード例 #10
0
ファイル: WSABooParserBase.cs プロジェクト: w4x/boolangstudio
        //throws RecognitionException, TokenStreamException
        protected ExpressionInterpolationExpression expression_interpolation()
        {
            ExpressionInterpolationExpression e;

            IToken  separator = null;

                e = null;
                Expression param = null;

            try {      // for error handling
            separator = LT(1);
            match(ESEPARATOR);
            if (0==inputState.guessing)
            {

                        LexicalInfo info = SourceLocationFactory.ToLexicalInfo(separator);
                        e = new ExpressionInterpolationExpression(info);

            }
            {    // ( ... )*
                for (;;)
                {
                    if ((LA(1)==ESEPARATOR) && (tokenSet_59_.member(LA(2))))
                    {
                        match(ESEPARATOR);
                        param=expression();
                        if (0==inputState.guessing)
                        {
                            if (null != param) { e.Expressions.Add(param); }
                        }
                        match(ESEPARATOR);
                    }
                    else
                    {
                        goto _loop522_breakloop;
                    }

                }
            _loop522_breakloop:				;
            }    // ( ... )*
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex);
                recover(ex,tokenSet_27_);
            }
            else
            {
                throw ex;
            }
            }
            return e;
        }
コード例 #11
0
ファイル: EmitAssembly.cs プロジェクト: w4x/boolangstudio
        public override void OnExpressionInterpolationExpression(ExpressionInterpolationExpression node)
        {
            Type stringBuilderType = typeof(StringBuilder);
            ConstructorInfo constructor = stringBuilderType.GetConstructor(new Type[0]);
            ConstructorInfo constructorString = stringBuilderType.GetConstructor(new Type[] { typeof(string) });
            MethodInfo appendObject = stringBuilderType.GetMethod("Append", new Type[] { typeof(object) });
            MethodInfo appendString = stringBuilderType.GetMethod("Append", new Type[] { typeof(string) });
            Expression arg0 = node.Expressions[0];
            IType argType = arg0.ExpressionType;

            /* if arg0 is a string, let's call StringBuilder constructor
             * directly with the string */
            if ( ( typeof(StringLiteralExpression) == arg0.GetType()
                   && ((StringLiteralExpression) arg0).Value.Length > 0 )
                || ( typeof(StringLiteralExpression) != arg0.GetType()
                     && TypeSystemServices.StringType == argType ) )
            {
                Visit(arg0);
                PopType();
                _il.Emit(OpCodes.Newobj, constructorString);
            }
            else
            {
                _il.Emit(OpCodes.Newobj, constructor);
                arg0 = null; /* arg0 is not a string so we want it to be appended below */
            }

            foreach (Expression arg in node.Expressions)
            {
                /* we do not need to append literal string.Empty
                 * or arg0 if it has been handled by ctor */
                if ( ( typeof(StringLiteralExpression) == arg.GetType()
                       && ((StringLiteralExpression) arg).Value.Length == 0 )
                    || arg == arg0 )
                {
                    continue;
                }

                Visit(arg);

                argType = PopType();
                if (TypeSystemServices.StringType == argType)
                {
                    _il.EmitCall(OpCodes.Call, appendString, null);
                }
                else
                {
                    EmitCastIfNeeded(TypeSystemServices.ObjectType, argType);
                    _il.EmitCall(OpCodes.Call, appendObject, null);
                }
            }
            _il.EmitCall(OpCodes.Call, stringBuilderType.GetMethod("ToString", new Type[0]), null);
            PushType(TypeSystemServices.StringType);
        }
コード例 #12
0
		override public object Clone()
		{
		
			ExpressionInterpolationExpression clone = new ExpressionInterpolationExpression();
			clone._lexicalInfo = _lexicalInfo;
			clone._endSourceLocation = _endSourceLocation;
			clone._documentation = _documentation;
			clone._isSynthetic = _isSynthetic;
			clone._entity = _entity;
			if (_annotations != null) clone._annotations = (Hashtable)_annotations.Clone();
			clone._expressionType = _expressionType;
			if (null != _expressions)
			{
				clone._expressions = _expressions.Clone() as ExpressionCollection;
				clone._expressions.InitializeParent(clone);
			}
			return clone;


		}
コード例 #13
0
 public override void OnExpressionInterpolationExpression(ExpressionInterpolationExpression node)
 {
     Write("\"");
     foreach (Expression arg in node.Expressions)
     {
         StringLiteralExpression s = arg as StringLiteralExpression;
         if (null == s)
         {
             Write("${");
             Visit(arg);
             Write("}");
         }
         else
         {
             WriteStringLiteralContents(s.Value, _writer, false);
         }
     }
     Write("\"");
 }
コード例 #14
0
ファイル: BooParserBase.cs プロジェクト: w4x/boolangstudio
        //throws RecognitionException, TokenStreamException
        protected ExpressionInterpolationExpression expression_interpolation()
        {
            ExpressionInterpolationExpression e;

            IToken  firstseparator = null;
            IToken  startsep = null;
            IToken  endsep = null;
            IToken  lastseparator = null;

            e = null;
            Expression param = null;
            LexicalInfo info = null;

            try {      // for error handling
            {
                if ((LA(1)==ESEPARATOR) && (LA(2)==ESEPARATOR))
                {
                    firstseparator = LT(1);
                    match(ESEPARATOR);
                }
                else if ((LA(1)==ESEPARATOR) && (tokenSet_59_.member(LA(2)))) {
                }
                else
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }

            }
            { // ( ... )+
                int _cnt575=0;
                for (;;)
                {
                    if ((LA(1)==ESEPARATOR) && (tokenSet_59_.member(LA(2))))
                    {
                        startsep = LT(1);
                        match(ESEPARATOR);
                        if (0==inputState.guessing)
                        {

                                        if (info == null)
                                        {
                                            info = ToLexicalInfo(startsep);
                                            e = new ExpressionInterpolationExpression(info);
                                        }

                        }
                        param=expression();
                        if (0==inputState.guessing)
                        {
                            if (null != param) { e.Expressions.Add(param); }
                        }
                        endsep = LT(1);
                        match(ESEPARATOR);
                    }
                    else
                    {
                        if (_cnt575 >= 1) { goto _loop575_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; }
                    }

                    _cnt575++;
                }
            _loop575_breakloop:				;
            }    // ( ... )+
            {
                if ((LA(1)==ESEPARATOR) && (tokenSet_27_.member(LA(2))))
                {
                    lastseparator = LT(1);
                    match(ESEPARATOR);
                }
                else if ((tokenSet_27_.member(LA(1))) && (tokenSet_30_.member(LA(2)))) {
                }
                else
                {
                    throw new NoViableAltException(LT(1), getFilename());
                }

            }
            }
            catch (RecognitionException ex)
            {
            if (0 == inputState.guessing)
            {
                reportError(ex);
                recover(ex,tokenSet_27_);
            }
            else
            {
                throw ex;
            }
            }
            return e;
        }
コード例 #15
0
ファイル: BooParserBase.cs プロジェクト: hlizard/boo
	protected ExpressionInterpolationExpression  expression_interpolation() //throws RecognitionException, TokenStreamException
{
		ExpressionInterpolationExpression e;
		
		IToken  firstseparator = null;
		IToken  startsep = null;
		IToken  format_sep = null;
		IToken  formatString = null;
		IToken  endsep = null;
		IToken  lastseparator = null;
		
			e = null;
			Expression param = null;
			LexicalInfo info = null;
		
		
		try {      // for error handling
			{
				if ((LA(1)==ESEPARATOR) && (LA(2)==ESEPARATOR))
				{
					firstseparator = LT(1);
					match(ESEPARATOR);
				}
				else if ((LA(1)==ESEPARATOR) && (tokenSet_5_.member(LA(2)))) {
				}
				else
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				
			}
			{ // ( ... )+
				int _cnt627=0;
				for (;;)
				{
					if ((LA(1)==ESEPARATOR) && (tokenSet_5_.member(LA(2))))
					{
						startsep = LT(1);
						match(ESEPARATOR);
						if (0==inputState.guessing)
						{
							
										if (info == null)
										{
											info = ToLexicalInfo(startsep);
											e = new ExpressionInterpolationExpression(info);
										}
									
						}
						param=expression();
						{
							switch ( LA(1) )
							{
							case ID:
							case COLON:
							{
								{
									switch ( LA(1) )
									{
									case COLON:
									{
										format_sep = LT(1);
										match(COLON);
										break;
									}
									case ID:
									{
										break;
									}
									default:
									{
										throw new NoViableAltException(LT(1), getFilename());
									}
									 }
								}
								formatString = LT(1);
								match(ID);
								break;
							}
							case ESEPARATOR:
							{
								break;
							}
							default:
							{
								throw new NoViableAltException(LT(1), getFilename());
							}
							 }
						}
						if (0==inputState.guessing)
						{
							
										if (null != param)
										{
											e.Expressions.Add(param);
											if (null != formatString)
												param.Annotate("formatString", formatString.getText());
										}
									
						}
						endsep = LT(1);
						match(ESEPARATOR);
					}
					else
					{
						if (_cnt627 >= 1) { goto _loop627_breakloop; } else { throw new NoViableAltException(LT(1), getFilename());; }
					}
					
					_cnt627++;
				}
_loop627_breakloop:				;
			}    // ( ... )+
			{
				if ((LA(1)==ESEPARATOR) && (tokenSet_44_.member(LA(2))))
				{
					lastseparator = LT(1);
					match(ESEPARATOR);
				}
				else if ((tokenSet_44_.member(LA(1))) && (tokenSet_15_.member(LA(2)))) {
				}
				else
				{
					throw new NoViableAltException(LT(1), getFilename());
				}
				
			}
		}
		catch (RecognitionException ex)
		{
			if (0 == inputState.guessing)
			{
				reportError(ex, "expression_interpolation");
				recover(ex,tokenSet_44_);
			}
			else
			{
				throw ex;
			}
		}
		return e;
	}
コード例 #16
0
 public override void LeaveExpressionInterpolationExpression(ExpressionInterpolationExpression node)
 {
     foreach (Expression e in node.Expressions)
     {
         CheckExpressionType(e);
     }
 }
コード例 #17
0
ファイル: ProcessMethodBodies.cs プロジェクト: stuman08/boo
 public override void LeaveExpressionInterpolationExpression(ExpressionInterpolationExpression node)
 {
     BindExpressionType(node, TypeSystemServices.StringType);
 }
コード例 #18
0
 private static Expression joinInterpolations(ExpressionInterpolationExpression expressionInterpolationExpression) {
     var srcexpressions = expressionInterpolationExpression.Expressions.ToList();
     ExpressionInterpolationExpression result = new ExpressionInterpolationExpression();
     StringLiteralExpression current = null;
     foreach (var srcexpression in srcexpressions) {
         if(srcexpression is LiteralExpression) {
             var str = new StringLiteralExpression(((LiteralExpression) srcexpression).ValueObject.toStr());
             if(null==current) {
                 current = str;
             }else {
                 current.Value += str.Value;
             }
         }else {
             if(current!=null) {
                 result.Expressions.Add(current);
                 current = null;
             }
             result.Expressions.Add(srcexpression);
         }
     }
     if (current != null)
     {
         result.Expressions.Add(current);
     }
     if(result.Expressions.Count>1) return result;
     return result.Expressions[0];
 }