[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH for Dlang support 1/2] d: add yyerrok()
From: |
Adela Vais |
Subject: |
[PATCH for Dlang support 1/2] d: add yyerrok() |
Date: |
Fri, 6 Nov 2020 17:18:04 +0200 |
In D's case, yyerrok() is a private method of the Parser class.
However, it can be called directly as `yyerrok()` from the grammar rules
section.
The examples were modified to demonstrate this functionality.
* data/skeletons/lalr1.d: Add yyerrok().
* examples/d/calc/calc.y, examples/d/simple/calc.y: Demonstrate yyerrok().
* tests/calc.at: Update D tests to use yyerrok().
---
data/skeletons/lalr1.d | 5 +++++
examples/d/calc/calc.y | 2 +-
examples/d/simple/calc.y | 2 +-
tests/calc.at | 2 +-
4 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/data/skeletons/lalr1.d b/data/skeletons/lalr1.d
index 9b7c786c..8e464907 100644
--- a/data/skeletons/lalr1.d
+++ b/data/skeletons/lalr1.d
@@ -307,6 +307,11 @@ b4_user_union_members
private static immutable YYSemanticType yy_semantic_null;])[
private int yyerrstatus_ = 0;
+ private void yyerrok()
+ {
+ yyerrstatus_ = 0;
+ }
+
/**
* Whether error recovery is being done. In this state, the parser
* reads token until it reaches a known state, and then restarts normal
diff --git a/examples/d/calc/calc.y b/examples/d/calc/calc.y
index 9fea82cd..98ec06c0 100644
--- a/examples/d/calc/calc.y
+++ b/examples/d/calc/calc.y
@@ -53,7 +53,7 @@ input:
line:
EOL
| exp EOL { writeln ($exp); }
-| error EOL
+| error EOL { yyerrok(); }
;
exp:
diff --git a/examples/d/simple/calc.y b/examples/d/simple/calc.y
index 0f441431..41800080 100644
--- a/examples/d/simple/calc.y
+++ b/examples/d/simple/calc.y
@@ -51,7 +51,7 @@ input:
line:
EOL
| exp EOL { writeln ($exp); }
-| error EOL
+| error EOL { yyerrok(); }
;
exp:
diff --git a/tests/calc.at b/tests/calc.at
index 94a5fdb0..139cc5c5 100644
--- a/tests/calc.at
+++ b/tests/calc.at
@@ -720,7 +720,7 @@ exp:
| "-" exp %prec NEG { $$ = -$2; }
| exp "^" exp { $$ = power ($1, $3); }
| "(" exp ")" { $$ = $2; }
-| "(" error ")" { $$ = 1111; }
+| "(" error ")" { $$ = 1111; yyerrok(); }
| "!" { $$ = 0; return YYERROR; }
| "-" error { $$ = 0; return YYERROR; }
;
--
2.17.1
- [PATCH for Dlang support 1/2] d: add yyerrok(),
Adela Vais <=