softlang / metalib

A Chrestomathy of DSL implementations
https://softlang.github.io/metalib
9 stars 1 forks source link

Factor URLs #4

Closed rlaemmel closed 7 years ago

rlaemmel commented 7 years ago

I am looking at:

https://github.com/softlang/metalib/blob/master/docs/models/pythonInternal.json

We have loads of long URLs, e.g.:

        "link": "https://raw.githubusercontent.com/softlang/yas/master/languages/FSML/Python/FsmlSample.py",

These URLs typically have a long common prefix.

In MegLib, cc @MarcelH91, we have a way of dealing with this. This should be somehow carried over to MetaLib.

le-cram commented 7 years ago

To explain the megalib solution: Let's say every file you ever want to link is in this folder: "link": "https://raw.githubusercontent.com/softlang/yas/master/languages/FSML/Python", Then, it would be a good idea to introduce a namespace for this, where I use the following syntax: pyNS :: "https://raw.githubusercontent.com/softlang/yas/master/languages/FSML/Python".

Then, you can use this namespace to shorten the link: "link": "pyNS::FsmlSample.py"

sschauss commented 7 years ago

Nice. I can add something like:

{
  "name": "...",
  "headline": "...",
  "namespaces": [
     {
       "prefix": "pyNs",
       "name": "https://raw.githubusercontent.com/softlang/...."
     }
  ],
  "sections": [
     ...
  ]
}

or

{
  "name": "...",
  "headline": "...",
  "namespaces":  {
     "pyNS": "https://raw.githubusercontent.com/softlang/...."
   },
  "sections": [
     ...
  ]
}

Than we should reflect these changes in https://github.com/softlang/yas/blob/b5414c3cc20efa783b2c50ad6fddf49ace63d1c1/languages/MLDF/mm.mml .

class document {
  value name : string; // The name of the contribution
  value headline : string; // A one-liner explanation
  part sections : section+; // Sections of the documentation
  part namespaces: namespace*; 
}

class namespace {
  value prefix: string;
  value name: string;
}
rlaemmel commented 7 years ago

I revised https://github.com/softlang/yas/blob/master/languages/MLDF/mm.mml

Namespaces are now mandatory.

class document {
  value name : string; // The name of the contribution
  value headline : string; // A one-liner explanation
  part namespaces : namespace+; // Namespaces for links
  part sections : section+; // Sections of the documentation
}

class namespace {
  value prefix : string;
  value url : string;
}

abstract class artifact {
  part link : link; // A structured link
  value format : string; // MIME-like format type
}

class link {
  value prefix : string; // Prefix of namespace
  value relative : string; // Relative URL
}