Added bnf when adding a new concept + Started logging filtering

This commit is contained in:
2019-12-13 20:26:11 +01:00
parent 75c8793d53
commit c668cc46d2
29 changed files with 1487 additions and 190 deletions
+105 -1
View File
@@ -493,4 +493,108 @@ Even now that I am writing it, I just can't believe it. I must I have implemente
it wrong. But the profiling shows that the time is lost in the under layers of the
FS library.
It's a shame !
It's a shame !
2019-12-01
**********
Using BNF to define concept
"""""""""""""""""""""""""""""
I always knew that there will be several ways to define the body of a concept (same
goes for the 'pre', 'post' and 'where' parts). It can be defined as Python code,
or something that is related to concepts. It can even be a new language that I will
design. The important point, is that contrarily to traditional development languages,
Sheerka must remain extensible.
Same goes for the definition of the name.
The traditional form is:
::
def concept boo bar baz as ...
So the concept is defined by the sequence 'foo', then 'bar' then 'baz'. In this order.
Another way is
::
def concept a plus b where a,b as ...
In this form, a and b are supposed to be variables.
It will be matched against :code:`one plus two`.
The concept name is 'a plus b'. It is a quick way to declare a concept with variable,
but if someone define another concept
::
def concept number1 plus number2 where number1,number2 as ...
This will produce another concept (with the same key although). I guess that, at
some point, Sheerka will be able to detect that the concepts are the same, but
the name of the concept includes its variables. Which may be annoying in some
situations.
Plus, it's not possible to define rules precedences in this way. For example,
::
def concept a plus b as ...
def concept a times b as ...
How do you express that multiplications have a higher priority in for example
:code:`one plus two times three` ?
The only right answer, at least to me, is to implement something that is inspired
by the BNF definition of a grammar.
So the definition of the concept will look like
::
def concept term as factor (('+' | '-') term)?
def concept factor as number (('*' | '/') factor)?
def number where number in ['one', 'two', 'three'] as match(body, 'one', 1, 'two', 2, 'three', 3)
This form seems great, but in the definition of term and factor, there is no more
room for the real body. ie once the components are recognized, what do we do with them ?
So we can try
::
def concept factor (('+') factor)* as factor[0] + factor[i]
def concept number (('*') number)? as number[0] + number[i]
def number where number in ['one', 'two', 'three'] as match(body, 'one', 1, 'two', 2, 'three', 3)
The body is defined, but the name of concept is to complicated ex: factor (('+') factor)*
It's quite impossible to reference a concept that is defined in this way.
So my last proposal, with marry the two ideas, is to introduce the two keyword 'using' 'bnf'
.. _bnf : https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form
::
def concept term using bnf factor (('+' | '-') term)? as factor + (or -) term
def concept factor using bnf number (('*' | '/') factor)? as number * (or /) factor
def number where number in ['one', 'two', 'three'] as match(body, 'one', 1, 'two', 2, 'three', 3)
In my implementation:
* Terminals are between quotes
* Sequences are separated by whitespaces
* '|' (vertical bar) is used for alternatives
Like in regular expressions, you will also find
* '*' (star) is used to express zero or many
* '+' (plus) to express one or many
* '?' (question mark) to expression zero or one
For those who doesn't know that BNF stands for, please have a look at the bnf_
wikipedia page.
I guess that I will need a complete chapter to explain how you retrieve what was parsed