0

I wanted to know if anyone had ideas about how to create an editor / gui for Python's DSL.

So I have a grammar (based on textX project) and a class which interpret my DSL grammar. But I want to create an editor which has auto-completion and syntax highlight for the grammar of my own DSL.

Is it possible ?

I went into PySide, Qscintilla, but I'm a little lost, it doesn't seem to be appropriate. Furthermore DSL is pretty new as a concept, so there is pretty much 0 docs on the net, that's why I'm here (you never know !)

EDIT : ^Sorry apparently I'm triggering everyone about that sentence up. My bad, I'm pretty new to DSL, and I wanted to say there is almost nothing about develop a DSL in Python compared to Java (with Eclipse Modeling...)

Cya !

tricky
  • 1,413
  • 1
  • 15
  • 26
  • "DSL is pretty new as a concept" -- that simply isn't true. It is decades old. – John Coleman Mar 26 '17 at 23:12
  • Ok cool, not the sure the history of DSL was the topic of my question :⁾ – tricky Mar 26 '17 at 23:14
  • @tricky You posted something as a fact on a website that people use to learn new things. If it's incorrect, pointing that out is a very good case for a comment. – viraptor Mar 26 '17 at 23:19
  • Yes sorry, but saying only that and go away is pretty frustrating compared to your answer : You answer me and correct my mistakes, So thx to you @Viraptor – tricky Mar 26 '17 at 23:22
  • 1
    Probably a duplicate: http://stackoverflow.com/q/1547782/4996248 Note that Python is already interpreted. When you implement a DSL in Python you have an interpreter running inside an interpreter, which will have a clear performance hit. This is doubtless one of the main reasons it is much easier to find resources on implementing DSLs in Java -- in many ways it just makes more sense to use a compiled language for implementing a DSL. – John Coleman Mar 26 '17 at 23:27
  • Yes the project goal was to code it in Java, but from the rest of the class we wanted to be original so we tried Python. Kinda a mistake, but getting bad results is results ! \^^ Thanks for the help, I will go look into this code ! – tricky Mar 26 '17 at 23:55
  • I would imagine that Python would be an excellent language for *prototyping* a DSL. Once you get the language how you like it in Python, you could always implement it in another language if speed is an issue. For light-weight DSLs it probably isn't an issue. – John Coleman Mar 27 '17 at 01:15
  • I understand you're a little lost in QScintilla. Not much documentation was around, until recently. On this website you can find very user-friendly docs: https://qscintilla.com/ – K.Mulier May 08 '17 at 07:00

3 Answers3

2

Writing a usable editor is not a trivial task. That's basically a months-long project on its own if you want anything more than trivial editing functions. Embeddable editors like Scintilla can help of course, but that's on you to figure out their API.

I'd recommend a different direction: since you've got the whole grammar, generate the autocompletion and syntax highlighting as a plugin for an existing editor. Usually that functionality is abstracted pretty well. You can do that for apps like vim, vscode, or really any editor you want.

If you really do want to use an embedded editor, ask a specific question about that part. Notepad++ uses Scintilla for example and works with pretty much every language there is. It will very likely fit your use case.

In general: yes it's possible, because anything is possible. You may get better answers if you ask a question about your specific issue with including Qscintilla in your project.

PS. DSLs existed for decades. If you can't find anything relevant, look harder. SQL is a DSL for example. Everything written in LISP is pretty much its own DSL.

viraptor
  • 33,322
  • 10
  • 107
  • 191
0

I agree with @viraptor:

Writing a usable editor is not a trivial task. That's basically a months-long project on its own if you want anything more than trivial editing functions. Embeddable editors like Scintilla can help of course, but that's on you to figure out their API.

However, the API of QScintilla (Scintilla on PyQt5) is recently described on the following website:

https://qscintilla.com/

The documentation on that website is beginner-friendly. Making a basic editor in your own PyQt GUI is no longer months of work :-)

K.Mulier
  • 8,069
  • 15
  • 79
  • 141
0

It would be far less effort to instead build a Language Server for your language. Many existing editors (VSCode, Vim, Emacs, Eclipse) can be configured to communicate with a Language Server to provide syntax highlighting and other common IDE features for languages they otherwise don't understand. The editors would communicate via the common Language Server Protocol (LSP) with your server. There are even Language Server SDKs so you only have to fill in the parts unique to your language - categorising the various tokens etc.

For reference have a look at https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/ and the many existing implementations https://microsoft.github.io/language-server-protocol/implementors/servers/.

Ian
  • 55
  • 4
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/32136101) – Francisco Maria Calisto Jul 06 '22 at 13:25