Comparing version 3.0.0 to 3.1.0
23
index.md
@@ -7,3 +7,4 @@ [<span style="font-size: 150%;font-weight:bold;">⌂</span> home](http://coasttocoastresearch.com/) | ||
0. The GitHub & npm README page. | ||
> [README.md](./README.html) | ||
> [README.md](./README.html)<br> | ||
> [RELEASE-NOTES.md](./RELEASE-NOTES.html) | ||
@@ -17,24 +18,4 @@ 1. The main or driver program. Controls the flow and error reporting, calling other modules to do the work. | ||
3. Read and verify the input grammar. Validates the character set and line ends. | ||
Creates a catalog (array of objects) of the grammar file lines. | ||
> [input-analysis-parser.js](./input-analysis-parser.html) | ||
4. Parse the input grammar. The syntax phase will check the grammar for syntax errors. | ||
The semantic phase will generate rule and opcode arrays. | ||
Generates the grammar object | ||
>[abnf-for-sabnf-parser.js](abnf-for-sabnf-parser.html)<br> | ||
>[syntax-callbacks.js](./syntax-callbacks.html)<br> | ||
>[semantic-callbacks.js](semantic-callbacks.html) | ||
5. Determine the grammar's attributes. | ||
>[attributes.js](./attributes.html)<br> | ||
>[attribute-types.js](./attribute-types.html)<br> | ||
>[attributes-non-recursive.js](./attributes-non-recursive.html)<br> | ||
>[attributes-recursive.js](./attributes-recursive.html) | ||
6. Powers the **apg.html** web-page generator. | ||
>[apgweb.js](./apgweb.html)<br> | ||
5. Exports the internal workings of **apg**. Returned by `require("apg")`. | ||
Used by [apg-exp](https://github.com/ldthomas/apg-js2-exp). | ||
>[exports.js](./exports.html)<br> |
{ | ||
"name": "apg", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"description": "An ABNF Parser Generator - generates recursive-descent parsers from grammars written in a superset of Augmented Backus-Naur Form (ABNF)", | ||
"main": "./src/exports.js", | ||
"main": "./src/apg.js", | ||
"scripts": { | ||
@@ -15,5 +15,5 @@ "test": "apg -v" | ||
"bin", | ||
"abnf", | ||
"index.md", | ||
"SABNF.md", | ||
"RELEASE-NOTES.md", | ||
"docco-gen", | ||
@@ -24,4 +24,4 @@ "apg.html", | ||
"dependencies": { | ||
"apg-lib": "3.x", | ||
"apg-conv": "1.x" | ||
"apg-api": "1.0.x", | ||
"apg-lib": "3.1.x" | ||
}, | ||
@@ -28,0 +28,0 @@ "repository": { |
## JavaScript APG | ||
**New in Version 3.0.0:** | ||
*See [release notes](https://github.com/ldthomas/apg-js2/blob/master/RELEASE-NOTES.md)* | ||
* The **apg** command line has been greatly simplified. | ||
* Command line **apg** has only console output. It no longer generates any HTML. | ||
* A GUI generator, **apg.html**, has been added. | ||
* **apg.html** is a self-contained, stand-alone, web-page interface to **apg**. | ||
* It does not load any external CSS, JavaScript or other resources. | ||
* It provides detailed information about the grammar and generated parser. | ||
* It allows testing of the generated parser. | ||
* It is a visual aid to writing [SABNF](https://github.com/ldthomas/apg-js2/blob/master/SABNF.md) grammars | ||
and the input strings or sentences that they are designed to accept. | ||
* Documentation for using **apg.html** is built in. Just click the 'Help' tab. | ||
**Description:** | ||
@@ -20,3 +9,3 @@ | ||
([RFC 5234](https://tools.ietf.org/html/rfc5234)) it has since grown to include a number of additional features requiring additional syntax terms. The resulting syntax is a superset of ABNF or [SABNF](https://github.com/ldthomas/apg-js2/blob/master/SABNF.md). | ||
Some features have been primarily developed to support the new [apg-exp](https://github.com/ldthomas/apg-js2-exp) pattern-matching application. A general description of how **APG** works is given [here](http://coasttocoastresearch.com/apg). | ||
Some features have been primarily developed to support the new [**apg-exp**](https://github.com/ldthomas/apg-js2-exp) pattern-matching application. A general description of how **APG** works is given [here](http://coasttocoastresearch.com/apg). | ||
@@ -23,0 +12,0 @@ **apg-exp** features: |
110
src/apg.js
@@ -5,6 +5,23 @@ // This is the main or driver function for the parser generator. | ||
// - execution of immediate commands (help, version) | ||
// - reading and verifying the input SABNF grammar file | ||
// - parsing the input SABNF grammar, reporting errors, or generating a grammar object | ||
// - reading and verifying the input SABNF grammar file(s) | ||
// - parsing the input SABNF grammar and reporting errors, if any | ||
// - evaluation of the input grammar's attributes | ||
// - if all is OK, writing the generated grammar object to the specified file | ||
// - if all is OK, generating the source code for a grammar object | ||
// - writing the source to a specified file | ||
// | ||
// Note on teminology. | ||
// | ||
// APG is a parser generator. | ||
// However, it really only generates a "grammar object" (see below) from the defining SABNF grammar. | ||
// The generated parser is incomplete at this stage. | ||
// Remaining, it is the job of the user to develop the generated parser from the grammar object and the APG Library (**apg-lib**). | ||
// | ||
// The following terminology my help clear up the confusion between the idea of a "generated parser" versus a "generated grammar object". | ||
// - The generating parser: APG is an APG parser (yes, there is a circular dependence between **apg** and **apg-lib**). We'll call it the generating parser. | ||
// - The target parser: APG's goal is to generate a parser. We'll call it the target parser. | ||
// - The target grammar: this is the (ASCII) SABNF grammar defining the target parser. | ||
// - The target grammar object: APG parses the SABNF grammar and generates the JavaScript source for a target grammar object. | ||
// - The final target parser: The user then develops the final target parser using the generated target grammar | ||
// object and the APG parsing library, **apg-lib**. | ||
/* | ||
@@ -21,11 +38,17 @@ * COPYRIGHT: Copyright (c) 2017 Lowell D. Thomas, all rights reserved | ||
"use strict"; | ||
function logErrors(api, header){ | ||
console.log("\n"); | ||
console.log(header + ":"); | ||
console.log(api.errorsToAscii()); | ||
console.log("\nORIGINAL GRAMMAR:"); | ||
console.log(api.linesToAscii()); | ||
} | ||
try { | ||
debugger; | ||
var thisFileName = "apg.js: "; | ||
var fs = require("fs"); | ||
var converter = require("apg-conv"); | ||
var api = require("apg-api"); | ||
var apglib = require("apg-lib"); | ||
var converter = require("apg-conv-api").converter; | ||
var getConfig = require("./command-line.js"); | ||
var inputAnalysis = new (require("./input-analysis-parser.js"))(); | ||
var sabnf = new (require("./abnf-for-sabnf-parser.js"))(); | ||
var attrs = new (require("./attributes.js"))(); | ||
var result, attrErrors; | ||
@@ -49,46 +72,57 @@ /* Get command line parameters and set up the configuration accordingly. */ | ||
/* Get and validate the input SABNF grammar. */ | ||
result = inputAnalysis.analyze(config.src, config.strict); | ||
if (result.hasErrors === true) { | ||
console.log("GRAMMAR CHARACTER ERRORS:"); | ||
console.log(inputAnalysis.errorsToString(result.errors)); | ||
console.log("\nORIGINAL GRAMMAR:"); | ||
console.log(converter.encode("STRING", config.src)); | ||
throw new Error("invalid input grammar"); | ||
api = new api(config.src); | ||
/* !!!! DEBUG !!!! */ | ||
/* test complete generation */ | ||
// api.generate(config.strict); | ||
// if (api.errors.length) { | ||
// logErrors(api, "GRAMMAR ERRORS"); | ||
// throw new Error(thisFileName + "grammar has errors"); | ||
// }else{ | ||
// fs.writeSync(config.outfd, api.toSource()); | ||
// console.log("\nJavaScript parser generated: " + config.outFilename); | ||
// } | ||
// return; | ||
/* !!!! DEBUG !!!! */ | ||
api.scan(config.strict); | ||
if (api.errors.length) { | ||
logErrors(api, "GRAMMAR CHARACTER ERRORS"); | ||
/* !!!! DEBUG !!!! */ | ||
// var html = apglib.utils.htmlToPage(api.errorsToHtml()); | ||
// fs.writeFileSync("errors.html", html); | ||
// html = apglib.utils.htmlToPage(api.linesToHtml()); | ||
// fs.writeFileSync("lines.html", html); | ||
/* !!!! DEBUG !!!! */ | ||
throw new Error(thisFileName + "invalid input grammar"); | ||
} | ||
/* parse the grammar - the syntax phase */ | ||
result = sabnf.syntax(inputAnalysis, config.strict, false); | ||
if (result.hasErrors) { | ||
console.log("GRAMMAR SYNTAX ERRORS:"); | ||
console.log(inputAnalysis.errorsToString(result.errors)); | ||
console.log("\nORIGINAL GRAMMAR:"); | ||
console.log(converter.encode("STRING", config.src)); | ||
throw new Error("grammar has syntax errors"); | ||
api.parse(config.strict); | ||
if (api.errors.length) { | ||
logErrors(api, "GRAMMAR SYNTAX ERRORS"); | ||
throw new Error(thisFileName + "grammar has syntax errors"); | ||
} | ||
/* translate the AST - the semantic phase */ | ||
result = sabnf.semantic(); | ||
if (result.hasErrors) { | ||
console.log("GRAMMAR SEMANTIC ERRORS:"); | ||
console.log(inputAnalysis.errorsToString(result.errors)); | ||
console.log("\nORIGINAL GRAMMAR:"); | ||
console.log(converter.encode("STRING", config.src)); | ||
throw new Error("grammar has semantic errors"); | ||
api.translate(); | ||
if (api.errors.length) { | ||
logErrors(api, "GRAMMAR SEMANTIC ERRORS"); | ||
throw new Error(thisFileName + "grammar has semantic errors"); | ||
} | ||
/* attribute generation */ | ||
attrErrors = attrs.getAttributes(result.rules, result.udts, result.rulesLineMap); | ||
if (attrErrors.length > 0) { | ||
console.log("ATTRIBUTE ERRORS:"); | ||
console.log(inputAnalysis.errorsToString(attrErrors)); | ||
console.log("\nORIGINAL GRAMMAR:"); | ||
console.log(converter.encode("STRING", config.src)); | ||
throw new Error("grammar has attribute errors"); | ||
api.attributes(); | ||
if (api.errors.length) { | ||
logErrors(api, "GRAMMAR ATTRIBUTE ERRORS"); | ||
throw new Error(thisFileName + "grammar has semantic errors"); | ||
} | ||
/* generate a JavaScript parser */ | ||
fs.writeSync(config.outfd, sabnf.generateSource(result.rules, result.udts)); | ||
fs.writeSync(config.outfd, api.toSource()); | ||
console.log("\nJavaScript parser generated: " + config.outFilename); | ||
} catch (e) { | ||
var msg = "\nEXCEPTION THROWN: "; | ||
var msg = "EXCEPTION THROWN: "; | ||
if (e instanceof Error) { | ||
@@ -95,0 +129,0 @@ msg += e.name + ": " + e.message; |
@@ -455,3 +455,3 @@ window.apgweb = (function() { | ||
var apglib = require("apg-lib"); | ||
var converter = require("apg-conv"); | ||
var converter = require("apg-conv-api").converter; | ||
var currentTab = 0; | ||
@@ -1451,5 +1451,3 @@ var parser = null; | ||
var apgWeb = function() { | ||
var attributes = require("./attributes.js"); | ||
var inputAnalysis = require("./input-analysis-parser.js"); | ||
var sabnfParser = require("./abnf-for-sabnf-parser.js"); | ||
var api = require("apg-api"); | ||
@@ -1557,3 +1555,3 @@ /* handle the main menu tabs */ | ||
this.generate = function() { | ||
var analyzer, sabnf, result, attrsObj; | ||
var attrsObj; | ||
var strict = false; | ||
@@ -1574,7 +1572,7 @@ var sabnfGrammar = PAGE_INFO[GRAMMAR_AREA].element.value; | ||
analyzer = new inputAnalysis(); | ||
result = analyzer.analyze(sabnfGrammar, false); | ||
grammarHtml = analyzer.toHtml(); | ||
if (result.hasErrors) { | ||
grammarHtml += analyzer.errorsToHtml(result.errors, "SABNF grammar has invalid characters"); | ||
api = new api(sabnfGrammar); | ||
api.scan(); | ||
grammarHtml = api.linesToHtml(); | ||
if(api.errors.length){ | ||
grammarHtml += api.errorsToHtml("SABNF grammar has invalid characters"); | ||
break; | ||
@@ -1584,6 +1582,5 @@ } | ||
/* validate the SABNF grammar syntax */ | ||
sabnf = new sabnfParser(); | ||
result = sabnf.syntax(analyzer, strict, false); | ||
if (result.hasErrors) { | ||
grammarHtml += analyzer.errorsToHtml(result.errors, "SABNF grammar has syntax errors"); | ||
api.parse(); | ||
if(api.errors.length){ | ||
grammarHtml += api.errorsToHtml("SABNF grammar has syntax errors"); | ||
break; | ||
@@ -1593,5 +1590,5 @@ } | ||
/* validate the SABNF grammar semantics */ | ||
result = sabnf.semantic(); | ||
if (result.hasErrors) { | ||
grammarHtml += analyzer.errorsToHtml(result.errors, "SABNF grammar has semantic errors"); | ||
api.translate(); | ||
if(api.errors.length){ | ||
grammarHtml += api.errorsToHtml("SABNF grammar has semantic errors"); | ||
break; | ||
@@ -1601,6 +1598,6 @@ } | ||
/* validate the SABNF grammar attributes */ | ||
attrsObj = new attributes(); | ||
var errors = attrsObj.getAttributes(result.rules, result.udts, result.rulesLineMap); | ||
if (errors.length > 0) { | ||
grammarHtml += analyzer.errorsToHtml(errors, "SABNF grammar has attribute errors"); | ||
attrsObj = api.getAttributesObject(); | ||
api.attributes(); | ||
if(api.errors.length){ | ||
grammarHtml += api.errorsToHtml("SABNF grammar has attribute errors"); | ||
attrErrors = true; | ||
@@ -1619,4 +1616,4 @@ break; | ||
if (validGrammar) { | ||
var src = sabnf.generateSource(result.rules, result.udts, "var generatedGrammar"); | ||
var obj = sabnf.generateObject(result.rules, result.udts); | ||
var src = api.toSource("generatedGrammar"); | ||
var obj = api.toObject(); | ||
this.parser.init(src, obj); | ||
@@ -1629,3 +1626,3 @@ } else { | ||
if (attrsObj) { | ||
this.rules.init(attrsObj.rulesWithReferencesData(), result.udts); | ||
this.rules.init(attrsObj.rulesWithReferencesData(), api.udts); | ||
this.attrs.init(attrsObj.ruleAttrsData(), attrsObj.udtAttrsData()); | ||
@@ -1632,0 +1629,0 @@ } else { |
@@ -58,3 +58,3 @@ // This module processes the command line arguments into a completed configuration | ||
var path = require("path"); | ||
var converter = require("apg-conv"); | ||
var converter = require("apg-conv-api").converter; | ||
var STRICTL = "--strict"; | ||
@@ -61,0 +61,0 @@ var STRICTS = "-s"; |
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
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
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
2
598912
13
1985
104
1
+ Addedapg-api@1.0.x
+ Addedapg-api@1.0.1(transitive)
+ Addedapg-lib@3.1.1(transitive)
- Removedapg-conv@1.x
- Removedapg-conv@1.1.1(transitive)
- Removedapg-lib@3.2.0(transitive)
Updatedapg-lib@3.1.x