trcombine 0.23.0

dotnet tool install --global trcombine --version 0.23.0
This package contains a .NET tool you can call from the shell/command line.
dotnet new tool-manifest # if you are setting up this repo
dotnet tool install --local trcombine --version 0.23.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=trcombine&version=0.23.0
nuke :add-package trcombine --version 0.23.0

trcombine

Summary

Combine a split Antlr4 grammar

Description

Combine two grammars into one. One grammar must be a lexer grammar, the other a parser grammar, order is irrelevant. The output is parse tree data.

Usage

trcombine <grammar1> <grammar2>

Details

trcombine combines grammars that are known as "split grammars" (separate Antlr4 lexer and parser grammars) into one grammar, known as a "combined grammar". This refactoring is useful if a simplified grammar grammar is wanted, and if possible if the split grammar does not use the "superClass" option in one or the other grammars. The opposite refactoring is implemented by trsplit.

The split refactoring performs several operations:

  • Combine the two files together, parser grammar first, then lexer grammar.
  • Remove the grammarDecl for the lexer rules, and change the grammarDecl for the parser rules to be a combined grammar declaration. Rename the name of the parser grammar to not have "Parser" at the tail of the name.
  • Remove the optionsSpec for the lexer section.
  • Remove any occurrence of "tokenVocab" from the optionsSpec of the parser section.
  • If the optionsSpec is empty, it is removed.

The order of the two grammars is ignored: the parser rules always will appear before the lexer rules.

Lexer modes will require manual fix-up.

Example

Consider the following grammar that is split.

Input to command

Lexer grammar in ExpressionLexer.g4:

lexer grammar ExpressionLexer;
VARIABLE : VALID_ID_START VALID_ID_CHAR* ;
fragment VALID_ID_START : ('a' .. 'z') | ('A' .. 'Z') | '_' ;
fragment VALID_ID_CHAR : VALID_ID_START | ('0' .. '9') ;
INT : ('0' .. '9')+ ;
MUL : '*' ;
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
LP : '(' ;
RP : ')' ;
WS : [ \r\n\t] + -> skip ;

Parser grammar in ExpressionParser.g4:

parser grammar ExpressionParser;
e : e ('*' | '/') e
 | e ('+' | '-') e
 | '(' e ')'
 | ('-' | '+')* a
 ;
a : number | variable ;
number : INT ;
variable : VARIABLE ;

Command

trcombine ExpressionLexer.g4 ExpressionParser.g4 | trprint > Expression.g4

Combined grammar in Expression.g4:

grammar Expression;
e : e ('*' | '/') e
 | e ('+' | '-') e
 | '(' e ')'
 | ('-' | '+')* a
 ;
a : number | variable ;
number : INT ;
variable : VARIABLE ;
VARIABLE : VALID_ID_START VALID_ID_CHAR* ;
fragment VALID_ID_START : ('a' .. 'z') | ('A' .. 'Z') | '_' ;
fragment VALID_ID_CHAR : VALID_ID_START | ('0' .. '9') ;
INT : ('0' .. '9')+ ;
MUL : '*' ;
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
LP : '(' ;
RP : ')' ;
WS : [ \r\n\t] + -> skip ;

The original grammars are left unchanged.

Current version

0.23.0 Major changes to trgen, trparse, trfoldlit, trquery. Removal of trinsert, trdelete, trmove, trdelabel, trstrip.

License

The MIT License

Copyright (c) 2024 Ken Domino

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

Version Downloads Last updated
0.23.0 132 4/25/2024
0.22.0 134 2/26/2024
0.21.16 226 11/16/2023
0.21.15 130 11/16/2023
0.21.14 137 11/15/2023
0.21.13 141 11/14/2023
0.21.12 228 10/27/2023
0.21.11 226 10/24/2023
0.21.9 238 9/27/2023
0.21.8 258 9/26/2023
0.21.7 186 9/26/2023
0.21.6 175 9/20/2023
0.21.5 162 9/18/2023
0.21.4 120 9/17/2023
0.21.3 168 9/14/2023
0.21.2 195 9/4/2023
0.21.1 271 8/15/2023
0.21.0 218 6/25/2023
0.20.27 177 6/15/2023
0.20.26 201 6/5/2023
0.20.25 187 6/3/2023
0.20.24 187 6/1/2023
0.20.23 146 5/31/2023
0.20.22 192 5/21/2023
0.20.21 196 5/15/2023
0.20.20 166 5/11/2023
0.20.19 167 5/8/2023
0.20.18 149 5/8/2023
0.20.17 183 5/4/2023
0.20.16 197 5/1/2023
0.20.15 183 4/27/2023
0.20.14 217 4/21/2023
0.20.13 244 4/13/2023
0.20.12 307 3/17/2023
0.20.11 266 3/15/2023
0.20.10 269 3/15/2023
0.20.9 271 3/14/2023
0.20.8 257 3/14/2023
0.20.7 251 3/13/2023
0.20.6 279 3/11/2023
0.20.5 300 3/11/2023
0.20.4 250 3/9/2023
0.20.3 252 3/8/2023
0.20.2 292 3/7/2023
0.20.1 267 3/7/2023
0.18.1 536 11/11/2022
0.18.0 422 11/7/2022
0.17.0 511 9/11/2022
0.16.5 513 7/29/2022
0.16.4 530 6/13/2022
0.16.3 597 5/7/2022
0.16.2 550 5/6/2022
0.16.1 540 5/5/2022
0.16.0 577 4/13/2022
0.15.1 564 4/4/2022
0.15.0 537 3/20/2022
0.14.3 554 2/27/2022
0.14.2 552 2/18/2022
0.14.1 580 1/26/2022
0.14.0 531 1/26/2022
0.13.8 555 1/14/2022
0.13.7 584 1/13/2022
0.13.6 547 1/13/2022
0.13.5 574 1/12/2022
0.13.4 556 1/11/2022
0.13.3 551 1/10/2022
0.13.2 365 12/24/2021
0.13.1 391 12/24/2021
0.13.0 394 12/23/2021
0.12.0 422 12/6/2021
0.11.5 475 10/17/2021
0.11.4 447 10/17/2021
0.11.3 445 9/28/2021
0.11.2 410 9/26/2021
0.11.1 428 9/25/2021
0.11.0 467 9/24/2021
0.10.0 502 9/9/2021
0.8.9 405 8/13/2021
0.8.8 405 8/5/2021
0.8.7 407 7/20/2021
0.8.6 438 7/13/2021
0.8.5 412 7/6/2021
0.8.4 392 6/24/2021
0.8.3 487 6/13/2021
0.8.2 400 6/8/2021
0.8.1 428 6/2/2021

# trcombine
## Summary
Combine a split Antlr4 grammar
## Description
Combine two grammars into one.
One grammar must be a lexer grammar, the other a parser grammar,
order is irrelevant. The output is parse tree data.
## Usage
trcombine <grammar1> <grammar2>
## Details
`trcombine` combines grammars that are known as "split grammars"
(separate Antlr4 lexer and parser grammars)
into one grammar, known as a "combined grammar". This refactoring is
useful if a simplified grammar grammar is wanted, and if possible if
the split grammar does not use the "superClass" option in one or the other
grammars. The opposite refactoring is implemented by
[trsplit](https://github.com/kaby76/Domemtech.Trash/tree/main/trsplit).
The split refactoring performs several operations:
* Combine the two files together, parser grammar first, then lexer grammar.
* Remove the `grammarDecl` for the lexer rules, and change the `grammarDecl`
for the parser rules to be a combined grammar declaration. Rename the name
of the parser grammar to not have "Parser" at the tail of the name.
* Remove the `optionsSpec` for the lexer section.
* Remove any occurrence of "tokenVocab" from the `optionsSpec` of the parser section.
* If the `optionsSpec` is empty, it is removed.
The order of the two grammars is ignored: the parser rules always will appear
before the lexer rules.
Lexer modes will require manual fix-up.
## Example
Consider the following grammar that is split.
_Input to command_
Lexer grammar in ExpressionLexer.g4:
lexer grammar ExpressionLexer;
VARIABLE : VALID_ID_START VALID_ID_CHAR* ;
fragment VALID_ID_START : ('a' .. 'z') | ('A' .. 'Z') | '_' ;
fragment VALID_ID_CHAR : VALID_ID_START | ('0' .. '9') ;
INT : ('0' .. '9')+ ;
MUL : '*' ;
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
LP : '(' ;
RP : ')' ;
WS : [ \r\n\t] + -> skip ;
Parser grammar in ExpressionParser.g4:
parser grammar ExpressionParser;
e : e ('*' | '/') e
| e ('+' | '-') e
| '(' e ')'
| ('-' | '+')* a
;
a : number | variable ;
number : INT ;
variable : VARIABLE ;
_Command_
trcombine ExpressionLexer.g4 ExpressionParser.g4 | trprint > Expression.g4
Combined grammar in Expression.g4:
grammar Expression;
e : e ('*' | '/') e
| e ('+' | '-') e
| '(' e ')'
| ('-' | '+')* a
;
a : number | variable ;
number : INT ;
variable : VARIABLE ;
VARIABLE : VALID_ID_START VALID_ID_CHAR* ;
fragment VALID_ID_START : ('a' .. 'z') | ('A' .. 'Z') | '_' ;
fragment VALID_ID_CHAR : VALID_ID_START | ('0' .. '9') ;
INT : ('0' .. '9')+ ;
MUL : '*' ;
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
LP : '(' ;
RP : ')' ;
WS : [ \r\n\t] + -> skip ;
The original grammars are left unchanged.
## Current version
0.23.0 Major changes to trgen, trparse, trfoldlit, trquery. Removal of trinsert, trdelete, trmove, trdelabel, trstrip.
## License
The MIT License
Copyright (c) 2024 Ken Domino
Permission is hereby granted, free of charge,
to any person obtaining a copy of this software and
associated documentation files (the "Software"), to
deal in the Software without restriction, including
without limitation the rights to use, copy, modify,
merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom
the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.