Skip to content

Latest commit

 

History

History
69 lines (65 loc) · 1.13 KB

File metadata and controls

69 lines (65 loc) · 1.13 KB

Scanner Generator Backend: JSON

This backend outputs a scanner as a JSON document. See the data types in internal/scannergen/backend for details about the JSON structure.

Example

The JSON output looks like this:

{
  "rules": [
    {
      "name": "NUMBER",
      "regex": {
        "kind": "Literal",
        "literal": {
          "text": "42"
        }
      }
    },
    {
      "name": "IDENT",
      "skip": true,
      "regex": {
        "kind": "CharClass",
        "charClass": {
          "negate": true,
          "ranges": [
            {
              "low": 48,
              "high": 57
            },
            {
              "low": 97,
              "high": 122
            }
          ]
        }
      }
    }
  ],
  "states": [
    {
      "ruleIdx": 0
    },
    {
      "ruleIdx": 1,
      "accept": true,
      "transitions": [
        {
          "byteRange": {
            "low": 48,
            "high": 57
          },
          "stateIdx": 0
        },
        {
          "byteRange": {
            "low": 97,
            "high": 122
          },
          "stateIdx": 1
        }
      ]
    }
  ]
}