On Mon, Aug 17, 2020 at 5:02 PM Marco Sulla <marco.sulla.pyt...@gmail.com>
wrote:

> On Mon, 17 Aug 2020 at 11:17, Steven D'Aprano <st...@pearwood.info> wrote:
> > Did you have a specific question to be answered or are you just hoping
> > to get people interested in the proposal?
>
> It seems I have to repost the proposal I already wrote...


> My proposal is to add a way for third party modules to add custom
> keywords.


You can already do something like this, using either an import hook or a
custom encoding.
Perhaps I should repost a link that I already included in an earlier, but
rather terse, reply  on this thread, about the specific "constant" example.

See: https://aroberge.github.io/ideas/docs/html/

You will find various examples of adding custom keywords.

(more below)



> Example:
>
> from mykeywords import @const
> @const a = 1
>
> Notice that I choose "@" but I hope another non c-alphanumeric
> character will be chosen.
>
> On Mon, 17 Aug 2020 at 12:46, Chris Angelico <ros...@gmail.com> wrote:
> > A proposal that requires syntactic changes [...]
>
> No syntactic changes are needed. Custom keywords *must* be prefixed
> with a non-alphanumeric character (@ for example).
>

Syntactic changes would be needed.  The way that your example would be
normally processed by Python
is as follows:
First, the entire content of the file would be read, and broken up into
tokens (individual words and symbols).
Next, these tokens would be interpreted according to Python's grammar: your
notation would raise a SyntaxError.
This would stop the entire process.

To actually do the import "from mykeywords import ...", one needs to go
beyond the parsing stage.
This is where a custom encoding or an import hook can help, by transforming
the source into valid Python code
before it is parsed.  More information available at the link given above.

André Roberge



>
>
> ACK
> _______________________________________________
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/python-ideas@python.org/message/NUAHVSON3HTHNEZ7GBCI3R6XE4RSSSZP/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/XPMUV3X7QNJVWNUOWUR5FOFKVCLQTVPI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to