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
1 change: 1 addition & 0 deletions Help/markdown/Table_of_Parse_Tree_Functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The return types include:  **INT** (integer), **PNODE** (parse tree node), **ST
| [**pnrpushval(pnode, var_str, val)**](pnrpushval.md) | | Push a value onto end of pnode's variable. **New in 2.7.3.2** |
| [**pndown(pnode)**](pndown.md) | **PNODE** | Fetch the child of a parse tree node. |
| [**pnsingletdown(pnode)**](pnsingletdown.md) | **PNODE** | Fetch the child of a parse tree node, obeying rules about going down a "singlet chain." I.e., get child only if no branching and if not going past node with BASE flag set. |
| [**pntype(pnode)**](pntype.md) | **STR** | Fetch a pnode's token type: alpha, num, punct, white, ctrl, emoji, or node for a nonleaf. **New in 4.2.10** |
| [**pnup(pnode)**](pnup.md) | **PNODE** | Fetch a pnode's parent, if any. Only leftmost pnode in a list has a parent. |
| [**pnsetfired(pnode, num)**](pnsetfired.md) | **NONE** | Set the fired flag of a pnode (num must be 0 or 1). |
| [**pnvar(pnode, var_str)**](pnvar.md) | **ARRAY** | Fetch a pnode's variable value(s). |
Expand Down
1 change: 1 addition & 0 deletions Help/markdown/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ to a topic.
- [pnroot](pnroot.md)
- [pnsetfired](pnsetfired.md)
- [pnsingletdown](pnsingletdown.md)
- [pntype](pntype.md)
- [pnup](pnup.md)
- [pnvar](pnvar.md)
- [pnvarnames](pnvarnames.md)
Expand Down
71 changes: 71 additions & 0 deletions Help/markdown/pntype.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[← Help Contents](index.md) | [📘 NLP++ Textbook](NLP++_Textbook.md)

# pntype

## Purpose

Fetch the token type of a parse tree node *aPnode*.

## Syntax

```
returnedString = pntype(aPnode)
```

```
returnedString - type: str

aPnode - type: pnode
```

## Returns

For a token (a leaf node made by the tokenizer), one of:

| Type | Token |
|---|---|
| `alpha` | Alphabetic, including accented and other Unicode letters |
| `num` | Digits |
| `punct` | Punctuation |
| `white` | Whitespace |
| `ctrl` | Control character |
| `emoji` | Emoji |

For a nonleaf node, one built by a rule such as `_np`, it returns `node`.

These are the same names the parse tree display shows after each node.

## Remarks

Use `pntype` when code walks the tree with [pndown](pndown.md) and [pnnext](pnnext.md) and needs to know what kind of token it is looking at. Rule elements such as `_xALPHA` and `_xPUNCT` only test the type while matching a rule; `pntype` answers the same question for any node in code.

**NEW 4.2.10**

## Example

```
@CODE

L("n") = pndown(pnroot());
while (L("n")) {
if (pntype(L("n")) != "white")
"tokens.txt" << pnname(L("n")) << "\t" << pntype(L("n")) << "\n";
L("n") = pnnext(L("n"));
}

@@CODE
```

For the input `Hi 42, 🔥!` this writes:

```
Hi alpha
42 num
, punct
🔥 emoji
! punct
```

## See Also

[pnname](pnname.md), [pnvartype](pnvartype.md), [pndown](pndown.md), [pnnext](pnnext.md), [Parse Tree Functions](Table_of_Parse_Tree_Functions.md)
Loading