Comments (6)
The lack of context does make some things a bit more difficult, that’s for sure. In the specific example of the SQL parser I’d probably just not make SELECT a keyword.
But generally, I’m not sure. I have solved this in one parser by pushing the statefulness down into the lexer. This was a parser for a nested string interpolation language eg. ”hello ${who “nested ${other}”}”
. A similar approach can be used for indentation aware languages like Python. I don’t think this approach would be very applicable to the SQL example though as too much logic would have to be pushed down into the lexer.
I’m not against non-CFG but I don’t know if there’s an elegant way to express the grammar like EBNF?
from participle.
just not make SELECT a keyword.
Well, it's still nice to have separate keyword type, in particular case - for case-insensitive keyword matching (btw, I've seen that pointlander/peg is using 'token'
for case-sensitive matching and "token"
for case-insensitive - a bit unobvious but quite elegant)
Regarding how this type ambiguity can be expressed in grammar, for me it seems like no changes here needed - if parser failed to parse current token with given type, it could ask lexer for other options. Or else lexer can have Token.Type
as []rune
, with standard parser return 1-element slice with option to create custom lexer with multiple choices.
from participle.
Regarding how this type ambiguity can be expressed in grammar, for me it seems like no changes here needed - if parser failed to parse current token with given type, it could ask lexer for other options. Or else lexer can have Token.Type as []rune, with standard parser return 1-element slice with option to create custom lexer with multiple choices.
I don't think that's a general solution to contextual-grammars, it just solves one specific example. For example that would not work for the example of the nested interpolation grammar I gave.
from participle.
btw, I've seen that pointlander/peg is using 'token' for case-sensitive matching and "token" for case-insensitive - a bit unobvious but quite elegant
I think this is a good idea; the current approach of case case normalisation isn't really a good one. I think I'll add a parser option to do this, eg. participle.CaseInsensitive("Keyword")
.
from participle.
I've been thinking about this for a while - yeah, looks like subj has too narrow scope; also have no other ideas, unfortunately, so I'd rather close issue.
from participle.
I've added the CaseInsensitive()
option.
from participle.
Related Issues (20)
- Declaring field parse order HOT 4
- Simple example fails with `unexpected token "<EOF>"` HOT 3
- Missing wildcard HOT 2
- Unquote function panics when an escape character exists in string. HOT 4
- Parser being greedy HOT 3
- Dependency Dashboard
- Action Required: Fix Renovate Configuration
- Panic when stateful lexer's non-Root rule has optional group but captures nothing HOT 3
- Need advice: Wrong branch is picked on non-trivial match HOT 1
- too many iterations panic HOT 1
- Adding a custom lexer rule without overriding current rules.
- Error recovery ideas HOT 4
- Request for help (aka so near and yet so far).
- Railroad diagram command HOT 6
- Feature Request: Custom Rules HOT 9
- Question: Are participle.Parser instances thread-safe? HOT 1
- Handling Booleans bug HOT 3
- PAnic vs return nil in validate function HOT 2
- Issue with a nested structure HOT 1
- JSON parser support
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 participle.