Skip to content

Commit 75e5631

Browse files
committed
Adding example project.
1 parent 8296449 commit 75e5631

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
test
2+
example

example/calc.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<html>
2+
<head>
3+
<script src="bundle.js"></script>
4+
</head>
5+
<body>
6+
<form onsubmit="run(); return false;">
7+
<input type="text" id="input" value="50 + 2 - 10" />
8+
<input type="submit" />
9+
Result: <span id="output">&ndash;</span>
10+
</form>
11+
</body>
12+
</html>

example/calc.jison

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
%lex
2+
%%
3+
4+
\s+ /* Skip whitespace. */
5+
[0-9]+ return 'NUMBER'
6+
"-" return '-'
7+
"+" return '+'
8+
<<EOF>> return 'EOF'
9+
. return 'INVALID'
10+
11+
/lex
12+
13+
%left '+' '-'
14+
%start expressions
15+
%%
16+
17+
expressions
18+
: expr EOF { return $1; }
19+
;
20+
21+
expr
22+
: expr '+' expr { $$ = $1 + $3; }
23+
| expr '-' expr { $$ = $1 - $3; }
24+
| NUMBER { $$ = Number(yytext); }
25+
;

example/main.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var parser = require('./calc.jison').parser;
2+
3+
exports = run = function() {
4+
var input = document.getElementById('input');
5+
var output = document.getElementById('output');
6+
output.innerText = parser.parse(input.value);
7+
};

example/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "jisonify-example",
3+
"description": "Jisonify example.",
4+
"version": "0.0.1",
5+
"dependencies": {
6+
"jisonify": "*",
7+
"browserify": "*"
8+
}
9+
}

0 commit comments

Comments
 (0)