Skip to content

Commit

Permalink
Spelling (#287)
Browse files Browse the repository at this point in the history
* spelling: bracket

Signed-off-by: Josh Soref <[email protected]>

* spelling: build

Signed-off-by: Josh Soref <[email protected]>

* spelling: commandline

Signed-off-by: Josh Soref <[email protected]>

* spelling: debugging

Signed-off-by: Josh Soref <[email protected]>

* spelling: definition

Signed-off-by: Josh Soref <[email protected]>

* spelling: editing

Signed-off-by: Josh Soref <[email protected]>

* spelling: editors

Signed-off-by: Josh Soref <[email protected]>

* spelling: github

Signed-off-by: Josh Soref <[email protected]>

* spelling: grammar

Signed-off-by: Josh Soref <[email protected]>

* spelling: multiplicative

Signed-off-by: Josh Soref <[email protected]>

* spelling: optimization

Signed-off-by: Josh Soref <[email protected]>

* spelling: optimize

Signed-off-by: Josh Soref <[email protected]>

* spelling: semicolon

Signed-off-by: Josh Soref <[email protected]>

* spelling: whitespace

Signed-off-by: Josh Soref <[email protected]>

---------

Signed-off-by: Josh Soref <[email protected]>
  • Loading branch information
jsoref authored Jan 2, 2024
1 parent bd0e43e commit 65ccaaa
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 96 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
working-directory: ${{runner.workspace}}/build
# Note the current convention is to use the -S and -B options here to specify source
# and build directories, but this is only available with CMake 3.13 and higher.
# The CMake binaries on the Github Actions machines are (as of this writing) 3.12
# The CMake binaries on the GitHub Actions machines are (as of this writing) 3.12
run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE

- name: Build
Expand Down
68 changes: 34 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cpp-peglib
==========

[![](https://github.com/yhirose/cpp-peglib/workflows/CMake/badge.svg)](https://github.com/yhirose/cpp-peglib/actions)
[![Bulid Status](https://ci.appveyor.com/api/projects/status/github/yhirose/cpp-peglib?branch=master&svg=true)](https://ci.appveyor.com/project/yhirose/cpp-peglib)
[![Build Status](https://ci.appveyor.com/api/projects/status/github/yhirose/cpp-peglib?branch=master&svg=true)](https://ci.appveyor.com/project/yhirose/cpp-peglib)

C++17 header-only [PEG](http://en.wikipedia.org/wiki/Parsing_expression_grammar) (Parsing Expression Grammars) library. You can start using it right away just by including `peglib.h` in your project.

Expand Down Expand Up @@ -33,7 +33,7 @@ The PEG syntax is well described on page 2 in the [document](http://www.brynosau
* `%recovery(` ... `)` (Error recovery operator)
* `exp⇑label` or `exp^label` (Syntax sugar for `(exp / %recover(label))`)
* `label { error_message "..." }` (Error message instruction)
* `{ no_ast_opt }` (No AST node optimazation instruction)
* `{ no_ast_opt }` (No AST node optimization instruction)

'End of Input' check will be done as default. In order to disable the check, please call `disable_eoi_check`.

Expand All @@ -59,8 +59,8 @@ int main(void) {
// (2) Make a parser
parser parser(R"(
# Grammar for Calculator...
Additive <- Multitive '+' Additive / Multitive
Multitive <- Primary '*' Multitive / Primary
Additive <- Multiplicative '+' Additive / Multiplicative
Multiplicative <- Primary '*' Multiplicative / Primary
Primary <- '(' Additive ')' / Number
Number <- < [0-9]+ >
%whitespace <- [ \t]*
Expand All @@ -71,16 +71,16 @@ int main(void) {
// (3) Setup actions
parser["Additive"] = [](const SemanticValues &vs) {
switch (vs.choice()) {
case 0: // "Multitive '+' Additive"
case 0: // "Multiplicative '+' Additive"
return any_cast<int>(vs[0]) + any_cast<int>(vs[1]);
default: // "Multitive"
default: // "Multiplicative"
return any_cast<int>(vs[0]);
}
};

parser["Multitive"] = [](const SemanticValues &vs) {
parser["Multiplicative"] = [](const SemanticValues &vs) {
switch (vs.choice()) {
case 0: // "Primary '*' Multitive"
case 0: // "Primary '*' Multiplicative"
return any_cast<int>(vs[0]) * any_cast<int>(vs[1]);
default: // "Primary"
return any_cast<int>(vs[0]);
Expand All @@ -106,8 +106,8 @@ To show syntax errors in grammar text:
```cpp
auto grammar = R"(
# Grammar for Calculator...
Additive <- Multitive '+' Additive / Multitive
Multitive <- Primary '*' Multitive / Primary
Additive <- Multiplicative '+' Additive / Multiplicative
Multiplicative <- Primary '*' Multiplicative / Primary
Primary <- '(' Additive ')' / Number
Number <- < [0-9]+ >
%whitespace <- [ \t]*
Expand Down Expand Up @@ -447,8 +447,8 @@ NOTE: An AST node holds a corresponding token as `std::string_vew` for performan
```
peg::parser parser(R"(
...
defenition1 <- ... { no_ast_opt }
defenition2 <- ... { no_ast_opt }
definition1 <- ... { no_ast_opt }
definition2 <- ... { no_ast_opt }
...
)");
Expand Down Expand Up @@ -659,27 +659,27 @@ usage: grammar_file_path [source_file_path]

```
> cat a.peg
Additive <- Multitive '+' Additive / Multitive
Multitive <- Primary '*' Multitive / Primary
Additive <- Multiplicative '+' Additive / Multiplicative
Multiplicative <- Primary '*' Multiplicative / Primary
Primary <- '(' Additive ')' / Number
%whitespace <- [ \t\r\n]*
> peglint a.peg
[commendline]:3:35: 'Number' is not defined.
[commandline]:3:35: 'Number' is not defined.
```

### Source check

```
> cat a.peg
Additive <- Multitive '+' Additive / Multitive
Multitive <- Primary '*' Multitive / Primary
Additive <- Multiplicative '+' Additive / Multiplicative
Multiplicative <- Primary '*' Multiplicative / Primary
Primary <- '(' Additive ')' / Number
Number <- < [0-9]+ >
%whitespace <- [ \t\r\n]*
> peglint --source "1 + a * 3" a.peg
[commendline]:1:3: syntax error
[commandline]:1:3: syntax error
```

### AST
Expand All @@ -690,57 +690,57 @@ Number <- < [0-9]+ >
> peglint --ast a.peg a.txt
+ Additive
+ Multitive
+ Multiplicative
+ Primary
- Number (1)
+ Additive
+ Multitive
+ Multiplicative
+ Primary
- Number (2)
+ Multitive
+ Multiplicative
+ Primary
- Number (3)
```

### AST optimazation
### AST optimization

```
> peglint --ast --opt --source "1 + 2 * 3" a.peg
+ Additive
- Multitive[Number] (1)
+ Additive[Multitive]
- Multiplicative[Number] (1)
+ Additive[Multiplicative]
- Primary[Number] (2)
- Multitive[Number] (3)
- Multiplicative[Number] (3)
```

### Adjust AST optimazation with `no_ast_opt` instruction
### Adjust AST optimization with `no_ast_opt` instruction

```
> cat a.peg
Additive <- Multitive '+' Additive / Multitive
Multitive <- Primary '*' Multitive / Primary
Additive <- Multiplicative '+' Additive / Multiplicative
Multiplicative <- Primary '*' Multiplicative / Primary
Primary <- '(' Additive ')' / Number { no_ast_opt }
Number <- < [0-9]+ >
%whitespace <- [ \t\r\n]*
> peglint --ast --opt --source "1 + 2 * 3" a.peg
+ Additive/0
+ Multitive/1[Primary]
+ Multiplicative/1[Primary]
- Number (1)
+ Additive/1[Multitive]
+ Additive/1[Multiplicative]
+ Primary/1
- Number (2)
+ Multitive/1[Primary]
+ Multiplicative/1[Primary]
- Number (3)
> peglint --ast --opt-only --source "1 + 2 * 3" a.peg
+ Additive/0
+ Multitive/1
+ Multiplicative/1
- Primary/1[Number] (1)
+ Additive/1
+ Multitive/0
+ Multiplicative/0
- Primary/1[Number] (2)
+ Multitive/1
+ Multiplicative/1
- Primary/1[Number] (3)
```

Expand Down
14 changes: 7 additions & 7 deletions docs/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Setup editros
// Setup editors
function setupInfoArea(id) {
const e = ace.edit(id);
e.setShowPrintMargin(false);
Expand Down Expand Up @@ -26,7 +26,7 @@ const codeAst = setupInfoArea("code-ast");
const codeAstOptimized = setupInfoArea("code-ast-optimized");
const codeProfile = setupInfoArea("code-profile");

$('#opt-mode').val(localStorage.getItem('optimazationMode') || 'all');
$('#opt-mode').val(localStorage.getItem('optimizationMode') || 'all');
$('#packrat').prop('checked', localStorage.getItem('packrat') === 'true');
$('#auto-refresh').prop('checked', localStorage.getItem('autoRefresh') === 'true');
$('#parse').prop('disabled', $('#auto-refresh').prop('checked'));
Expand Down Expand Up @@ -60,7 +60,7 @@ function generateErrorListHTML(errors) {
function updateLocalStorage() {
localStorage.setItem('grammarText', grammar.getValue());
localStorage.setItem('codeText', code.getValue());
localStorage.setItem('optimazationMode', $('#opt-mode').val());
localStorage.setItem('optimizationMode', $('#opt-mode').val());
localStorage.setItem('packrat', $('#packrat').prop('checked'));
localStorage.setItem('autoRefresh', $('#auto-refresh').prop('checked'));
}
Expand All @@ -74,7 +74,7 @@ function parse() {
const $codeInfo = $('#code-info');
const codeText = code.getValue();

const optimazationMode = $('#opt-mode').val();
const optimizationMode = $('#opt-mode').val();
const packrat = $('#packrat').prop('checked');

$grammarInfo.html('');
Expand All @@ -89,7 +89,7 @@ function parse() {
return;
}

const mode = optimazationMode == 'all';
const mode = optimizationMode == 'all';

$('#overlay').css({
'z-index': '1',
Expand Down Expand Up @@ -132,7 +132,7 @@ function parse() {
}, 0);
}

// Event handing for text editiing
// Event handing for text editing
let timer;
function setupTimer() {
clearTimeout(timer);
Expand Down Expand Up @@ -163,7 +163,7 @@ function makeOnClickInInfo(editor) {
$('#grammar-info').on('click', 'li', makeOnClickInInfo(grammar));
$('#code-info').on('click', 'li', makeOnClickInInfo(code));

// Event handing in the AST optimazation
// Event handing in the AST optimization
$('#opt-mode').on('change', setupTimer);
$('#packrat').on('change', setupTimer);
$('#auto-refresh').on('change', () => {
Expand Down
14 changes: 7 additions & 7 deletions example/calc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,29 @@ int main(void) {
// (2) Make a parser
parser parser(R"(
# Grammar for Calculator...
Additive <- Multitive '+' Additive / Multitive
Multitive <- Primary '*' Multitive^cond / Primary
Additive <- Multiplicative '+' Additive / Multiplicative
Multiplicative <- Primary '*' Multiplicative^cond / Primary
Primary <- '(' Additive ')' / Number
Number <- < [0-9]+ >
%whitespace <- [ \t]*
cond <- '' { error_message "missing multitative" }
cond <- '' { error_message "missing multiplicative" }
)");

assert(static_cast<bool>(parser) == true);

// (3) Setup actions
parser["Additive"] = [](const SemanticValues &vs) {
switch (vs.choice()) {
case 0: // "Multitive '+' Additive"
case 0: // "Multiplicative '+' Additive"
return any_cast<int>(vs[0]) + any_cast<int>(vs[1]);
default: // "Multitive"
default: // "Multiplicative"
return any_cast<int>(vs[0]);
}
};

parser["Multitive"] = [](const SemanticValues &vs) {
parser["Multiplicative"] = [](const SemanticValues &vs) {
switch (vs.choice()) {
case 0: // "Primary '*' Multitive"
case 0: // "Primary '*' Multiplicative"
return any_cast<int>(vs[0]) * any_cast<int>(vs[1]);
default: // "Primary"
return any_cast<int>(vs[0]);
Expand Down
10 changes: 5 additions & 5 deletions grammar/cpp-peglib.peg
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Char <-
/ "\\u" (((('0' [0-9a-fA-F]) / "10") [0-9a-fA-F]{4,4}) / [0-9a-fA-F]{4,5})
/ !'\\' .

Repetition <- BeginBlacket RepetitionRange EndBlacket
Repetition <- BeginBracket RepetitionRange EndBracket

RepetitionRange <-
Number COMMA Number
Expand Down Expand Up @@ -124,14 +124,14 @@ Arguments <- OPEN Expression (COMMA Expression)* CLOSE

# Instruction grammars
Instruction <-
BeginBlacket (InstructionItem (InstructionItemSeparator InstructionItem)*)? EndBlacket
BeginBracket (InstructionItem (InstructionItemSeparator InstructionItem)*)? EndBracket
InstructionItem <- PrecedenceClimbing / ErrorMessage / NoAstOpt
~InstructionItemSeparator <- ';' Spacing

~SpacesZom <- Space*
~SpacesOom <- Space+
~BeginBlacket <- '{' Spacing
~EndBlacket <- '}' Spacing
~BeginBracket <- '{' Spacing
~EndBracket <- '}' Spacing

# PrecedenceClimbing instruction
PrecedenceClimbing <- "precedence" SpacesOom PrecedenceInfo (SpacesOom PrecedenceInfo)* SpacesZom
Expand All @@ -145,5 +145,5 @@ PrecedenceAssoc <- [LR]
# Error message instruction
ErrorMessage <- "message" SpacesOom LiteralD SpacesZom

# No Ast node optimazation instruction
# No Ast node optimization instruction
NoAstOpt <- "no_ast_opt" SpacesZom
Loading

0 comments on commit 65ccaaa

Please sign in to comment.