-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (framework): new nearley framework
- Loading branch information
Showing
7 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--- | ||
permalink: /frameworks/nearley/ | ||
layout: single | ||
--- | ||
|
||
Nearley | ||
======= | ||
|
||
[Nearley](https://nearley.js.org/) . | ||
|
||
~~~ | ||
npm install nearley | ||
npx nearleyc grammar/01-basic.ne -o js/01-basic.js | ||
~~~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
main -> (statement "\n"):+ | ||
statement -> "foo" | "bar" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Create a Parser object from our grammar. | ||
const parser = new nearley.Parser(nearley.Grammar.fromCompiled(grammar)); | ||
|
||
// Parse something! | ||
parser.feed("foo\n"); | ||
|
||
// parser.results is an array of possible parsings. | ||
console.log(JSON.stringify(parser.results)); // [[[[["foo"],"\n"]]]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Generated automatically by nearley, version 2.20.1 | ||
// http://github.com/Hardmath123/nearley | ||
(function () { | ||
function id(x) { return x[0]; } | ||
var grammar = { | ||
Lexer: undefined, | ||
ParserRules: [ | ||
{"name": "main$ebnf$1$subexpression$1", "symbols": ["statement", {"literal":"\n"}]}, | ||
{"name": "main$ebnf$1", "symbols": ["main$ebnf$1$subexpression$1"]}, | ||
{"name": "main$ebnf$1$subexpression$2", "symbols": ["statement", {"literal":"\n"}]}, | ||
{"name": "main$ebnf$1", "symbols": ["main$ebnf$1", "main$ebnf$1$subexpression$2"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}}, | ||
{"name": "main", "symbols": ["main$ebnf$1"]}, | ||
{"name": "statement$string$1", "symbols": [{"literal":"f"}, {"literal":"o"}, {"literal":"o"}], "postprocess": function joiner(d) {return d.join('');}}, | ||
{"name": "statement", "symbols": ["statement$string$1"]}, | ||
{"name": "statement$string$2", "symbols": [{"literal":"b"}, {"literal":"a"}, {"literal":"r"}], "postprocess": function joiner(d) {return d.join('');}}, | ||
{"name": "statement", "symbols": ["statement$string$2"]} | ||
] | ||
, ParserStart: "main" | ||
} | ||
if (typeof module !== 'undefined'&& typeof module.exports !== 'undefined') { | ||
module.exports = grammar; | ||
} else { | ||
window.grammar = grammar; | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<title>Basic Example</title> | ||
<script src="https://cdn.jsdelivr.net/npm/nearley@2.20.1/lib/nearley.min.js"></script> | ||
<script src="01-basic.js"></script> | ||
</head> | ||
<body> | ||
<script src="01-basic-app.js"></script> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"dependencies": { | ||
"nearley": "^2.20.1" | ||
} | ||
} |