/// <summary> /// Transforms a type name specified in a given URN to a .Net-compatible type name. /// </summary> public string Parse(Uri uri) { if (!uri.Scheme.Equals("urn", StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException("A CodeFeatureId must be a URN", "uri"); } string absolutePath = uri.AbsolutePath; const string featurePreamble = "feature:"; const string contextPreamble = "context:"; if (absolutePath.StartsWith(featurePreamble, StringComparison.OrdinalIgnoreCase)) { absolutePath = absolutePath.Substring(featurePreamble.Length); } else if (absolutePath.StartsWith(contextPreamble, StringComparison.OrdinalIgnoreCase)) { absolutePath = absolutePath.Substring(contextPreamble.Length); } // Workaround for a bug in .NET < 4.5.1 which incorrectly // escapes '[' and ']' as %5B and %5D (respectively) under some // circumstances, even though both are RFC 2396 unreserved characters. // http://stackoverflow.com/questions/20003106/uri-escapeuristring-with-square-braces // http://msdn.microsoft.com/en-us/library/hh367887%28v=vs.110%29.aspx absolutePath = absolutePath.Replace("%5B", "[").Replace("%5D", "]"); var root = new TypeNameNode(); TypeNameNode current = root; foreach (char c in absolutePath) { switch (c) { case '[': // go one level down var child = new TypeNameNode(current); current.Children.Add(child); current = child; break; case ']': // go one level up current = current.Parent; break; case ',': // sibling will be caugth by '[' case ' ': // ignore whitespace break; default: current.ContentBuilder.Append(c); break; } } root.Flatten(); return(root.ToString()); }
public override SQLiteParseTreeNode VisitType_name(SQLiteParserSimpleParser.Type_nameContext context) { var ret = new TypeNameNode(context) { TypeName = context.id().GetText(), SignedNumbers = context.signed_number().Select(i => i.GetText()).ToList() }; return(ret); }
public ForeachLoopStatementNode Foreach(string variable, TypeNameNode variableType, ExpressionNode expression, StatementNodeBase body, AttributeNode[] attributes) { if (string.IsNullOrWhiteSpace(variable)) ThrowHelper.ThrowException("The 'variable' is blank!"); if (expression == null) ThrowHelper.ThrowArgumentNullException(() => expression); if (body == null) ThrowHelper.ThrowArgumentNullException(() => body); if (attributes == null) ThrowHelper.ThrowArgumentNullException(() => attributes); return new ForeachLoopStatementNode(variable, variableType, expression, body, attributes); }
/// <summary> /// Transforms a type name specified in a given URN to a .Net-compatible type name. /// </summary> public string Parse(Uri uri) { if (!uri.Scheme.Equals("urn", StringComparison.OrdinalIgnoreCase)) throw new ArgumentException("A CodeFeatureId must be a URN", "uri"); string absolutePath = uri.AbsolutePath; const string featurePreamble = "feature:"; const string contextPreamble = "context:"; if (absolutePath.StartsWith(featurePreamble, StringComparison.OrdinalIgnoreCase)) absolutePath = absolutePath.Substring(featurePreamble.Length); else if (absolutePath.StartsWith(contextPreamble, StringComparison.OrdinalIgnoreCase)) absolutePath = absolutePath.Substring(contextPreamble.Length); // Workaround for a bug in .NET < 4.5.1 which incorrectly // escapes '[' and ']' as %5B and %5D (respectively) under some // circumstances, even though both are RFC 2396 unreserved characters. // http://stackoverflow.com/questions/20003106/uri-escapeuristring-with-square-braces // http://msdn.microsoft.com/en-us/library/hh367887%28v=vs.110%29.aspx absolutePath = absolutePath.Replace("%5B", "[").Replace("%5D", "]"); var root = new TypeNameNode(); TypeNameNode current = root; foreach (char c in absolutePath) { switch (c) { case '[': // go one level down var child = new TypeNameNode(current); current.Children.Add(child); current = child; break; case ']': // go one level up current = current.Parent; break; case ',': // sibling will be caugth by '[' case ' ': // ignore whitespace break; default: current.ContentBuilder.Append(c); break; } } root.Flatten(); return root.ToString(); }
/// <summary> /// Transforms a type name specified in a given URN to a .Net-compatible type name. /// </summary> public static string Parse(string absolutePath) { const string preamble = "message:"; if (absolutePath.StartsWith(preamble)) { absolutePath = absolutePath.Substring(preamble.Length); } // Workaround for a bug in .NET < 4.5.1 which incorrectly // escapes '[' and ']' as %5B and %5D (respectively) under some // circumstances, even though both are RFC 2396 unreserved characters. // http://stackoverflow.com/questions/20003106/uri-escapeuristring-with-square-braces // http://msdn.microsoft.com/en-us/library/hh367887%28v=vs.110%29.aspx absolutePath = absolutePath.Replace("%5B", "[").Replace("%5D", "]"); TypeNameNode root = new TypeNameNode(); var current = root; foreach (char c in absolutePath) { switch (c) { case '[': // go one level down var child = new TypeNameNode { Parent = current }; current.Children.Add(child); current = child; break; case ']': // go one level up current = current.Parent; break; case ',': // sibling will be caugth by '[' case ' ': // ignore whitespace break; default: current.ContentBuilder.Append(c); break; } } root.Flatten(); return(root.ToString()); }
public StringBuilder Visit(TypeNameNode typeNameNode) { var sb = new StringBuilder(); sb.Append(typeNameNode.TypeName); sb.Append(" "); if (typeNameNode.SignedNumbers != null && typeNameNode.SignedNumbers.Any()) { sb.Append("("); sb.Append(string.Join(", ", typeNameNode.SignedNumbers)); sb.Append(") "); } return(sb); }
public ForeachLoopStatementNode(string variable, TypeNameNode variableType, ExpressionNode expression, StatementNodeBase body, AttributeNode[] attributes) : base(body, attributes) { if (string.IsNullOrWhiteSpace(variable)) ThrowHelper.ThrowException("The 'variable' is blank!"); if (expression == null) throw new ArgumentNullException("expression", "The expression is null!"); if (attributes == null) ThrowHelper.ThrowArgumentNullException(() => attributes); LoopVariable = new IdentifierExpressionNode(variable); Expression = expression; LoopVariableType = variableType; AddChildren(LoopVariable, LoopVariableType, Expression); }
public VariableDeclarationStatementNode(string name, TypeNameNode variableType, ExpressionNode initialValue, AttributeNode[] attributes) { if (name == null) ThrowHelper.ThrowArgumentNullException(() => name); if (variableType == null) ThrowHelper.ThrowArgumentNullException(() => variableType); if (initialValue == null) ThrowHelper.ThrowArgumentNullException(() => initialValue); InitialValue = initialValue; Identifier = new IdentifierExpressionNode(name, null); VariableType = variableType; Attributes = attributes.ToList(); AddChildren(Identifier, VariableType, InitialValue); AddChildren(Attributes); }
public override void build() { if (children.Length == 4) { typeNameNode = (TypeNameNode)children[1]; methodName = TermPay(children[3]); } else if (children.Length == 3) { methodName = TermPay(children[2]); } else { throw new Exception(); } frameNode = (FrameNode)children[0]; // Todo: i am pretty sure the payload of Term<CS_name> can never be null or "" , ... like 95% or so }
public FunctionDeclarationStatementNode(string name, BlockStatementNode functionBody, TypeNameNode returnType, FormalParameterNode[] parameters, IEnumerable<AttributeNode> attributes) : base(name) { if (functionBody == null) ThrowHelper.ThrowArgumentNullException(() => functionBody); if (returnType == null) ThrowHelper.ThrowArgumentNullException(() => returnType); if (parameters == null) ThrowHelper.ThrowArgumentNullException(() => parameters); if (attributes == null) ThrowHelper.ThrowArgumentNullException(() => attributes); FunctionBody = functionBody; ReturnType = returnType; Parameters = parameters; Attributes = attributes.ToList(); AddChildren(FunctionBody, ReturnType); AddChildren(Parameters); AddChildren(Attributes); }
public TypeNameNode(TypeNameNode parent) : this() { Parent = parent; }
public VariableDeclarationStatementNode DeclareVariable(string name, TypeNameNode typeName, ExpressionNode initialValue) { return DeclareVariable(name, typeName, initialValue, new AttributeNode[0]); }
public VariableDeclarationStatementNode DeclareVariable(string name, TypeNameNode typeName, ExpressionNode initialValue, AttributeNode[] attributes) { if (string.IsNullOrWhiteSpace(name)) ThrowHelper.ThrowException("The name is blank!"); if (attributes == null) ThrowHelper.ThrowArgumentNullException(() => attributes); return new VariableDeclarationStatementNode(name, typeName, initialValue, attributes); }
public UnaryCastExprNode makeCastExprNode(ExprNode namelist, TypeNameNode name) { return(null); }
public SizeofTypeExprNode makeSizeofTypeExprNode(TypeNameNode name) { return(null); }
public FunctionDeclarationStatementNode Function(string name, TypeNameNode returnType, FormalParameterNode[] parameters, ExpressionNode body, AttributeNode[] attributes) { var statementFactory = CompilerService.StatementFactory; return Function(name, returnType, parameters, statementFactory.Block(new StatementNodeBase[] { statementFactory.Expression(body) }), attributes); }
private static void GenerateTypeName(TypeNameNode node, DataContext data) { Append(data, "ScriptType.FromValue("); GenerateExpression(node.TypeExpression, data); if (node.GenericArgs.Count > 0) { Append(data, ", "); for (int i = 0; i < node.GenericArgs.Count; i++) { if (i > 0) Append(data, ", "); GenerateTypeName(node.GenericArgs[i], data); } } Append(data, ")"); }
public FunctionDeclarationStatementNode Function(string name, TypeNameNode returnType, FormalParameterNode[] parameters, BlockStatementNode body, AttributeNode[] attributes) { if (string.IsNullOrWhiteSpace(name)) ThrowHelper.ThrowException("The 'name' is blank!"); if (body == null) ThrowHelper.ThrowArgumentNullException(() => body); if (parameters == null) ThrowHelper.ThrowArgumentNullException(() => parameters); if (attributes == null) ThrowHelper.ThrowArgumentNullException(() => attributes); var type = returnType ?? new TypeNameNode("void"); return new FunctionDeclarationStatementNode(name, body, type, parameters, attributes); }
public FormalParameterNode FormalParameter(string name, TypeNameNode type) { return FormalParameter(name, type, new AttributeNode[0]); }
public ForeachLoopStatementNode Foreach(string variable, TypeNameNode variableType, ExpressionNode expression, StatementNodeBase body) { return Foreach(variable, variableType, expression, body, new AttributeNode[0]); }
public FormalParameterNode FormalParameter(string name, TypeNameNode type, IEnumerable<AttributeNode> attributes) { if (string.IsNullOrWhiteSpace(name)) ThrowHelper.ThrowException("The name is blank!"); if (type == null) ThrowHelper.ThrowArgumentNullException(() => type); return new FormalParameterNode(name, type, attributes); }