Let's Design and Build a (mostly) Digital Theremin!

Posted: 10/7/2019 9:44:46 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Thanks tinkeringdude!  The HDL editor in Quartus is what I use, no real need to go outside the IDE.  I've heard that HDLs are divided somewhat costally here, and depending on who you work for / the work you do.  VHDL isn't so very high level IMO, and the verboseness and function prototyping really slow me down.  SV ain't perfect, but it's less horrible.

For the past day or so I've tried to get a custom syntax highlighter to work with my HAL assembly code and Genie, but have had zero luck - I believe I've read every tutorial and tried everything!  This morning I looked into how to do this in VS code, but got stumped installing the necessary nodejs and npm crap in order to do it.  Right now I'm working on a custom highlight file for gedit, which at least responds to the existence and contents of the file, though there doesn't seem to be any provision for custom tab spacing based on the language.  notepad++ really did this whole thing right by incorporating a syntax highlight editor, no coding necessary.  So right now I'm trying to learn the language (XML?) that defines the gedit syntax highlighting (gaa!).

Posted: 10/7/2019 11:16:32 PM
tinkeringdude

From: Germany

Joined: 8/30/2014

Ah yeah, those fancy editors of today seem to be written with web tech, for what ever reason (github's Atom editor is similar I believe, and it's also similar to VS Code look & feel wise, other than at least a year ago people said it was slower for bigger files and jumped ship over to VSC).

You mean, notepad++ infers a grammar from you telling it "color this thing such, and that thing such"? That would indeed save some headaches.
Haven't looked much into gedit, other than occasional use.

This seems fairly recent:
https://tecadmin.net/install-latest-nodejs-npm-on-ubuntu/

This precedes the installation with the adding of a non-standard (not part of regular distribution) software repository.
Which suggests to me that it might indeed be missing in your installation and hence your attempts at installing fail.
That kind of stuff happens sometimes esp. with developer software.
https://askubuntu.com/questions/4983/what-are-ppas-and-how-do-i-use-them/4990#4990

If I noticed one thing when installing anything on Linux, is that: assuming I have the luxury to use a current version for desktop, then before searching about info for installing anything, I make sure to set the search engine to filter stuff out that's more than a year old... much lower incidence of "a dozen broken dependencies and sub-dependencies, nothing works, what's going on?", if one can't half absent-mindedly click on a top google hit without realizing that it's a couple years old.
Sometimes the site offering the software does not mention everything that's really needed to install something - some people will stumble upon it, and then there will be some forum entry somewhere with a solution for a certain version of a certain Linux distribution...


Yeah. This is more involved than some tool which infers grammars
https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide
https://stackoverflow.com/questions/33403324/how-to-create-a-simple-custom-language-colorization-to-vs-code

Posted: 10/8/2019 12:46:24 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"And about software going crazy, fashion. Well at least it seems to me that they are stuffing languages too full of stuff too quickly. I like some of the additions to C++ because I have to use C++ and am familiar with the concepts behind some of the things they added (even though it's still more awkward to use than in more modern languages), and for somewhat higher level stuff, it decreases the amount of work to be done. But C++ code and ways of doing things of today is hard to recognize from the view of pre-2011 C++. Things have become "deprecated". C# is much younger, but still they are cramming stuff in high-speed, and sometimes "ok, to make XYZ easier, we introduce this". Next round: "ok, yeah, that was kinda ugly. So now we bend the meaning of your beloved keywords ABC in some contexts, which now makes XYZ even easier!" Meanwhile, there are several different ways to do the same thing, and you have to understand them all to maintain code written in that language, even though some of the things shouldn't be used anymore in new code. And a newcomer has to learn it all to be employable, depending on the company and the code in need to deal with, I guess."  - tinkeringdude

I can imagine that there is a tension between including too much / too little higher functionality in the base language itself - make it too simple and everyone gets busy reinventing their own unique and incompatible versions of various wheels, make it too complex and you're making it harder to learn initially, and maybe tying the hands of the library developers?  Though learning the libraries really is part of learning the language.  It seems folks have have high expectations of new languages, particularly of their libraries - they want to be able to do machine learning right out of the box!  Which I suppose is natural - who wants to build everything (like containers) from scratch?  Still, it must be easier to design a language and libraries these days, with LLVM and so much working code in other languages to parlay.  But it's sad when they muck around with basic syntax in ways that aren't consistent with the conventions of the language.

"You mean, notepad++ infers a grammar from you telling it "color this thing such, and that thing such"? That would indeed save some headaches."

Yes, it has a dialog driven syntax coloring / italics / bold feature that kicks out XML.  I had my HAL assembly looking sharp in no time flat, though there was a trick to getting it to color hex like the other numbers, and you have to order the operators from most characters to least.

Aside: it seems most language syntax editor definitions don't highlight the operators (logical, arithmetic, etc.)?  I think this is due to typing conventions, where the operation mode (signed / unsigned / extended / etc.) is dictated by the input data types, rather than by the operator.  And I think this is due to the lack of mixed operations in the processors themselves?  All arithmetic operations in Hive can be mixed, hence my use of signed / unsigned / mixed operators in the HAL assembly language (example: "s0 *us= s1" multiplies the values on stack 0 and stack 1 and places the result on stack 0; the value on stack 0 is treated as unsigned, the value on stack 1 is treated as signed, and the result is unsigned).  This is a really fundamental thing IMO, and I much prefer the signedness of operations to be dictated explicitly via operator syntax rather than implicitly via the input types (where much hilarity often ensues).

"Haven't looked much into gedit, other than occasional use."

It's the default tiny text editor in Ubuntu Gnome.  It's really almost too minimal for general code editing use, it doesn't even match up parens (oops, yes it can!).  But it recognizes various languages, and those are extensible.  And it shows line numbers if you turn that on.

[EDIT] So I'm having to edit the gedit HAL config file in the system area (/usr/share/gtksourceview-3.0/language-specs/hal.lang) and to do this I invoke gedit from the console with su permissions (sudo gedit hal.lang) which brings up a much prettier and more fully featured gedit than the default!  At least I think the default is some form of lobotomized gedit, there's no help|about (!) and Ubuntu just calls it "text editor".

[EDIT2] Solution was to launch Tweaks and go to the "Top Bar" section. Then toggle the "Application Menu" option OFF and relaunch gedit.  This shows all preferences and plugins.  Don't think I could have fixed that without help from the web..

Posted: 10/9/2019 4:24:25 AM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Crazy Little Thing Called XML

After a lot of Googling, head scratching, and looking at how many other languages perform their syntax highlighting in gedit, I've finally got a working XML file for my HAL (Hive Assembly Language) - mostly via pattern recognition on my part and a whole lotta' trial and error.  One typo and everything breaks, so I had to be really careful and check my work after every minor edit, which meant closing the editor with the test file and opening it again hundreds of times. 

After reading about it for hours I'm not really sure what the whole point of XML is?  It seems to be a poorly constructed generic syntax that you can use for anything?  But every definition of it is different?  And those definitions can be hundreds of pages long?  And the deal is that it's supposedly somehow both machine and human readable?  Docs say there are only five or so reserved characters, but you wouldn't know that when programming as many others need escaping and such just to function.  Here's a snippet that I can't fully decode for you, which detects hex numbers:

Code:
(?%lt;![\w\.])
0[xX][a-fA-F0-9]+
(?![\w\.])

I understand this part, where a 0x or 0X is the prefix, and what follows is 0 through F with no case preference, and the + means there can be more than one character following:

Code:
0[xX][a-fA-F0-9]+

And %lt; is the escaped version of the less than sign, but I really don't get the rest.  Good luck finding any definitions out there.  The most useful is a short "tutorial" of the way to apply this to the C language syntax, but it's largely just a pattern recognition / leap of faith kind of thing.  Their instructions are literally "look at how it's done for similar languages and copy whatever".  Where's my t-shirt?

Posted: 10/9/2019 8:18:31 PM
tinkeringdude

From: Germany

Joined: 8/30/2014

Ah, seems like XML has its own dialect of Regular Expressions.
https://www.regular-expressions.info/xml.html

I wasn't aware of that. When I was using "a lot" of XML, the kind of applications and scope of usage did not require schemata to be defined, never bothered, just used it bare.
JSON has become more liked in many places these days, as it's less verbose (all those repeat..../repeat tags in XML...), but still has all the advantages. That was/is not optimal in XML, but as things are, you have to start from somewhere, and XML was designed looking at HTML, and IIRC even initially it was mostly intended for web things, not desktop applications, but it became popular for that, too.

When XML was new, binary formats for everything were king. Next to the not very powerful "*.ini" style text files.
Binary formats are harder to debug. Let alone fix, or create / modify, without custom tools, in case of a partially broken file.
The latter once saved my butt, actually. When developing content creation tools for a new video game in an understaffed, underfinanced startup, and others need to use your stuff ASAP, way before prime time, it can happen that after some work was done, the app crashes. Saved data seems corrupted. I open the thing in a reasonably capable text editor, and after 5 minutes, 2 hours worth of work were saved. That happened a couple times before all was straightened out.
I was very thankful for a text-based storage format

Also, text based formats can be diffed (e.g. git diff, or whatever), to see what changed. Yeah, you could do that with binary files in a hex editor that can do diffs. Way less "fun" and much more error prone, though.
Sometimes even more interesting if source code* management is used: see *who* changed what in a file.
Of course, only, to ask the person kindly what it's about. (nevermind that the command is "git blame", haha.)

* may sound weird, but if you're developing content for a product, which is stored in a text-based structured file, that that's also a kind of "source", and it makes sense to put it under versioned source code management such as git (which, incidentally, does handle binary files absolutely poorly - for game media assets, SVN, which does that well, was used - but that's about its only saving grace)

The same goes for MSWord docs etc, their XML based formats.

While the exact, hierarchical layout of a XML file format (as e.g. defined by a schema... or just... the fact that your program writes / reads in that kind of a structure) is application specific, the fact that there are elements to define a hierarchical structure of arbitrary complexity, and some "optimizations" for common occurrences (e.g. attributes of tags, instead of having to use own tag levels for every little thing), are universal.
That means that there can be an XML library for a programming language, which does the basic reading/writing (and validation of adherence to / integrity of the application specific format via schema) of such a structure, correctly.
So at least the handling of a big part of your custom format is outsourced, and shared between possibly many different custom formats of yours.
Or somebody else's, that you want to read/write, and don't want to implement a parser for on the byte level.

A lot of software started to use it instead of binary formats, where sizes is not really an issue. E.g. saving/loading settings for applications, storing data where the amount is not so big that it will be gigabytes. Documents like of the MS Office suite and similar.
If things do get too big, you can still compress it using a standard, open compression format for which libraries exist - as you can imagine, it compresses rather well.
https://stackoverflow.com/questions/1082285/best-compression-algorithm-for-xml

Some comments there lamenting how this defeats the purpose - well, not so. Using standard compression formats will still yield the magic of a custom format that yet everybody can write and read, because for the XML inside, as well as the (de-)compression algorithm, standard tools available for everyone are used.

But now looking at this: really a lot less verbose
https://en.wikipedia.org/wiki/JSON#Example

Posted: 10/9/2019 10:00:47 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

"Ah, seems like XML has its own dialect of Regular Expressions.

https://www.regular-expressions.info/xml.html"  - tinkeringdude

Wow, thanks for that!  I'll read it and take another look at my HAL syntax code. 

And thanks for your very clear explanation of why XML is everywhere lately!  At some point we'll all be reduced to compressed text files...

[EDIT] Ha!  Check this out: https://regex101.com/  ("human readable" my ass! )

Posted: 10/10/2019 8:17:17 PM
tinkeringdude

From: Germany

Joined: 8/30/2014

Human-readable, well, not the schema part. In normal use that gets done once, and then the files complying with the schema are the written/read (updated) ones.
Now I wonder why you'd have to fiddle with XML schema in this context...
Digging somewhat, it seems I didn't send you 100% on the right track.
The Gedit stuff seems to have its own RegEx flavor, which is to appear, not in a schema file (which would define an XML format - but they should already have one, so no make sense!), but in very certain tags of a XML file instance itself, where it gets to the details of parsing the custom language - at least from looking at these things, it seems to me that way, and that would seem to make sense.

Here is the special regex flavor (instead of the XML schema one I linked to earlier):
https://developer.gnome.org/glib/stable/glib-regex-syntax.html

Which I found here...
https://developer.gnome.org/gtksourceview/stable/lang-reference.html

which in turn I found here:
https://superuser.com/questions/353391/custom-gedit-syntax-highlighting-for-dummies


But yeah, those online regex validators are very helpful, had forgotten about those.
To the left of the one you linked, you can set the "flavor", a special Gnome one is not there it seems.

Posted: 10/11/2019 8:50:09 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Thanks again tinkeringdude!  I've seen your second and third links, but not the first, which is what I was really looking for.  The on-line regex validator is a thing of beauty, though I can see why it exists: regex is anything but regular!   After wrestling with regex for days now, I feel that literally any other type of programming syntax must be simpler!  Found out this morning that one can't simply switch languages inside gedit to pick up all of the regex edits, gedit needs to be closed and opened again.  Switching languages picks up some of the edit changes, but not all, which that caused all sorts of confusion (on top of the inscrutability & fragility of regex itself).

My regex ain't pretty, but my HAL code is looking almost as nice as it did in notepad++.  I rely on syntax highlighting to let me know if the various operators are valid, so they had to be defined as well, but the keyword mechanism doesn't work for that so I had to go to manual override.  I guess it's time to make my own color scheme in gedit - there's an add-on that is supposed to help but it seems buggy.

Turns out ncurses is POSIX (!) which I assume means not portable to Windows machines.  Making a crummy cross-platform console app that captures keystrokes and paints to the text window is way tougher than it should be (IMO due to MS doing their own thing from the ground up).  Makes me wonder if the work involved in making a cross-platform GUI is all that much harder...

I was feeling somewhat stalled out and thought HAL syntax highlighting might take an afternoon or so and help get me going again - hah! (two weeks later)

[EDIT] 800k views!

Posted: 10/11/2019 11:31:06 PM
tinkeringdude

From: Germany

Joined: 8/30/2014

Oh, still need windows compatibility?

There is this, but I have never used it nor know anyone who did (to my knowledge), it seems to be an effort of making the predecessor of ncurses - curses - multi-platform, and appears to be still maintained:

https://github.com/wmcbrine/PDCurses/blob/master/docs/USERS.md
https://github.com/wmcbrine/PDCurses


Also, now that you mention operators again: I remember a time when you couldn't set an own color for them in editors, for me that's a long time ago, though. But I guess some people don't regard it as essential and there are some less widely used tools (for software development as such) that still don't do that. could even be that I'm using some that don't have an explicit color for them, but everything else, so the effect is almost the same. I certainly like them to be different from other stuff to make them stick out more. And it's weird if they have the same color as *some* of the text (if there generally is highlighting, i.e. at least some words are not just the default text color), but not other parts, so they don't stick out to the same degree consistently.

Posted: 10/12/2019 9:41:06 PM
dewster

From: Northern NJ, USA

Joined: 2/17/2012

Thanks tinkeringdude, I'm probably just going to try to adapt things to Linux, then use preprocessor statements to build it the Win way or the Linux way.

Took me a day, but I got my HAL themed gedit colors more or less worked out.  More XML, but nowhere near as tricky as the syntax highlighting code.  Here's a snippet of the D-Lev code in gedit:

I like my code to go bold when it's recognized as valid syntax, and the various elements separated by color, even though these make it kinda "cartoonish" looking.  I also like comments to be italic, neutral colored, and somewhat dimmed out.

[EDIT] Hmm.  There's more to this than I thought because the coloring motif you select in gedit is global rather than per language.  So I get things set up to view HAL files the way I like and it makes everything else look weird, which is kind of a problem as it's the general text editor in Ubuntu.  You can pull in features from specific languages for special treatment, but I'm not sure if it's surgical enough to make it all work out.  For one thing I like really wide tab stops to form the HAL code columns, and I don't think there is a way to tie custom tab widths to a language.  (I suppose this is one reason why many coders eschew tabs for billions of spaces.)

You must be logged in to post a reply. Please log in or register for a new account.