支持全扫描、基于状态的词法分析和前瞻的词法分析器的python实现

pylexer的Python项目详细描述


Pylexer

一个支持全扫描、基于状态的词法和前瞻性

的词法分析器的Python实现

Build StatusPyPI - Python VersionPyPI versionPyPI license

Warning This is not a GENERATOR like classical lexer is. It does not produce any python code. It's a simple plain scanner of the given input string and tokenizer into given set of tokens by matching regular expressions. Thus, at runtime you can change the token definition and use one same code for any token set

安装

使用pip安装到项目中:

pip install pylexer

用法

示例用法:

frompylexerimportPyLexerconfig={'\\s':'','\\d+':'number','\\+':'plus','-':'minus','\\*':'mul','/':'div',}#Static Scan method that returns list of tokenstokens=PyLexer.scan(config,'2 + 3')map(lambdax:x.get_name(),tokens)#PyLexer Config is a dict, so you can also use it likelexer=PyLexer()lexer.set_input('2 + 3')lexer.move_next()whilelexer.get_look_ahead():print(lexer.get_look_ahead().get_name())lexer.move_next()

令牌定义

令牌是用保存令牌名称和正则表达式的TokenDefinition类定义的。令牌名称可以为空,在这种情况下,lexer将忽略/跳过此类令牌

Lexer配置

lexer配置包含所有令牌定义的列表。使用lexerdictconfig,可以很容易地从一个数组中创建它,其中键是正则表达式,值是令牌的名称

全扫描

pylexer的静态扫描方法可用于扫描给定的输入字符串并返回令牌列表,pylexer还可用于通过具有单个前瞻性的扫描令牌

许可证

麻省理工学院执照。有关详细信息,请参见LICENSE.md

贡献者

pylexer的灵感来自于php的lexer(https://github.com/tmilos/lexer),并大量使用了docternapi中的代码,所有这些都归功于milos tomic

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
image Java:设置iconimage而不使用完整路径   javaant和Eclipse构建   Java标签检查图像   java为什么我的glassfish服务器会重定向到另一台服务器?   java MySQL简单查询错误   java你能告诉我如何在图像视图中显示图像吗   Java驱动程序4.0:是否支持对象映射?   java在通过SourceDataLine播放音频时发出一致的爆裂声   java组织。金特罗普。dcom。常见的JIException:未找到错误代码0xC0000070的消息   运行Dijkstra算法实现时的java IndexOutOfBoundsException   java swing gui闪烁白色错误   java单元测试:我应该使用null还是可选的。返回()中的空()?   javajaxb创建空对象   如何拒绝Java构造函数中的非限定参数?   单元测试的java分类