Title: replacing ly.slexer and ly.lex · Issue #139 · frescobaldi/python-ly · GitHub
Open Graph Title: replacing ly.slexer and ly.lex · Issue #139 · frescobaldi/python-ly
X Title: replacing ly.slexer and ly.lex · Issue #139 · frescobaldi/python-ly
Description: (related to #3, #55, and possibly others). Dear Friends, on the Salzburg conference I announced that I am writing a new lexer that wil replace ly.slexer and the ly.lex.xxx definition modules. The reason is that it is almost impossible to...
Open Graph Description: (related to #3, #55, and possibly others). Dear Friends, on the Salzburg conference I announced that I am writing a new lexer that wil replace ly.slexer and the ly.lex.xxx definition modules. The r...
X Description: (related to #3, #55, and possibly others). Dear Friends, on the Salzburg conference I announced that I am writing a new lexer that wil replace ly.slexer and the ly.lex.xxx definition modules. The r...
Opengraph URL: https://github.com/frescobaldi/python-ly/issues/139
X: @github
Domain: github.com
IPv4 address: 140.82.113.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"replacing ly.slexer and ly.lex","articleBody":"(related to #3, #55, and possibly others).\r\n\r\nDear Friends,\r\n\r\non the Salzburg conference I announced that I am writing a new lexer that wil replace ``ly.slexer`` and the ``ly.lex.xxx`` definition modules.\r\n\r\nThe reason is that it is almost impossible to inherit from, say, ``ly.lex.lilypond`` to implement small changes in lexing between versions of LilyPond, because when one changes a class, all references still point to the old one. Also, the tokens generated by the slexer module are instances of different classes, making it necessary to import the lexing definitions to be able to refer to classes and e.g. find instances. And finally, the linear structure of the tokens in the current ``ly`` module makes it tedious to find ranges in a text where e.g. a certain parser state is active (e.g. find the start of a lyrics expression, etc). ``ly.document.Source`` and ``Runner`` try to adress that a little but basically they are a PITA to work with (I can say that because I wrote them 7 years ago:-) )\r\n\r\nThe module that will replace ``ly.slexer`` and ``ly.lex`` will be a generic parsing package which I'm writing right now; I first called it LiveLex, but because that coincides with a German company name, I renamed it ``parce``.\r\n\r\n``parce`` addresses all of the aforementioned shortcomings:\r\n\r\n* A language definition is just a very simple class instead of a module global namespace. What ``slexer`` calls a ``Parser`` (or a context) is a lexicon (which is basically a class method yielding the parsing rules).\r\n It is very simple to inherit from a language definition and override just one lexicon to make a few adjustments. Because a lexicon is basically a class method, targets in other lexicons automatically refer to the inherited version of the lexicon. So supporting multiple versions of LilyPond becomes possible.\r\n* What ``slexer`` calls a Token instance is a token, but the \"type\" is stored in an ``action`` attribute. So there are no classes anymore for every possible token, and manipulating tokens does not require one to import a language module to get all the definitions. And all the ``isinstance(token, ly.lex.lilypond.BlaBla)`` calls can go!\r\n* Instead of a linear stream, the ``parce`` module creates a tree structure of the tokens, nested in contexts, and can update the structure when the user types in the document. So starting from a token, it is as simple as accessing its ``parent`` attribute to get the encompassing context. You can easily navigate to sibling or child tokens and there is a very powerful ``query`` method on every node, to search for anything in the tree structure.\r\n\r\nThis ``parce`` package already works very well, and I created good quality documentation and a web site for it, see https://parce.info/ . To get an idea of what a language definition looks like, compare [ly.lex.lilypond](https://github.com/frescobaldi/python-ly/blob/master/ly/lex/lilypond.py) (1659 lines) with [parce.lang.lilypond](https://github.com/wbsoft/parce/blob/master/parce/lang/lilypond.py) (currently 534 lines).\r\n\r\nParsing and updating can be done in a background thread. There is already a small package bringing ``parce`` to Qt's QTextDocument, which can be used later to enable highlighting of text in Frescobaldi using the new lexer.\r\n\r\nRight now, in ``ly`` and Frescobaldi, the music manipulation functionality uses either plain ``slexer`` tokens (such as the rhythm functions) or the ``ly.music`` tree structure. But also code such as the MusicXml output uses both the Music tree and also the original tokens.\r\n\r\nBoth can be ported to the new parser/lexer. But because that causes a rewrite of almost the whole of the ``ly`` package, I propose to create a new package from scratch, providing the same (and more) functionality, and that can be developed until the moment that it is possible to port Frescobaldi to it.\r\n\r\nIt is still desirable to have a tree structure like ``ly.music``, but now the ``parce`` tree structure can probably form a solid base of such a structure.\r\n\r\n(How/whether ``parce`` can support a custom data structure attached to a ``parce`` tree is yet to be determined. But we could also opt for an independent tree, which can replace ``ly.music`` and, while at it, also has a simpler structure (with fewer classes as current ``ly.music``). Because ``parce`` can exactly report which part of the tree got updated, it is easy to invalidate just the modified part of a music tree instead of rebuilding it completely after every change, as is the case now.)\r\n\r\nSo, we could think of a name for the new ly module. We could use ``ly2`` but I don't like the number in the name. I am currently thinking of ``quickly``. :-)","author":{"url":"https://github.com/wbsoft","@type":"Person","name":"wbsoft"},"datePublished":"2020-03-27T13:25:35Z","url":"https://github.com/frescobaldi/python-ly/issues/139"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d9de4214-cb72-5557-f12f-2d5aad3afadb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B0AA:101EA3:C62619:1063AC8:6B09B6F4 |
| html-safe-nonce | 4e53e32820f7a3e06c51b1f5cbdc4e9f0c177b16fff7918b6d7761c097400834 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMEFBOjEwMUVBMzpDNjI2MTk6MTA2M0FDODo2QjA5QjZGNCIsInZpc2l0b3JfaWQiOiI4NzI2MTk4NTU1ODg0NzYyODY4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 48d4ea70ee0bd7df379d65cd9150ff3f46682edb7bef9e580384ec1b2424d48d |
| hovercard-subject-tag | issue:589131943 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/frescobaldi/python-ly/139/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dee34166da317e97637dc6b9bce2a0f60b2ff12e99332239eb7c5934a6742b99/frescobaldi/python-ly/issues/139 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dee34166da317e97637dc6b9bce2a0f60b2ff12e99332239eb7c5934a6742b99/frescobaldi/python-ly/issues/139 |
| og:image:alt | (related to #3, #55, and possibly others). Dear Friends, on the Salzburg conference I announced that I am writing a new lexer that wil replace ly.slexer and the ly.lex.xxx definition modules. The r... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | wbsoft |
| hostname | github.com |
| expected-hostname | github.com |
| None | 29e6866c4c5b6697a062df08d37fa80bbfb75810ca4280c0d277f04956012d39 |
| turbo-cache-control | no-preview |
| go-import | github.com/frescobaldi/python-ly git https://github.com/frescobaldi/python-ly.git |
| octolytics-dimension-user_id | 19853952 |
| octolytics-dimension-user_login | frescobaldi |
| octolytics-dimension-repository_id | 29728425 |
| octolytics-dimension-repository_nwo | frescobaldi/python-ly |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 29728425 |
| octolytics-dimension-repository_network_root_nwo | frescobaldi/python-ly |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | e72aac8801621433bb0313888fbbe243f5998abc |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width