Uncaught Error


#1

I’ve been working on a new grammar for MUSHcode, but I’m having difficulty. Atom isn’t helping me debug my grammar and I’m not sure how to read the error message to find which regular expression is causing the problem.

As a secondary question, a bit of Googling has not revealed any guides for how to write grammars for Atom (only TextMate). Does anyone know of something like that which might not have made its way up the page ranks yet?

Atom Version: 1.7.1
System: Microsoft Windows 10 Home
Thrown From: Atom Core

Stack Trace

Uncaught Error: target of repeat operator is not specified

At C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\node_modules\first-mate\lib\scanner.js:31

Error: target of repeat operator is not specified
    at Error (native)
    at Scanner.module.exports.Scanner.createScanner (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\node_modules\first-mate\lib\scanner.js:31:24)
    at Scanner.module.exports.Scanner.getScanner (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\node_modules\first-mate\lib\scanner.js:37:31)
    at Scanner.module.exports.Scanner.findNextMatch (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\node_modules\first-mate\lib\scanner.js:56:22)
    at Rule.module.exports.Rule.findNextMatch (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\node_modules\first-mate\lib\rule.js:99:28)
    at Rule.module.exports.Rule.getNextTags (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\node_modules\first-mate\lib\rule.js:141:21)
    at Grammar.module.exports.Grammar.tokenizeLine (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\node_modules\first-mate\lib\grammar.js:150:44)
    at TokenizedBuffer.module.exports.TokenizedBuffer.buildTokenizedLineForRowWithText (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\src\tokenized-buffer.js:540:28)
    at TokenizedBuffer.module.exports.TokenizedBuffer.buildTokenizedLineForRow (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\src\tokenized-buffer.js:526:19)
    at TokenizedBuffer.module.exports.TokenizedBuffer.tokenizeNextChunk (C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\src\tokenized-buffer.js:311:43)
    at C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\src\tokenized-buffer.js:288:26
    at C:\Users\Holland\AppData\Local\atom\app-1.7.1\resources\app.asar\node_modules\underscore-plus\node_modules\underscore\underscore.js:666:47

Commands

  3x -0:32.1.0 grammar-selector:show (atom-workspace.workspace.scrollbars-visible-always.seti-ui-no-icons.theme-one-dark-syntax.theme-one-dark-ui)

Config

{
  "core": {
    "customFileTypes": {
      "source.mushcode": [
        "muc"
      ]
    },
    "openEmptyEditorOnStart": false,
    "projectHome": "D:\\github"
  },
  "editor": {
    "backUpBeforeSaving": true,
    "confirmCheckoutHeadRevision": false,
    "fontFamily": "LM Mono 10",
    "invisibles": {},
    "showIndentGuide": true,
    "softWrap": true
  }
}

Installed Packages

# User
autocomplete-html-entities, v0.1.0
autocomplete-python, v1.7.2
autocomplete-wordpress-hooks, v0.2.0
color-picker, v2.1.1
file-icons, v1.7.2
file-types, v0.5.1
minimap, v4.22.1
pigments, v0.26.0
project-manager, v2.9.7

# Dev
No dev packages

#2

Hi,

I cloned your repository and gave it a shot but I guess you are a couple of commits ahead the grammar CSON wasn’t valid. I’m in a similar boat, in that I am building a grammar for Azure Resource Manager Deployment Templates. It seems that Atom uses almost exactly the same syntax as TextMate, so much so that I haven’t found a TextMate example that hasn’t worked in Atom - in short the TextMate documentation is good :slight_smile:

In terms of editing a Grammar being a challenge, then yes Atom really doesn’t do anything to help you out - there is a package called atom-live-grammar-reload which allows you to reload a grammar each time you save the file, this makes it viable to take a ‘binary search’ methodology to find the root cause, specifically comment out half of your grammar see if the error occurs, if it does then comment out half of what is left - if it doesn’t then comment out the other half and uncomment the original block, repeat until you find the issue.

I created a little animation to demonstrate this, happy to hop on Slack and help if I can:


#3

Regarding resources for creating language packages, see the FAQ:


#4

Thanks for taking a look. I uploaded all the current files shortly before posting this thread, and I haven’t made any changes since then. I’m new to CSON, so I must be missing the bit that makes it invalid. All of the required brackets are in the right place, and I’ve read through the TextMate tutorial plus the language-javascript and language-less grammars and I can’t see anything different.

The TextMate documentation is good, and JSON syntax is easy to translate to CSON, but it’s a different platform and it takes a bit of searching to get to it (and then more searching to understand things like scope). Atom-native documentation about grammar creation would be better just due to being easier to find and requiring no translation for the user. As I’m learning about the formatting (not having been a TextMate user), I’m going through and making an annotated template that a new user (me, in this case) can drop into and start editing without having to sort through a bunch of information first and then populate a blank document with unfamiliar data structures.


#5

I’ve been following the TextMate grammar reference. I have all the correct fields filled out, in the dictionary CSON at least. That’s where my issue arises. There’s not any Atom-specific documentation, and my problem seems to be an Atom-specific problem. Does Atom look at any other files when figuring out how to handle a grammar package?

I missed the apeth.com link when I was looking before, and that seems to be pretty thorough and will probably help me in fleshing out my grammar past what’s immediately obvious from the TextMate documentation (I’ve already learned that you can have a whole dictionary inside a repository rule, which is funky and promising), but it’s not directly related to the current fatal error unless my error stems from a misunderstanding of the TextMate docs.


#6

If you install linter and coffee-lint it will lint your CSON for you as you type, not specific to grammars but it is one less thing to think about, in your case you have an error here:

'softcodeFunctions'
  'name': 'soft.function.mux' '(ostaff|andlist|dash|dice|findpc|mmm-dd-yyyy|isstaff|roll|scanobj|scan|header|footer|middle|isapproved|alert|posebreak-allow|atplace|placeinfo|whichplace|wfooter|wheader|wdivider|divider)'
  'end': '\((.?)\)'

would become

'softcodeFunctions'
  'name': 'soft.function.mux'
  'match': '(ostaff|andlist|dash|dice|findpc|mmm-dd-yyyy|isstaff|roll|scanobj|scan|header|footer|middle|isapproved|alert|posebreak-allow|atplace|placeinfo|whichplace|wfooter|wheader|wdivider|divider)'
  'end': '\((.?)\)'

#7

Damn it. Thank you. I stared at it several times and missed it each time. My newbieness showing through. I’ve installed the packages you recommended.

…and that fixed my problem. Back to work. :slight_smile:


#8

\o> - happy to help, look forward to seeing your grammar completed and published - ping me on here or on Slack if you need a sounding board, it’s always easier when you can put too heads against a problem.