         comment: "third section of the file - user code"
         contentName: "meta.section.user-code.jisonlex"
         end: "\\Z.\\A(?# never end)"
-        patterns: [
-          {
-            include: "#jssource"
-          }
-        ]
+        patterns: [include: "#user_code_section"]
       }
     ]
   }
 ]
+
 repository:
+  definitions_section:
+    patterns: [
+      {
+        include: "#includes"
+      }
+      {
+        begin: "/\\*"
+        end: "\\*/|$"
+        name: "comment.block.js.jisonlex"
+      }
+      {
+        begin: "^(?i)([a-z_][a-z0-9_-]*)(?=\\s|$)"
+        beginCaptures:
+          1:
+            name: "entity.name.function.jisonlex"
+        end: "$"
+        name: "meta.definition.jisonlex"
+        patterns: [
+          {
+            include: "#regexp"
+          }
+        ]
+      }
+      {
+        begin: "^(%[sx])(?=\\s|$)"
+        beginCaptures:
+          1:
+            name: "punctuation.definition.start-condition.jisonlex"
+        end: "$"
+        name: "meta.start-condition.jisonlex"
+        patterns: [
+          {
+            match: "(?i)[a-z_][a-z0-9_-]*"
+          }
+          {
+            match: "\\S"
+            name: "invalid.illegal.jisonlex"
+          }
+        ]
+      }
+      {
+        begin: "^(%option)\\s(?=\\S)"
+        beginCaptures:
+          1:
+            name: "keyword.other.option.jisonlex"
+        end: "$"
+        name: "meta.options.jisonlex"
+        patterns: [
+          {
+            match: "\\b(?:(?:no)?(?:[78]bit|align|backup|batch|c\\+\\+|debug|default|ecs|fast|full|interactive|lex-compat|meta-ecs|perf-report|read|stdout|verbose|warn|array|pointer|input|unput|yy_(?:(?:push|pop|top)_state|scan_(?:buffer|bytes|string))|main|stack|stdinit|yylineno|yywrap)|(?:case(?:ful|less)|case-(?:in)?sensitive|(?:always|never)-interactive))\\b"
+            name: "support.other.option.jisonlex"
+          }
+        ]
+      }
+      {
+        begin: "^%(?:array|pointer)"
+        end: "$"
+        name: "keyword.other.option.jisonlex"
+        patterns: [
+          {
+            match: "\\S"
+            name: "invalid.illegal.jisonlex"
+          }
+        ]
+      }
+    ]
+
+  rules_section:
+    patterns: [
+      {
+        begin: "^(?!$)"
+        end: "$"
+        name: "meta.rule.jisonlex"
+        patterns: [
+          {
+            include: "#includes"
+          }
+          {
+            begin: "(?i)^(<(?:(?:[a-z_][a-z0-9_-]*,)*[a-z_][a-z0-9_-]|\\*)>)?(?:(<<EOF>>)(\\s*))?(?=\\S)"
+            beginCaptures:
+              1:
+                name: "keyword.other.start-condition.jisonlex"
+              2:
+                name: "keyword.operator.eof.jisonlex"
+              3:
+                name: "invalid.illegal.regexp.jisonlex"
+            comment: "rule pattern"
+            end: "(?=\\s)|$"
+            patterns: [
+              {
+                include: "#regexp"
+              }
+            ]
+          }
+          {
+            begin: "(%\\{)"
+            beginCaptures:
+              1:
+                name: "punctuation.definition.code.jisonlex"
+            comment: "TODO: %} should override embedded scopes"
+            end: "(%\\})(.*)"
+            endCaptures:
+              1:
+                name: "punctuation.terminator.code.jisonlex"
+              2:
+                name: "invalid.illegal.ignored.jisonlex"
+            patterns: [
+              {
+                include: "#jssource"
+              }
+            ]
+          }
+          {
+            begin: "(?=\\S)"
+            comment: "TODO: eol should override embedded scopes"
+            end: "$"
+            name: "meta.rule.action.jisonlex"
+            patterns: [
+              {
+                include: "#jssource"
+              }
+            ]
+          }
+        ]
+      }
+    ]
+
+  user_code_section:
+    patterns: [
+      {
+        include: "#jssource"
+      }
+    ]
+
+
   jssource:
     patterns: [
       {

        comment: "second section of the file - rules"
        end: "^(?=%%$)"
        name: "meta.section.rules.jisonlex"
        patterns: [
          {
            begin: "^(?!$)"
            end: "$"
            name: "meta.rule.jisonlex"
            patterns: [
              {
                include: "#includes"
              }
              {
                begin: "(?i)^(<(?:(?:[a-z_][a-z0-9_-]*,)*[a-z_][a-z0-9_-]|\\*)>)?(?:(<<EOF>>)(\\s*))?(?=\\S)"
                beginCaptures:
                  1:
                    name: "keyword.other.start-condition.jisonlex"
                  2:
                    name: "keyword.operator.eof.jisonlex"
                  3:
                    name: "invalid.illegal.regexp.jisonlex"
                comment: "rule pattern"
                end: "(?=\\s)|$"
                patterns: [
                  {
                    include: "#regexp"
                  }
                ]
              }
              {
                begin: "(%\\{)"
                beginCaptures:
                  1:
                    name: "punctuation.definition.code.jisonlex"
                comment: "TODO: %} should override embedded scopes"
                end: "(%\\})(.*)"
                endCaptures:
                  1:
                    name: "punctuation.terminator.code.jisonlex"
                  2:
                    name: "invalid.illegal.ignored.jisonlex"
                patterns: [
                  {
                    include: "#jssource"
                  }
                ]
              }
              {
                begin: "(?=\\S)"
                comment: "TODO: eol should override embedded scopes"
                end: "$"
                name: "meta.rule.action.jisonlex"
                patterns: [
                  {
                    include: "#jssource"
                  }
                ]
              }
            ]
          }
        ]
      }
      {
        begin: "^(%%)$"

    comment: "first section of the file - definitions"
    end: "^(?=%%$)"
    name: "meta.section.definitions.jisonlex"
    patterns: [include: "#definitions_section"]
  }
  {
    begin: "^(%%)$"
