Skip to content

Instantly share code, notes, and snippets.

View kaby76's full-sized avatar
💭
Working on Trash, a tool for refactoring grammars

Ken Domino kaby76

💭
Working on Trash, a tool for refactoring grammars
View GitHub Profile
@kaby76
kaby76 / find-inconsistent-grammar.sh
Created November 25, 2021 17:19
Detect inconsistent Antlr grammar files in the same directory
#!/bin/sh
d=`find . -name '*.g4' | grep -v examples | grep -v Generated | sed 's#/[^/]*.g4##' | sort -u`
# find all other grammars in this directory and check if they are
# inconsistently combined or splitted.
for i in $d
do
for j in $i/*.g4
do
spgrammar=no
(function PlaygroundExample() {
const createToken = chevrotain.createToken;
const Lexer = chevrotain.Lexer;
const EmbeddedActionsParser = chevrotain.EmbeddedActionsParser;
const tokenMatcher = chevrotain.tokenMatcher;
/**
* An Example of implementing a Calculator with embedded actions (semantics).
*
grammar InternalAlf ;
entryRuleUnit : ruleUnit EOF ;
ruleUnit : ( ruleAnonymousPackage | rulePackageUnit | ruleClassifierUnitDefinition | ruleClassUnit | ruleDataTypeUnit | ruleAssociationUnit | ruleInteractionUnit | ruleBehaviorUnit | ruleFunctionUnit | ruleFeatureUnit ) ;
entryRuleAnonymousPackage : ruleAnonymousPackage EOF ;
ruleAnonymousPackage : rulePackageBody ;
entryRulePackageUnit : rulePackageUnit EOF ;
rulePackageUnit : ( ruleUnitPrefix rulePackageDefinition ) ;
entryRuleClassifierUnitDefinition : ruleClassifierUnitDefinition EOF ;
ruleClassifierUnitDefinition : ( ruleUnitPrefix ruleClassifierDeclaration ruleTypeBody ) ;
entryRuleClassUnit : ruleClassUnit EOF ;
@kaby76
kaby76 / lark
Created June 29, 2021 13:20
Conversion of lark.lark to lark.g4 Antlr4 syntax
// https://github.com/lark-parser/lark/blob/d676df9b888ead42daffd31c035d95241bff0920/lark/grammars/lark.lark
// LarkParser.g4
parser grammar LarkParser;
options {
tokenVocab = LarkLexer;
contextSuperClass=AttributedParseTreeNode;
}
start: (item? NL)* item? EOF ;
@kaby76
kaby76 / abb.lark
Created June 29, 2021 13:13
Translation of github.com/antlr/grammars-v4/abb/*.g4 to Lark
start : module
module : moduledata
moduledata : MODULE modulename NEWLINE datalist NEWLINE* ENDMODULE
modulename : IDENTIFIER
| proccall
datalist : (NEWLINE
| declaration NEWLINE
| procedure NEWLINE)*
procedure : PROC proccall NEWLINE (functioncall NEWLINE)* ENDPROC
proccall : procname procparameter?