Code Monkey home page Code Monkey logo

jawn-to-ast's People

Contributors

matori avatar

Watchers

 avatar  avatar

jawn-to-ast's Issues

強調内でルビが最後の場合に空のStrノードが追加される

input

《《|新《あたら》しい|季節《きせつ》》》

output

{
  "type": "Document",
  "raw": "《《|新《あたら》しい|季節《きせつ》》》\n",
  "range": [
    0,
    22
  ],
  "loc": {
    "start": {
      "line": 1,
      "column": 0
    },
    "end": {
      "line": 2,
      "column": 0
    }
  },
  "children": [
    {
      "type": "Paragraph",
      "raw": "《《|新《あたら》しい|季節《きせつ》》》",
      "range": [
        0,
        21
      ],
      "loc": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 1,
          "column": 21
        }
      },
      "children": [
        {
          "type": "Emphasis",
          "raw": "《《|新《あたら》しい|季節《きせつ》》》",
          "loc": {
            "start": {
              "line": 1,
              "column": 0
            },
            "end": {
              "line": 1,
              "column": 21
            }
          },
          "range": [
            0,
            21
          ],
          "children": [
            {
              "type": "Ruby",
              "raw": "|新《あたら》",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 2
                },
                "end": {
                  "line": 1,
                  "column": 9
                }
              },
              "range": [
                2,
                9
              ],
              "children": [
                {
                  "type": "RubyBase",
                  "raw": "|新",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 2
                    },
                    "end": {
                      "line": 1,
                      "column": 4
                    }
                  },
                  "range": [
                    2,
                    4
                  ],
                  "children": [
                    {
                      "type": "Str",
                      "raw": "",
                      "value": "",
                      "loc": {
                        "start": {
                          "line": 1,
                          "column": 3
                        },
                        "end": {
                          "line": 1,
                          "column": 4
                        }
                      },
                      "range": [
                        3,
                        4
                      ]
                    }
                  ]
                },
                {
                  "type": "RubyParenthesis",
                  "raw": "",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 4
                    },
                    "end": {
                      "line": 1,
                      "column": 5
                    }
                  },
                  "range": [
                    4,
                    5
                  ],
                  "children": [
                    {
                      "type": "Str",
                      "raw": "",
                      "value": "",
                      "loc": {
                        "start": {
                          "line": 1,
                          "column": 4
                        },
                        "end": {
                          "line": 1,
                          "column": 5
                        }
                      },
                      "range": [
                        4,
                        5
                      ]
                    }
                  ]
                },
                {
                  "type": "RubyText",
                  "raw": "あたら",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 5
                    },
                    "end": {
                      "line": 1,
                      "column": 8
                    }
                  },
                  "range": [
                    5,
                    8
                  ],
                  "children": [
                    {
                      "type": "Str",
                      "raw": "あたら",
                      "value": "あたら",
                      "loc": {
                        "start": {
                          "line": 1,
                          "column": 5
                        },
                        "end": {
                          "line": 1,
                          "column": 8
                        }
                      },
                      "range": [
                        5,
                        8
                      ]
                    }
                  ]
                },
                {
                  "type": "RubyParenthesis",
                  "raw": "",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 8
                    },
                    "end": {
                      "line": 1,
                      "column": 9
                    }
                  },
                  "range": [
                    8,
                    9
                  ],
                  "children": [
                    {
                      "type": "Str",
                      "raw": "",
                      "value": "",
                      "loc": {
                        "start": {
                          "line": 1,
                          "column": 8
                        },
                        "end": {
                          "line": 1,
                          "column": 9
                        }
                      },
                      "range": [
                        8,
                        9
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "type": "Str",
              "raw": "しい",
              "value": "しい",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 2
                },
                "end": {
                  "line": 1,
                  "column": 11
                }
              },
              "range": [
                2,
                11
              ]
            },
            {
              "type": "Ruby",
              "raw": "|季節《きせつ》",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 11
                },
                "end": {
                  "line": 1,
                  "column": 19
                }
              },
              "range": [
                11,
                19
              ],
              "children": [
                {
                  "type": "RubyBase",
                  "raw": "|季節",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 11
                    },
                    "end": {
                      "line": 1,
                      "column": 14
                    }
                  },
                  "range": [
                    11,
                    14
                  ],
                  "children": [
                    {
                      "type": "Str",
                      "raw": "季節",
                      "value": "季節",
                      "loc": {
                        "start": {
                          "line": 1,
                          "column": 12
                        },
                        "end": {
                          "line": 1,
                          "column": 14
                        }
                      },
                      "range": [
                        12,
                        14
                      ]
                    }
                  ]
                },
                {
                  "type": "RubyParenthesis",
                  "raw": "",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 14
                    },
                    "end": {
                      "line": 1,
                      "column": 15
                    }
                  },
                  "range": [
                    14,
                    15
                  ],
                  "children": [
                    {
                      "type": "Str",
                      "raw": "",
                      "value": "",
                      "loc": {
                        "start": {
                          "line": 1,
                          "column": 14
                        },
                        "end": {
                          "line": 1,
                          "column": 15
                        }
                      },
                      "range": [
                        14,
                        15
                      ]
                    }
                  ]
                },
                {
                  "type": "RubyText",
                  "raw": "きせつ",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 15
                    },
                    "end": {
                      "line": 1,
                      "column": 18
                    }
                  },
                  "range": [
                    15,
                    18
                  ],
                  "children": [
                    {
                      "type": "Str",
                      "raw": "きせつ",
                      "value": "きせつ",
                      "loc": {
                        "start": {
                          "line": 1,
                          "column": 15
                        },
                        "end": {
                          "line": 1,
                          "column": 18
                        }
                      },
                      "range": [
                        15,
                        18
                      ]
                    }
                  ]
                },
                {
                  "type": "RubyParenthesis",
                  "raw": "",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 18
                    },
                    "end": {
                      "line": 1,
                      "column": 19
                    }
                  },
                  "range": [
                    18,
                    19
                  ],
                  "children": [
                    {
                      "type": "Str",
                      "raw": "",
                      "value": "",
                      "loc": {
                        "start": {
                          "line": 1,
                          "column": 18
                        },
                        "end": {
                          "line": 1,
                          "column": 19
                        }
                      },
                      "range": [
                        18,
                        19
                      ]
                    }
                  ]
                }
              ]
            },
            {
              "type": "Str",
              "raw": "",
              "value": "",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 19
                },
                "end": {
                  "line": 1,
                  "column": 19
                }
              },
              "range": [
                19,
                19
              ]
            }
          ]
        }
      ]
    },
    {
      "type": "Break",
      "raw": "\n",
      "value": "\n",
      "range": [
        21,
        22
      ],
      "loc": {
        "start": {
          "line": 1,
          "column": 21
        },
        "end": {
          "line": 1,
          "column": 22
        }
      }
    }
  ]
}
{
  "type": "RubyParenthesis",
  "raw": ""
}

の次のノード

ルビが連続したときに、ルビ間に空のStrノードが入っている

import { parse } from 'jawn-to-ast';

const input = `|親A《ルビA》|親B《ルビB》`;
const AST = parse(input);
console.log(JSON.stringify(AST, null, 2));
{
  "type": "Document",
  "raw": "|親A《ルビA》|親B《ルビB》",
  "range": [
    0,
    16
  ],
  "loc": {
    "start": {
      "line": 1,
      "column": 0
    },
    "end": {
      "line": 1,
      "column": 16
    }
  },
  "children": [
    {
      "type": "Paragraph",
      "raw": "|親A《ルビA》|親B《ルビB》",
      "range": [
        0,
        16
      ],
      "loc": {
        "start": {
          "line": 1,
          "column": 0
        },
        "end": {
          "line": 1,
          "column": 16
        }
      },
      "children": [
        {
          "type": "Ruby",
          "raw": "|親A《ルビA》",
          "loc": {
            "start": {
              "line": 1,
              "column": 0
            },
            "end": {
              "line": 1,
              "column": 8
            }
          },
          "range": [
            0,
            8
          ],
          "children": [
            {
              "type": "RubyBase",
              "raw": "|親A",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 0
                },
                "end": {
                  "line": 1,
                  "column": 3
                }
              },
              "range": [
                0,
                3
              ],
              "children": [
                {
                  "type": "Str",
                  "raw": "親A",
                  "value": "親A",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 1
                    },
                    "end": {
                      "line": 1,
                      "column": 3
                    }
                  },
                  "range": [
                    1,
                    3
                  ]
                }
              ]
            },
            {
              "type": "RubyParenthesis",
              "raw": "",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 3
                },
                "end": {
                  "line": 1,
                  "column": 4
                }
              },
              "range": [
                3,
                4
              ],
              "children": [
                {
                  "type": "Str",
                  "raw": "",
                  "value": "",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 3
                    },
                    "end": {
                      "line": 1,
                      "column": 4
                    }
                  },
                  "range": [
                    3,
                    4
                  ]
                }
              ]
            },
            {
              "type": "RubyText",
              "raw": "ルビA",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 4
                },
                "end": {
                  "line": 1,
                  "column": 7
                }
              },
              "range": [
                4,
                7
              ],
              "children": [
                {
                  "type": "Str",
                  "raw": "ルビA",
                  "value": "ルビA",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 4
                    },
                    "end": {
                      "line": 1,
                      "column": 7
                    }
                  },
                  "range": [
                    4,
                    7
                  ]
                }
              ]
            },
            {
              "type": "RubyParenthesis",
              "raw": "",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 7
                },
                "end": {
                  "line": 1,
                  "column": 8
                }
              },
              "range": [
                7,
                8
              ],
              "children": [
                {
                  "type": "Str",
                  "raw": "",
                  "value": "",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 7
                    },
                    "end": {
                      "line": 1,
                      "column": 8
                    }
                  },
                  "range": [
                    7,
                    8
                  ]
                }
              ]
            }
          ]
        },
        {
          "type": "Str",
          "raw": "",
          "value": "",
          "loc": {
            "start": {
              "line": 1,
              "column": 0
            },
            "end": {
              "line": 1,
              "column": 8
            }
          },
          "range": [
            0,
            8
          ]
        },
        {
          "type": "Ruby",
          "raw": "|親B《ルビB》",
          "loc": {
            "start": {
              "line": 1,
              "column": 8
            },
            "end": {
              "line": 1,
              "column": 16
            }
          },
          "range": [
            8,
            16
          ],
          "children": [
            {
              "type": "RubyBase",
              "raw": "|親B",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 8
                },
                "end": {
                  "line": 1,
                  "column": 11
                }
              },
              "range": [
                8,
                11
              ],
              "children": [
                {
                  "type": "Str",
                  "raw": "親B",
                  "value": "親B",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 9
                    },
                    "end": {
                      "line": 1,
                      "column": 11
                    }
                  },
                  "range": [
                    9,
                    11
                  ]
                }
              ]
            },
            {
              "type": "RubyParenthesis",
              "raw": "",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 11
                },
                "end": {
                  "line": 1,
                  "column": 12
                }
              },
              "range": [
                11,
                12
              ],
              "children": [
                {
                  "type": "Str",
                  "raw": "",
                  "value": "",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 11
                    },
                    "end": {
                      "line": 1,
                      "column": 12
                    }
                  },
                  "range": [
                    11,
                    12
                  ]
                }
              ]
            },
            {
              "type": "RubyText",
              "raw": "ルビB",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 12
                },
                "end": {
                  "line": 1,
                  "column": 15
                }
              },
              "range": [
                12,
                15
              ],
              "children": [
                {
                  "type": "Str",
                  "raw": "ルビB",
                  "value": "ルビB",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 12
                    },
                    "end": {
                      "line": 1,
                      "column": 15
                    }
                  },
                  "range": [
                    12,
                    15
                  ]
                }
              ]
            },
            {
              "type": "RubyParenthesis",
              "raw": "",
              "loc": {
                "start": {
                  "line": 1,
                  "column": 15
                },
                "end": {
                  "line": 1,
                  "column": 16
                }
              },
              "range": [
                15,
                16
              ],
              "children": [
                {
                  "type": "Str",
                  "raw": "",
                  "value": "",
                  "loc": {
                    "start": {
                      "line": 1,
                      "column": 15
                    },
                    "end": {
                      "line": 1,
                      "column": 16
                    }
                  },
                  "range": [
                    15,
                    16
                  ]
                }
              ]
            }
          ]
        }
      ]
    }
  ]
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.