Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Help/markdown/@@POSTCODE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# @@POSTCODE

A region marker that indicates the end of the POSTCODE Region. It is optional.

**NEW 4.2.19**

## See Also

[POSTCODE Region](POSTCODE.md)

[@POSTCODE](@POSTCODE.md)
13 changes: 13 additions & 0 deletions Help/markdown/@POSTCODE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# @POSTCODE

A region marker that indicates the start of the POSTCODE Region, which runs after the pass's rules.

**NEW 4.2.19**

## See Also

[POSTCODE Region](POSTCODE.md)

[@@POSTCODE](@@POSTCODE.md)
6 changes: 4 additions & 2 deletions Help/markdown/CODE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@

The Code Zone may optionally contain a single CODE Region, which begins with the @CODE marker and optionally terminates with the @@CODE marker.

NLP++ code in the CODE Region is executed prior to any rule matching for the current pass.
NLP++ code in the CODE Region is executed prior to any rule matching for the current pass. To run code *after* the rules have matched, use the [POSTCODE Region](POSTCODE.md).

The CODE Region may, in addition to NLP++ code syntax, incorporate CODE Actions, i.e., specialized functions that are constrained to the CODE Region.

The **exitpass()** function is useful for conditionally and immediately terminating the current pass, without executing any rules.
The **exitpass()** function is useful for conditionally and immediately terminating the current pass, without executing any rules or the POSTCODE Region.

## See Also

[CODE Zone](NLP_PP_Stuff/Code_Zone.md)

[POSTCODE Region](POSTCODE.md)

[CODE Action](NLP_PP_Stuff/AT-CODE_Actions.md)
10 changes: 9 additions & 1 deletion Help/markdown/NLP_PP_Stuff/Code_Zone.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,20 @@ The Code Zone is reserved for regions of NLP++ code that are independent of rule

## Code Region

Currently, the only region implemented within the Code Zone is the CODE Region, which is delimited by @CODE and (optionally) by @@CODE, and operates *before* any rule matching is executed for the current pass file.
The CODE Region is delimited by @CODE and (optionally) by @@CODE, and operates *before* any rule matching is executed for the current pass file.

A pass file may consist entirely of a Code Region.

## Postcode Region

The POSTCODE Region is delimited by @POSTCODE and (optionally) by @@POSTCODE, and operates *after* the current pass file has finished matching its rules. It may follow the CODE Region or end the pass file.

**NEW 4.2.19**

## See Also

[CODE Region](../CODE.md)

[POSTCODE Region](../POSTCODE.md)

[CODE Action](AT-CODE_Actions.md)
4 changes: 2 additions & 2 deletions Help/markdown/NLP_PP_Stuff/Pass_Files.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The pass file, which is used by a single analyzer PAT pass, consists of sets of
| **Minipass** | **YES** | Recursive minipasses. Each recurse region is named and can contain repeating rules regions. Rule elements in the main RULES region (below) can invoke these named rule sets. |
| **Grammar** | **YES** | The main actions-rules regions for the current file (i.e., the current pass). |

A pass file must contain at least a @CODE region or a main @RULES region.
A pass file must contain at least a @CODE region, a @POSTCODE region, or a main @RULES region.

## Code Region

Expand Down Expand Up @@ -244,7 +244,7 @@ Output is complex, but to allow the analyzer developer as much flexibility as po

## Code Actions

Code actions are not tied to any rule, but execute operations for the entire pass. They are placed within the @CODE and @@CODE markers at the head of the file, called the *code region*. There is only one such region per file, and its actions operate before the pattern matching of the rules in the file. This region represents an embryonic programming language that enables the analyzer developer to perform useful tasks without having to write and compile regular programming language code.
Code actions are not tied to any rule, but execute operations for the entire pass. They are placed within the @CODE and @@CODE markers at the head of the file, called the *code region*. There is only one such region per file, and its actions operate before the pattern matching of the rules in the file. Code that should run after the rules goes in a [@POSTCODE region](../POSTCODE.md). This region represents an embryonic programming language that enables the analyzer developer to perform useful tasks without having to write and compile regular programming language code.

Code actions operate *before* the rules in the file operate on the parse tree. At present, there is no "post code" region to execute actions *after* the rules for a pass have matched. The user must place such code actions in a subsequent analyzer pass.

Expand Down
67 changes: 67 additions & 0 deletions Help/markdown/POSTCODE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# POSTCODE Region

The Code Zone may contain a POSTCODE Region, which begins with the @POSTCODE marker and optionally ends with the @@POSTCODE marker.

NLP++ code in the POSTCODE Region runs *after* the current pass has finished matching its rules. The CODE Region is its counterpart, which runs *before* rule matching. Use POSTCODE to report on or clean up after what the rules just did. Before this region existed, that meant a separate pass made only of a CODE Region.

## Remarks

- **Placement:** the POSTCODE Region can come right after the CODE Region or at the end of the pass file. A pass file may also consist of nothing but a POSTCODE Region.
- **Pass types:** works in `nlp` and `rec` passes.
- **Variables:** sees the same variables as the CODE Region: global `G()` variables, local `L()` variables, and functions from the DECL Region. Like the CODE Region, it has no current node, so it uses functions such as [pnroot](pnroot.md) to reach the parse tree.
- **exitpass():** when the CODE Region calls [exitpass](exitpass.md), the pass skips its rules and its POSTCODE Region too. An **exitpass()** inside the POSTCODE Region just ends that region.

**NEW 4.2.19**

## Example

Count the letters a pass reduces, then report the count once the pass is done:

```
@CODE
G("letters") = 0;
@@CODE

@POSTCODE
"output.txt" << "letters: " << G("letters") << "\n";
@@POSTCODE

@NODES _ROOT

@POST
G("letters") = G("letters") + 1;
single();
@RULES
_letter <- _xALPHA @@
```

For the input `a b c` this writes `letters: 3`.

The POSTCODE Region can also end the file:

```
@NODES _ROOT

@POST
single();
@RULES
_pair <- _letter _xWHITE [s] _letter @@

@POSTCODE
L("n") = pndown(pnroot());
while (L("n")) {
if (pnname(L("n")) == "_pair")
"output.txt" << "pair: " << pnvar(L("n"), "$text") << "\n";
L("n") = pnnext(L("n"));
}
```

## See Also

[CODE Region](CODE.md)

[Code Zone](NLP_PP_Stuff/Code_Zone.md)

[@POSTCODE](@POSTCODE.md), [@@POSTCODE](@@POSTCODE.md)
3 changes: 2 additions & 1 deletion Help/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ to a topic.
- [Code Zone](NLP_PP_Stuff/Code_Zone.md)
- [Code Zone](NLP_PP_Stuff/Code_Zone.md)
- [CODE Region](CODE.md)
- [POSTCODE Region](POSTCODE.md)
- [Context Zone](NLP_PP_Stuff/Context_Zone.md)
- [Context Zone](NLP_PP_Stuff/Context_Zone.md)
- [SELECT Region](SELECT.md)
Expand Down Expand Up @@ -592,7 +593,7 @@ above. They are grouped here so that every page remains reachable from this inde

### Regions & Region Markers

[@@](@@.md) &nbsp;|&nbsp; [@@CHECK](@@CHECK.md) &nbsp;|&nbsp; [@@CODE](@@CODE.md) &nbsp;|&nbsp; [@@MULTI](@@MULTI.md) &nbsp;|&nbsp; [@@NODES](@@NODES.md) &nbsp;|&nbsp; [@@PATH](@@PATH.md) &nbsp;|&nbsp; [@@POST](@@POST.md) &nbsp;|&nbsp; [@@PRE](@@PRE.md) &nbsp;|&nbsp; [@@RECURSE](@@RECURSE.md) &nbsp;|&nbsp; [@@RULES](@@RULES.md) &nbsp;|&nbsp; [@@SELECT](@@SELECT.md) &nbsp;|&nbsp; [@CHECK](@CHECK.md) &nbsp;|&nbsp; [@CODE](@CODE.md) &nbsp;|&nbsp; [@DECL](@DECL.md) &nbsp;|&nbsp; [@MULTI](@MULTI.md) &nbsp;|&nbsp; [@NODES](@NODES.md) &nbsp;|&nbsp; [@PATH](@PATH.md) &nbsp;|&nbsp; [@POST](@POST.md) &nbsp;|&nbsp; [@PRE](@PRE.md) &nbsp;|&nbsp; [@RECURSE](@RECURSE.md) &nbsp;|&nbsp; [@RULES](@RULES.md) &nbsp;|&nbsp; [@SELECT](@SELECT.md)
[@@](@@.md) &nbsp;|&nbsp; [@@CHECK](@@CHECK.md) &nbsp;|&nbsp; [@@CODE](@@CODE.md) &nbsp;|&nbsp; [@@MULTI](@@MULTI.md) &nbsp;|&nbsp; [@@NODES](@@NODES.md) &nbsp;|&nbsp; [@@PATH](@@PATH.md) &nbsp;|&nbsp; [@@POST](@@POST.md) &nbsp;|&nbsp; [@@POSTCODE](@@POSTCODE.md) &nbsp;|&nbsp; [@@PRE](@@PRE.md) &nbsp;|&nbsp; [@@RECURSE](@@RECURSE.md) &nbsp;|&nbsp; [@@RULES](@@RULES.md) &nbsp;|&nbsp; [@@SELECT](@@SELECT.md) &nbsp;|&nbsp; [@CHECK](@CHECK.md) &nbsp;|&nbsp; [@CODE](@CODE.md) &nbsp;|&nbsp; [@DECL](@DECL.md) &nbsp;|&nbsp; [@MULTI](@MULTI.md) &nbsp;|&nbsp; [@NODES](@NODES.md) &nbsp;|&nbsp; [@PATH](@PATH.md) &nbsp;|&nbsp; [@POST](@POST.md) &nbsp;|&nbsp; [@POSTCODE](@POSTCODE.md) &nbsp;|&nbsp; [@PRE](@PRE.md) &nbsp;|&nbsp; [@RECURSE](@RECURSE.md) &nbsp;|&nbsp; [@RULES](@RULES.md) &nbsp;|&nbsp; [@SELECT](@SELECT.md)

### NLP++ Variables

Expand Down
Loading