使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
google.appengine.api.search.expression_parser 的源代码
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Wrapper for ExpressionParser."""
from google.appengine._internal import antlr3
from google.appengine.api.search import ExpressionLexer
from google.appengine.api.search import ExpressionParser
from google.appengine.api.search import unicode_util
[docs]class ExpressionException(Exception):
"""An error occurred while parsing the expression input string."""
[docs]class ExpressionLexerWithErrors(ExpressionLexer.ExpressionLexer):
"""An overridden Lexer that raises exceptions."""
[docs] def emitErrorMessage(self, msg):
"""Raise an exception if the input fails to parse correctly.
Overriding the default, which normally just prints a message to
stderr.
Arguments:
msg: the error message
Raises:
ExpressionException: always.
"""
raise ExpressionException(msg)
[docs]class ExpressionParserWithErrors(ExpressionParser.ExpressionParser):
"""An overridden Parser that raises exceptions."""
[docs] def emitErrorMessage(self, msg):
"""Raise an exception if the input fails to parse correctly.
Overriding the default, which normally just prints a message to
stderr.
Arguments:
msg: the error message
Raises:
ExpressionException: always.
"""
raise ExpressionException(msg)
[docs]def CreateParser(expression):
"""Creates a Expression Parser."""
input_string = antlr3.ANTLRStringStream(unicode_util.LimitUnicode(expression))
lexer = ExpressionLexerWithErrors(input_string)
tokens = antlr3.CommonTokenStream(lexer)
parser = ExpressionParserWithErrors(tokens)
return parser
[docs]def Parse(expression):
"""Parses an expression and returns the ANTLR tree."""
parser = CreateParser(expression)
try:
return parser.expression()
except Exception, e:
raise ExpressionException(e.message)
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2022-10-21。
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"翻译问题"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"其他"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"易于理解"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"解决了我的问题"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"其他"
}]