Comparing version 0.0.1 to 0.0.2
315
lib/3-chr.js
// Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var $new, BNP, TRM, XRE, alert, badge, debug, echo, help, info, log, rpr, warn, whisper, ƒ; | ||
var BNP, TRM, XRE, alert, badge, debug, echo, help, info, log, rpr, warn, whisper, ƒ; | ||
@@ -27,15 +27,41 @@ TRM = require('coffeenode-trm'); | ||
BNP = require('coffeenode-bitsnpieces'); | ||
ƒ = require('flowmatic'); | ||
$new = ƒ["new"]; | ||
this.$new = ƒ["new"]["new"](this); | ||
BNP = require('coffeenode-bitsnpieces'); | ||
XRE = require('./9-xre'); | ||
this.$_constants = { | ||
'ascii-punctuation': "-!\"#%&'()*,./:;?@[\\]_{}", | ||
this.$ = { | ||
/* ASCII Punctuation: */ | ||
'ascii-punctuation': /[-_!"\#%&'(\[{\\}\])*,.\/:;?@]/, | ||
/* Whitespace: */ | ||
/* Unicode line endings (RegEx should have the global flag set): */ | ||
'newlines': /\r\n|[\n\v\f\r\x85\u2028\u2029]/g, | ||
/* Unicode linear whitespace: */ | ||
'linear-whitespace': XRE('\\L+'), | ||
/* Anything but whitespace: */ | ||
'no-whitespace': /[^\s\x85]+/, | ||
/* Names: */ | ||
/* Leading character in names (excluding sigils): */ | ||
'name-first-chr': XRE('\\p{L}'), | ||
/* Trailing characters in names: */ | ||
'name-trailing-chrs': XRE('(?:-|\\p{L}|\\d)*'), | ||
/* Character used to form URL-like routes out of crumbs: */ | ||
'crumbs-joiner': '/', | ||
/* Sigils may start and classify simple names: */ | ||
'sigils': { | ||
'@': 'attribute', | ||
'~': 'system', | ||
'.': 'hidden', | ||
@@ -48,72 +74,170 @@ '_': 'private', | ||
this.$new.$ascii_punctuation = function(G, $) { | ||
var R; | ||
R = ƒ.regex($['ascii-punctuation']); | ||
return R; | ||
}; | ||
/* TAINT `ƒ.or` is an expedient here */ | ||
this.$new.$chr = function(G, $) { | ||
var R; | ||
R = ƒ.regex(XRE('.', 'Qs')); | ||
R = R.onMatch(function(match) { | ||
return match[0]; | ||
}); | ||
return R; | ||
}; | ||
/* TAINT no memoizing */ | ||
/* TAINT `ƒ.or` is an expedient here */ | ||
this.$_ascii_punctuation = ƒ.or((function(_this) { | ||
return function() { | ||
return ƒ.regex(XRE('[' + (XRE.$esc(_this.$_constants['ascii-punctuation'])) + ']')); | ||
}; | ||
})(this)); | ||
this.$new.chr = function(G, $) { | ||
var R; | ||
R = ƒ.or(function() { | ||
return G.$chr; | ||
}); | ||
R = R.onMatch(function(match) { | ||
return ƒ["new"].literal('chr', match, match); | ||
}); | ||
return R; | ||
}; | ||
this.$_chr = (ƒ.regex(XRE('.', 'Qs'))).onMatch(function(match) { | ||
return match[0]; | ||
}); | ||
/* TAINT `ƒ.or` is an expedient here */ | ||
this.chr = (ƒ.or(this.$_chr)).onMatch(function(match) { | ||
return $new.literal('chr', match, match); | ||
}); | ||
this.$new.$letter = function(G, $) { | ||
var R; | ||
R = ƒ.regex(XRE('\\p{L}')); | ||
R = R.onMatch(function(match) { | ||
return match[0]; | ||
}); | ||
return R; | ||
}; | ||
this.$new.$lws = function(G, $) { | ||
/* Linear WhiteSpace */ | ||
/* Linear WhiteSpace */ | ||
var R; | ||
R = ƒ.regex($['linear-whitespace']); | ||
R = R.onMatch(function(match) { | ||
return match[0]; | ||
}); | ||
R = R.describe('linear whitespace'); | ||
return R; | ||
}; | ||
this.lws = (ƒ.regex(/\x20+/)).onMatch(function(match) { | ||
return $new.literal('lws', match[0], match[0]); | ||
}); | ||
this.$new.lws = function(G, $) { | ||
/* Linear WhiteSpace */ | ||
var R; | ||
R = G.$lws.onMatch(function(match) { | ||
return ƒ["new"].literal('lws', match, match); | ||
}); | ||
R = R.describe('linear whitespace'); | ||
return R; | ||
}; | ||
/* invisible LWS */ | ||
this.$new.ilws = function(G, $) { | ||
this.ilws = ƒ.drop(ƒ.regex(/\x20+/)); | ||
/* invisible LWS */ | ||
var R; | ||
R = ƒ.drop(ƒ.regex($['linear-whitespace'])); | ||
return R; | ||
}; | ||
this.$new.$nws = function(G, $) { | ||
/* no WhiteSpace */ | ||
/* no WhiteSpace */ | ||
var R; | ||
R = ƒ.regex($['no-whitespace']); | ||
return R; | ||
}; | ||
this.$nws = ƒ.regex(/[^\s\x85]+/); | ||
this.$new.nws = function(G, $) { | ||
var R; | ||
R = ƒ.or(function() { | ||
return G.$nws.onMatch(function(match) { | ||
return ƒ["new"].literal('nws', match[0], match[0]); | ||
}); | ||
}); | ||
R = R.describe("no-whitespace"); | ||
return R; | ||
}; | ||
this.$new.$nl = function(G, $) { | ||
var R; | ||
R = ƒ.regex($['newlines']); | ||
return R; | ||
}; | ||
/* TAINT better way to chain methods? */ | ||
this.$new.$name_first_chr = function(G, $) { | ||
var R; | ||
R = ƒ.regex($['name-first-chr']); | ||
R = R.onMatch(function(match) { | ||
return match[0]; | ||
}); | ||
R = R.describe('first character of name'); | ||
return R; | ||
}; | ||
this.nws = this.$nws.onMatch((function(_this) { | ||
return function(match) { | ||
return $new.literal('nws', match[0], match[0]); | ||
}; | ||
})(this)); | ||
this.$new.$name_trailing_chrs = function(G, $) { | ||
var R; | ||
R = ƒ.regex($['name-trailing-chrs']); | ||
R = R.onMatch(function(match) { | ||
return match[0]; | ||
}); | ||
R = R.describe('trailing characters of name'); | ||
return R; | ||
}; | ||
this.nws = this.nws.describe("no-whitespace"); | ||
this.$new.$name_sigil = function(G, $) { | ||
var R, key, sigils; | ||
sigils = ((function() { | ||
var _results; | ||
_results = []; | ||
for (key in $['sigils']) { | ||
_results.push(XRE.$esc(key)); | ||
} | ||
return _results; | ||
})()).join(''); | ||
R = ƒ.regex(XRE("[" + sigils + "]")); | ||
R = R.onMatch(function(match) { | ||
return match[0]; | ||
}); | ||
R = R.describe('name'); | ||
return R; | ||
}; | ||
this.$new.$name = function(G, $) { | ||
var R; | ||
R = ƒ.seq(ƒ.optional(function() { | ||
return G.$name_sigil; | ||
}), (function() { | ||
return G.$name_first_chr; | ||
}), (function() { | ||
return G.$name_trailing_chrs; | ||
})); | ||
R = R.onMatch(function(match) { | ||
return match.join(''); | ||
}); | ||
R = R.describe('name'); | ||
return R; | ||
}; | ||
/* Unicode line endings: */ | ||
this.$nl_re = /\r\n|[\n\v\f\r\x85\u2028\u2029]/g; | ||
/* Run `@$new` to make `@` (`this`) an instance of this grammar with default options: */ | ||
this.$nl = ƒ.regex(this.$nl_re); | ||
this.$new(this, null); | ||
this.$TESTS = { | ||
'$chr: matches code points (instead of code units) and newlines': function(test) { | ||
test.eq(this.$_chr.run('x'), 'x'); | ||
test.eq(this.$_chr.run('\r'), '\r'); | ||
test.eq(this.$_chr.run('\n'), '\n'); | ||
return test.eq(this.$_chr.run('𠀝'), '𠀝'); | ||
test.eq(this.$chr.run('x'), 'x'); | ||
test.eq(this.$chr.run('\r'), '\r'); | ||
test.eq(this.$chr.run('\n'), '\n'); | ||
return test.eq(this.$chr.run('𠀝'), '𠀝'); | ||
}, | ||
'chr: matches code points (instead of code units) and newlines': function(test) { | ||
test.eq(this.chr.run('x'), $new.literal('chr', 'x', 'x')); | ||
test.eq(this.chr.run('\r'), $new.literal('chr', '\r', '\r')); | ||
test.eq(this.chr.run('\n'), $new.literal('chr', '\n', '\n')); | ||
return test.eq(this.chr.run('𠀝'), $new.literal('chr', '𠀝', '𠀝')); | ||
test.eq(this.chr.run('x'), ƒ["new"].literal('chr', 'x', 'x')); | ||
test.eq(this.chr.run('\r'), ƒ["new"].literal('chr', '\r', '\r')); | ||
test.eq(this.chr.run('\n'), ƒ["new"].literal('chr', '\n', '\n')); | ||
return test.eq(this.chr.run('𠀝'), ƒ["new"].literal('chr', '𠀝', '𠀝')); | ||
}, | ||
@@ -126,3 +250,3 @@ '$chr: accepts single character, be it one or two code units': function(test) { | ||
_ref = probes_and_results[_i], probe = _ref[0], result = _ref[1]; | ||
_results.push(test.eq(this.$_chr.run(probe), result)); | ||
_results.push(test.eq(this.$chr.run(probe), result)); | ||
} | ||
@@ -139,3 +263,3 @@ return _results; | ||
return function() { | ||
return _this.$_chr.run(probe); | ||
return _this.$chr.run(probe); | ||
}; | ||
@@ -154,3 +278,3 @@ })(this)), /Expected end/)); | ||
return function() { | ||
return _this.$_ascii_punctuation.run(probe); | ||
return _this.$ascii_punctuation.run(probe); | ||
}; | ||
@@ -197,3 +321,3 @@ })(this)), /Expected /)); | ||
probe = probes[_i]; | ||
_results.push(test.eq(this.nws.run(probe), $new.literal('nws', probe, probe))); | ||
_results.push(test.eq(this.nws.run(probe), ƒ["new"].literal('nws', probe, probe))); | ||
} | ||
@@ -208,3 +332,3 @@ return _results; | ||
probe = probes[_i]; | ||
_results.push(test.eq(this.lws.run(probe), $new.literal('lws', probe, probe))); | ||
_results.push(test.eq(this.lws.run(probe), ƒ["new"].literal('lws', probe, probe))); | ||
} | ||
@@ -223,7 +347,88 @@ return _results; | ||
}, | ||
'$nl_re: splits string with Unicode line endings correctly': function(test) { | ||
return test.eq('1\r\n2\n3\v4\f5\r6\x857\u20288\u20299'.split(this.$nl_re), ['1', '2', '3', '4', '5', '6', '7', '8', '9']); | ||
"G$[ 'newlines' ]: splits string with Unicode line endings correctly": function(test) { | ||
var G; | ||
G = this; | ||
return test.eq('1\r\n2\n3\v4\f5\r6\x857\u20288\u20299'.split(this.$['newlines']), ['1', '2', '3', '4', '5', '6', '7', '8', '9']); | ||
}, | ||
'$nl_re: allows global replace': function(test) { | ||
return test.eq('1\r\n2\n3\v4\f5\r6\x857\u20288\u20299'.replace(this.$nl_re, '#'), '1#2#3#4#5#6#7#8#9'); | ||
"G$[ 'newlines' ]: allows global replace": function(test) { | ||
return test.eq('1\r\n2\n3\v4\f5\r6\x857\u20288\u20299'.replace(this.$['newlines'], '#'), '1#2#3#4#5#6#7#8#9'); | ||
}, | ||
'$letter: matches single letters, including 32bit code points': function(test) { | ||
var probe, probes_and_results, result, _i, _len, _ref, _results; | ||
probes_and_results = [['q', 'q'], ['中', '中'], ['𠀝', '𠀝']]; | ||
_results = []; | ||
for (_i = 0, _len = probes_and_results.length; _i < _len; _i++) { | ||
_ref = probes_and_results[_i], probe = _ref[0], result = _ref[1]; | ||
_results.push(test.eq(this.$letter.run(probe), result)); | ||
} | ||
return _results; | ||
}, | ||
'$letter: rejects anything but single letters': function(test) { | ||
var probe, probes, _i, _len, _results; | ||
probes = ['0', '-', '(', '؟', 'xx']; | ||
_results = []; | ||
for (_i = 0, _len = probes.length; _i < _len; _i++) { | ||
probe = probes[_i]; | ||
_results.push(test.throws(((function(_this) { | ||
return function() { | ||
return _this.$letter.run(probe); | ||
}; | ||
})(this)), /Expected/)); | ||
} | ||
return _results; | ||
}, | ||
'$name_first_chr: matches first character of names': function(test) { | ||
var probe, probes, _i, _len, _results; | ||
probes = ['a', 'A', '𠀁']; | ||
_results = []; | ||
for (_i = 0, _len = probes.length; _i < _len; _i++) { | ||
probe = probes[_i]; | ||
_results.push(test.eq(this.$name_first_chr.run(probe), probe)); | ||
} | ||
return _results; | ||
}, | ||
'$name_trailing_chrs: matches trailing characters of names': function(test) { | ||
var probe, probes, _i, _len, _results; | ||
probes = ['abc', 'abc-def', 'abc-def-45']; | ||
_results = []; | ||
for (_i = 0, _len = probes.length; _i < _len; _i++) { | ||
probe = probes[_i]; | ||
_results.push(test.eq(this.$name_trailing_chrs.run(probe), probe)); | ||
} | ||
return _results; | ||
}, | ||
'$name: matches names': function(test) { | ||
var probe, probes, _i, _len, _results; | ||
probes = ['n', 'n0', 'readable-names', 'foo-32']; | ||
_results = []; | ||
for (_i = 0, _len = probes.length; _i < _len; _i++) { | ||
probe = probes[_i]; | ||
_results.push(test.eq(this.$name.run(probe), probe)); | ||
} | ||
return _results; | ||
}, | ||
'$name: matches names with sigils': function(test) { | ||
var probe, probes, _i, _len, _results; | ||
probes = ['@n', '%n0', '_readable-names', '.foo-32', '~isa']; | ||
_results = []; | ||
for (_i = 0, _len = probes.length; _i < _len; _i++) { | ||
probe = probes[_i]; | ||
whisper(probe); | ||
_results.push(test.eq(this.$name.run(probe), probe)); | ||
} | ||
return _results; | ||
}, | ||
'$name: rejects non-names': function(test) { | ||
var probe, probes, _i, _len, _results; | ||
probes = ['034', '-/-', '()', '؟?']; | ||
_results = []; | ||
for (_i = 0, _len = probes.length; _i < _len; _i++) { | ||
probe = probes[_i]; | ||
_results.push(test.throws(((function(_this) { | ||
return function() { | ||
return _this.$name.run(probe); | ||
}; | ||
})(this)), /Expected/)); | ||
} | ||
return _results; | ||
} | ||
@@ -230,0 +435,0 @@ }; |
@@ -18,3 +18,3 @@ // Generated by CoffeeScript 1.6.3 | ||
(function() { | ||
var $new, CHR, TRM, TYPES, XRE, alert, badge, debug, echo, help, info, log, rainbow, rpr, warn, whisper, ƒ, | ||
var CHR, TRM, TYPES, XRE, alert, badge, debug, echo, help, info, log, rainbow, rpr, warn, whisper, ƒ, | ||
__slice = [].slice; | ||
@@ -50,3 +50,3 @@ | ||
$new = ƒ["new"]; | ||
this.$new = ƒ["new"]["new"](this); | ||
@@ -102,5 +102,3 @@ CHR = require('./3-chr'); | ||
this.$new = $new["new"](this); | ||
/* TAINT must parameterize */ | ||
@@ -107,0 +105,0 @@ |
146
lib/9-xre.js
// Generated by CoffeeScript 1.6.3 | ||
/* | ||
[Whitespace in Unicode 6.3](http://en.wikipedia.org/wiki/Whitespace_character): | ||
Linear: | ||
U+0009 HT, Horizontal Tab | ||
U+0020 space | ||
U+00A0 no-break space | ||
U+1680 ogham space mark | ||
U+2000 en quad | ||
U+2001 em quad | ||
U+2002 en space | ||
U+2003 em space | ||
U+2004 three-per-em space | ||
U+2005 four-per-em space | ||
U+2006 six-per-em space | ||
U+2007 figure space | ||
U+2008 punctuation space | ||
U+2009 thin space | ||
U+200A hair space | ||
U+202F narrow no-break space | ||
U+205F medium mathematical space | ||
U+3000 ideographic space | ||
Line breaking: | ||
U+000A LF, Line feed | ||
U+000B VT, Vertical Tab | ||
U+000C FF, Form feed | ||
U+000D CR, Carriage return | ||
U+0085 NEL, Next line | ||
U+2028 line separator | ||
U+2029 paragraph separator | ||
*/ | ||
(function() { | ||
var BNP, TRM, XRE, XRegExp, alert, badge, debug, echo, extension_u, help, info, log, rainbow, rpr, warn, whisper, | ||
var BNP, TRM, XRE, XRegExp, alert, badge, debug, echo, help, info, log, rainbow, rpr, warn, whisper, | ||
__slice = [].slice; | ||
@@ -52,38 +88,37 @@ | ||
extension_u = { | ||
matcher: /\\u{([0-9A-Fa-f]{1,6})}/, | ||
handler: (function() { | ||
var dec, hex, pad4; | ||
pad4 = function(s) { | ||
while (s.length < 4) { | ||
s = "0" + s; | ||
} | ||
return s; | ||
}; | ||
dec = function(hex) { | ||
return parseInt(hex, 16); | ||
}; | ||
hex = function(dec) { | ||
return parseInt(dec, 10).toString(16); | ||
}; | ||
return function(match) { | ||
var code, offset; | ||
code = dec(match[1]); | ||
offset = void 0; | ||
if (code > 0x10FFFF) { | ||
throw new SyntaxError("invalid Unicode code point " + match[0]); | ||
} | ||
if (code <= 0xFFFF) { | ||
return "\\u" + pad4(hex(code)); | ||
} | ||
offset = code - 0x10000; | ||
return "\\u" + pad4(hex(0xD800 + (offset >> 10))) + "\\u" + pad4(hex(0xDC00 + (offset & 0x3FF))); | ||
}; | ||
})(), | ||
options: { | ||
scope: 'all' | ||
} | ||
}; | ||
XRegExp.addToken(/\\u{([0-9A-Fa-f]{1,6})}/, (function() { | ||
var as_dec, as_hex, pad; | ||
pad = function(literal) { | ||
while (literal.length < 4) { | ||
'0' + literal; | ||
} | ||
return literal; | ||
}; | ||
as_dec = function(literal) { | ||
return parseInt(literal, 16); | ||
}; | ||
as_hex = function(n) { | ||
return (parseInt(n, 10)).toString(16); | ||
}; | ||
return function(match, scope, flags) { | ||
var cid, lead_surrogate, offset, trail_surrogate; | ||
cid = as_dec(match[1]); | ||
if (cid > 0x10FFFF) { | ||
throw new SyntaxError("invalid Unicode code point " + match[0]); | ||
} | ||
XRegExp.addToken(extension_u.matcher, extension_u.handler, extension_u.options); | ||
/* Converting to \uNNNN avoids needing to escape the character and keep it separate | ||
from preceding tokens: | ||
*/ | ||
if (cid <= 0xFFFF) { | ||
return "\\u" + (pad(as_hex(cid))); | ||
} | ||
offset = cid - 0x10000; | ||
lead_surrogate = pad(as_hex(0xD800 + (offset >> 10))); | ||
trail_surrogate = pad(as_hex(0xDC00 + (offset & 0x3FF))); | ||
return "\\u" + lead_surrogate + "\\u" + trail_surrogate; | ||
}; | ||
})(), { | ||
scope: 'all' | ||
}); | ||
@@ -105,2 +140,11 @@ | ||
/* Add the \L escape that matches all linear whitespace: */ | ||
XRegExp.addToken(/\\L/, function(match, scope, flags) { | ||
return "[\\u0009\\u0020\\u00A0\\u1680\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200A\\u202F\\u205F\\u3000]"; | ||
}, { | ||
scope: 'all' | ||
}); | ||
/* Add the U (ungreedy) flag from PCRE and RE2, which reverses greedy and lazy quantifiers: */ | ||
@@ -122,3 +166,3 @@ | ||
XRE.TESTS = { | ||
XRE.$TESTS = { | ||
'(all): even without flag `A`, `\\p{}` expressions match astral characters': function(test) { | ||
@@ -133,2 +177,30 @@ var matcher; | ||
}, | ||
'(all): even without flag `u`, `\\u{}` is rejected when argument is not a hexadecimal digit': function(test) { | ||
test.throws((function() { | ||
return '〇𠀝x'.match(XRegExp('\\u{}')); | ||
}), /Invalid/); | ||
return test.throws((function() { | ||
return '〇𠀝x'.match(XRegExp('\\u{xxx}')); | ||
}), /Invalid/); | ||
}, | ||
'(all): even without flag `u`, `\\u{}` is rejected when argument is beyond limits': function(test) { | ||
return test.throws((function() { | ||
return '〇𠀝x'.match(XRegExp('\\u{201234}')); | ||
}), /invalid Unicode code point/); | ||
}, | ||
'(all): `\\L` matches linear whitespace': function(test) { | ||
test.ok((XRegExp('\\L')).test(' ')); | ||
test.ok((XRegExp('\\L')).test('\t')); | ||
return test.ok((XRegExp('\\L')).test('\u3000')); | ||
}, | ||
'(all): `\\L+` matches stretches of linear whitespace': function(test) { | ||
test.eq((' \t '.match(XRegExp('\\L+')))[0], ' \t '); | ||
test.eq(('\t\t\t\t'.match(XRegExp('\\L+')))[0], '\t\t\t\t'); | ||
return test.eq(('\u3000 \t'.match(XRegExp('\\L+')))[0], '\u3000 \t'); | ||
}, | ||
'(all): `\\L` does not match other characters than linear whitespace': function(test) { | ||
test.ok(!(XRegExp('\\L')).test('x')); | ||
test.ok(!(XRegExp('\\L')).test('\n')); | ||
return test.ok(!(XRegExp('\\L')).test('\r')); | ||
}, | ||
'(`Q` flag): make dot match code points (instead of code units)': function(test) { | ||
@@ -135,0 +207,0 @@ return test.eq(('𠀝x'.match(XRegExp('.', 'Q')))[0], '𠀝'); |
{ | ||
"name": "arabika", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A language that compiles to JavaScript", | ||
@@ -5,0 +5,0 @@ "main": "lib/main.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
277769
2415
1