From 8e720436eacf3ee2eaf2261bc719e145cc9dad39 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Thu, 26 Aug 2021 12:42:03 +0300 Subject: [PATCH 1/3] Add a small syntax cheatsheet --- docs/grammar.html | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/grammar.html b/docs/grammar.html index 10cf1887..92005f51 100644 --- a/docs/grammar.html +++ b/docs/grammar.html @@ -319,6 +319,21 @@

Vocabulary

following nonterminal matches zero or more cows in a row, such as cowcowcow:

a -> null | a "cow"
+ +

Matching Rules

+

Syntax for matching input if you're not using a tokenizer.

+

+  * `"if"` - match `if` literally
+  * `"if"i` - match `if` case-insensitive
+  * `.` - match any symbol except newline
+  * `[^]` - match anything including newline
+  * `[a-zA-Z]` - match symbols in range
+  * `[^a-zA-Z]` - match symbols not in range
+  * `:+` - match previous construction one or more time
+  * `:*` - match zero times or more
+  * `:?` - zero time or one time
+
+

Postprocessors

By default, nearley wraps everything matched by a rule into an array. For example, when rule -> "tick" "tock" matches the string "ticktock", it @@ -389,7 +404,7 @@

Postprocessors

+

More syntax: tips and tricks

Comments

Comments are marked with ‘#’. Everything from # to the end of a line is From c4d3cff55d94aa3641b3f5782739c126b01dd1ef Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 28 Aug 2021 12:00:37 +0300 Subject: [PATCH 2/3] Make edits in `.md` and regenerate docs --- docs/grammar.html | 29 ++++++++++++++--------------- docs/md/grammar.md | 14 ++++++++++++++ docs/package-lock.json | 1 - 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/docs/grammar.html b/docs/grammar.html index 92005f51..923f58e2 100644 --- a/docs/grammar.html +++ b/docs/grammar.html @@ -259,6 +259,7 @@

nearley.js2 Writing a parser

More syntax: tips and tricks

Comments

Comments are marked with ‘#’. Everything from # to the end of a line is diff --git a/docs/md/grammar.md b/docs/md/grammar.md index ddaf5784..6f212eb5 100644 --- a/docs/md/grammar.md +++ b/docs/md/grammar.md @@ -62,6 +62,20 @@ following nonterminal matches zero or more `cow`s in a row, such as a -> null | a "cow" ``` +### Matching Rules + +Syntax for matching input if you're not using a tokenizer. + + * `"if"` - match `if` literally + * `"if"i` - match `if` case-insensitive + * `.` - match any symbol except newline + * `[^]` - match anything including newline + * `[a-zA-Z]` - match symbols in range + * `[^a-zA-Z]` - match symbols not in range + * `:+` - match previous construction one or more time + * `:*` - match zero times or more + * `:?` - zero time or one time + ### Postprocessors By default, nearley wraps everything matched by a rule into an array. For diff --git a/docs/package-lock.json b/docs/package-lock.json index 3445c0af..f743ef24 100644 --- a/docs/package-lock.json +++ b/docs/package-lock.json @@ -472,7 +472,6 @@ "minimist": "^1.2.5", "neo-async": "^2.6.0", "source-map": "^0.6.1", - "uglify-js": "^3.1.4", "wordwrap": "^1.0.0" }, "bin": { From 84f7a24df27b2974016849bea910cce92fb95116 Mon Sep 17 00:00:00 2001 From: Anatoli Babenia Date: Sat, 28 Aug 2021 14:28:28 +0300 Subject: [PATCH 3/3] Join comments about syntax into single section --- docs/grammar.html | 17 +++++------------ docs/md/grammar.md | 30 ++++++++---------------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/docs/grammar.html b/docs/grammar.html index 923f58e2..a9465dd6 100644 --- a/docs/grammar.html +++ b/docs/grammar.html @@ -324,15 +324,18 @@

Matching Rules

Syntax for matching input if you’re not using a tokenizer.

+

(1) i suffix will not work with a lexer if you’re using one. Your lexer +should use the i flag in its regexes instead.

+

(2) RegExp charsets will not work with tokenizer.

Postprocessors

By default, nearley wraps everything matched by a rule into an array. For example, when rule -> "tick" "tock" matches the string "ticktock", it @@ -409,16 +412,6 @@

Comments

Comments are marked with ‘#’. Everything from # to the end of a line is ignored:

expression -> number "+" number # sum of two numbers
-

Charsets

-

You can use valid RegExp charsets in a rule (unless you’re using a -tokenizer):

-
not_a_letter -> [^a-zA-Z]

The . character can be used to represent any character.

-

Case-insensitive string literals

-

You can create case-insensitive string literals by adding an i after the -string literal:

-
cow -> "cow"i # matches CoW, COW, and so on.

Note that if you are using a lexer, your lexer should use the i flag in its -regexes instead. That is, if you are using a lexer, you should not use the -i suffix in nearley.

EBNF

nearley supports the *, ?, and + operators from EBNF as shown:

diff --git a/docs/md/grammar.md b/docs/md/grammar.md index 6f212eb5..02bfebf7 100644 --- a/docs/md/grammar.md +++ b/docs/md/grammar.md @@ -67,15 +67,21 @@ a -> null | a "cow" Syntax for matching input if you're not using a tokenizer. * `"if"` - match `if` literally - * `"if"i` - match `if` case-insensitive + * `"if"i` - match `if` case-insensitive (1) * `.` - match any symbol except newline * `[^]` - match anything including newline - * `[a-zA-Z]` - match symbols in range + * `[a-zA-Z]` - match symbols in range (2) * `[^a-zA-Z]` - match symbols not in range * `:+` - match previous construction one or more time * `:*` - match zero times or more * `:?` - zero time or one time +(1) `i` suffix will *not* work with a lexer if you're using one. Your lexer +should use the `i` flag in its regexes instead. + +(2) RegExp charsets will not work with [tokenizer](tokenizers). + + ### Postprocessors By default, nearley wraps everything matched by a rule into an array. For @@ -168,26 +174,6 @@ ignored: expression -> number "+" number # sum of two numbers ``` -#### Charsets - -You can use valid RegExp charsets in a rule (unless you're using a -[tokenizer](tokenizers)): - - not_a_letter -> [^a-zA-Z] - -The `.` character can be used to represent any character. - -#### Case-insensitive string literals - -You can create case-insensitive string literals by adding an `i` after the -string literal: - - cow -> "cow"i # matches CoW, COW, and so on. - -Note that if you are using a lexer, your lexer should use the `i` flag in its -regexes instead. That is, if you are using a lexer, you should *not* use the -`i` suffix in nearley. - #### EBNF nearley supports the `*`, `?`, and `+` operators from