diff --git a/Help/markdown/Table_of_Parse_Tree_Functions.md b/Help/markdown/Table_of_Parse_Tree_Functions.md index fdf8241..461be7f 100644 --- a/Help/markdown/Table_of_Parse_Tree_Functions.md +++ b/Help/markdown/Table_of_Parse_Tree_Functions.md @@ -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). | diff --git a/Help/markdown/index.md b/Help/markdown/index.md index 6c49e6c..25a56bf 100644 --- a/Help/markdown/index.md +++ b/Help/markdown/index.md @@ -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) diff --git a/Help/markdown/pntype.md b/Help/markdown/pntype.md new file mode 100644 index 0000000..9b14ee5 --- /dev/null +++ b/Help/markdown/pntype.md @@ -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)