Shop OBEX P1 Docs P2 Docs Learn Events
HTML-based Propeller IDE -- now with auto-completion — Parallax Forums

HTML-based Propeller IDE -- now with auto-completion

Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
edited 2011-07-05 20:40 in Propeller 1
In another thread, I broached the possibility of an HTML-based Propeller IDE. Among other things, there was an open question about whether HTML(5?)/Javascript/Ajax could provide a rich-enough environment for such an endeavor. In an effort to find out, I've spent the last two weeks investigating both Ajax-related topics and HTML-based editors. I found a rather nice editor written in Javascript called CodeMirror 2, which provides hooks for doing text highlighting and other things a code editor might need. I wrote a Spin "mode" program for it in Javascript to do the highlighting, and modified the CodeMirror.js code to accommodate Spin's rather unusual tabbing and indentation functions.

You can try out the result here: http://www.phipi.com/editspin It's preloaded with Float32Full.spin, but you can delete that and type or paste your own code if you like.

I chose highlighting colors that I liked and elected not to do any section-dependent background shading. Such shading could easily be accommodated: it would just require a more comprehensive spin.css file. I also added syntax checking to catch the easier-to-detect, low-context errors, which show up in red as typing/editing occurs. In addition, I changed the way a shift-tab is handled when no text is selected. In the Propeller Tool, such an action just moves the cursor. In this editor, everything to the right of the cursor shifts left until it hits the previous tab stop or a non-blank character. Finally, I added bold-facing to document comment words that begin with a backtick, in line with the autodocumentation markup proposed for "gold standard" objects.

Here's the Javascript function I wrote for the Spin highlighting:
function tokenLexer(stream, state) {
  var matched;
  if (stream.match(/^\{\{/)) {
    state.superComment++;
    return 'doccomment';
  }
  if (stream.match(/^\}\}/)) {
    if (state.superComment) {
      state.superComment--;
      return 'doccomment';
    } else {
      return 'error';
    }
  }
  if (state.superComment) {
    if (state.bold) {
      if (stream.match(/^\W/)) {
        state.bold = false;
        return 'doccomment'
      } else {
        stream.next();
        return 'boldcomment'
      }
    }
    if (stream.match(/^`/)) {
      state.bold = true;
    } else {
      stream.next();
    }
    return 'doccomment';
  }
  if (stream.match(/^\{/)) {
    state.nestedComment++;
    return 'codecomment';
  }
  if (stream.match(/^\}/)) {
    if (state.nestedComment) {
      state.nestedComment--;
      return 'codecomment';
    } else {
      return 'error';
    }
  }
  if (state.nestedComment) {
    stream.next();
    return 'codecomment';
  }
  if (stream.match(/^"/)) {
    if (!(stream.skipTo('"') && stream.next())) {
      stream.skipToEnd();
    }
    return 'string';
  }
  if (matched = stream.match(/^''/)) {
    stream.skipToEnd();
      return 'doccomment';
  }
  if (matched = stream.match(/^'/)) {
    stream.skipToEnd();
      return 'codecomment';
  }
  if (stream.match(sectionHeaders, false)) {
    var sol = stream.sol();
    matched = stream.match(sectionHeaders);
    if (!sol) {
      state.section = 'none';
      return 'error';
    }
    state.section = matched[0].toLowerCase();
    return 'keyword';
  }
  if (stream.match(wordOperators)) {
    return 'operator';
  }
  if (state.section === 'dat') {
    if (stream.match(/^\$(?=(\W|$))/i)) return 'keyword';
    keywords = pasmKeywords; errors = pasmErrors;
  } else {
    keywords = spinKeywords; errors = spinErrors;
  }
  if (stream.match(keywords)) {
    return 'keyword';
  }
  if (stream.match(errors)) {
    return 'error';
  }
  if (matched = stream.match(/^[+-\.]*[$%\d]/, false)) {
    stream.match(/^[+-]?\d[\d_]*(\.\d[\d_]*(e[\+\-]?\d[\d_]*)?)?/i) 
    || stream.match(/^[+-]?\$[\da-f][\da-f_]*/i)
    || stream.match(/^[+-]?%[01][01_]*/)
    || stream.match(/^[+-]?%%[0-3][0-3]*/)
    if (stream.match(/^[\da-f$%\._]+/)) {
      return 'error';
    } else {
      return 'number';
    }
  }
  if (stream.match(tripleOperators) || stream.match(doubleOperators) || stream.match(singleOperators)) {
    return 'operator';
  }
  stream.match(identifiers) || stream.next(); return 'normal';
}

This editor only scratches the surface of the features supported by CodeMirror, which can also include autocompletion. I've not made any effort at dynamic window resizing, although that could be done, too.

Anyway, an editor is a necessary first step to any IDE framework. For the Ajax part, I've been investigating jQuery and have read reviews for other such frameworks. Since I'm very new to this stuff, jQuery seems to be the most approachable and still has a rich feature set.

At this point, it's unclear how much more effort I want to expend in this feasibility study, even though the results are very encouraging so far. If jQuery seems easy enough to grok, I may take it one step further to produce a demo IDE with simple open, save, compile, and load functionality.

-Phil
«1

Comments

  • TorTor Posts: 2,010
    edited 2011-07-01 16:16
    The editor seems to work nicely. This could get very interesting.

    -Tor
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2011-07-01 17:47
    That's pretty amazing.. How do we throw a Spinneret in the mix? :)

    OBC
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-01 17:51
    OBC wrote:
    How do we throw a Spinneret in the mix?
    Sphinx

    -Phil
  • Mike GMike G Posts: 2,702
    edited 2011-07-01 18:28
    Very nice Phil. This is right up my alley :)

    My first thought was using Propellent.dll to generate a binary file on the server, then send the binary file via HTTP the to the Spinneret. I believe Kye's SD fat driver can load the binary into EEPROM (have not tried it yet). Could be a little sketchy if the program caused an unresponsive Spinneret/Propeller.

    EDIT: My mind is reeling...consume the Propellent.dll in a service on the host.
  • jazzedjazzed Posts: 11,803
    edited 2011-07-01 19:16
    Sphinx

    -Phil
    Don't you have to upload a file from the local host to the server anyway? I don't think AJAX has the hooks to write to a file on the server .... I could be wrong. Got pointer?
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-01 19:36
    jazzed wrote:
    I don't think AJAX has the hooks to write to a file on the server
    Not directly, of course. But it can send the file's contents, along with a command to the server. It's up to the server to interpret that command and do the save, compile, or compile/load to RAM or EEPROM.

    -Phil
  • Kevin WoodKevin Wood Posts: 1,266
    edited 2011-07-01 21:05
    You might want to look at node.js.: http://nodejs.org
  • jazzedjazzed Posts: 11,803
    edited 2011-07-01 21:41
    Kevin Wood wrote: »
    You might want to look at node.js.: http://nodejs.org
    Cute server :)

    With all this Javascript flying around next thing you know Phil will be losing interest in Perl especially having all those RegEx abilities.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-01 21:58
    jazzed wrote:
    With all this Javascript flying around next thing you know Phil will be losing interest in Perl especially having all those RegEx abilities.
    Unfortunately, there's no universally-supported client-side Perl for web browsers. So I have to make do with Javascript. JS is not such a bad language, really, but I do miss Perl's idiomatic shortcuts. You can rest assured, though, that any server-side scripting for this study (not yet a "project") will be done in Perl. :)

    -Phil
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-07-01 22:56
    Phil: This sounds interesting. Unfortunately it is slow, so I could not write a program with it, especially after you add all the other requirements :(

    However, for someone with an iPad, android tablet, or even one of the new mobile phones, who just needs to modify or extend some programs and compile and download, this would be great. That way we wouldn't need to take the laptop. So a way is needed to upload and download the source files.

    This could be a neat app for Parallax Semiconductor to have on their server so that users could check out a virtual prop, or program and download some simple apps to the Quick Start board.

    For those of us with web servers or paid web servers, this could be a nice touch :)

    I really think there could be a lot of publicity mileage for the prop if this worked sufficiently.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-01 23:06
    Cluso99 wrote:
    Unfortunately it is slow, ...
    That's one of the things I was interested in finding out. What kind of system are you testing it on? I get snappy performance on a Pentiium 4 (3.2 GHz) with Opera, but things are a little slower -- yet still usable -- on my iMac G5 with Firefox.

    -Phil
  • TorTor Posts: 2,010
    edited 2011-07-02 06:02
    I tried it again because I didn't notice any slowness problem when I tested it the first time. I see no slowness at all, text appears as I enter it, no delay. For every character entered the page will move down half a line or so, and the next character will make it jump up half a line again. So there is that little jerkiness, but it's not very bothering.

    That was with the google Chromium browser, on a 64-bit quad-core 2.66GHz Linux box. So now I tried it again, but in Firefox 3.5 on the same machine.. there's a definite delay there, when entering characters. It must be noted though that this particular instance of Firefox has about 50 windows open right now and is connected to two dozen sites.

    Conclusion: Chromium on my particular machine works just fine with that editor. Firefox must be re-tested with less load. Haven't tried Opera or any of the other browsers yet.

    -Tor
  • Mike GMike G Posts: 2,702
    edited 2011-07-02 06:30
    Cluso99, what's slow?

    It's snappy for me. Firefox on a Intel Quad 2.4G Windows box and Firefox on an old AMD box running Linux. The underline characters that decorate Revision History has an encoding issue on my Firefox/Linux system.

    I think this is a splendid idea, just the cross platform aspect alone is killer.
  • jazzedjazzed Posts: 11,803
    edited 2011-07-02 10:03
    I'm warming up to this idea for cross-platform use - thanks for the reminder Mike G.

    It would be just as easy to send a binary (any binary) down for boot-up programming.
    I just wish we could make some of those cheap SDCARD dongles work with Propeller.

    I use Chrome and rarely have performance issues with that - Internet Exploder? No Thanks!
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-07-02 22:11
    I am using an old and slowish laptop. Acer 1.5GHz Celeron, 1GB Ram, original 40GB H/D upgraded to 80GB, Windows XP and Microsoft Essentials (which does slow my laptop a lot) & IE8. I am using WiFi to my router with ADSL2+.

    I don't have any problems typing into the forum software, but I did have problems with your program keeping up with my typing.

    Just tried with firefox and it was fine. I retried with IE8 and it was a little jerky in displaying the characters I typed. Not really surprising :)
    So I am interested to see comparisons by anyone who can try both on the same pc.

    I could definately work with firefox :)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-03 09:26
    Cluso99,

    IE8's JS interpreter is extremely sluggish and somewhat buggy. Google has an Chrome V8 add-in for it that helps to speed things up a bit. I've been experimenting with it and will post a link later today on the editor page so IE users can install it.

    -Phil
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-03 11:43
    I've uploaded a slightly-tweaked version of the editor which better handles section heading entry errors. Also included is a link to Google's Chrome Frame add-on for IE. One known issue: and and or are highlighted as operators, rather than keywords, when used as instructions in the DAT section. They can be used both ways here, and I need to figure out a way to make the highlighting more context-dependent.

    -Phil
  • markaericmarkaeric Posts: 282
    edited 2011-07-04 15:48
    This is very interesting indeed. The capabilities of modern web browsers is pretty amazing, and that's certainly not something that's going to change any time soon. Consider what Google is doing with Chrome OS - basing an entire OS GUI on web browser-based technologies. It might be somewhat hard to see at first, but I think The Goog is onto at least *something* here. Now with the emphasis on substantially improving JavaScript performance, browsers are becoming very powerful UI platforms.


    OBC,
    Ever since Phil first brought this up, I've been thinking about the Spinneret thing too. My first thought was using it to host an HTML/JavaScript-based IDE and compiler which would run entirely on the user's machine. Any important data (compiled/non-compiled code, settings, etc) could be PUT/POST on the Spinneret's SD card. Of course, it should also have the ability to act as a program/debug interface. Now, I don't know much about JavaScript, so I couldn't say for sure if you can write an entire compiler out of it, but I imagine it should be possible (Any thoughts?). The Sphinx idea is a cool too, and probably the least far fetched. Either way is cool since they both have their merits. Just the thought of having everything you need to program a Prop aside from ANY computer (phone/PDA even?) with a web browser and an ethernet cable, in the form factor of a Spinneret sounds really awesome.
  • Mike GMike G Posts: 2,702
    edited 2011-07-04 16:23
    You would not necessarily write the compiler in JavaScript, you'd send the content to a server via JavaScript; AJAX. The server would process the data (compile) then determine where the results are sent. Target location is dependent on where the Spinneret is physically located.

    EDIT: IMO Phil's approach is very powerful. Besides cross platform, you also have one server end point that deals with compiling the source code. Updates are done directly on the centralized server (end point) and available to all clients. No need to install a new client app. The only sticky part is the target Propeller must be attached to a system that knows how to transmit the binary to the Prop.
  • jazzedjazzed Posts: 11,803
    edited 2011-07-04 18:18
    Mike G wrote: »
    Updates are done directly on the centralized server (end point) and available to all clients.
    And when the server can't keep up with demand, you'll know Propeller has reached a new height ! :)
  • BatangBatang Posts: 234
    edited 2011-07-05 06:15
    We have cases where we go on site (in the middle of the jungle) to make firmware changes/adjustments, no internet there lah.
  • TorTor Posts: 2,010
    edited 2011-07-05 06:42
    I just tried the editor again, this time from a Nokia N900 Maemo phone. It's entirely usable, although this keyboard which I'm writing on lacks a lot in speed & convenience compared to a regular computer. Opera 11 on this same phone got confused about what to do in that edit window though, it's otherwise my preferred browser on this device. Will check more later. The built-in Gecko-based one (think firefox) is ok though and it works with that page.
    So, internet cafeteria, vacation, caffe latte, quickstart board and usb stub cable in pocket, there are maybe no astronomical hurdles in the way for connecting everything together? :)

    -Tor
  • Mike GMike G Posts: 2,702
    edited 2011-07-05 06:53
    @Batang, [scratching my head]

    Obviously, you need the editor/compiler loaded on your jungle box. If you don't have internet access, well, an Internet based app would not make much sense. For those of us that have Internet access, I think it makes sense.

    @Tor, cool
  • jazzedjazzed Posts: 11,803
    edited 2011-07-05 07:43
    The "server" could just as easily run on the local PC so you can do work without the internet.
  • Mike GMike G Posts: 2,702
    edited 2011-07-05 08:28
    @jazzed, very true... good point
  • Heater.Heater. Posts: 21,230
    edited 2011-07-05 08:29
    I'm not very comfortable with this web browser based IDE idea. I can't help thinking I'd rather have the source code for the tools and be able to compile them on whatever platform I have.

    On the one hand I need an internet connection all the time. I need to work in a browser all the time which has to be clunkier than having a native app.

    On the other hand I can run my own server but then I've still got the clunky web browser interface but now with the added complication of running my own web server. I've also lost the automatic update of the tools that a network would provide.

    Still, this guy http://bellard.org/jslinux/ has written a whole x86 emulator in java script that runs and boots up Linux in a web page!!! So I guess writing the entire Spin tool, for example, in javascript is not out of the question.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-05 08:52
    Doing the entire IDE in native Javascript is not possible, since (for security reasons as a browser add-on) JS does not have access to the hardware (i.e. files, USB ports). However, the Google JS framework cited above by Kevin Wood does have this capability. So then it becomes a question of do you want to write the back end in JS? My love/hate relationship with JS and my long-term infatuation with Perl probably disqualifies me from making that judgment. :)

    -Phil
  • Mike GMike G Posts: 2,702
    edited 2011-07-05 09:21
    Maybe I'm missing something...I'm thinking of a distributed application. You have an editor, a target service, a binary loader. The language is ancillary to the architecture.

    JavaScript is cool because it can be severed up.

    Anyway, I've got this Spinneret thing I'm doing so when I get that done I'd like to take a closer look at Phil's HTML-based Propeller IDE.
  • markaericmarkaeric Posts: 282
    edited 2011-07-05 17:07
    Doing the entire IDE in native Javascript is not possible, since (for security reasons as a browser add-on) JS does not have access to the hardware (i.e. files, USB ports).

    A network-connected "Prop Plug" would would avoid such limitations, as you wouldn't need to use any USB port. It would also certainly be possible to up/download files to/from the device through the browser, given that it's configured to act as a server.

    A full-featured back end written in JS probably isn't too practical. My thought was more along the line of something lightweight that could be hosted by something like a Spinneret, while delegating the comiling duties to the web browser's JS engine. I know this isn't exactly what Phil was talking about, so I apologize if I created some confusion.

    What I'm really interested in, and mentioned it elsewhere, is that if a web browser can in fact provide a suitable UI, a Prop2 based web server/compiler/programmer could offer the benefit of native multi-platform support, and the convienience of having all the development tools you need all in a little box connected to the network. Someone has to think this is at least a *little* compelling :)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-07-05 17:53
    I've updated the editor to include context-sensitive auto-completion. By "context-sensitive" I just mean that if you're in a DAT section you won't get an auto-complete for repeat; or, if in a non-DAT section, one for rdlong.

    Auto-completion priority is alphabetical: e.g. rdbyte is displayed for "rd", not rdlong. A better strategy would be to base the priority on frequency of usage. In any event, it's important that, once a strategy is settled upon, not to change it, because fast typists will become accustomed to typing "rd[rt-arrow]" for rdbyte and would not be amused if it suddenly produced rdword instead due to a software change.

    -Phil
Sign In or Register to comment.