Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (775)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (856)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  TreeML markup language  (Read 39835 times)
0 Members and 1 Guest are viewing this topic.
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Posted 2016-05-26 10:48:20 »

I posted this under shared code a while ago, but I have been using this for real stuff for around a year now, so I decided to make it a real project.

TreeML is a YAML-like, JSON-like structured document language. It parses tab-indented files into trees of nodes. It supports lists, integers, floats, booleans, strings, tokens and explicit nulls.

How does it differ from YAML? It has a LOT less features and and the parser is one class. It also uses tabs and and doesn't support arbitrary indentation levels.

How does it differ from JSON? It uses curly brackets or indentation for nesting, and doesn't force you to use quotes around string tokens. It also allows repeated keys in maps (which, by extension, are not maps). It has a schema language.

Some notes about TreeML best practices:

1. Don't use it for operating a nuclear facility.

2. It may or may not work. So far it seems to work for me.

WIP posts need a picture, so here is a picture of the Christmas Tree Nebula:



It's not my picture, credit goes to: http://www.guidescope.net/nebulae/cone.htm

I have decided I need a schema language to keep my huge Vangard asset files sane, so I'm working an adding ultra-lightweight schema support.

Sources:

https://github.com/agnes1/TreeML

Offline KaiHH

JGO Kernel


Medals: 636



« Reply #1 - Posted 2016-05-26 12:38:57 »

I always tip my hat to people writing parsers by hand. Smiley

BTW: Here is a working JavaCC grammar for your language, which accepts your example file: https://gist.github.com/httpdigest/ce6479b041dec9efe3b42b54f6836461

One thing to note: It creates a standard Map that contains the keys and the values are simple Strings or Integers or Maps themselves. In the case of multiple values for the same key, the Map then contains an ArrayList under that key containing the values.
Offline nsigma
« Reply #2 - Posted 2016-05-26 13:40:10 »

Nice! ... but, tabs?  Undecided  Doesn't everyone else set their IDE and text editor to output spaces instead of tabs?  persecutioncomplex

Praxis LIVE - hybrid visual IDE for (live) creative coding
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline J0
« Reply #3 - Posted 2016-05-26 16:28:12 »

What's wrong with tabs?

Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #4 - Posted 2016-05-26 16:35:49 »

Tabs are dreadful if they are mixed with spaces for indentation.

I opted for tabs because 1 tab means 1 level of indentation. The mapping of spaces to indentation is arbitrary.

I use spaces for everything else though. Had to set up an exception in IntelliJ for treeml...

Offline purenickery
« Reply #5 - Posted 2016-05-26 17:12:48 »

Wow, this markup language is almost exactly like the one I wrote for my game  Grin

Working on Questica!
Twitter: @purenickery
Website: http://www.questica.net
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #6 - Posted 2016-05-26 19:09:11 »

I always tip my hat to people writing parsers by hand. Smiley

BTW: Here is a working JavaCC grammar for your language, which accepts your example file: https://gist.github.com/httpdigest/ce6479b041dec9efe3b42b54f6836461

One thing to note: It creates a standard Map that contains the keys and the values are simple Strings or Integers or Maps themselves. In the case of multiple values for the same key, the Map then contains an ArrayList under that key containing the values.

It's an official, for-real markup language when it has two different parsers written by two different people! Smiley

Offline KaiHH

JGO Kernel


Medals: 636



« Reply #7 - Posted 2016-05-26 19:27:18 »

Absolutely!
You should create a GitHub repository and deploy to Maven Central. Pointing
Offline Riven
Administrator

« JGO Overlord »


Medals: 1356
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #8 - Posted 2016-05-26 19:54:28 »

BTW: Here is a working JavaCC grammar for your language, which accepts your example file: https://gist.github.com/httpdigest/ce6479b041dec9efe3b42b54f6836461
Negative floats! Pointing

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline J0
« Reply #9 - Posted 2016-05-26 20:39:40 »

Tabs are dreadful if they are mixed with spaces for indentation.
I opted for tabs because 1 tab means 1 level of indentation. The mapping of spaces to indentation is arbitrary.
Yep. Indentating with spaces is cancer Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline princec

« JGO Spiffy Duke »


Medals: 1059
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #10 - Posted 2016-05-26 21:20:54 »

Only freaks use spaces for indentation, because proportional fonts.
But then only freaks use proportional fonts.

However: whitespace as a syntactical feature of any language? Just reprehensible. You should be hung.

Cas Smiley

Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #11 - Posted 2016-05-26 22:22:40 »

Given that programmers slavishly follow whitespace rules in languages even where whitespace is insignificant, and bad indentation is one of the worst developer thought crimes, why not make indenting the law?

Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #12 - Posted 2016-05-26 22:52:19 »

yet, indentiation is visual and doesn't share much with code semantics. using a code formatter is asking for trouble.
Offline nsigma
« Reply #13 - Posted 2016-05-27 09:21:43 »

What's wrong with tabs?

Because every project I work on or with uses spaces by convention.  Standard Java style is spaces, or spaces and tabs (yuck!).  This means my editors and IDE are set to output spaces by default.  Even @ags1 mentioned he uses spaces everywhere else and has to put an exception in his IDE to output tabs instead for this.  IMO, that's where this falls down and becomes less useful.

I also agree with @princec that whitespace as a syntactical feature is horrible (although I don't on spaces - who codes in a proportional font - you'll be using Comic Sans next)

Praxis LIVE has a similar-ish format for its patch files, except the syntax is based on Tcl and so uses braces for structure.  I have some similar parser code (though there's no way @KaiHH is writing a JavaCC grammar for it!  Wink )

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline princec

« JGO Spiffy Duke »


Medals: 1059
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #14 - Posted 2016-05-27 09:30:23 »

Standard Java style is tabs, not spaces.

You can see now why whitespace with semantic meaning is a disaster.

Cas Smiley

Offline nsigma
« Reply #15 - Posted 2016-05-27 09:44:14 »

Standard Java style is tabs, not spaces.

er, no it isn't, unless it's changed since this http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html

Indentation is 4 spaces - tabs must be set to 8 spaces.  Which means you either have all spaces or a mix, but it's not possible just with tabs.  The default NetBeans formatting is definitely based on 4 spaces.

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline basil_

« JGO Bitwise Duke »


Medals: 418
Exp: 13 years



« Reply #16 - Posted 2016-05-27 09:55:17 »

if there is an option "replace tabs by spaces on save" - i cannot imagine why one woudln't check it and forget about tabs altogether.
Offline princec

« JGO Spiffy Duke »


Medals: 1059
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #17 - Posted 2016-05-27 10:05:35 »

Since Eclipse has used tabs by default for code formatting since before it was even called Eclipse that sort of made tabs a defacto standard.

I like tabs because they don't require as many keypresses to navigate around, or indeed to type in the first place.

I make extensive use of //formatter:off/on too in my code.

Cas Smiley

Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #18 - Posted 2016-05-27 10:26:18 »

Standard Java style is tabs, not spaces.

You can see now why whitespace with semantic meaning is a disaster.

Cas Smiley

A disaster ONLY if the language syntax allows a mix of tabs and spaces.

Also, to be totally correct I am using the tab character as semantically significant, not the whitespace it is represented with in the editor. There is a difference. You can configure your editor to represent the tabs with one space or eight (or even zero), but that doesn't change the meaning of the document.

I could use a different character without a whitespace representation if that would make more sense (but it wouldn't).

I opted for tabs because spaces were worse. Would I hardcode that a specific number of spaces equals an official indentation level? Or would I follow YAML and allow any change in indentation to be significant? In my opinion the YAML approach is just nasty and dirty, and hard-coding a number of spaces (or allowing each user to configure it somehow) means hard coding a visual preference into every treeml file. Tabs feel wrong, but in this case they're right.

Here's what the YAML spec has to say about indenting:

Quote
In general, a node must be indented further than its parent node. All sibling nodes must use the exact same indentation level, however the content of each sibling node may be further indented independently. The “-”, “?” and “:” characters used to denote block collection entries are perceived by people to be part of the indentation. Hence the indentation rules are slightly more flexible when dealing with these indicators. First, a block sequence need not be indented relative to its parent node, unless that node is also a block sequence. Second, compact in-line notations allow a nested collection to begin immediately following the indicator (where the indicator is counted as part of the indentation). This provides for an intuitive collection nesting syntax.

This was the inspiration for treeml, after reading that paragraph I knew I would never willingly use YAML Smiley

Also, regarding proportional fonts: I don't use proportional fonts but spaces are fine for indenting a proportional font file. The spaces are at the beginning of the line (i.e. with zero characters before them) so proportionality is not a factor.

Offline nsigma
« Reply #19 - Posted 2016-05-27 11:02:28 »

I like tabs because they don't require as many keypresses ... to type in the first place.

The crux of the issue is that most people who works with space indented projects (and I don't currently work with anything Java or otherwise that doesn't use spaces) has their editor set up to output spaces when the tab key is used.

I'm currently working on something with lots of YAML, and I don't disagree with the "nasty and dirty" comment, but for me using tabs is even more of a PITA because of the above issue.

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #20 - Posted 2016-05-27 11:05:06 »

Over the next few years as the language becomes wildly popular I expect the major IDEs will recognize .treeml files and make an appropriate exception for tabs... Wink

Offline Riven
Administrator

« JGO Overlord »


Medals: 1356
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #21 - Posted 2016-05-27 14:43:58 »

That document is as relevant as the reason it gives for the line-width of 80 characters Pointing



Why are we hijacking this innocent little thread?

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
Offline J0
« Reply #22 - Posted 2016-05-27 14:54:55 »

although I don't on spaces - who codes in a proportional font - you'll be using Comic Sans next
I'm sorry, I'm so sorry... Roll Eyes

Offline princec

« JGO Spiffy Duke »


Medals: 1059
Projects: 3
Exp: 20 years


Eh? Who? What? ... Me?


« Reply #23 - Posted 2016-05-27 19:29:51 »

I think there is a case for a whole new computer programming language based entirely on the difference between spaces and tabs, and that it should be enforced as a matter of style to use Comic Sans to edit it. Perhaps it should be entirely defined in terms of overloaded ascii operators as well.

Cas Smiley

Offline BurntPizza

« JGO Bitwise Duke »


Medals: 486
Exp: 7 years



« Reply #24 - Posted 2016-05-27 19:51:25 »

You mean defined entirely in trigraphs of invalid unicode code points.
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #25 - Posted 2016-05-27 22:23:27 »

I just updated the Gist with my first version of my validating parser. Currently it only validates field names and order, with support for optional and repeating fields.

https://gist.github.com/agnes1/08b157dba6a3f37b2ab6

A schema for my careers asets looks like this (the "d" elements are dummy list items):

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
career: d, d
   id: single, d, d
   name: single, d, d
   description : single, d, d
   minimumLevel: single, d, d
   status: single, d, d
   reputation: single, d, d
   alignment: single, d, d
   wealth : single, d, d
   possessions: single, d, d
      token : d, d
   skills : single, d, d
      token : d, d
   behaviors: single, d, d


The schema language does not support recursion so the schema schema isn't pretty:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
token : single, list, token
   token : optional, list, token
      token : optional, list, token
         token : optional, list, token
            token : optional, list, token
               token : optional, list, token
                  token : optional, list, token
                     token : optional, list, token
                        token : optional, list, token
                           token : optional, list, token

Offline KaiHH

JGO Kernel


Medals: 636



« Reply #26 - Posted 2016-05-27 22:45:25 »

I really like that language! Smiley
Tiny suggestion, maybe?
1  
2  
3  
4  
5  
6  
7  
career: 0-n
    id: 1 // <- 1 could be default multiplicity
    name
    description
    possessions: 0-n
    skills: 0-n
    behaviour: 0-n

To model more complex things such as XML Schema's "choice" element, it would require some "meta" element/hierarchy with special syntax support, such as:
1  
2  
3  
4  
5  
6  
7  
8  
career: 0-n
    id
    name
    description
    #choice: 0-n // <- possessions, skills and behaviours may occur in any order
        possessions
        skills
        behaviours

The simple enumeration of attributes/properties of an object would be syntactic sugar for the "sequence" schema construct, which is implicit, but could be made explicit:
1  
2  
3  
4  
5  
6  
7  
8  
9  
career: 0-n
    #sequence
        id
        name
        description
        #choice: 0-n // <- possessions, skills and behaviours may occur in any order
            possessions
            skills
            behaviours
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #27 - Posted 2016-05-27 23:03:01 »

It's possible to get these structural assertions with nested name values without overly elaborating the syntax, i.e. keeping to the basic structure of nested name:values.

We add a new keyword like 'flow' to the value list. As its on the value side it does not force a restriction on node names. Any node with a flow token is treated as a structural assertion not an element definition...

The cardinality ranges are tougher - as each schema entry value is defined as a list of tokens, numbers are not allowed.

1  
2  
3  
4  
5  
6  
7  
8  
9  
career: min0max20 //it's a valid token now :)
+   sequence : flow
        id
        name
        description
+      choice : flow
            possessions
            skills
            behaviours


I guess I could borrow from schemas and get recursion thusly:

1  
2  
3  
4  
5  
6  
7  
8  
9  
root : ...
    moot : ...
        foot : ...
        soot : ...
        loot : ....
    woot :...
       ref : flow, shoot
+shoot : referenced, ....
+    ref : flow, shoot, optional


EDIT: added a refs node as otherwise the shoot would be interpreted as a valid root node of the document, which is probably not desired.

EDIT: Simpler, added a "referenced" keyword to indicate the node definition is neither optional nor required, and doesn't in fact form part of the document flow unless it is reffed from elsewhere.

Offline KaiHH

JGO Kernel


Medals: 636



« Reply #28 - Posted 2016-05-27 23:11:55 »

Quote
We add a new keyword like 'flow' to the value list.
Yeah, that is a great idea.

Quote
...numbers are not allowed.
Okay. I thought your schema language was just your actualy TreeML language, where you also showed examples of numbers as values.
Offline ags1

JGO Kernel


Medals: 367
Projects: 7


Make code not war!


« Reply #29 - Posted 2016-05-27 23:14:26 »

Yes this is pure treeml. But if you have a list of values like:

field : val1, val2, val3, 4

The values in the list have to be of the same type. So 4 would be a violation, as val1, val2, and val3 are tokens/strings. Tokens are not allowed to start with a number. But I'm not sure i really need cardinality.

Using the proposed syntax for recursion cleans up the schema schema (also adding in the missed definition of enums):

1  
2  
3  
4  
token : single, list, token, enum, single, optional, string, token, integer, decimal, boolean, empty, list, set, flow
   ref: optional, flow, token
token : referenced, list, token, enum, single, optional, string, token, integer, decimal, boolean, empty, list, set, flow, referenced
    ref: optional, flow, token


Basically everything after enum is an enum value, like a varags argument.

Pages: [1] 2
  ignore  |  Print  
 
 

 
hadezbladez (25 views)
2018-11-16 13:46:03

hadezbladez (34 views)
2018-11-16 13:41:33

hadezbladez (18 views)
2018-11-16 13:35:35

hadezbladez (12 views)
2018-11-16 13:32:03

EgonOlsen (1890 views)
2018-06-10 19:43:48

EgonOlsen (1926 views)
2018-06-10 19:43:44

EgonOlsen (1283 views)
2018-06-10 19:43:20

DesertCoockie (1711 views)
2018-05-13 18:23:11

nelsongames (1400 views)
2018-04-24 18:15:36

nelsongames (2032 views)
2018-04-24 18:14:32
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!