Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement parser/generator for LiNo (Links Notation) (like JSON for Links) #158

Open
1 task
Konard opened this issue Mar 19, 2016 · 5 comments
Open
1 task

Comments

@Konard
Copy link
Owner

Konard commented Mar 19, 2016

  • Publish as an NPM package

https://github.com/pegjs/pegjs can be used to actually parse Links Notation to JavaScript object, which then will be transfered to C# code to be loaded to associative memory storage.

@Konard Konard added this to the Patterns milestone Mar 19, 2016
@Konard
Copy link
Owner Author

Konard commented Mar 19, 2016

2016-03-19 05-22-16

LiNo (Links Notation) Grammar:

// Links Notation Grammar

Expression = expression:(_ (Link) _)* 
{
  var result = [];
  for (var i = 0; i < expression.length; i++)
    result.push(expression[i][1]);
  return result;
}

IdentityOrLink = Identity / Link

Link = "(" id:(IdOrNull) _
source:(IdentityOrLink) _ target:(IdentityOrLink) _ ")"
{ return { "Id": id, "Source": source, "Target": target }; }

IdOrNull = idParts:(_ Identity _ ":" / "")
{ if(idParts.length > 1) { return idParts[1]; } else { return null; } }

Identity "identity" = [0-9a-zA-Zа-яёА-ЯЁ]+ { return text(); }

_ "whitespace" = [ \t\n\r]*

Generated using http://pegjs.org/online

@Konard
Copy link
Owner Author

Konard commented Mar 21, 2016

https://github.com/otac0n/Pegasus (another possible solution)

May be it is better to write links as parsing goes. And not to create intermediate object notation.

@Konard Konard mentioned this issue Mar 22, 2016
7 tasks
@Konard
Copy link
Owner Author

Konard commented May 8, 2016

3:
  loves
  mama
papa 
  3
son
  3
everyone
  3
3
  is
    loves
      mama
point
point:
  point
  point

Could be an example of indented notation, that is exactly the same as:

(papa (3: loves mama))
(son 3)
(everyone 3)
(3 (is (loves mama)))
(point)
(point: point point)

Possible grammar:

// Links Notation Grammar

Expression = expression:(___ AnyLink ___)* 
{
  var result = [];
  for (var i = 0; i < expression.length; i++)
    result.push(expression[i][1]);
  return result;
}

IdentityOrLink = Identity / AnyLink

AnyLink = LinkWithId / Link

LinkWithId = id:(Id) __ _
source:(IdentityOrLink) __ _ target:(IdentityOrLink)
{ return { "Id": id, "Source": source, "Target": target }; }

Link = source:(Identity) __ _ target:(IdentityOrLink)
{ return { "Source": source, "Target": target }; }

Id = idParts:(Identity ":") { return idParts[0]; }

Identity "identity" = [0-9a-zA-Zа-яёА-ЯЁ]+ { return text(); }

_ "space" = " "

__ "newline" = "\n" / "\n\r" / "\r\n"

___ "whitespace" = [\n\r]*

@Konard
Copy link
Owner Author

Konard commented May 8, 2016

JSON:

{
  "users": [
    {
      "id": "43",
      "name": {
        "first": "John",
        "last": "Williams"
      },
      "location": "New York",
      "age": 23
    },
    {
      "id": "56",
      "name": {
        "first": "Igor",
        "middle": "Petrovich",
        "last": "Ivanov"
      },
      "location": "Moscow",
      "age": 20
    }
  ]
}

Indented LiNo:

users
  user1
    id
      43
    name
      first
        John
      last
        Williams
    location
      New York
    age
      23
  user2
    id
      56
    name
      first
        Igor
      middle
        Petrovich
      last
        Ivanov
    location
      Moscow
    age
      20

This may be useful for keeping track of the indentation level:
https://gist.github.com/dmajda/04002578dd41ae8190fc
https://github.com/otac0n/Pegasus/wiki/Significant-Whitespace-Parsing

@Konard
Copy link
Owner Author

Konard commented Mar 29, 2019

https://github.com/Konard/PegasusExample can be used to finish this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant