First Commit

This commit is contained in:
2024-07-15 15:57:41 +03:00
commit 2f7b948cda
2137 changed files with 402438 additions and 0 deletions

7
node_modules/fastparse/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,7 @@
Copyright 2018 Tobias Koppers
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

118
node_modules/fastparse/README.md generated vendored Normal file
View File

@@ -0,0 +1,118 @@
# fastparse
A very simple and stupid parser, based on a statemachine and regular expressions.
It's not intended for complex languages. It's intended to easily write a simple parser for a simple language.
## Usage
Pass a description of statemachine to the constructor. The description must be in this form:
``` javascript
new Parser(description)
description is {
// The key is the name of the state
// The value is an object containing possible transitions
"state-name": {
// The key is a regular expression
// If the regular expression matches the transition is executed
// The value can be "true", a other state name or a function
"a": true,
// true will make the parser stay in the current state
"b": "other-state-name",
// a string will make the parser transit to a new state
"[cde]": function(match, index, matchLength) {
// "match" will be the matched string
// "index" will be the position in the complete string
// "matchLength" will be "match.length"
// "this" will be the "context" passed to the "parse" method"
// A new state name (string) can be returned
return "other-state-name";
},
"([0-9]+)(\\.[0-9]+)?": function(match, first, second, index, matchLength) {
// groups can be used in the regular expression
// they will match to arguments "first", "second"
},
// the parser stops when it cannot match the string anymore
// order of keys is the order in which regular expressions are matched
// if the javascript runtime preserves the order of keys in an object
// (this is not standardized, but it's a de-facto standard)
}
}
```
The statemachine is compiled down to a single regular expression per state. So basically the parsing work is delegated to the (native) regular expression logic of the javascript runtime.
``` javascript
Parser.prototype.parse(initialState: String, parsedString: String, context: Object)
```
`initialState`: state where the parser starts to parse.
`parsedString`: the string which should be parsed.
`context`: an object which can be used to save state and results. Available as `this` in transition functions.
returns `context`
## Example
``` javascript
var Parser = require("fastparse");
// A simple parser that extracts @licence ... from comments in a JS file
var parser = new Parser({
// The "source" state
"source": {
// matches comment start
"/\\*": "comment",
"//": "linecomment",
// this would be necessary for a complex language like JS
// but omitted here for simplicity
// "\"": "string1",
// "\'": "string2",
// "\/": "regexp"
},
// The "comment" state
"comment": {
"\\*/": "source",
"@licen[cs]e\\s((?:[^*\n]|\\*+[^*/\n])*)": function(match, licenseText) {
this.licences.push(licenseText.trim());
}
},
// The "linecomment" state
"linecomment": {
"\n": "source",
"@licen[cs]e\\s(.*)": function(match, licenseText) {
this.licences.push(licenseText.trim());
}
}
});
var licences = parser.parse("source", sourceCode, { licences: [] }).licences;
console.log(licences);
```
## License
MIT (http://www.opensource.org/licenses/mit-license.php)

108
node_modules/fastparse/lib/Parser.js generated vendored Normal file
View File

@@ -0,0 +1,108 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
function ignoreFunction() {}
function createReturningFunction(value) {
return function() {
return value;
};
}
function Parser(states) {
this.states = this.compileStates(states);
}
Parser.prototype.compileStates = function(states) {
var result = {};
Object.keys(states).forEach(function(name) {
result[name] = this.compileState(states[name], states);
}, this);
return result;
};
Parser.prototype.compileState = function(state, states) {
var regExps = [];
function iterator(str, value) {
regExps.push({
groups: Parser.getGroupCount(str),
regExp: str,
value: value
});
}
function processState(statePart) {
if(Array.isArray(statePart)) {
statePart.forEach(processState);
} else if(typeof statePart === "object") {
Object.keys(statePart).forEach(function(key) {
iterator(key, statePart[key]);
});
} else if(typeof statePart === "string") {
processState(states[statePart]);
} else {
throw new Error("Unexpected 'state' format");
}
}
processState(state);
var total = regExps.map(function(r) {
return "(" + r.regExp + ")";
}).join("|");
var actions = [];
var pos = 1;
regExps.forEach(function(r) {
var fn;
if(typeof r.value === "function") {
fn = r.value;
} else if(typeof r.value === "string") {
fn = createReturningFunction(r.value);
} else {
fn = ignoreFunction;
}
actions.push({
name: r.regExp,
fn: fn,
pos: pos,
pos2: pos + r.groups + 1
});
pos += r.groups + 1;
});
return {
regExp: new RegExp(total, "g"),
actions: actions
};
};
Parser.getGroupCount = function(regExpStr) {
return new RegExp("(" + regExpStr + ")|^$").exec("").length - 2;
};
Parser.prototype.parse = function(initialState, string, context) {
context = context || {};
var currentState = initialState;
var currentIndex = 0;
for(;;) {
var state = this.states[currentState];
var regExp = state.regExp;
regExp.lastIndex = currentIndex;
var match = regExp.exec(string);
if(!match) return context;
var actions = state.actions;
currentIndex = state.regExp.lastIndex;
for(var i = 0; i < actions.length; i++) {
var action = actions[i];
if(match[action.pos]) {
var ret = action.fn.apply(context, Array.prototype.slice.call(match, action.pos, action.pos2).concat([state.regExp.lastIndex - match[0].length, match[0].length]));
if(ret) {
if(!(ret in this.states))
throw new Error("State '" + ret + "' doesn't exist");
currentState = ret;
}
break;
}
}
}
};
module.exports = Parser;

39
node_modules/fastparse/package.json generated vendored Normal file
View File

@@ -0,0 +1,39 @@
{
"name": "fastparse",
"version": "1.1.2",
"description": "A very simple and stupid parser, based on a statemachine and regular expressions.",
"main": "lib/Parser.js",
"scripts": {
"pretest": "npm run lint",
"test": "mocha",
"travis": "npm run cover -- --report lcovonly",
"lint": "eslint lib",
"precover": "npm run lint",
"cover": "istanbul cover node_modules/mocha/bin/_mocha",
"publish-patch": "mocha && npm version patch && git push && git push --tags && npm publish"
},
"repository": {
"type": "git",
"url": "https://github.com/webpack/fastparse.git"
},
"keywords": [
"parser",
"regexp"
],
"files": [
"lib"
],
"author": "Tobias Koppers @sokra",
"license": "MIT",
"bugs": {
"url": "https://github.com/webpack/fastparse/issues"
},
"homepage": "https://github.com/webpack/fastparse",
"devDependencies": {
"coveralls": "^2.11.2",
"eslint": "^0.21.2",
"istanbul": "^0.3.14",
"mocha": "^2.2.5",
"should": "^6.0.3"
}
}