Comments (3)
You're just needing a lower upper limit, right? If so, I'd be happy with lexy::bounded<T, Max>
.
Your proposed bounded<T, Min, Max>
has a couple of issues. The first is a bug: add_digit_checked()
is only called for the last digit: if the number has fewer than max digits, it won't be called and as such, the Min
check never happens. The fix would require an additional validate
function that is called by the parser after the entire number has been constructed. The second is philosophical: the only reason dsl::integer
does overflow checking is that the digits won't fit into the integer otherwise - there is nothing it can do. In principle, it would be cleaner if lexy doesn't need to produce any overflow errors, those aren't really syntax errors, but more semantic errors that should be handled at a later stage.
As such,I feel that checking whether e.g. a register is out of bounds isn't something that lexy should do, it's something that should be handled later, just like any other semantic errors. I'm already making an exception for overflow in general and lexy::code_point in particular, so checking for a maximal value is probably okay, but I don't like the min check. Does it make sense to you what I'm saying? :D
from lexy.
Your proposed
bounded<T, Min, Max>
has a couple of issues. The first is a bug:add_digit_checked()
is only called for the last digit: if the number has fewer than max digits, it won't be called and as such, theMin
check never happens.
You're quite right - I hadn't fully thought that part of it through, and as I hadn't done any test cases for the minimum bound checking, I hadn't discovered it that way yet!
As such,I feel that checking whether e.g. a register is out of bounds isn't something that lexy should do, it's something that should be handled later, just like any other semantic errors. I'm already making an exception for overflow in general and lexy::code_point in particular, so checking for a maximal value is probably okay, but I don't like the min check. Does it make sense to you what I'm saying? :D
Yeah, that makes sense - I think my preference for doing some semantic checking within the parser (and potentially getting better locality of where the error occurred within the input text) probably comes from ANTLR's semantic predicates, as ANTLR was the first parser generator I used. And, to be honest, most of the range checking I want to do in a parser tends to be of unsigned integers, so the Min
bound is less useful.
I'll put together a PR with a bounded<T, Max>
and take it from there.
from lexy.
I'll put together a PR with a bounded<T, Max> and take it from there.
Thanks, please also try and use it to implement the specialization for lexy::code_point
.
from lexy.
Related Issues (20)
- Including lexy in CMake project forces use of C++20 HOT 2
- Implement Top level Language Parser
- example-or-fix-request: delimited-dsl where closing delimiter is also an escape leader HOT 1
- Pruduction is not a branch rule HOT 1
- Unicode-aware identifier in calculator example does not work HOT 3
- Example for Callback lexy::new_ in documentation appears to be incorrect. HOT 1
- Support case folding in `lexy::as_string` callback
- Turn `dsl::terminator(branch)` into a branch
- Documention is unreadable if TOC takes too much space HOT 1
- Any plan to support grammar-file writing dsl rule? HOT 1
- benchmar compile errors HOT 1
- Infinite compilation caused by dsl::times with separator and automatic whitespace HOT 1
- dsl for real numbers HOT 9
- [Question] dsl::integer and negative numbers HOT 1
- lexy_ext::report_error on Windows 10 (MSVC) HOT 1
- `utf8_char_encoding::eof()` produces warning C4310 on MSVC HOT 1
- Runtime error (assert failed) on print tree HOT 1
- Custom allocator causes fold_inplace cannot be compiled on MSVC HOT 1
- missing lexyConfig.cmake.in in release file HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lexy.