Jump to content

Photo

ZScript Code Editor


  • Please log in to reply
123 replies to this topic

#1 bobby_light

bobby_light

    Experienced Forumer

  • Members

Posted 14 July 2012 - 10:11 PM

Hi folks,

I'm a long-time lurker. I think PureZC is a pretty good community and ZC is a really cool project, but I'm just not creative enough to actually create a game with it. When it comes to development, I'm really more of a tooly guy, but I thought I'd try to contribute something to the community anyway. Hopefully this won't be considered spam!

I've written an editor component for ZScript. You can try it out or download it from here: http://bobbylight.gi...anguageSupport/

 

Current features include:

  • Syntax highlighting
  • Code folding
  • Code completion (triggered via Ctrl+Space & typing "->", local variables, std.zh & string.zh)
  • Parameter completion for functions

I'm not sure if most scripts written for ZQuest are long or complex enough for such a component, but I thought I'd put it out there to gauge interest. Perhaps such a tool can help encourage script development? It could even be used as the basis for a ZScript IDE.

I have ideas on how this can be taken further, but again, I wanted to gauge whether there's any interest in it in the first place. Whether there is or not, I'll keep the source available as modified BSD so anyone can tinker with it.

 

Source is on GitHub here.

 

Thanks!


Edited by bobby_light, 19 December 2015 - 01:12 AM.


#2 Russ

Russ

    Caelan, the Encouraging

  • Administrators
  • Location:Washington

Posted 14 July 2012 - 10:46 PM

This is actually pretty nifty. I've mainly be using Notepad for scripts (The horror!), but with this... I might just switch to this. Consider me interested.

Edit: Doh, I almost forgot, welcome to PureZC!

#3 LinktheMaster

LinktheMaster

    Hey Listen, Kid

  • Members
  • Real Name:Matt
  • Location:United States

Posted 14 July 2012 - 11:03 PM

QUOTE(Russ @ Jul 14 2012, 10:46 PM) View Post

This is actually pretty nifty. I've mainly be using Notepad for scripts (The horror!), but with this... I might just switch to this. Consider me interested.

Edit: Doh, I almost forgot, welcome to PureZC!
This comment makes me sad. icon_frown.gif Don't ever use notepad. Notepad++ and Programmer's Notepad are two great programs that you can get to highlight ZScript syntax, and they come with features like line numbers, auto-indent, project support, and things like that. If people want, I can try to whip up a tutorial to setup those programs.

Anyway, I actually made a somewhat basic ZScript editor myself a couple of years ago. It was kind of a pain, so I definitely commend you for giving it a shot. This definitely looks like it'll be interesting. I'll be honest that it'll take a lot to push me away from using Programmer's Notepad or Notepad++ (you'll have to add some sort of project support for me to consider switching), but I'll definitely try to keep an eye out for this. icon_smile.gif So definitely keep this up. icon_thumbsup.gif

Oh, and this topic probably is more suitable for the scripting forums. I'll move it over for you.

#4 Russ

Russ

    Caelan, the Encouraging

  • Administrators
  • Location:Washington

Posted 14 July 2012 - 11:06 PM

QUOTE(LinktheMaster @ Jul 14 2012, 09:03 PM) View Post

Oh, and this topic probably is more suitable for the scripting forums. I'll move it over for you.

icon_doh.gif I feel stupid for not catching that...

QUOTE
Notepad++ and Programmer's Notepad are two great programs that you can get to highlight ZScript syntax, and they come with features like line numbers, auto-indent, project support, and things like that. If people want, I can try to whip up a tutorial to setup those programs.

hrm... I probably don't need a tutorial, but maybe just an explanation of what it does that Bobby's program doesn't, and how it's helpful for me.

#5 bobby_light

bobby_light

    Experienced Forumer

  • Members

Posted 15 July 2012 - 09:14 AM

Thanks for the feedback guys!

What I made available is just a demo of the editor component. It could easily be shoved into an actual application to provide things like project support.

What I believe this project offers over vanilla Notepad++ is that it can provide an experience more akin to editing Java in Eclipse or C# in Visual Studio. It's semantics-aware; code completion choices don't come from a static list, but rather are determined by what's appropriate for the current caret position.
  • Global objects are understood, i.e. typing "Link->" presents a completion popup with all fields and methods relevant for the Link object. If you type a member manually, you'll know if you mistype something as it'll be highlighted differently.
  • In the completion choices list, the documentation for each member (from std.txt & string.txt currently, more could be added) is shown in an adjacent popup so you don't have to look up documentation while scripting. It's just integrated into the editor.
  • When you complete a function name, a list of local variables is suggested for argument values based on their appropriate type (this isn't 100% correct yet for arrays, but I believe is working for primitives).

The code completion information is loaded by parsing the documentation files included with ZScript, so as long as those are kept up-to-date, the editor can be up to date as well.

Another useful feature I could easily add, if there were a way to compile scripts from the command line, is squiggle-underlining of errors and warnings. The functionality is already there, I would just need to know how to call the compiler from the command line. Does anyone know if that's possible? I've been looking at the Wiki but it doesn't mention a means of compiling scripts outside of the UI.

Alternatively, if there were a grammar available for ZScript, I could simply write my own parser, which should be more efficient than calling an external process to compile just for error identification. Is a grammar available?

#6 MoscowModder

MoscowModder

    Sometimes lurking. Rarely posting.

  • Members
  • Location:Wisconsin

Posted 15 July 2012 - 11:01 AM

That sounds pretty awesome, but I'm not sure I could leave Notepad++ for it. Do you think you could possibly convert that into a plugin for NP++?

#7 aaa2

aaa2

    Wizard

  • Banned

Posted 18 July 2012 - 03:47 PM

That seems like it could definately save a lot of typing. Very cool!

Just one question how much effort did it take to program that? I wouldn't know how to implement something like starting with plain C++ at least not without putting a lot of effort(even in visual studio only using libraries coming with it it would be a lot of effort needed i think).

#8 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 18 July 2012 - 05:42 PM

Cool. I already use MSVC for editing anything code related but I'm sure this will be useful to many other people (not just for zscript or java also).

QUOTE

Another useful feature I could easily add, if there were a way to compile scripts from the command line, is squiggle-underlining of errors and warnings. The functionality is already there, I would just need to know how to call the compiler from the command line. Does anyone know if that's possible? I've been looking at the Wiki but it doesn't mention a means of compiling scripts outside of the UI.

Alternatively, if there were a grammar available for ZScript, I could simply write my own parser, which should be more efficient than calling an external process to compile just for error identification. Is a grammar available?


Unfortunately the compiler as it is written right now is completely stubborn about both needing raw files with no nested import directories, and being able to use memory buffers or streams. It is also not possible to invoke separately via argument.

As for the the grammer -- that one's easy: It's just C with the two distinctions:
-import "filename" is the same as an #include directive.
-"->" is the only dereference operator, so built in types would just be static global pointer.



QUOTE(MoscowModder @ Jul 15 2012, 09:01 AM) View Post

That sounds pretty awesome, but I'm not sure I could leave Notepad++ for it. Do you think you could possibly convert that into a plugin for NP++?

QUOTE(aaa2 @ Jul 18 2012, 01:47 PM) View Post

Just one question how much effort did it take to program that? I wouldn't know how to implement something like starting with plain C++ at least not without putting a lot of effort(even in visual studio only using libraries coming with it it would be a lot of effort needed i think).

It looks like it's written in java, so no, lots, and dont try it without some proper low-level text and windowing gui libraries. icon_razz.gif

#9 bobby_light

bobby_light

    Experienced Forumer

  • Members

Posted 18 July 2012 - 09:29 PM

Gleeok's right, there's no chance of a Notepad++ plugin since it's written in Java. An Eclipse plugin would be very possible, however. As far as a level of effort, it was quite a lot of work. I've been working off-and-on on the editor for quite awhile. It's essentially a Java version of Scintilla (the code editor component used by Notepad++) - syntax highlighting for ~ 30 languages, code folding for languages I understand icon_smile.gif, and an API for adding runtime parsers & code completion. It's just easy to wrap it into a Windows binary, and an OS X version is just the jar file in a standard .app bundle.

Since there's no grammar, I just started rolling my own parser. The language, I believe, is actually considerably simpler to parse than something like C since there's no structs or other user-defined typish things. In the interest of getting something working I'll keep error recovery to a minimum and add more of it over time. I would have liked to have guaranteed parsing identical to ZQuest's, but if the language is straightforward it might not be too difficult to re-implement.

There is already a code editor built on top of RSyntaxTextArea (shameless plug) that this ZQuest highlighting could be made into a plugin for. Then you'd have the vast majority of functionality found in an application like N++ (load/save local & remote files, highlighting for multiple languages, fully configurable, etc.). But perhaps there'd be more interest in a simpler, stand-alone application specifically for ZScript?

Out of curiosity, does anybody write ZASM anymore? Or has that effectively been superseded by ZScript?

Edited by bobby_light, 18 July 2012 - 09:30 PM.


#10 bobby_light

bobby_light

    Experienced Forumer

  • Members

Posted 22 July 2012 - 10:36 PM

Just updated the demos (online and Windows). I've started implementing my own parser in order to highlight syntax errors on the fly in the editor; it's probably pretty bad at the moment but should get better. I also use the parser to identify variables and functions for code completion now, whereas previously I was doing a simple scan for code blocks ( { ... } ). The newer method should prove better in the long run but right now is easily affected by any parsing issues. This should improve as I add better error recovery.

Anyway, I'd appreciate it if somebody would check it out and give some feedback! Besides squiggle-underlining of errors, the demo now includes a source tree so you can see an outline of the structure of your script, as well as a list of error markers so you can easily navigate to them.

IPB Image

#11 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 24 July 2012 - 11:11 PM

This is looking pretty good. Just curious: are you planning on implementing or defining rules for other programming languages as well? (I suppose C#/Java and C/C++ would be very similar and use most of the same underlying code) -- Including possible support for other scripting languages? It looks like you had to go through the trouble of parsing the zscript.txt file, which was only ever meant as a reference. We could change the format to something more friendly and standard for other languages (not only for you, but for doxygen etc..) Maybe..:
CODE

class _Screen {
public:
  /* @ Description/comment block..
   * ..boogie boogie boogie...
   */
  void DrawCombo(int, int, ...);

or...
   /// <summary>
   /// Finds a pot of gold at the end of a rainbow.
   /// </summary>
   /// <param name="name">Something about the param</param>
  void Method(int foo);

  int Var; //technically a get/set but we don't really care right now.
} *Screen;


#12 Russ

Russ

    Caelan, the Encouraging

  • Administrators
  • Location:Washington

Posted 24 July 2012 - 11:18 PM

Looking at this... this is... just wow. This is like a dream come true. It's amazing. I'm officially switching over to this what you've finished. Keep up the work, this looks amazing.

#13 Xenix

Xenix

    Well excuse me princess.

  • Members
  • Real Name:Chris
  • Location:Newport News, VA

Posted 24 July 2012 - 11:24 PM

This is fantastic! I am in love with this and will be using it quite often when/if it gets finished. icon_smile.gif

#14 bobby_light

bobby_light

    Experienced Forumer

  • Members

Posted 25 July 2012 - 08:12 AM

QUOTE(Gleeok @ Jul 25 2012, 12:11 AM) View Post

This is looking pretty good. Just curious: are you planning on implementing or defining rules for other programming languages as well? (I suppose C#/Java and C/C++ would be very similar and use most of the same underlying code) -- Including possible support for other scripting languages?


Aye, I've already added code completion for a few languages, to varying degrees of completeness and with varying feature sets. This kind of stuff is great fun to me. There's varying levels of support for C, HTML, Java, JavaScript, JSP, Perl, PHP, and Unix shell. I've written about it on the project's blog. Besides code completion, there is syntax highlighting support for 30+ languages.

QUOTE

It looks like you had to go through the trouble of parsing the zscript.txt file, which was only ever meant as a reference. We could change the format to something more friendly and standard for other languages (not only for you, but for doxygen etc..) Maybe..:


And funny enough, if there was interest in this kind of thing, one of the things I was going to suggest was a more robust (parsable!) documentation plan. I'm a big fan of Javadoc/JSDoc since they support documentation inline with the code itself and are easily parsable (I've already got working parsers for these). I'm less familar with doxygen but I'm pretty sure it's just a very similar alternative, mostly used with C and C++. If so then that's definitely a route we could take. Right now, for example, I cannot provide documentation for functions/variables defined inline, in the script currently being edited, since there's no standardized way of doing so. If something like doxygen were implemented, I could grab that and display the doc for inline stuff as well as the "core" language constructs.

I was impressed with the documentation in zscript.txt, etc. - thorough, and (almost!) parsable out-of-the-box; I only had to make a few tweaks here and there. Usually fan-based projects struggle with documentation. For the short term, when RC4 comes out I was planning on just diffing the RC3 doc files with the RC4 ones and making sure my parsable versions had all the newly-added stuff.

I've got more updates arriving shortly, and promise to get the source up into an SVN repository soon. Unfortunately, an OS X version of the demo is on hiatus for now. My Macbook died and alas, I have no replacement for now. Once I find a cheap used one for sale I can put that up as well. If there are any Linux users I could happy provide a Linux demo, though that would be little more than a shell script and some jars.

#15 Gleeok

Gleeok

    It's dangerous to dough alone, bake this.

  • Members
  • Real Name:Pillsbury
  • Location:Magical Land of Dough

Posted 25 July 2012 - 05:58 PM

Sure, JavaDoc styles would be fine. If I am not mistaken these are: "/** description */", "/*! description */", and optionally "/** ..\n @param foo number of foos\n @param bar number of bars */. I've actually been meaning to do this anyway so that we could get some zscript docs on the wiki. http://www.shardstor...Cwiki/Main_Page

I'll try and throw together a quick-and-dirty utility to convert the zscript reference into a more usable format.


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users