From a6001b32cf805c4e72e05adc37ee60272a600bf1 Mon Sep 17 00:00:00 2001 From: Ryo Nihei Date: Sat, 5 Nov 2022 16:52:37 +0900 Subject: Remove anonymous symbol system Remove unimportant features to tidy up the specification. --- README.md | 64 +++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 26 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 568190f..006781e 100644 --- a/README.md +++ b/README.md @@ -304,14 +304,12 @@ Alternative: ... ``` -An element an alternative contains is a terminal symbol, a non-terminal symbol, or a string literal. Unlike string literals, patterns cannot be contained in alternatives. - -You can define terminal symbols in the same grammar as non-terminal symbols. +An element an alternative contains is a terminal symbol or a non-terminal symbol. If a production rule satisfies all of the following conditions, it is considered to define a terminal symbol. -* A production rule has only one alternative. -* the alternative has only one pattern or string literal. +* A rule has only one alternative. +* The alternative has only one pattern or string literal. Fragment: @@ -367,15 +365,21 @@ Consider a grammar that accepts comma-separated list of integers. You can avoid #name example; list - : '[' elems ']' #ast elems... + : l_bracket elems r_bracket #ast elems... ; elems - : elems ',' int #ast elems... int + : elems comma int #ast elems... int | int ; ws #skip - : "[\u{0009}\u{0020}]+"; + : "[\u{0009}\u{0020}]+"; +l_bracket + : '['; +r_bracket + : ']'; +comma + : ','; int : "0|[1-9][0-9]*"; ``` @@ -398,11 +402,15 @@ Consider a grammar that accepts ternary-if expression (` ? ";" -├─ statement +│ └─ semi_colon ";" +├─ eq_expr │ ├─ error -│ └─ ";" -└─ statement +│ └─ semi_colon ";" +└─ eq_expr ├─ name "x" └─ int "1" +1:2: unexpected token: ';' (semi_colon): expected: eq +1:7: unexpected token: ';' (semi_colon): expected: int ``` -- cgit v1.2.3