trconvert 0.22.0

dotnet tool install --global trconvert --version 0.22.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 trconvert --version 0.22.0
This package contains a .NET tool you can call from the shell/command line.
#tool dotnet:?package=trconvert&version=0.22.0
nuke :add-package trconvert --version 0.22.0

trconvert

Summary

Convert a grammar from one for to another

Description

Reads a grammar from stdin and converts the grammar to/from Antlr version 4 syntax. The original grammar must be for a supported type (Antlr2, Antlr3, Bison, W3C EBNF, Lark). The input and output are Parse Tree Data.

Usage

trconvert [-t <type>]

Details

This command converts a grammar from one type to another. Most conversions will handle only simple syntax differences. More complicated scenarios are supported depending on the source and target grammar types. For example, Bison is converted to Antlr4, but the reverse is not implemented yet.

trconvert takes an option target type. If it is not used, the default is to convert the input of whatever type to Antlr4 syntax. The output of trconvert is a parse tree containing the converted grammar.

Examples

Conversion of Antlr4 Abnf to Lark Abnf

grammar Abnf;

rulelist : rule_* EOF ;
rule_ : ID '=' '/'? elements ;
elements : alternation ;
alternation : concatenation ( '/' concatenation )* ;
concatenation : repetition + ;
repetition : repeat_? element ;
repeat_ : INT | ( INT? '*' INT? ) ;
element : ID | group | option | STRING | NumberValue | ProseValue ;
group : '(' alternation ')' ;
option : '[' alternation ']' ;
NumberValue : '%' ( BinaryValue | DecimalValue | HexValue ) ;
fragment BinaryValue : 'b' BIT+ ( ( '.' BIT+ )+ | ( '-' BIT+ ) )? ;
fragment DecimalValue : 'd' DIGIT+ ( ( '.' DIGIT+ )+ | ( '-' DIGIT+ ) )? ;
fragment HexValue : 'x' HEX_DIGIT+ ( ( '.' HEX_DIGIT+ )+ | ( '-' HEX_DIGIT+ ) )? ;
ProseValue : '<' ( ~ '>' )* '>' ;
ID : LETTER ( LETTER | DIGIT | '-' )* ;
INT : '0' .. '9'+ ;
COMMENT : ';' ~ ( '\n' | '\r' )* '\r'? '\n' -> channel ( HIDDEN ) ;
WS : ( ' ' | '\t' | '\r' | '\n' ) -> channel ( HIDDEN ) ;
STRING : ( '%s' | '%i' )? '"' ( ~ '"' )* '"' ;
fragment LETTER : 'a' .. 'z' | 'A' .. 'Z' ;
fragment BIT : '0' .. '1' ;
fragment DIGIT : '0' .. '9' ;
fragment HEX_DIGIT : ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' ) ;

Command

trparse Abnf.g4 | trconvert -t lark | trprint > Abnf.lark

Output

rulelist :  rule_ * EOF 
rule_ :  ID "=" "/" ? elements 
elements :  alternation 
alternation :  concatenation ( "/" concatenation ) * 
concatenation :  repetition + 
repetition :  repeat_ ? element 
repeat_ :  INT | ( INT ? "*" INT ? ) 
element :  ID | group | option | STRING | NUMBERVALUE | PROSEVALUE 
group :  "(" alternation ")" 
option :  "[" alternation "]" 
NUMBERVALUE :  "%" ( BINARYVALUE | DECIMALVALUE | HEXVALUE ) 
BINARYVALUE :  "b" BIT + ( ( "." BIT + ) + | ( "-" BIT + ) ) ? 
DECIMALVALUE :  "d" DIGIT + ( ( "." DIGIT + ) + | ( "-" DIGIT + ) ) ? 
HEXVALUE :  "x" HEX_DIGIT + ( ( "." HEX_DIGIT + ) + | ( "-" HEX_DIGIT + ) ) ? 
PROSEVALUE :  "<" ( /(?!>)/ ) * ">" 
ID :  LETTER ( LETTER | DIGIT | "-" ) * 
INT :  "0" .. "9" + 
COMMENT :  ";" /(?!\n|\r)/ * "\r" ? "\n" 
WS :  ( " " | "\t" | "\r" | "\n" ) 
STRING :  ( "%s" | "%i" ) ? "\"" ( /(?!")/ ) * "\"" 
LETTER :  "a" .. "z" | "A" .. "Z" 
BIT :  "0" .. "1" 
DIGIT :  "0" .. "9" 
HEX_DIGIT :  ( "0" .. "9" | "a" .. "f" | "A" .. "F" ) 

%ignore COMMENT
%ignore WS

Current version

0.22.0 Add trdot. Update to Antlr 4.13.1 and Dotnet 8.0.

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.22.0 165 2/26/2024
0.21.16 247 11/16/2023
0.21.15 125 11/16/2023
0.21.14 169 11/15/2023
0.21.13 128 11/14/2023
0.21.12 234 10/27/2023
0.21.11 288 10/24/2023
0.21.9 260 9/27/2023
0.21.8 211 9/26/2023
0.21.7 238 9/26/2023
0.21.6 283 9/20/2023
0.21.5 233 9/18/2023
0.21.4 254 9/17/2023
0.21.3 266 9/14/2023
0.21.2 285 9/4/2023
0.21.1 366 8/15/2023
0.21.0 215 6/25/2023
0.20.27 199 6/15/2023
0.20.25 152 6/3/2023
0.20.24 205 6/1/2023
0.20.23 180 5/31/2023
0.20.22 208 5/21/2023
0.20.21 205 5/15/2023
0.20.20 194 5/11/2023
0.20.19 171 5/8/2023
0.20.18 256 5/8/2023
0.20.17 221 5/4/2023
0.20.16 199 5/1/2023
0.20.15 254 4/27/2023
0.20.14 253 4/21/2023
0.18.1 575 11/11/2022
0.18.0 500 11/7/2022
0.17.0 529 9/11/2022
0.16.5 588 7/29/2022
0.16.4 551 6/13/2022
0.16.3 595 5/7/2022
0.16.2 547 5/6/2022
0.16.1 550 5/5/2022
0.16.0 573 4/13/2022
0.15.1 595 4/4/2022
0.15.0 523 3/20/2022
0.14.3 549 2/27/2022
0.14.2 571 2/18/2022
0.14.1 619 1/26/2022
0.14.0 603 1/26/2022
0.13.8 566 1/14/2022
0.13.7 553 1/13/2022
0.13.6 574 1/13/2022
0.13.5 561 1/12/2022
0.13.4 556 1/11/2022
0.13.3 566 1/10/2022
0.13.2 381 12/24/2021
0.13.1 391 12/24/2021
0.13.0 378 12/23/2021
0.12.0 398 12/6/2021
0.11.5 515 10/17/2021
0.11.4 482 10/17/2021
0.11.3 410 9/28/2021
0.11.2 417 9/26/2021
0.11.1 462 9/25/2021
0.11.0 453 9/24/2021
0.10.0 413 9/9/2021
0.8.9 415 8/13/2021
0.8.8 475 8/5/2021
0.8.7 448 7/20/2021
0.8.6 433 7/13/2021
0.8.5 417 7/6/2021
0.8.4 403 6/24/2021
0.8.3 494 6/13/2021
0.8.2 428 6/8/2021
0.8.1 435 6/2/2021
0.8.0 401 5/27/2021
0.7.0 422 5/10/2021
0.6.0 366 5/3/2021
0.5.5 428 4/22/2021

# trconvert
## Summary
Convert a grammar from one for to another
## Description
Reads a grammar from stdin and converts the grammar to/from Antlr version 4
syntax. The original grammar must be for a supported type (Antlr2, Antlr3,
Bison, W3C EBNF, Lark). The input and output are Parse Tree Data.
## Usage
trconvert [-t <type>]
## Details
This command converts a grammar from one type to another. Most
conversions will handle only simple syntax differences. More complicated
scenarios are supported depending on the source and target grammar types.
For example, Bison is converted to Antlr4, but the reverse is not
implemented yet.
`trconvert` takes an option target type. If it is not used, the default
is to convert the input of whatever type to Antlr4 syntax. The output
of `trconvert` is a parse tree containing the converted grammar.
## Examples
_Conversion of Antlr4 Abnf to Lark Abnf_
grammar Abnf;
rulelist : rule_* EOF ;
rule_ : ID '=' '/'? elements ;
elements : alternation ;
alternation : concatenation ( '/' concatenation )* ;
concatenation : repetition + ;
repetition : repeat_? element ;
repeat_ : INT | ( INT? '*' INT? ) ;
element : ID | group | option | STRING | NumberValue | ProseValue ;
group : '(' alternation ')' ;
option : '[' alternation ']' ;
NumberValue : '%' ( BinaryValue | DecimalValue | HexValue ) ;
fragment BinaryValue : 'b' BIT+ ( ( '.' BIT+ )+ | ( '-' BIT+ ) )? ;
fragment DecimalValue : 'd' DIGIT+ ( ( '.' DIGIT+ )+ | ( '-' DIGIT+ ) )? ;
fragment HexValue : 'x' HEX_DIGIT+ ( ( '.' HEX_DIGIT+ )+ | ( '-' HEX_DIGIT+ ) )? ;
ProseValue : '<' ( ~ '>' )* '>' ;
ID : LETTER ( LETTER | DIGIT | '-' )* ;
INT : '0' .. '9'+ ;
COMMENT : ';' ~ ( '\n' | '\r' )* '\r'? '\n' -> channel ( HIDDEN ) ;
WS : ( ' ' | '\t' | '\r' | '\n' ) -> channel ( HIDDEN ) ;
STRING : ( '%s' | '%i' )? '"' ( ~ '"' )* '"' ;
fragment LETTER : 'a' .. 'z' | 'A' .. 'Z' ;
fragment BIT : '0' .. '1' ;
fragment DIGIT : '0' .. '9' ;
fragment HEX_DIGIT : ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' ) ;
_Command_
trparse Abnf.g4 | trconvert -t lark | trprint > Abnf.lark
_Output_
rulelist :  rule_ * EOF
rule_ :  ID "=" "/" ? elements
elements :  alternation
alternation :  concatenation ( "/" concatenation ) *
concatenation :  repetition +
repetition :  repeat_ ? element
repeat_ :  INT | ( INT ? "*" INT ? )
element :  ID | group | option | STRING | NUMBERVALUE | PROSEVALUE
group :  "(" alternation ")"
option :  "[" alternation "]"
NUMBERVALUE :  "%" ( BINARYVALUE | DECIMALVALUE | HEXVALUE )
BINARYVALUE :  "b" BIT + ( ( "." BIT + ) + | ( "-" BIT + ) ) ?
DECIMALVALUE :  "d" DIGIT + ( ( "." DIGIT + ) + | ( "-" DIGIT + ) ) ?
HEXVALUE :  "x" HEX_DIGIT + ( ( "." HEX_DIGIT + ) + | ( "-" HEX_DIGIT + ) ) ?
PROSEVALUE :  "<" ( /(?!>)/ ) * ">"
ID :  LETTER ( LETTER | DIGIT | "-" ) *
INT :  "0" .. "9" +
COMMENT :  ";" /(?!\n|\r)/ * "\r" ? "\n"
WS :  ( " " | "\t" | "\r" | "\n" )
STRING :  ( "%s" | "%i" ) ? "\"" ( /(?!")/ ) * "\""
LETTER :  "a" .. "z" | "A" .. "Z"
BIT :  "0" .. "1"
DIGIT :  "0" .. "9"
HEX_DIGIT :  ( "0" .. "9" | "a" .. "f" | "A" .. "F" )
%ignore COMMENT
%ignore WS
## Current version
0.22.0 Add trdot. Update to Antlr 4.13.1 and Dotnet 8.0.
## 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.