Comments (7)
Hi Ed,
I have so far only used gogll for domain specific languages in which I write the program in a markdown file in the spirit of Don Knuth's web and weave. I have intended to add ignored tokens to the lexer specification (in the style of github.com/goccmack/gocc). That would allow you to specify tokens to be suppressed by the lexer.
Your suggestion of providing a custom function in lexer.New() is elegant and very a simple change to gogll. But perhaps it is inconvenient to deal with lexical issues outside the grammar specification.
I find specifying every place in the grammar where comments are allowed obfuscates the grammar, unless you need the comments for code generation.
What are your thoughts on the alternatives? If you need this urgently I can quickly add the custom function to lexer.New() and return to suppressed tokens later.
from gogll.
@EdSchouten
gogll v3.2.0 supports token suppression by the generated lexer. See gogll.md for details.
This can be used to implement code comments.
from gogll.
from gogll.
I was merely using gogll as an experiment to keep myself busy on a Sunday. There’s no need to implement anything quickly just for me. I’m happy with the solution that you think is best!
from gogll.
OK. Having thought about it I still prefer suppressed tokens because it keeps the complete lexical specification in one place. I will implement it as soon as I have the time.
from gogll.
Nice! I've just given it a try and it seems to work. One limitation that I've noticed is that the provided example:
!block_comment : '/''*' {not "*"} '*''/' ;
doesn't allow parsing these kinds of comments that you often see in C-like programming languages:
/*
* This is a block comment.
*/
I guess that a non-greedy matching operator (a la regex .*?
) is needed to support constructs like those.
from gogll.
from gogll.
Related Issues (15)
- Fix plain BNF input
- Examples fail to parse HOT 3
- how to get comments ? HOT 1
- Add a v3.2.2 tag HOT 1
- Please support the go module correctly. HOT 1
- Generated files are set as executable HOT 2
- Is there a char_set? HOT 1
- Support For Named Unicode Character Classes HOT 3
- Cannot build grammar containing backtick as token HOT 1
- Incorrect installation instructions
- Error supporting \n as part of the grammar HOT 4
- backslash used as operator (integer division) HOT 2
- generate a parser for ASN1 grammar HOT 2
- Bug with using "\"" HOT 4
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 gogll.