README.md: Fixed formatting.

redux
David Majda 14 years ago
parent 7822379c70
commit db4cc71f2c

@ -31,28 +31,28 @@ This command will create the parser from the `examples/arithmetics.pegjs` file a
To use the parser in a web page, follow the following example: To use the parser in a web page, follow the following example:
<!DOCTYPE html> <!DOCTYPE html>
<head> <head>
<title>Arithmetics Parser Example</title> <title>Arithmetics Parser Example</title>
<script src="examples/arithmetics.js"></script> <!-- Include the parser. --> <script src="examples/arithmetics.js"></script> <!-- Include the parser. -->
<script> <script>
function calculate(expression) { function calculate(expression) {
/* Use the parser to compute a value of an arithmetic expression. */ /* Use the parser to compute a value of an arithmetic expression. */
var result; var result;
try { try {
result = arithmeticsParser.parse(document.getElementById("expression").value); result = arithmeticsParser.parse(document.getElementById("expression").value);
} catch (e) { } catch (e) {
result = e.message; result = e.message;
}
document.getElementById("result").innerText = result;
} }
document.getElementById("result").innerText = result; </script>
} </head>
</script> <body>
</head> <input type="text" id="expression" value="2*(3+4)">
<body> <input type="button" id="calculate" value="Calculate" onclick="calculate();">
<input type="text" id="expression" value="2*(3+4)"> <div id="result"></div>
<input type="button" id="calculate" value="Calculate" onclick="calculate();"> </body>
<div id="result"></div>
</body>
The `parse` method of the generated parser will return either the result of the parsing (dependent on the actions you specified in the grammar) or throw `PEG.Parser.SyntaxError` exception if the input contains a syntax error. The exception has properties `message`, `line` and `column`, which contain details about the error. The `parse` method of the generated parser will return either the result of the parsing (dependent on the actions you specified in the grammar) or throw `PEG.Parser.SyntaxError` exception if the input contains a syntax error. The exception has properties `message`, `line` and `column`, which contain details about the error.

Loading…
Cancel
Save