开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 0

NULL/lexy

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
main
分支 (2)
main
gh-pages
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
贡献代码
同步代码
对比差异 通过 Pull Request 同步
同步更新到分支
通过 Pull Request 同步
将会在向当前分支创建一个 Pull
Request,合入后将完成同步
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
BSL-1.0

lexy

lexy is a parser combinator library for C++17 and onwards. It allows you to write a parser by specifying it in a convenient C++ DSL, which gives you all the flexibility and control of a handwritten parser without all the manual work.

See tutorial to learn how to write your own grammars.

Features

Describe the parser, not some abstract grammar

Unlike parser generators that use some table driven magic for parsing, `lexy’s grammar is just syntax sugar for a hand-written recursive descent parser. The parsing algorithm does exactly what you’ve instructed it to do. No more ambiguities or weird shift/reduce errors!

A pure C++ DSL

No need to use an external grammar file, embed the DSL directly in your C++ using operator overloading and functions.

No implicit backtracking or lookahead

It will only backtrack when you say it should, and only lookahead when and how far you want it. Don’t worry about rules that have side-effects, they won’t be executed unnecessarily thanks to the user-specified lookahead conditions.

Bring your own data structures

The input is parsed into the data structures you’ve provided. It will not do heap allocations to store output unless you’ve instructed it to do so. You can even evaluate the input on the fly, without storing anything.

Good error reporting

On a parse error, it will invoke a user-defined callback with information about what went wrong and during which production. Custom error messages can be injected using the special dsl::error, dsl::require and dsl::prevent error. Write parse rules that detect common mistakes and issue appropriate diagnostics!

Unicode support

You can parse UTF-8, UTF-16, or UTF-32. lexy takes care of code point encoding and decoding as necessary, as well as endianness and byte-order marks. Want to match a string literal containing arbitrary Unicode code points or \u21D4 and store the result in a std::string? You can do so out of the box.

Fully constexpr parsing

You want to parse a string literal at compile-time? You can do so.

Minimal standard library dependencies

The core parsing library only depends on the required headers such as <type_traits> or <cstddef>. Some input classes required <cstdio>.

Header-only core library

By necessity, not by choice — it’s constexpr after all.

Planned features

The following features are in various stages of development and will be added before the 1.0.0 release.

Debug facility

Figure out why the grammar isn’t working the way you want it to.

Operator parsing

Parse operators with different precedences using Pratt parsing.

Keyword parsing

Reserve a set of keywords that won’t be matched as regular identifiers.

Error recovery

Log an error, recover, and continue parsing!

FAQ

Why should I use lexy over XYZ?

lexy is closest to other PEG parsers. However, they usually do more implicit backtracking, which can hurt performance and you need to be very careful with rules that have side-effects. This is not the case for lexy, where backtracking is controlled using branch conditions.

PEGTL

PEGTL is very similar and was a big inspiration. The biggest difference is that lexy uses an operator based DSL instead of inheriting from templated classes as PEGTL does; depending on your preference this can be an advantage or disadvantage.

Handwritten Parsers

Writing a handwritten parser is more manual work and error prone. lexy automates that away without having to sacrifice control. You can use it to quickly prototype a parser and then slowly replace more and more with a handwritten parser over time.

How bad are the compilation times?

They’re not as bad as you might expect (in debug mode, that is).

Compiling the example JSON parser with any of the lexy specific things removed, i.e. just the datastructure built using std::variant and std::map, takes about one second one my machine. The entire parser takes about two seconds if you disable force inline on the parse productions. With force inline, it takes about five seconds.

Compile time benchmarks and optimizations are planned. Keep in mind, that you can fully isolate lexy in a single translation unit that only needs to be touched when you change the parser.

How bad are the C++ error messages if you mess something up?

They’re certainly worse than the error message lexy gives you. The big problem here is that the first line gives you the error, followed by dozens of template instantiations, which end at your lexy::parse call. Besides providing an external tool to filter those error messages, there is nothing I can do about that.

How fast is it?

The library is currently not optimized and does not feature benchmarks. However, as it just parses what you specify, performance should be comparable to the corresponding hand-written parser. In preliminary benchmarks, I can validate JSON in ~400MB/s.

Why is it called lexy?

I previously had a tokenizer library called foonathan/lex. I’ve tried adding a parser to it, but found that the line between pure tokenization and parsing has become increasingly blurred. lexy is a re-imagination on of the parser I’ve added to foonathan/lex, and I’ve simply kept a similar name.

Building

The library uses CMake as its build system. Simply put it somewhere and use add_subdirectory() to make the following targets available

foonathan::lexy::core

This target is required. It is an INTERFACE target that sets the required include path and C++ standard flags.

foonathan::lexy::file

Link to this library if you want to use the (not header only) lexy::read_file() functionality.

foonathan::lexy

Umbrella target that links to all other targets.

Configuration is supported by providing a lexy_user_config.hpp somewhere in the include search path, or setting the LEXY_USER_CONFIG_HEADER CMake option to a header path. This header can then override many of the detections in lexy/_detail/config.hpp. Refer to that header for details.

The library is continuously tested on GCC 7 or higher, clang 6 or higher, as well as clang-cl. It requires C++17 support, but works best with C++20. Building the tests with MSVC fails, but simple examples might work. If you want to use it on Windows, it is recommended to use clang-cl instead.

Documentation

Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

C++ parser combinator library
暂无标签
README
BSL-1.0
使用 BSL-1.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/delete_user/lexy.git
git@gitee.com:delete_user/lexy.git
delete_user
lexy
lexy
main
点此查找更多帮助

搜索帮助

Git 命令在线学习 如何在 Gitee 导入 GitHub 仓库
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /