Comments (3)
Wow! Thanks! And yes, log time is perfectly fine for the kind of thing I'm doing. I am happy storing spans for the moment, but I look forward to using your patch. :)
from grmtools.
Hello Arjun :)
If so, I suppose the smart approach is to store a Span, and only invoke line_col when I need to print a location.
It depends a bit on your use case, but commonly "yes". If you only ever want to print line/column for a subset of spans and you rarely do so more than once for each Span
, then calling line_col
lazily is likely to pay off. Indeed, that's why Span
exists: it's a more compact representation than the four usize
s that line_col
returns, on the expectation that most Span
s are thrown away without being converted to line/columns. [At some point, I might even pack Span
down into a single machine word, but I haven't had the need to descend to that level of micro-optimisation yet.]
There are probably some use cases where the cost of repeated line_col
calls isn't worth it, but I expect they're fairly rare. Also, at least in theory, line_col
should have a worst case of O(n)
where n
is the number of lines in the file, although the current implementation is actually O(2n)
. If that factor of 2 becomes a bottleneck, reducing it to genuinely O(n)
won't be difficult.
from grmtools.
#229 partially addresses this (and it turns out I got the complexity wrong -- it was worse than I first realised!). I think, in general, line_col
is now adequately fast. It could be further optimised, ever so slightly, but I think we're now firmly in the land of diminishing returns for this function. Hopefully it's fast enough to convince people that it's OK to use :)
from grmtools.
Related Issues (20)
- Permit stack operations on start conditions HOT 28
- The way we serialise output makes cross compiling across architectures hard HOT 1
- Adding a %grammar-kind declaration? HOT 2
- how to use “ and space with .l file HOT 4
- how to use lrlex with rust code HOT 1
- write .l with var for lrlex HOT 1
- Generated code incompatible with `-D rust-2018-idioms` HOT 7
- Broken links for YACC and LEX Manual in grmtools-book HOT 5
- %ignore like in flex HOT 8
- Is it possible to perform side effects while parsing? HOT 3
- Would be nice to have an online playground HOT 8
- Order of execution of grammar statements? HOT 7
- Bug in grmtools documentation - traits not displaying required method names HOT 12
- Is there a way to avoid global variables for compile time data structures? HOT 5
- Request for example of handling string literals in lexer HOT 2
- error when using fake UMINUS token in %prec directive HOT 9
- GDB Support? HOT 5
- Add support for comments in lrlex files HOT 3
- Explain why Copy is required for a type specified %parse-param HOT 7
- Nondeterministic generation of Rust code 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 grmtools.