public static bool TryAddSqlServerSpatialTypes(this ISyntax self) { // NOTE I: you need to install package "Microsoft.SqlServer.Types (spatial)" in order to let the following functions work // these bindings do NOT work with entity framework (at least not with all versions) // you need to reference XPression.EntityFramework in order to let these functions interact with EF from version EF5/.NET 4 and higher var result = false; var geo = Type.GetType("Microsoft.SqlServer.Types.SqlGeography, Microsoft.SqlServer.Types"); if (geo != null) { result = true; self.Functions.Add(new FunctionMap("geo.distance", geo.GetMethod("STDistance"))); self.Functions.Add(new FunctionMap("geo.length", geo.GetMethod("STLength"))); self.Functions.Add(new FunctionMap("geo.intersects", geo.GetMethod("STIntersects"))); } geo = Type.GetType("Microsoft.SqlServer.Types.SqlGeometry, Microsoft.SqlServer.Types"); if (geo != null) { result = true; self.Functions.Add(new FunctionMap("geo.distance", geo.GetMethod("STDistance"))); self.Functions.Add(new FunctionMap("geo.length", geo.GetMethod("STLength"))); self.Functions.Add(new FunctionMap("geo.intersects", geo.GetMethod("STIntersects"))); } return(result); }
public static string AsString(this ISyntax node) { var visitor = new SyntaxStringifyVisitor(); node.Accept(visitor); return(visitor.ToString()); }
public static void Setup(ISyntax Syntax) { Syntax .Entity <HostExtenderRef>() .Property(x => x.ExtenderIndex) .ByRegexPattern(CommonRegexPatterns._HEXINT32, CommonConverters.HexInt32Converter) .WithPostfix(new LiteralToken("=")); Syntax .Entity <HostExtenderRef>() .Property(x => x.ExtenderGuid) .ByRegexPattern(CommonRegexPatterns._GUID) .WithPostfix(new LiteralToken(";")); Syntax .Entity <HostExtenderRef>() .Property(x => x.LibName) .ByRegexPattern("VBE[\x21-\x3A\x3C-\xFF]*") .WithPostfix(new LiteralToken(";")); Syntax .Entity <HostExtenderRef>() .Property(x => x.CreationFlags) .ByRegexPattern(CommonRegexPatterns._HEXINT32, CommonConverters.HexInt32Converter) .WithPostfix(CommonTokens.NWLN); }
public void Add(ISyntax xoToken) { if (xoToken != null) { aoItems.Add(xoToken); } }
public static string Visit(Random random, ISyntax syntax) { SyntaxVisitor syntaxVisitor = new SyntaxVisitor(random); syntax.Accept(syntaxVisitor); return(syntaxVisitor.builder_.ToString()); }
public static Concept As(this Concept concept, ISyntax syntax) { var grammar = new Syntax(concept.Name + " (syntax)", syntax); concept.Grammar = grammar; return(concept); }
protected override void WalkNonNull(ISyntax syntax) { switch (syntax) { case IReachabilityAnnotationSyntax _: // Ignore for now return; case IClassDeclarationSyntax _: // Don't recur into body, we will see those as separate members return; case ITypeSyntax type: WalkChildren(type); type.NamedType.Assigned(); return; case IForeachExpressionSyntax foreachExpression: WalkChildren(foreachExpression); foreachExpression.DataType.Assigned(); return; case IExpressionSyntax expression: WalkChildren(expression); expression.DataType.Assigned(); return; } WalkChildren(syntax); }
public static void Setup(ISyntax Syntax) { Syntax .Entity <ProjectWorkspace>() .EnumerableProperty(x => x.ProjectWindowRecords) .ByRegisteredTypes(typeof(ProjectWindowRecord)); }
public SyntaxNode(IGrammar grammar, ISyntax syntax, Token token) { this.Grammar = grammar; this.Syntax = syntax; this.Token = token; this.State = State.Valid; }
public void Insert(ISyntax xoNewNode, int xiIndex = -1) { if (xiIndex == -1) { aoItems.Insert(xiIndex == -1 ? Position : xiIndex, xoNewNode); } }
public SyntaxNode(IGrammar grammar, Token token) { this.Grammar = grammar; this.Syntax = null; this.Token = token; this.State = State.Valid; }
public Repetition(string name, IGrammar item, ISyntax whitespace, int mincount) { this.Name = name; this.whitespace = whitespace; this.mincount = mincount; this.item = item; }
public SyntaxNode(IGrammar grammar, ISyntax syntax, Token token, State state) { this.Grammar = grammar; this.Syntax = syntax; this.Token = token; this.State = state; }
public static void Setup(ISyntax Syntax) { Syntax .Entity <ProjectWindow>() .Property(x => x.WindowLeft) .ByRegexPattern(CommonRegexPatterns._INT32) .WithPostfix(new LiteralToken(", ")); Syntax .Entity <ProjectWindow>() .Property(x => x.WindowTop) .ByRegexPattern(CommonRegexPatterns._INT32) .WithPostfix(new LiteralToken(", ")); Syntax .Entity <ProjectWindow>() .Property(x => x.WindowRight) .ByRegexPattern(CommonRegexPatterns._INT32) .WithPostfix(new LiteralToken(", ")); Syntax .Entity <ProjectWindow>() .Property(x => x.WindowBottom) .ByRegexPattern(CommonRegexPatterns._INT32) .WithPostfix(new LiteralToken(", ")); Syntax .Entity <ProjectWindow>() .Property(x => x.WindowState) .ByRegexPattern("[CZI]{0,1}"); // todo: documentation not quite clear to me.. is could there be two chars? e.g. CZ ? }
protected override void WalkNonNull(ISyntax syntax, NamespaceOrPackageSymbol containingSymbol) { switch (syntax) { case ICompilationUnitSyntax syn: { var sym = BuildNamespaceSymbol(containingSymbol, syn.ImplicitNamespaceName); WalkChildren(syn, sym); } break; case INamespaceDeclarationSyntax syn: { syn.ContainingNamespaceSymbol = containingSymbol; // TODO correctly handle Global qualifier var sym = BuildNamespaceSymbol(containingSymbol, syn.DeclaredNames); syn.Symbol.Fulfill(sym); WalkChildren(syn, sym); } break; case INonMemberEntityDeclarationSyntax syn: syn.ContainingNamespaceSymbol = containingSymbol; break; default: // do nothing return; } }
protected void WalkChildrenInReverse(ISyntax syntax, T arg) { foreach (var child in syntax.Children().Reverse()) { WalkNonNull(child, arg); } }
public static SyntaxNode Create(IGrammar grammar, ISyntax syntax, Token token) { var state = token.IsValid ? State.Valid : State.Error; var node = new SyntaxNode(grammar, syntax, token, state); return(node); }
protected void VerifyLocation(ISyntax syntax, int startLine, int startColumn, int endLine, int endColumn) { Assert.AreEqual(startLine, syntax.Loc.Start.Line); Assert.AreEqual(startColumn, syntax.Loc.Start.Column); Assert.AreEqual(endLine, syntax.Loc.End.Line); Assert.AreEqual(endColumn, syntax.Loc.End.Column); }
private static IEnumerable <ISyntax> Parse(ref CharacterReader r) { var state = State.Start; var parsed = new List <ISyntax>(); while (state != State.End) { ISyntax syntax = null; if (state == State.Start) { (state, syntax) = ParseStart(ref r); } else if (state == State.Next) { (state, syntax) = ParseNext(ref r); } else if (state == State.AfterProperty) { (state, syntax) = ParseAfterProperty(ref r); } if (syntax != null) { parsed.Add(syntax); } } if (state != State.End && r.End) { throw new ExpressionParseException(r.Position, "Unexpected end of property path"); } return(parsed); }
/// <summary> /// Scans ahead for a possibly Identifier/Alias and returns the value /// if it finds one. if it does find one, it will move the Window accordingly /// </summary> /// <param name="xoToken"></param> /// <param name="xoList"></param> /// <returns></returns> public static String ScanAheadForAlias(SyntaxList xoList) { String sAlias = String.Empty; // SCAN AHEAD - To grab an alias if there is one if (xoList.HasTokensLeftToProcess()) { ISyntax oNextNode = xoList.Peek(); // Explicit if (oNextNode.ExpectedType == SyntaxKind.AsKeyword) { // And the next node after that is an identifier if (xoList.Peek(1).ExpectedType == SyntaxKind.IdentifierToken) { // Alias found sAlias = xoList.Peek(1).RawSQLText; xoList.Pop(2); } } // Implicit else if (oNextNode.ExpectedType == SyntaxKind.IdentifierToken) { // Alias found sAlias = oNextNode.RawSQLText; xoList.Pop(); } } // Return the newly created table node return(sAlias); }
public static Type GetType(this ISyntax self, string typename) { TypeParser type; return(self.KnownTypes.TryGetValue(typename, out type) ? type.Type : TypeResolver.GetType(typename, true, false)); }
public Interlace(string name, IGrammar glue, IGrammar item, ISyntax whitespace, int mincount) { this.Name = name; this.whitespace = whitespace; this.Item = item; this.Glue = glue; this.mincount = mincount; }
public static void Setup(ISyntax Syntax) { Syntax .Entity <ProjectPackage>() .Property(x => x.GUID) .ByRegexPattern(CommonRegexPatterns._GUID) .WithPrefix(new LiteralToken("Package=")); }
public static void Setup(ISyntax Syntax) { Syntax .Entity <ProjectDesignerModule>() .Property(x => x.ModuleIdentifier) .ByRegexPattern(CommonRegexPatterns._ANYCHAR + "{0,31}") .WithPrefix(new LiteralToken("BaseClass=")); }
public static void Setup(ISyntax Syntax) { Syntax .Entity <HostExtenders>() .EnumerableProperty(x => x.HostExtenderRef) .ByRegisteredTypes(typeof(HostExtenderRef)) .WithPrefix(new LiteralToken("[Host Extender Info]") + CommonTokens.NWLN); }
public SyntaxList(ISyntax xoGiven) { aoItems = new List <ISyntax>() { xoGiven }; Position = 0; }
public virtual void ExtendSyntax(ISyntax syntax) { _syntax[GetType()] = syntax; foreach (var type in AppDomain.CurrentDomain.GetExportedTypes().Where(t => !t.IsAbstract && typeof(IAutoSyntaxExtender).IsAssignableFrom(t))) { Activator.CreateInstance(type).CastTo <ISyntaxExtender>().ExtendSyntax(syntax); } }
public static void Setup(ISyntax Syntax) { Syntax .Entity <ProjectId>() .Property(x => x.ProjectCLSID) .ByRegexPattern(CommonRegexPatterns._GUID) .WithPrefix(new LiteralToken("ID=\"")) .WithPostfix(CommonTokens.DQUOTE + CommonTokens.NWLN); }
public Lexer(Grammar grammar) { if (grammar == null) { throw new ArgumentNullException("grammar"); } _grammar = grammar; _syntax = grammar.Syntax; }
public Grammar(ISyntax syntax) { if (syntax == null) { throw new ArgumentNullException("syntax"); } Syntax = syntax; _lexer = new Lexer(this); }
public string Generate(ISyntax syntax) { var sb = new StringBuilder(); var typeName = syntax.GetType().Name; switch (typeName) { #region "Program" case "Program": var program = (syntax as Program); sb.Append("using System;"); sb.Append("using Storm;"); sb.Append("public class C0 : JsObject"); sb.Append("{"); _context.DeclaredVarNames.ToList().ForEach( p => sb.Append(string.Format("private object {0}{{get;set;}}", p))); _context.Actions.ToList().ForEach( a => sb.Append(string.Format("private {0} {1};", TypeAsString(a.Value.GetType()), a.Key))); sb.Append("public C0("); _context.Actions.ToList().ForEach( a => sb.Append(string.Format("{0} {1}, ", TypeAsString(a.Value.GetType()), a.Key))); sb.Append("IDebugger debugger):base(debugger){"); _context.Actions.ToList().ForEach(a => sb.Append(string.Format("this.{0} = {0};", a.Key))); sb.Append("}"); this.DeclarationContext = true; // colocar esceção para tipo não suportado program.Body.ToList().Where(inst => inst is VariableDeclaration).ToList().ForEach( b => sb.Append(b.ToString())); this.DeclarationContext = false; sb.Append("public override object Exec()"); sb.Append("{"); var ret = false; var index = 0; program.Body.ForEach(b => { if (index == program.Body.Count - 1) { if (b.Type == "ExpressionStatement") { if (b.Expression.Type == "CallExpression") { if (_context.Actions.ContainsKey(b.Expression.Callee.Name)) { if ( TypeAsString( _context.Actions[b.Expression.Callee.Name]. GetType()). StartsWith("System.Func")) { sb.Append("return "); ret = true; } } else throw new Exception(); } else if (b.Type == "Literal" || b.Type == "Identifier" || b.Type == "ExpressionStatement") { sb.Append("return "); ret = true; } } else if (b.Type == "Literal" || b.Type == "Identifier" || b.Type == "ExpressionStatement") { sb.Append("return "); ret = true; } } sb.Append(b.ToString()); index++; }); this.ReturnContext = true; if (!ret) sb.Append("return JsObject.Undefined;"); this.ReturnContext = true; sb.Append("}"); sb.Append("}"); break; #endregion #region "VariableDeclaration": case "VariableDeclaration": var variableDeclaration = (syntax as VariableDeclaration); if (this.ReturnContext) { sb.Append(variableDeclaration.Declarations.Last().ToString()); } else { foreach (var d in variableDeclaration.Declarations) { if (_debugMode && !this.DeclarationContext) sb.Append(string.Format("Debugger.BreakPoint({0}, {1}, {2}, {3}, {4}, {5});", d.Range.Start, d.Range.End, d.Loc.Start.Line, d.Loc.Start.Column, d.Loc.End.Line, d.Loc.End.Column)); if (this.DeclarationContext) { if (!_context.DeclaredVarNames.Contains(d.ToString())) { sb.Append("private object "); sb.Append(d.ToString()); sb.Append("{get;set;}"); _context.DeclaredVarNames.Add(d.ToString()); } } else { sb.Append(d.ToString()); sb.Append(";"); } if (_debugMode && !this.DeclarationContext) sb.Append("Debugger.BreakPoint(this);"); } } break; #endregion #region "VariableDeclarator" case "VariableDeclarator": var variableDeclarator = (syntax as VariableDeclarator); if (this.ReturnContext) { sb.Append(variableDeclarator.Id); } else { sb.Append(variableDeclarator.Id); if (!this.DeclarationContext) { sb.Append(" = "); if (variableDeclarator.Init != null) { sb.Append(variableDeclarator.Init); } else { sb.Append("JsObject.Undefined"); } } } break; #endregion #region "Identifier" case "Identifier": var identifier = (syntax as Identifier); var name = identifier.Name.Replace("$", "@"); if(name == "String" || name == "string") { name = "@" + name; } if (this.DeclarationContext) sb.Append(name); else sb.Append("((dynamic)this)." + name); break; #endregion #region "Literal" case "Literal": var literal = (syntax as Literal); if (literal.IsString) sb.Append("@\""); sb.Append(literal.Value.Replace("\"", "\"\"")); if (literal.IsString) sb.Append("\""); break; #endregion #region "ExpressionStatement" case "ExpressionStatement": var expression = (syntax as ExpressionStatement); if (_debugMode && !this.DeclarationContext) sb.Append(string.Format("Debugger.BreakPoint({0}, {1}, {2}, {3}, {4}, {5});", expression.Range.Start, expression.Range.End, expression.Loc.Start.Line, expression.Loc.Start.Column, expression.Loc.End.Line, expression.Loc.End.Column)); sb.Append(expression.Expression.ToString()); sb.Append(";"); if (_debugMode && !this.DeclarationContext) sb.Append("Debugger.BreakPoint(this);"); break; #endregion #region "AssignmentExpression" case "AssignmentExpression": var assign = (syntax as AssignmentExpression); sb.Append(assign.Left.ToString()); sb.Append(string.Format(" {0} ", assign.Operator)); sb.Append(assign.Right.ToString()); break; #endregion #region "BinaryExpression" case "BinaryExpression": var binary = (syntax as BinaryExpression); sb.Append("("); sb.Append(binary.Left.ToString()); var op = binary.Operator; if (binary.Operator == "!==") { op = "!="; } else if (binary.Operator == "===") { op = "=="; } else if (binary.Operator == "!=") { sb.Append(".ToString()"); } else if (binary.Operator == "==") { sb.Append(".ToString()"); } sb.Append(string.Format(" {0} ", op)); sb.Append(binary.Right.ToString()); if (binary.Operator == "!=" || binary.Operator == "==") sb.Append(".ToString()"); sb.Append(")"); break; #endregion #region "CallExpression" case "CallExpression": var call = (syntax as CallExpression); sb.Append(call.Callee.ToString()); sb.Append("("); call.Arguments.ToList().ForEach(a => sb.Append(a.ToString())); sb.Append(")"); break; #endregion #region "IfStatement" case "IfStatement": var @if = (syntax as IfStatement); sb.Append(string.Format("if({0})", @if.Test.ToString())); sb.Append("{"); sb.Append(@if.Consequent.ToString()); sb.Append("}"); if (@if.Alternate != null) { sb.Append("else"); sb.Append("{"); sb.Append(@if.Alternate.ToString()); sb.Append("}"); } break; #endregion #region "BlockStatement" case "BlockStatement": var block = (syntax as BlockStatement); block.Body.ForEach(b => sb.Append(b.ToString())); break; #endregion #region "EmptyStatement" case "EmptyStatement": sb.Append(""); break; #endregion #region "UpdateExpression" case "UpdateExpression": var update = (syntax as UpdateExpression); //if (update.Prefix) //{ // sb.Append(update.Operator); //} //sb.Append(update.Argument.ToString()); sb.AppendFormat("{0} = JsObject.PlusPlus({0}, {1})", update.Argument.ToString(), update.Prefix.ToString().ToLower()); //if (!update.Prefix) //{ // sb.Append(update.Operator); //} break; #endregion #region "MemberExpression" case "MemberExpression": var member = (syntax as MemberExpression); //sb.AppendFormat("((dynamic){0}).{1}", member.Object.ToString(), member.Property.ToString()); sb.Append(member.Property.ToString()); break; #endregion #region "ArrayExpression" case "ArrayExpression": var array = (syntax as ArrayExpression); sb.Append("new object[]{"); sb.Append(string.Join(", ", array.Elements.Select(el => el.ToString()))); sb.Append("}"); break; #endregion } return sb.ToString(); }
protected BinaryOperandsSyntax(ISyntax left, ISyntax right) { this.Left = left; this.Right = right; }
public string Generate(ISyntax syntax) { var sb = new StringBuilder(); var typeName = syntax.GetType().Name; switch (typeName) { #region "Program" case "Program": var program = (syntax as Program); program.Body.ForEach(b => sb.Append(b.ToString())); break; #endregion #region "VariableDeclaration": case "VariableDeclaration": var variableDeclaration = (syntax as VariableDeclaration); sb.Append("var "); var index = 0; foreach (var d in variableDeclaration.Declarations) { if (index > 0) sb.Append(", "); sb.Append(d.ToString()); index++; } sb.Append("; "); break; #endregion #region "VariableDeclarator" case "VariableDeclarator": var variableDeclarator = (syntax as VariableDeclarator); sb.Append(variableDeclarator.Id.ToString()); if (variableDeclarator.Init != null) { sb.Append(" = "); sb.Append(variableDeclarator.Init.ToString()); } break; #endregion #region "Identifier" case "Identifier": var identifier = (syntax as Identifier); sb.Append(identifier.Name); break; #endregion #region "Literal" case "Literal": var literal = (syntax as Literal); if (literal.IsString) sb.Append("\""); sb.Append(literal.Value); if (literal.IsString) sb.Append("\""); break; #endregion #region "ExpressionStatement" case "ExpressionStatement": var expression = (syntax as ExpressionStatement); sb.Append(expression.Expression.ToString()); break; #endregion #region "ThisExpression" case "ThisExpression": var thisExpression = (syntax as ThisExpression); sb.Append(thisExpression.ToString()); break; #endregion } return sb.ToString(); }
public AppendSyntax(ISyntax left, ISyntax right) : base(left, right) { }
public OrSyntax(ISyntax left, ISyntax right) : base(left, right) { }
protected void VerifyRange(ISyntax syntax, int start, int end) { Assert.AreEqual(start, syntax.Range.Start); Assert.AreEqual(end, syntax.Range.End); }