Skip to content

Instantly share code, notes, and snippets.

@rksm
Last active May 18, 2017 01:24
Show Gist options
  • Save rksm/1397dd160826c2e8f7fe5048cfaaf390 to your computer and use it in GitHub Desktop.
Save rksm/1397dd160826c2e8f7fe5048cfaaf390 to your computer and use it in GitHub Desktop.
first-mate-web
<!DOCTYPE html>
<html>
<head>
<title>first-mate-web</title>
</head>
<body>
<h2>expected</h2>
<pre>
[ { value: 'var', scopes: [ 'source.js', 'storage.type.var.js' ] },
{ value: ' x ', scopes: [ 'source.js' ] },
{ value: '=',
scopes: [ 'source.js', 'keyword.operator.assignment.js' ] },
{ value: ' ', scopes: [ 'source.js' ] },
{ value: '123',
scopes: [ 'source.js', 'constant.numeric.decimal.js' ] },
{ value: ';',
scopes: [ 'source.js', 'punctuation.terminator.statement.js' ] } ]
</pre>
<h2>actual</h2>
<pre id="out"></pre>
<script src="https://rawgit.com/rksm/first-mate-web/master/build/first-mate-web.js"></script>
<script src="https://wzrd.in/debug-standalone/cson-parser@latest"></script>
<script>
(async function() {
let registry = new first_mate.GrammarRegistry(),
grammarURL = "https://rawgit.com/atom/language-javascript/master/grammars/javascript.cson",
grammar = await new Promise((resolve, reject) =>
registry.loadGrammar(grammarURL, (err, g) => err ? reject(err) : resolve(g))),
tokenized = grammar.tokenizeLine('var x = 123;', null),
tokens = registry.decodeTokens(tokenized.line, tokenized.tags);
document.querySelector("#out").textContent = JSON.stringify(tokens, null, 2);
})();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment