一个简单的库,用于标记具有附加功能的文本。
SBLex的Python项目详细描述
一个简单的库,用于标记具有附加功能的文本。
概述
sblex是一个lexer,它只需要几行代码就可以标记文本,它还包括其他额外的函数。
功能
- 依赖令牌
- 自定义错误
- 找到标记时的自定义函数
- 自定义捕获组
- 支持多个正则表达式
计划功能
- 忽略图案
安装
pypi
您可以通过pip轻松安装sblex,如下所示:
pip install SBLex
如果您遇到环境错误,也可以尝试使用–user选项:
pip install SBLex --user
用法
开始使用SBLeX与导入SBLeX一样简单,并声明LexER,这里有一个World World World World的工作示例。:
fromSBLeximportlexlexer=lex.lex()lexer.add("Hello World",r'Hello World\!')lexer.evaluate("Hello World!")""" Returns: >>> [token(type: 'Hello World', value: 'Hello World!', line: 0)] """
下面是另一个使用自定义捕获组的示例。
fromSBLeximportlexlexer=lex.lex()# Try to lex: The weather today is {weather}lexer.add("The weather today is",r'The weather today is ([a-zA-Z]+)',capturing_group=1)lexer.evaluate("The weather today is rainy")""" Returns: >>> [token(type: 'The weather today is', value: 'rainy', line: 0)] """
兼容性
sblex与python2&;python3兼容。
许可证
sblex在MIT License下面。