Skip to content

Commit

Permalink
Upgrade Moo!
Browse files Browse the repository at this point in the history
A time when reading one's own release notes comes in handy.
  • Loading branch information
tjvr committed Oct 17, 2017
1 parent 83db189 commit ac8cdcd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
18 changes: 9 additions & 9 deletions editor/grammar.ne
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ const moo = require('moo')

const backslashes = s => s.replace(/\\["\\]/g, x => x[1])


let lexer = moo.compile([
{name: 'NL', match: '\n', lineBreaks: true },
{name: 'WS', match: /[ \t]+/},
{name: 'ellips', match: /\.{3}/},
{name: 'comment', match: /\/{2}(.*)$/},
{name: 'comment', match: /\/{2}(?:.*)$/, value: x => x.slice(2)},
{name: 'false', match: '<>'},
{name: 'zero', match: '()'},
{name: 'empty', match: '_'},
{name: 'number', match: /([0-9]+(?:\.[0-9]+)?e-?[0-9]+)/}, // 123[.123]e[-]123
{name: 'number', match: /((?:0|[1-9][0-9]*)?\.[0-9]+)/}, // [123].123
{name: 'number', match: /((?:0|[1-9][0-9]*)\.[0-9]*)/}, // 123.[123]
{name: 'number', match: /(0|[1-9][0-9]*)/}, // 123
{name: 'color', match: /#([A-Fa-f0-9]{3}(?:[A-Fa-f0-9]{3})?)/},
{name: 'string', match: /"((?:\\["\\]|[^\n"\\])*)"/}, // strings are backslash-escaped
{name: 'string', match: /'((?:\\['\\]|[^\n'\\])*)'/},
{name: 'number', match: /[0-9]+(?:\.[0-9]+)?e-?[0-9]+/}, // 123[.123]e[-]123
{name: 'number', match: /(?:0|[1-9][0-9]*)?\.[0-9]+/}, // [123].123
{name: 'number', match: /(?:0|[1-9][0-9]*)\.[0-9]*/}, // 123.[123]
{name: 'number', match: /0|[1-9][0-9]*/}, // 123
{name: 'color', match: /#[A-Fa-f0-9]{3}(?:[A-Fa-f0-9]{3})?/, value: x => x.slice(1)},
// strings are backslash-escaped
{name: 'string', match: /"(?:(?:\\["\\]|[^\n"\\])*)"/, value: x => x.slice(1, -1)},
{name: 'string', match: /'(?:(?:\\['\\]|[^\n'\\])*)'/, value: x => x.slice(1, -1)},
{name: 'lparen', match: '('},
{name: 'rparen', match: ')'},
{name: 'langle', match: '<'},
Expand Down
4 changes: 2 additions & 2 deletions editor/mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ CodeMirror.defineMode('tosh', module.exports = function(cfg, modeCfg) {
const ranges = []
for (var i=remaining.length; i--; ) {
const token = remaining[i]
const text = line.substr(token.offset, token.size)
const text = line.substr(token.offset, token.text.length)
ranges.push({className: 'error', text})
}

Expand All @@ -149,7 +149,7 @@ CodeMirror.defineMode('tosh', module.exports = function(cfg, modeCfg) {

// TODO can we avoid running highlighting if CM is using processLine?
completer.highlight(startCol, endCol, (className, token) => {
const text = line.substr(token.offset, token.size)
const text = line.substr(token.offset, token.text.length)
if (text === '{') { this.indent++ }
if (text === '}') { this.indent-- }
ranges.push({
Expand Down
1 change: 1 addition & 0 deletions editor/reverse.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const grammar = nearley.Grammar.fromCompiled(require('../editor/grammar'))
const reverse = require('nearley-reverse')
const itt = require('itt')

// TODO backslash-escaping, single or double quotes, etc
const str = JSON.stringify

function generate(scripts) {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"dependencies": {
"codemirror": "^5.25.0",
"jszip": "^2",
"moo": "^0.3.2",
"nearley": "^2.11.0",
"moo": "^0.4.2",
"nearley": "git://github.com/hardmath123/nearley.git#05e4c47",
"nearley-reverse": "git://github.com/tjvr/nearley-reverse.git#f32249d",
"v2": "git://github.com/nathan/v2.git#03984d2"
},
Expand Down
13 changes: 7 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2240,9 +2240,9 @@ [email protected], "mkdirp@>=0.5 0", mkdirp@^0.5.1, mkdirp@~0.5.0:
dependencies:
minimist "0.0.8"

moo@^0.3.2:
version "0.3.3"
resolved "https://registry.yarnpkg.com/moo/-/moo-0.3.3.tgz#a05ec95ea2bf29777cc402eeb5b20ac757128786"
moo@^0.4.2:
version "0.4.3"
resolved "https://registry.yarnpkg.com/moo/-/moo-0.4.3.tgz#3f847a26f31cf625a956a87f2b10fbc013bfd10e"

[email protected]:
version "2.0.0"
Expand All @@ -2262,13 +2262,14 @@ natural-compare@^1.4.0:
dependencies:
nearley "^2.11.0"

nearley@^2.11.0:
nearley@^2.11.0, "nearley@git://github.com/hardmath123/nearley.git#05e4c47":
version "2.11.0"
resolved "https://registry.yarnpkg.com/nearley/-/nearley-2.11.0.tgz#5e626c79a6cd2f6ab9e7e5d5805e7668967757ae"
resolved "git://github.com/hardmath123/nearley.git#05e4c4745d825724a5099d5c05e0525ac7dc5e1b"
dependencies:
nomnom "~1.6.2"
railroad-diagrams "^1.0.0"
randexp "^0.4.2"
semver "^5.4.1"

node-int64@^0.4.0:
version "0.4.0"
Expand Down Expand Up @@ -2884,7 +2885,7 @@ sax@^1.2.1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9"

"semver@2 || 3 || 4 || 5", semver@^5.3.0:
"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1:
version "5.4.1"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e"

Expand Down

0 comments on commit ac8cdcd

Please sign in to comment.