Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lexing

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lexing - npm Package Compare versions

Comparing version 0.3.6 to 0.4.0

browser.js

94

index.js

@@ -1,2 +0,3 @@

var __extends = this.__extends || function (d, b) {
//// export module lexing {
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];

@@ -7,4 +8,2 @@ function __() { this.constructor = d; }

};
/// <reference path="type_declarations/DefinitelyTyped/node/node.d.ts" />
var fs = require('fs');
/**

@@ -162,11 +161,11 @@ Wraps a Buffer as a stateful iterable.

When calling `read()` on the underlying file, it will read batches of
When calling `read()` on the underlying file, it will read in batches of
`_block_size` (default: 1024) bytes.
*/
var BufferedFileReader = (function () {
// when reading more data, pull in chunks of `_block_size` bytes.
function BufferedFileReader(_fd, _position, _block_size) {
var BufferedSourceReader = (function () {
// when reading more data, pull in chunks of `block_size` bytes.
function BufferedSourceReader(_source, _position, _block_size) {
if (_position === void 0) { _position = 0; }
if (_block_size === void 0) { _block_size = 1024; }
this._fd = _fd;
this._source = _source;
this._position = _position;

@@ -176,3 +175,3 @@ this._block_size = _block_size;

}
Object.defineProperty(BufferedFileReader.prototype, "position", {
Object.defineProperty(BufferedSourceReader.prototype, "position", {
/**

@@ -189,3 +188,3 @@ Return the position in the file that would be read from if we called

});
Object.defineProperty(BufferedFileReader.prototype, "size", {
Object.defineProperty(BufferedSourceReader.prototype, "size", {
/**

@@ -195,3 +194,3 @@ Return the total size (in bytes) of the underlying file.

get: function () {
return fs.fstatSync(this._fd).size;
return this._source.size;
},

@@ -207,6 +206,6 @@ enumerable: true,

*/
BufferedFileReader.prototype._fillBuffer = function (length) {
BufferedSourceReader.prototype._fillBuffer = function (length) {
var buffer = new Buffer(length);
// always read from the current position
var bytesRead = fs.readSync(this._fd, buffer, 0, length, this._position);
var bytesRead = this._source.read(buffer, 0, length, this._position);
// and update it accordingly

@@ -227,3 +226,3 @@ this._position += bytesRead;

*/
BufferedFileReader.prototype._readWhile = function (predicate) {
BufferedSourceReader.prototype._readWhile = function (predicate) {
while (predicate(this._buffer)) {

@@ -237,13 +236,13 @@ var EOF = this._fillBuffer(this._block_size);

};
return BufferedFileReader;
return BufferedSourceReader;
})();
exports.BufferedFileReader = BufferedFileReader;
var FileBufferIterator = (function (_super) {
__extends(FileBufferIterator, _super);
function FileBufferIterator(_fd, _position, _block_size) {
if (_position === void 0) { _position = 0; }
if (_block_size === void 0) { _block_size = 1024; }
_super.call(this, _fd, _position, _block_size);
exports.BufferedSourceReader = BufferedSourceReader;
var SourceBufferIterator = (function (_super) {
__extends(SourceBufferIterator, _super);
function SourceBufferIterator(source, position, block_size) {
if (position === void 0) { position = 0; }
if (block_size === void 0) { block_size = 1024; }
_super.call(this, source, position, block_size);
}
FileBufferIterator.prototype._ensureLength = function (length) {
SourceBufferIterator.prototype._ensureLength = function (length) {
var _this = this;

@@ -253,3 +252,3 @@ // all the action happens only if we need more bytes than are in the buffer

};
FileBufferIterator.prototype.next = function (length) {
SourceBufferIterator.prototype.next = function (length) {
this._ensureLength(length);

@@ -260,3 +259,3 @@ var buffer = this._buffer.slice(0, length);

};
FileBufferIterator.prototype.peek = function (length) {
SourceBufferIterator.prototype.peek = function (length) {
this._ensureLength(length);

@@ -269,5 +268,5 @@ return this._buffer.slice(0, length);

*/
FileBufferIterator.prototype.skip = function (length) {
SourceBufferIterator.prototype.skip = function (length) {
this._ensureLength(length);
// we cannot skip more than `this.buffer.length` bytes
// we cannot skip more than `this._buffer.length` bytes
var bytesSkipped = Math.min(length, this._buffer.length);

@@ -277,14 +276,14 @@ this._buffer = this._buffer.slice(length);

};
return FileBufferIterator;
})(BufferedFileReader);
exports.FileBufferIterator = FileBufferIterator;
var FileStringIterator = (function (_super) {
__extends(FileStringIterator, _super);
function FileStringIterator(_fd, _encoding, _position, _block_size) {
if (_position === void 0) { _position = 0; }
if (_block_size === void 0) { _block_size = 1024; }
_super.call(this, _fd, _position, _block_size);
return SourceBufferIterator;
})(BufferedSourceReader);
exports.SourceBufferIterator = SourceBufferIterator;
var SourceStringIterator = (function (_super) {
__extends(SourceStringIterator, _super);
function SourceStringIterator(source, _encoding, position, block_size) {
if (position === void 0) { position = 0; }
if (block_size === void 0) { block_size = 1024; }
_super.call(this, source, position, block_size);
this._encoding = _encoding;
}
FileStringIterator.prototype._ensureLength = function (length) {
SourceStringIterator.prototype._ensureLength = function (length) {
var _this = this;

@@ -294,3 +293,3 @@ // TODO: count characters without reencoding

};
FileStringIterator.prototype.next = function (length) {
SourceStringIterator.prototype.next = function (length) {
// TODO: don't re-encode the whole string and then only use a tiny bit of it

@@ -303,3 +302,3 @@ this._ensureLength(length);

};
FileStringIterator.prototype.peek = function (length) {
SourceStringIterator.prototype.peek = function (length) {
// TODO (see TODO in next())

@@ -313,3 +312,3 @@ this._ensureLength(length);

*/
FileStringIterator.prototype.skip = function (length) {
SourceStringIterator.prototype.skip = function (length) {
// TODO (see TODO in next())

@@ -327,3 +326,3 @@ this._ensureLength(length);

*/
FileStringIterator.prototype.nextBytes = function (length) {
SourceStringIterator.prototype.nextBytes = function (length) {
this._ensureLength(length);

@@ -334,7 +333,7 @@ var buffer = this._buffer.slice(0, length);

};
FileStringIterator.prototype.peekBytes = function (length) {
SourceStringIterator.prototype.peekBytes = function (length) {
this._ensureLength(length);
return this._buffer.slice(0, length);
};
FileStringIterator.prototype.skipBytes = function (length) {
SourceStringIterator.prototype.skipBytes = function (length) {
this._ensureLength(length);

@@ -345,5 +344,5 @@ var bytesSkipped = Math.min(length, this._buffer.length);

};
return FileStringIterator;
})(BufferedFileReader);
exports.FileStringIterator = FileStringIterator;
return SourceStringIterator;
})(BufferedSourceReader);
exports.SourceStringIterator = SourceStringIterator;
function Token(name, value) {

@@ -561,3 +560,4 @@ if (value === void 0) { value = null; }

if (match === null) {
throw new Error("Invalid language; could not find a match in input \"" + input + "\" for state \"" + this.name + "\"");
var clean_input = input.slice(0, 128).replace(/\r\n|\r/g, '\n').replace(/\t|\v|\f/g, ' ').replace(/\0|\b/g, '');
throw new Error("Invalid language; could not find a match in input \"" + clean_input + "\" for state \"" + this.name + "\"");
}

@@ -564,0 +564,0 @@ }

@@ -1,6 +0,38 @@

/// <reference path="type_declarations/DefinitelyTyped/node/node.d.ts" />
import fs = require('fs');
//// export module lexing {
/**
Very trimmed-down version of Node's Buffer.
*/
export interface Buffer {
new (str: string, encoding?: string): Buffer;
new (size: number): Buffer;
toString(encoding?: string, start?: number, end?: number): string;
slice(start?: number, end?: number): Buffer;
length: number;
}
declare var Buffer: {
new (str: string, encoding?: string): Buffer;
new (size: number): Buffer;
byteLength(string: string, encoding?: string): number;
concat(list: Buffer[], totalLength?: number): Buffer;
};
export interface Source {
/**
Read `length` bytes from the underlying source starting from `position`,
into the given `buffer` starting at `offset`, returning the number of bytes
read.
*/
read(buffer: Buffer, offset: number, length: number, position: number): number;
/**
Read `length` bytes of the underlying file as a Buffer. May return a
Buffer shorter than `length` iff EOF has been reached.
*/
readBuffer(length: number, position: number): Buffer;
/**
Return the total number of bytes in the underlying source.
*/
size: number;
}
// #############################################################################

@@ -188,10 +220,12 @@ // ITERABLES

When calling `read()` on the underlying file, it will read batches of
When calling `read()` on the underlying file, it will read in batches of
`_block_size` (default: 1024) bytes.
*/
export class BufferedFileReader {
export class BufferedSourceReader {
protected _buffer: Buffer = new Buffer(0);
// when reading more data, pull in chunks of `_block_size` bytes.
constructor(private _fd: number, private _position = 0, private _block_size = 1024) { }
// when reading more data, pull in chunks of `block_size` bytes.
constructor(private _source: Source,
private _position = 0,
private _block_size = 1024) { }

@@ -211,3 +245,3 @@ /**

get size(): number {
return fs.fstatSync(this._fd).size;
return this._source.size;
}

@@ -224,3 +258,3 @@

// always read from the current position
var bytesRead = fs.readSync(this._fd, buffer, 0, length, this._position);
var bytesRead = this._source.read(buffer, 0, length, this._position);
// and update it accordingly

@@ -253,5 +287,5 @@ this._position += bytesRead;

export class FileBufferIterator extends BufferedFileReader implements BufferIterable {
constructor(_fd: number, _position = 0, _block_size = 1024) {
super(_fd, _position, _block_size);
export class SourceBufferIterator extends BufferedSourceReader implements BufferIterable {
constructor(source: Source, position = 0, block_size = 1024) {
super(source, position, block_size);
}

@@ -282,3 +316,3 @@

this._ensureLength(length);
// we cannot skip more than `this.buffer.length` bytes
// we cannot skip more than `this._buffer.length` bytes
var bytesSkipped = Math.min(length, this._buffer.length);

@@ -290,5 +324,5 @@ this._buffer = this._buffer.slice(length);

export class FileStringIterator extends BufferedFileReader implements StringIterable {
constructor(_fd: number, private _encoding: string, _position = 0, _block_size = 1024) {
super(_fd, _position, _block_size);
export class SourceStringIterator extends BufferedSourceReader implements StringIterable {
constructor(source: Source, private _encoding: string, position = 0, block_size = 1024) {
super(source, position, block_size);
}

@@ -603,3 +637,4 @@

if (match === null) {
throw new Error(`Invalid language; could not find a match in input "${input}" for state "${this.name}"`);
var clean_input = input.slice(0, 128).replace(/\r\n|\r/g, '\n').replace(/\t|\v|\f/g, ' ').replace(/\0|\b/g, '');
throw new Error(`Invalid language; could not find a match in input "${clean_input}" for state "${this.name}"`);
}

@@ -606,0 +641,0 @@ }

@@ -1,4 +0,30 @@

/// <reference path="../../type_declarations/DefinitelyTyped/node/node.d.ts" />
declare module "lexing" {
/**
Very trimmed-down version of Node's Buffer.
*/
interface Buffer {
new (str: string, encoding?: string): Buffer;
new (size: number): Buffer;
toString(encoding?: string, start?: number, end?: number): string;
slice(start?: number, end?: number): Buffer;
length: number;
}
interface Source {
/**
Read `length` bytes from the underlying source starting from `position`,
into the given `buffer` starting at `offset`, returning the number of bytes
read.
*/
read(buffer: Buffer, offset: number, length: number, position: number): number;
/**
Read `length` bytes of the underlying file as a Buffer. May return a
Buffer shorter than `length` iff EOF has been reached.
*/
readBuffer(length: number, position: number): Buffer;
/**
Return the total number of bytes in the underlying source.
*/
size: number;
}
/**
Any sort of sequence can implement Iterable<T>. It's a lot like Array<T>, but

@@ -121,11 +147,11 @@ read-only, and without random access.

When calling `read()` on the underlying file, it will read batches of
When calling `read()` on the underlying file, it will read in batches of
`_block_size` (default: 1024) bytes.
*/
class BufferedFileReader {
private _fd;
class BufferedSourceReader {
private _source;
private _position;
private _block_size;
protected _buffer: Buffer;
constructor(_fd: number, _position?: number, _block_size?: number);
constructor(_source: Source, _position?: number, _block_size?: number);
/**

@@ -159,4 +185,4 @@ Return the position in the file that would be read from if we called

}
class FileBufferIterator extends BufferedFileReader implements BufferIterable {
constructor(_fd: number, _position?: number, _block_size?: number);
class SourceBufferIterator extends BufferedSourceReader implements BufferIterable {
constructor(source: Source, position?: number, block_size?: number);
private _ensureLength(length);

@@ -171,5 +197,5 @@ next(length: number): Buffer;

}
class FileStringIterator extends BufferedFileReader implements StringIterable {
class SourceStringIterator extends BufferedSourceReader implements StringIterable {
private _encoding;
constructor(_fd: number, _encoding: string, _position?: number, _block_size?: number);
constructor(source: Source, _encoding: string, position?: number, block_size?: number);
private _ensureLength(length);

@@ -176,0 +202,0 @@ next(length: number): string;

{
"name": "lexing",
"version": "0.3.6",
"version": "0.4.0",
"description": "Regex-based lexer",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc