Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / ndp / fx / src / DataEntity / System / Data / Common / EntitySql / CqlParserHelpers.cs / 2 / CqlParserHelpers.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Common.EntitySql { using System; using System.IO; using System.Globalization; ////// Represents the Cql Parser engine. Also, implements helpers and util routines. /// internal sealed partial class CqlParser { private Expr _parsedTree; private CqlLexer _lexer; private string _query; private ParserOptions _parserOptions = new ParserOptions(); private const string _internalYaccSyntaxErrorMessage = "syntax error"; private uint _methodCallNodeCount; private string _version = YYMAJOR.ToString(NumberFormatInfo.InvariantInfo) + '.' + YYMINOR.ToString(NumberFormatInfo.InvariantInfo); internal CqlParser( ParserOptions parserOptions, bool debug ) { _parserOptions = parserOptions; yydebug = debug; } ////// Main entry point for parsing cql. /// /// cql query string ///Thrown when Syntatic rules are violated and the query cannot be accepted ///Abstract Syntax Tree internal Expr Parse( string query ) { _query = query; _parsedTree = null; _methodCallNodeCount = 0; _parserOptions = _parserOptions.MakeReadOnly(); internalParseEntryPoint(); return _parsedTree; } ////// Returns query string /// internal string Query { get { return _query; } } #if EXTRA_ENTITYSQL_PARSER_DEBUGGING ////// Enables/Disables yacc debugging. /// internal bool EnableDebug { get { return yydebug; } set { yydebug = value; } } #endif ////// Returns ParserOptions used /// ///Once parse has been invoked, ParserOptions are frozen and cannot be changed. otherwise a EntityException exception will be thrown internal ParserOptions ParserOptions { get { return _parserOptions; } } ////// Internal entry point /// private void internalParseEntryPoint() { _lexer = new CqlLexer(Query, ParserOptions); #if EXTRA_ENTITYSQL_PARSER_DEBUGGING CqlLexer.Token tk = lexer.yylex(); while (null != tk) { Console.WriteLine("{0} := {1}", tk.TokenId, lexer.yytext()); tk = lexer.yylex(); } #endif yyparse(); } // // Conversion/Cast/Helpers // private static AstNode AstNode( object o ) { return ((AstNode)o); } private static int AstNodePos( object o ) { return ((AstNode)o).ErrCtx.InputPosition; } private static CqlLexer.TerminalToken Terminal( object o ) { return ((CqlLexer.TerminalToken)o); } private static int TerminalPos( object o ) { return ((CqlLexer.TerminalToken)o).IPos; } private static ExprListToExprList ( object o ) { return ((ExprList )o); } private short yylex() { CqlLexer.Token token = null; token = _lexer.yylex(); if (null == token) { return 0; } _lexer.AdvanceIPos(); yylval = token.Value; return token.TokenId; } private void yyerror_stackoverflow() { yyerror(System.Data.Entity.Strings.StackOverflowInParser); } private void yyerror( string s ) { if (s.Equals(_internalYaccSyntaxErrorMessage, StringComparison.Ordinal)) { int errorPosition = _lexer.IPos; string syntaxContextInfo = null; string term = _lexer.YYText; if (!String.IsNullOrEmpty(term)) { syntaxContextInfo = System.Data.Entity.Strings.LocalizedTerm; ErrorContext errCtx = null; AstNode astNode = yylval as AstNode; if (null != astNode && (null != astNode.ErrCtx) && (!String.IsNullOrEmpty(astNode.ErrCtx.ErrorContextInfo))) { errCtx = astNode.ErrCtx; errorPosition = Math.Min(errorPosition, errorPosition - term.Length); } if ((yylval is CqlLexer.TerminalToken) && CqlLexer.IsReservedKeyword(term) && !(astNode is Identifier)) { syntaxContextInfo = System.Data.Entity.Strings.LocalizedKeyword; term = term.ToUpperInvariant(); errorPosition = Math.Min(errorPosition, errorPosition - term.Length); } else if (null != errCtx) { syntaxContextInfo = EntityRes.GetString(errCtx.ErrorContextInfo); } syntaxContextInfo = String.Format(CultureInfo.CurrentCulture, "{0} '{1}'", syntaxContextInfo, term); } throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.GenericSyntaxError, errorPosition, syntaxContextInfo, false /* loadErrorContextInfoFromResource */); } throw EntityUtil.EntitySqlError(_query, s, _lexer.IPos); } // // Error tracking helpers // private void SetErrCtx( AstNode astExpr, CqlLexer.TerminalToken tokenValue, string info ) { SetErrCtx(astExpr, tokenValue.IPos, info); } private void SetErrCtx( AstNode astExpr, int inputPos, string info ) { astExpr.ErrCtx.InputPosition = inputPos; astExpr.ErrCtx.ErrorContextInfo = info; astExpr.ErrCtx.QueryText = _query; } private void ResetMethodCallCount() { _methodCallNodeCount = 0; } private void IncrementMethodCallCount() { unchecked { _methodCallNodeCount++; } } private uint MethodCallCount { get { return _methodCallNodeCount; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Common.EntitySql { using System; using System.IO; using System.Globalization; ////// Represents the Cql Parser engine. Also, implements helpers and util routines. /// internal sealed partial class CqlParser { private Expr _parsedTree; private CqlLexer _lexer; private string _query; private ParserOptions _parserOptions = new ParserOptions(); private const string _internalYaccSyntaxErrorMessage = "syntax error"; private uint _methodCallNodeCount; private string _version = YYMAJOR.ToString(NumberFormatInfo.InvariantInfo) + '.' + YYMINOR.ToString(NumberFormatInfo.InvariantInfo); internal CqlParser( ParserOptions parserOptions, bool debug ) { _parserOptions = parserOptions; yydebug = debug; } ////// Main entry point for parsing cql. /// /// cql query string ///Thrown when Syntatic rules are violated and the query cannot be accepted ///Abstract Syntax Tree internal Expr Parse( string query ) { _query = query; _parsedTree = null; _methodCallNodeCount = 0; _parserOptions = _parserOptions.MakeReadOnly(); internalParseEntryPoint(); return _parsedTree; } ////// Returns query string /// internal string Query { get { return _query; } } #if EXTRA_ENTITYSQL_PARSER_DEBUGGING ////// Enables/Disables yacc debugging. /// internal bool EnableDebug { get { return yydebug; } set { yydebug = value; } } #endif ////// Returns ParserOptions used /// ///Once parse has been invoked, ParserOptions are frozen and cannot be changed. otherwise a EntityException exception will be thrown internal ParserOptions ParserOptions { get { return _parserOptions; } } ////// Internal entry point /// private void internalParseEntryPoint() { _lexer = new CqlLexer(Query, ParserOptions); #if EXTRA_ENTITYSQL_PARSER_DEBUGGING CqlLexer.Token tk = lexer.yylex(); while (null != tk) { Console.WriteLine("{0} := {1}", tk.TokenId, lexer.yytext()); tk = lexer.yylex(); } #endif yyparse(); } // // Conversion/Cast/Helpers // private static AstNode AstNode( object o ) { return ((AstNode)o); } private static int AstNodePos( object o ) { return ((AstNode)o).ErrCtx.InputPosition; } private static CqlLexer.TerminalToken Terminal( object o ) { return ((CqlLexer.TerminalToken)o); } private static int TerminalPos( object o ) { return ((CqlLexer.TerminalToken)o).IPos; } private static ExprListToExprList ( object o ) { return ((ExprList )o); } private short yylex() { CqlLexer.Token token = null; token = _lexer.yylex(); if (null == token) { return 0; } _lexer.AdvanceIPos(); yylval = token.Value; return token.TokenId; } private void yyerror_stackoverflow() { yyerror(System.Data.Entity.Strings.StackOverflowInParser); } private void yyerror( string s ) { if (s.Equals(_internalYaccSyntaxErrorMessage, StringComparison.Ordinal)) { int errorPosition = _lexer.IPos; string syntaxContextInfo = null; string term = _lexer.YYText; if (!String.IsNullOrEmpty(term)) { syntaxContextInfo = System.Data.Entity.Strings.LocalizedTerm; ErrorContext errCtx = null; AstNode astNode = yylval as AstNode; if (null != astNode && (null != astNode.ErrCtx) && (!String.IsNullOrEmpty(astNode.ErrCtx.ErrorContextInfo))) { errCtx = astNode.ErrCtx; errorPosition = Math.Min(errorPosition, errorPosition - term.Length); } if ((yylval is CqlLexer.TerminalToken) && CqlLexer.IsReservedKeyword(term) && !(astNode is Identifier)) { syntaxContextInfo = System.Data.Entity.Strings.LocalizedKeyword; term = term.ToUpperInvariant(); errorPosition = Math.Min(errorPosition, errorPosition - term.Length); } else if (null != errCtx) { syntaxContextInfo = EntityRes.GetString(errCtx.ErrorContextInfo); } syntaxContextInfo = String.Format(CultureInfo.CurrentCulture, "{0} '{1}'", syntaxContextInfo, term); } throw EntityUtil.EntitySqlError(_query, System.Data.Entity.Strings.GenericSyntaxError, errorPosition, syntaxContextInfo, false /* loadErrorContextInfoFromResource */); } throw EntityUtil.EntitySqlError(_query, s, _lexer.IPos); } // // Error tracking helpers // private void SetErrCtx( AstNode astExpr, CqlLexer.TerminalToken tokenValue, string info ) { SetErrCtx(astExpr, tokenValue.IPos, info); } private void SetErrCtx( AstNode astExpr, int inputPos, string info ) { astExpr.ErrCtx.InputPosition = inputPos; astExpr.ErrCtx.ErrorContextInfo = info; astExpr.ErrCtx.QueryText = _query; } private void ResetMethodCallCount() { _methodCallNodeCount = 0; } private void IncrementMethodCallCount() { unchecked { _methodCallNodeCount++; } } private uint MethodCallCount { get { return _methodCallNodeCount; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SqlProfileProvider.cs
- EntityObject.cs
- UserNamePasswordValidator.cs
- DataGridViewSelectedCellCollection.cs
- PerformanceCounterPermission.cs
- CodeTryCatchFinallyStatement.cs
- HiddenFieldPageStatePersister.cs
- SizeAnimationClockResource.cs
- StringExpressionSet.cs
- FusionWrap.cs
- XpsPackagingPolicy.cs
- HashStream.cs
- PersistenceParticipant.cs
- ListViewHitTestInfo.cs
- ObjectItemConventionAssemblyLoader.cs
- Clipboard.cs
- WrappingXamlSchemaContext.cs
- WindowPattern.cs
- Model3DCollection.cs
- ObjectView.cs
- StylusLogic.cs
- ClipboardData.cs
- SelectionWordBreaker.cs
- OleDbFactory.cs
- Matrix3DConverter.cs
- UserCancellationException.cs
- DataGridTextBoxColumn.cs
- MsmqIntegrationChannelFactory.cs
- Visitor.cs
- ChannelServices.cs
- CodeTypeReferenceExpression.cs
- InternalTypeHelper.cs
- MemberHolder.cs
- UIntPtr.cs
- StylusButton.cs
- ADMembershipUser.cs
- CollectionChangeEventArgs.cs
- MetadataProperty.cs
- SubclassTypeValidator.cs
- PathGeometry.cs
- DataSourceExpression.cs
- OdbcCommandBuilder.cs
- PersistNameAttribute.cs
- DBPropSet.cs
- ZipArchive.cs
- ViewManager.cs
- XPathBuilder.cs
- Tablet.cs
- TraceHandlerErrorFormatter.cs
- EventLogPermissionEntry.cs
- DataGridViewRowConverter.cs
- BaseCodePageEncoding.cs
- XsdDuration.cs
- ToolStripSystemRenderer.cs
- GeneralTransform3DTo2DTo3D.cs
- ProxyFragment.cs
- System.Data_BID.cs
- RowToParametersTransformer.cs
- FrameDimension.cs
- ServicePointManagerElement.cs
- WmfPlaceableFileHeader.cs
- InstanceData.cs
- CellConstant.cs
- SubMenuStyle.cs
- TextLine.cs
- TagNameToTypeMapper.cs
- UnknownWrapper.cs
- ScanQueryOperator.cs
- RectangleConverter.cs
- DependentList.cs
- BitmapEffectDrawingContextWalker.cs
- EUCJPEncoding.cs
- EnumMemberAttribute.cs
- GraphicsContainer.cs
- CharEntityEncoderFallback.cs
- SystemIcons.cs
- ReflectPropertyDescriptor.cs
- MethodExpression.cs
- COM2IVsPerPropertyBrowsingHandler.cs
- X509Utils.cs
- SqlCharStream.cs
- SQLCharsStorage.cs
- DataSpaceManager.cs
- Menu.cs
- GroupPartitionExpr.cs
- ApplicationManager.cs
- KeysConverter.cs
- CodeDirectoryCompiler.cs
- CertificateManager.cs
- NullEntityWrapper.cs
- OleCmdHelper.cs
- XsdBuilder.cs
- GenericAuthenticationEventArgs.cs
- SessionPageStatePersister.cs
- PreviewPrintController.cs
- ImageSourceConverter.cs
- ListenerElementsCollection.cs
- WindowsGraphics2.cs
- Schema.cs
- RelatedPropertyManager.cs