---
title: "ANTLR Language Rules"
description: "rules for extracting symbols from a target ANTLR AST"
source: "https://github.com/log-10x/modules/tree/main/pipelines/compile/modules/scanner/antlr/rules/module.yaml"
icon: "material/code-tags-check"

---
Specifies conditions for selecting [symbols](https://doc.log10x.com/run/transform/structure/#symbols) from ANTLR [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree){target="\_blank"} nodes.

Rules apply per [language](https://doc.log10x.com/compile/scanner/antlr/langs/ "Extract symbol values from a source code in a variety of programming language using ANTLR") to extract symbol values matching defined criteria.

## :material-menu: Options

Specify the options below to [configure](/config "configure") multiple ANTLR language rules:

|Name|Description|Category|
|---|---|---|
|[antlrRuleLang](#antlrrulelang "lang to apply rule selector to")|Lang to apply rule selector to|Rule|
|[antlrRuleName](#antlrrulename "grammar rule to apply this selector to")|Grammar rule to apply this selector to|Rule|
|[antlrRuleContext](#antlrrulecontext "context to assign to symbols collected from this selector")|Context to assign to symbols collected from this selector|Rule|
|[antlrRuleRecursive](#antlrrulerecursive "sets whether to collect symbols from sub-nodes")|Sets whether to collect symbols from sub-nodes|Capture|
|[antlrRuleSubRule](#antlrrulesubrule "rule name to matched for any direct children of the current AST node for which extend its 'capture' behavior")|Rule name to matched for any direct children of the current AST node for which extend its 'capture' behavior|Capture|
|[antlrRuleCapture](#antlrrulecapture "symbols values to capture from the current AST node. Possible: [literalsOnly,allSymbols,allSymbolsIfMatchCond,literalsIfMatchCond]")|Symbols values to capture from the current AST node. Possible: \[literalsOnly,allSymbols,allSymbolsIfMatchCond,literalsIfMatchCond\]|Capture|
|[antlrRuleTag](#antlrruletag "a pattern to match to apply this rule's tag")|A pattern to match to apply this rule's tag|Tag|
|[antlrRuleCondition](#antlrrulecondition "a pattern to match against the current AST node value to set 'antlrRuleTag'")|A pattern to match against the current AST node value to set 'antlrRuleTag'|Tag|
|[antlrRuleIfTag](#antlrruleiftag "tag value to compare against the 'tag' value that")|Tag value to compare against the 'tag' value that|Tag|

### Rule

#### :material-menu-right-outline:**`antlrRuleLang`**

Lang to apply rule selector to.

|Type|Required|Category|
|---|---|---|
|String|✔|Rule|

Specifies the name of the [antlrLang](https://doc.log10x.com/compile/scanner/antlr/langs "Extract symbol values from a source code in a variety of programming language using ANTLR") this rule selector will apply to (e.g., 'cpp').


#### :material-menu-right-outline:**`antlrRuleName`**

Grammar rule to apply this selector to.

|Type|Required|Category|
|---|---|---|
|String|✔|Rule|

Specifies the rule within the target ANTLR grammar (e.g., 'enumerator')
to apply this selector to.


#### :material-menu-right-outline:**`antlrRuleContext`**

Context to assign to symbols collected from this selector.

|Type|Required|Category|
|---|---|---|
|String|✔|Rule|

Sets the source context to assign any symbols collected using this
this selector. For possible values, see symbol [contexts](https://doc.log10x.com/run/transform/symbol/#contexts).


### Capture

#### :material-menu-right-outline:**`antlrRuleRecursive`**

Sets whether to collect symbols from sub-nodes.

|Type|Required|Category|
|---|---|---|
|String|✔|Capture|

Sets whether to collect symbol values from child nodes of an ANTLR AST node selected by this rule.


#### :material-menu-right-outline:**`antlrRuleSubRule`**

Rule name to matched for any direct children of the current AST node for which extend its 'capture' behavior.

|Type|Default|Category|
|---|---|---|
|String|""|Capture|

Sets an optional rule name that, if matched for any direct children
of the current AST node will extend the `antlrRuleCapture` behavior
for this node to its child node as well. This option enables
capturing symbol values from a target node based on the name of its direct parent.


#### :material-menu-right-outline:**`antlrRuleCapture`**

Symbols values to capture from the current AST node. Possible: \[literalsOnly,allSymbols,allSymbolsIfMatchCond,literalsIfMatchCond\].

|Type|Required|Category|
|---|---|---|
|String|✔|Capture|

Controls which values to capture from an AST node matching this rule. Possible values:

  - **literalsOnly**: capture only string literals (e.g., 'ERROR', "hello world")
  - **allSymbols**: capture all symbols, both literal (e.g., "hello") and non-quoted (e.g., 'MyClass', 'foo') values
  - **allSymbolsIfMatchCond**: capture all symbols if this selector's `antlrRuleIfTag` equals the current tag.
  - **literalsIfMatchCond**: capture only literal symbols if this selector's `antlrRuleIfTag` equals the current tag.


### Tag

#### :material-menu-right-outline:**`antlrRuleTag`**

A pattern to match to apply this rule's tag.

|Type|Default|Category|
|---|---|---|
|String|""|Tag|

Specifies a string value to set as the current ANTLR node tag and its children if the `antlrRuleCondition` pattern matches the current node.
If 'antlrRuleCondition' is set, this value is required.


#### :material-menu-right-outline:**`antlrRuleCondition`**

A pattern to match against the current AST node value to set 'antlrRuleTag'.

|Type|Default|Category|
|---|---|---|
|String|""|Tag|

Sets an optional pattern to match against either the rule name or the text value of the ANTLR AST node.
If the pattern is a match, `antlrRuleTag` is set as the current tag value for
the current node or its children.

Any children whose `ifTag` matches the current tag
and `antlrRuleCapture` will capture their values based on their `antlrRuleCapture` is
set to 'allSymbolsIfMatchCond' or 'literalsIfMatchCond'.


#### :material-menu-right-outline:**`antlrRuleIfTag`**

Tag value to compare against the 'tag' value that.

|Type|Default|Category|
|---|---|---|
|String|""|Tag|

Specifies a string value to compare for the current node against the `tag` value set by its direct/indirect parent.

If the current `tag` set by a parent node value is equal to the current node's
`antlrRuleIfTag` value, the `allSymbolsIfMatchCond` and `literalsIfMatchCond`
literal capture values below are triggered based on whether the node's value is literal (i.e., in quotations).

For example, in the [Python ANTLR rule-set](https://github.com/log-10x/config/blob/main/pipelines/compile/config/scan/antlr/python.yaml){target="\_blank"}, tagging enables a class that has
an `Enum` child to select left-side statement expressions
(i.e., its enum literals), but skip them for any other non-enum class.


<br/>:material-github: This module is defined in [rules/module.yaml](https://github.com/log-10x/modules/tree/main/pipelines/compile/modules/scanner/antlr/rules/module.yaml "rules/module.yaml"){target="\_blank"}.

