Comments (5)
Yes, but also extending grammars, or importing rules from other grammars might be possible. It is quite similar to packages and symbols, but I'd tend not to try to map the former to the latter, because they operate on different semantic levels.
from cl-bnf.
@Harleqin Thanks for bring this up. I'm still thinking on a better (proper) way to write the rules. I'll do some work on the weekend to improve this. Any suggestions?
from cl-bnf.
The obvious solution that changes as little as possible is to actually name the macro cl-bnf:|:=|
. You'd need to write (defmacro |:=| …)
or (defmacro \:= …)
, and every invocation would need to be changed as well.
Going a bit further would be to rename it to defrule
or define-rule
. This would also make it clearer that it is a toplevel definition (I had to look twice at the documentation to understand this).
Thinking a bit more about it, as a user I'd maybe not want the rules to be global, but always part of a grammar, so that I can define several grammars in one program without name clashes. You can then maybe keep the :=
, because it would be interpreted by a defgrammar
macro, instead of being a macro itself.
(defgrammar json-number ()
(:= decimal-number (:many (:one #'numeric-char-p)))
(:= real-number (:or (:and #'decimal-number
(:char #\.)
#'decimal-number)
(:and #'decimal-number
(:char #\.))))
(:= signed-part (:or (:char #\+) (:char #\-)))
(:= exp-chars (:or (:char #\e)
(:char #\E)))
(:= exp-part (:or (:and #'exp-chars
#'signed-part
#'decimal-number)
(:and #'exp-chars
#'decimal-number)))
(:= numeric (:or #'real-number
#'decimal-number))
(:= number-literal (:or (:and #'numeric
#'exp-part)
#'numeric)
:call (lambda (matches)
(cons :number (stringify matches))))
(parse json-number number-literal "1e3")
from cl-bnf.
Yeah, that's pretty much what I had in mind. See #5.
Perhaps, we can keep both...the defgrammar
and defrule
.
(defrule real-number 'the rule' :apply ...))
(defrule decimal-number 'the rule' :apply ...))
(defgrammar json-parser ()
(number := (:or #'real-number #'decimal-number) :apply ...)
(strings := 'rule' :apply ...)
(...)
(parse number strings objects array))
Maybe this way, we can allow sharing rules.
from cl-bnf.
Both macros are available now. Thanks for all the help and ideas.
from cl-bnf.
Related Issues (13)
- First implementation.
- Move the rule tranformation to the define-rule macro. HOT 1
- What is sequence:position? HOT 3
- define-grammar defines the stuff only at compile file HOT 5
- Use stream interface. HOT 1
- Borrow ideas from Haskell's Alex...
- Save and return the stream position in case of non-match HOT 1
- Documentation.
- Set up continuous integration.
- Find a way to improve the rule declaration. HOT 1
- More operators and common patterns.
- Update documentation and start releasing versions.
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 cl-bnf.