Merge pull request #1485 from parrt/rm-legacy-tests

rm legacy tests
This commit is contained in:
Terence Parr 2016-12-10 15:16:10 -08:00 committed by GitHub
commit 8ed3e1303d
530 changed files with 0 additions and 137373 deletions

View File

@ -83,7 +83,6 @@
<module>tool-testsuite</module>
<module>runtime-testsuite/annotations</module>
<module>runtime-testsuite/processors</module>
<!-- <module>runtime-testsuite-legacy</module> -->
<module>runtime-testsuite</module>
</modules>

View File

@ -1,120 +0,0 @@
<!--
~ Copyright (c) 2012-2016 The ANTLR Project. All rights reserved.
~ Use of this file is governed by the BSD 3-clause license that
~ can be found in the LICENSE.txt file in the project root.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.antlr</groupId>
<artifactId>antlr4-master</artifactId>
<version>4.6-SNAPSHOT</version>
</parent>
<artifactId>antlr4-runtime-testsuite-legacy</artifactId>
<name>ANTLR 4 Legacy Runtime Test Generator</name>
<description>Legacy collection of tests for ANTLR 4 Runtime libraries.</description>
<prerequisites>
<maven>3.0</maven>
</prerequisites>
<inceptionYear>2009</inceptionYear>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>ST4</artifactId>
<version>4.0.8</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.46.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.16.v20140903</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<!--
<testSourceDirectory>test</testSourceDirectory>
-->
<resources>
<resource>
<directory>resources</directory>
</resource>
<resource>
<directory>../runtime</directory>
</resource>
</resources>
</build>
<profiles>
<profile>
<id>gen</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<phase>generate-test-sources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.antlr.v4.testgen.TestGenerator</mainClass>
<arguments>
<argument>${basedir}/..</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/Test*.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>

View File

@ -1,111 +0,0 @@
file(className, descriptors) ::= <<
package org.antlr.v4.test.runtime.xxx.tests.junk;
import org.antlr.v4.runtime.misc.Pair;
import org.antlr.v4.test.runtime.CommentHasStringValue;
import org.antlr.v4.test.runtime.xxx.*;
import org.antlr.v4.test.runtime.xxx.tests.*;
import java.util.ArrayList;
import java.util.List;
public class <className> {
<descriptors; separator="\n\n">
}
>>
rig(targetName, groupName, go, subdir) ::= <<
package org.antlr.v4.test.runtime.xxx.tests.<subdir:{s|<s>.}><targetName; format="lower">;
import org.antlr.v4.test.runtime.xxx.RuntimeTestDescriptor;
import org.antlr.v4.test.runtime.xxx.XXXBaseTest;
import org.antlr.v4.test.runtime.xxx.descriptors.*;
import org.junit.*;
import org.junit.runner.*;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class Test<groupName> extends XXXBaseTest {
public Test<groupName>(RuntimeTestDescriptor descriptor) {
super(descriptor,new Base<targetName>Test());
}
<if(go)>
@BeforeClass
public static void groupSetUp() throws Exception { BaseGoTest.groupSetUp(); }
@AfterClass
public static void groupTearDown() throws Exception { BaseGoTest.groupTearDown(); }
<endif>
@Parameterized.Parameters(name="{0}")
public static RuntimeTestDescriptor[] getAllTestDescriptors() {
return XXXBaseTest.getRuntimeTestDescriptors(<groupName>Descriptors.class, "<targetName>");
}
}
>>
descriptor(testName, TestType, Input, LongInput, Errors, LongErrors, Rule, Output, LongOutput,
grammar, slaveGrammars, grammarName, LongAfterGrammar) ::= <<
public static class <testName> extends Base<TestType>TestDescriptor {
<if(LongInput)>
/**
<LongInput>
*/
@CommentHasStringValue
public String input;<\n>
<else>
public String input = "<Input>";
<endif>
<if(LongOutput)>
/**
<LongOutput>
*/
@CommentHasStringValue
public String output;<\n>
<else>
public String output = "<Output>";
<endif>
<if(LongErrors)>
/**
<LongErrors>
*/
@CommentHasStringValue
public String errors;<\n>
<else>
public String errors = "<Errors>";
<endif>
public String startRule = "<Rule>";
public String grammarName = "<grammarName>";
<if(LongAfterGrammar)>
/**
<LongAfterGrammar>
*/
@CommentHasStringValue
public String afterGrammar;
<endif>
/**
<grammar>
*/
@CommentHasStringValue
public String grammar;
<if(slaveGrammars)>
<slaveGrammars:{sg |
/**
<sg.grammar>
*/
@CommentHasStringValue
public String slaveGrammar<sg.name>;
}>
@Override
public List\<Pair\<String, String>\> getSlaveGrammars() {
List\<Pair\<String,String>\> slaves = new ArrayList\<Pair\<String, String>\>();
<slaveGrammars:{sg | slaves.add(new Pair\<String, String>("<sg.name>",slaveGrammar<sg.name>));<\n>}>
return slaves;
\}
<endif>
}
>>

View File

@ -1,280 +0,0 @@
writeln(s) ::= "std::cout \<\< <s> \<\< std::endl;"
write(s) ::= "std::cout \<\< <s>;"
writeList(s) ::= << std::cout \<\< <s; separator=" \<\< "> \<\< std::endl;>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= ""
Cast(t,v) ::= "dynamic_cast\<<t> *>(<v>)" // Should actually use a more specific name. We may have to use other casts as well.
Append(a,b) ::= "<a> + <b>->toString()"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "<s> = <v>"
AssertIsList(v) ::= "assert(<v>.size() >= 0);" // Use a method that exists only on a list (vector actually).
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= "int <n> = <v>;"
InitBooleanMember(n,v) ::= "bool <n> = <v>;"
GetMember(n) ::= "<n>"
SetMember(n,v) ::= "<n> = <v>;"
AddMember(n,v) ::= "<n> += <v>;"
PlusMember(v,n) ::= "<v> + <n>"
MemberEquals(n,v) ::= "<n> == <v>"
ModMemberEquals(n,m,v) ::= "<n> % <m> == <v>"
ModMemberNotEquals(n,m,v) ::= "<n> % <m> != <v>"
DumpDFA() ::= "dumpDFA();"
Pass() ::= "/* do nothing */"
StringList() ::= "std::vector\<std::string>"
BuildParseTrees() ::= "setBuildParseTree(true);"
BailErrorStrategy() ::= "_errHandler = std::make_shared\<BailErrorStrategy>();"
ToStringTree(s) ::= "<s>->toStringTree(this)"
Column() ::= "getCharPositionInLine()"
Text() ::= "getText()"
ValEquals(a,b) ::= "<a> == <b>"
TextEquals(a) ::= "getText() == \"<a>\""
PlusText(a) ::="\"<a>\" + getText()"
InputText() ::= "_input->getText()"
LTEquals(i, v) ::= "_input->LT(<i>)->getText() == <v>"
LANotEquals(i, v) ::= "_input->LA(<i>) != <v>"
TokenStartColumnEquals(i) ::= "tokenStartCharPositionInLine == <i>"
ImportListener(X) ::= ""
GetExpectedTokenNames() ::= "getExpectedTokens().toString(_tokenNames)"
RuleInvocationStack() ::= "Arrays::listToString(getRuleInvocationStack(), \", \")"
LL_EXACT_AMBIG_DETECTION() ::= <<getInterpreter\<atn::ParserATNSimulator>()->setPredictionMode(atn::PredictionMode::LL_EXACT_AMBIG_DETECTION);>>
ParserToken(parser, token) ::= <%<parser>::<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
bool Property() {
return true;
}
}
>>
ParserPropertyCall(p, call) ::= "<call>"
PositionAdjustingLexer() ::= <<
protected:
class PositionAdjustingLexerATNSimulator : public atn::LexerATNSimulator {
public:
PositionAdjustingLexerATNSimulator(Lexer *recog, const atn::ATN &atn, std::vector\<dfa::DFA> &decisionToDFA,
atn::PredictionContextCache &sharedContextCache)
: atn::LexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache) {
}
void resetAcceptPosition(CharStream *input, int index, int line, int charPositionInLine) {
input->seek(index);
_line = line;
_charPositionInLine = charPositionInLine;
consume(input);
}
};
public:
virtual std::unique_ptr\<Token> nextToken() override {
if (dynamic_cast\<PositionAdjustingLexerATNSimulator *>(_interpreter) == nullptr) {
delete _interpreter;
_interpreter = new PositionAdjustingLexerATNSimulator(this, _atn, _decisionToDFA, _sharedContextCache);
}
return Lexer::nextToken();
}
virtual Token* emit() override {
switch (type) {
case TOKENS:
handleAcceptPositionForKeyword("tokens");
break;
case LABEL:
handleAcceptPositionForIdentifier();
break;
default:
break;
}
return Lexer::emit();
}
private:
bool handleAcceptPositionForIdentifier() {
std::string tokenText = getText();
int identifierLength = 0;
while (identifierLength \< tokenText.length() && isIdentifierChar(tokenText[identifierLength])) {
identifierLength++;
}
if (getInputStream()->index() > tokenStartCharIndex + identifierLength) {
int offset = identifierLength - 1;
getInterpreter\<PositionAdjustingLexerATNSimulator>()->resetAcceptPosition(getInputStream(),
tokenStartCharIndex + offset, tokenStartLine, tokenStartCharPositionInLine + offset);
return true;
}
return false;
}
bool handleAcceptPositionForKeyword(const std::string &keyword) {
if (getInputStream()->index() > tokenStartCharIndex + keyword.length()) {
long offset = keyword.size() - 1;
getInterpreter\<PositionAdjustingLexerATNSimulator>()->resetAcceptPosition(getInputStream(),
tokenStartCharIndex + offset, tokenStartLine, tokenStartCharPositionInLine + offset);
return true;
}
return false;
}
static bool isIdentifierChar(char c) {
return std::isalnum(c) || c == '_';
}
public:
>>
BasicListener(X) ::= <<
@parser::definitions {
#include "TBaseListener.h"
class LeafListener : public TBaseListener {
public:
virtual void visitTerminal(tree::TerminalNode *node) override {
std::cout \<\< node->getSymbol()->getText() \<\< std::endl;
}
};
}
>>
WalkListener(s) ::= <<
LeafListener listener;
tree::ParseTreeWalker::DEFAULT.walk(&listener, <s>);
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::members {
class MyRuleNode : public ParserRuleContext {
public:
size_t altNum;
MyRuleNode(ParserRuleContext *parent, int invokingStateNumber)
: ParserRuleContext(parent, invokingStateNumber) {
}
virtual size_t getAltNumber() const override { return altNum; }
virtual void setAltNumber(size_t altNum) override { this->altNum = altNum; }
};
}
>>
TokenGetterListener(X) ::= <<
@parser::definitions {
#include "TBaseListener.h"
class LeafListener : public TBaseListener {
public:
virtual void exitA(TParser::AContext *ctx) override {
if (ctx->children.size() == 2)
std::cout \<\< ctx->INT(0)->getSymbol()->getText() \<\< " " \<\< ctx->INT(1)->getSymbol()->getText()
\<\< " " \<\< Arrays::toString(ctx->INT()) \<\< std::endl;
else
std::cout \<\< ctx->ID()->getSymbol()->toString() \<\< std::endl;
}
};
}
>>
RuleGetterListener(X) ::= <<
@parser::definitions {
#include "TBaseListener.h"
class LeafListener : public TBaseListener {
public:
virtual void exitA(TParser::AContext *ctx) override {
if (ctx->children.size() == 2) {
std::cout \<\< ctx->b(0)->start->getText() \<\< " " \<\< ctx->b(1)->start->getText() \<\< " " \<\< ctx->b()[0]->start->getText() \<\< std::endl;
} else {
std::cout \<\< ctx->b(0)->start->getText() \<\< std::endl;
}
}
};
}
>>
LRListener(X) ::= <<
@parser::definitions {
#include "TBaseListener.h"
class LeafListener : public TBaseListener {
public:
virtual void exitE(TParser::EContext *ctx) override {
if (ctx->children.size() == 3) {
std::cout \<\< ctx->e(0)->start->getText() \<\< " " \<\< ctx->e(1)->start->getText() \<\< " " \<\< ctx->e()[0]->start->getText() \<\< std::endl;
} else {
std::cout \<\< ctx->INT()->getSymbol()->getText() \<\< std::endl;
}
}
};
}
>>
LRWithLabelsListener(X) ::= <<
@parser::definitions {
#include "TBaseListener.h"
class LeafListener : public TBaseListener {
public:
virtual void exitCall(TParser::CallContext *ctx) override {
std::cout \<\< ctx->e()->start->getText() \<\< " " \<\< ctx->eList()->toString() \<\< std::endl;
}
virtual void exitInt(TParser::IntContext *ctx) override {
std::cout \<\< ctx->INT()->getSymbol()->getText() \<\< std::endl;
}
};
}
>>
ImportVisitor(X) ::= ""
BasicVisitor(X) ::= ""
WalkVisitor(s) ::= ""
LRWithLabelsVisitor(X) ::= ""
RuleGetterVisitor(X) ::= ""
LRVisitor(x) ::= ""
TokenGetterVisitor(x) ::= ""
DeclareContextListGettersFunction() ::= <<
void foo() {
SContext *s;
std::vector\<AContext *> a = s->a();
std::vector\<BContext *> b = s->b();
}
>>
Declare_foo() ::= <<void foo() {
std::cout \<\< "foo";
}
>>
Invoke_foo() ::= "foo();"
Declare_pred() ::= <<
bool pred(bool v) {
std::cout \<\< "eval=" \<\< std::boolalpha \<\< v \<\< std::endl;
return v;
}
>>
Invoke_pred(v) ::= <<pred(<v>)>>
ContextRuleFunction(ctx, rule) ::= "<ctx>-><rule>"
StringType() ::= "std::string"
ContextMember(ctx, subctx, member) ::= "<ctx>-><subctx>-><member>"

View File

@ -1,51 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EDC70A11-C4C1-4209-93A6-CCE2B19E8E95}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Antlr4.Test.mono</RootNamespace>
<AssemblyName>Test</AssemblyName>
<StartupObject>Test</StartupObject>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="Antlr4.Runtime.mono.csproj">
<Project>{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}</Project>
<Name>Antlr4.Runtime.mono</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="Test.cs" />
<Compile Include="L.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<None Include="App.config">
<LogicalName>Test.exe.config</LogicalName>
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?><Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{EDC70A11-C4C1-4209-93A6-CCE2B19E8E95}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Antlr4.Test.mono</RootNamespace>
<AssemblyName>Test</AssemblyName>
<StartupObject>Test</StartupObject>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs"/>
<Compile Include="Test.cs"/>
<Compile Include="L.cs"/>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets"/>
<ItemGroup>
<ProjectReference Include="Antlr4.Runtime.vs2013.csproj">
<Project>{E1A46D9D-66CB-46E8-93B0-7FC87299ABEF}</Project>
<Name>Antlr4.Runtime.vs2013</Name>
</ProjectReference>
</ItemGroup>
</Project>

View File

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<startup>
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0"/>
</startup>
</configuration>

View File

@ -1,28 +0,0 @@
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.
[assembly: AssemblyTitle ("Antlr4.Test.mono")]
[assembly: AssemblyDescription ("")]
[assembly: AssemblyConfiguration ("")]
[assembly: AssemblyCompany ("")]
[assembly: AssemblyProduct ("")]
[assembly: AssemblyCopyright ("ericvergnaud")]
[assembly: AssemblyTrademark ("")]
[assembly: AssemblyCulture ("")]
[assembly: CLSCompliant (true)]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
[assembly: AssemblyVersion ("1.0.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]

View File

@ -1,299 +0,0 @@
writeln(s) ::= <<Console.WriteLine(<s>);>>
write(s) ::= <<Console.Write(<s>);>>
writeList(s) ::= <<Console.WriteLine(<s; separator="+">);>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= <<Debug.Assert(<s>);>>
Cast(t,v) ::= "((<t>)<v>)"
Append(a,b) ::= "<a> + <b>"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "Object <s> = <v>;"
AssertIsList(v) ::= "System.Collections.IList __ttt__ = <v>;" // just use static type system
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= <%int <n> = <v>;%>
InitBooleanMember(n,v) ::= <%bool <n> = <v>;%>
GetMember(n) ::= <%this.<n>%>
SetMember(n,v) ::= <%this.<n> = <v>;%>
AddMember(n,v) ::= <%this.<n> += <v>;%>
PlusMember(v,n) ::= <%<v> + this.<n>%>
MemberEquals(n,v) ::= <%this.<n> == <v>%>
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
DumpDFA() ::= "this.DumpDFA();"
Pass() ::= ""
StringList() ::= "List\<String>"
BuildParseTrees() ::= "this.BuildParseTree = true;"
BailErrorStrategy() ::= <%ErrorHandler = new BailErrorStrategy();%>
ToStringTree(s) ::= <%<s>.ToStringTree(this)%>
Column() ::= "this.Column"
Text() ::= "this.Text"
ValEquals(a,b) ::= <%<a>==<b>%>
TextEquals(a) ::= <%this.Text.Equals("<a>")%>
PlusText(a) ::= <%"<a>" + this.Text%>
InputText() ::= "this.TokenStream.GetText()"
LTEquals(i, v) ::= <%this.TokenStream.Lt(<i>).Text.Equals(<v>)%>
LANotEquals(i, v) ::= <%this.InputStream.La(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%this.TokenStartColumn==<i>%>
ImportListener(X) ::= ""
GetExpectedTokenNames() ::= "this.GetExpectedTokens().ToString(this.Vocabulary)"
RuleInvocationStack() ::= "GetRuleInvocationStackAsString()"
LL_EXACT_AMBIG_DETECTION() ::= <<Interpreter.PredictionMode = PredictionMode.LlExactAmbigDetection;>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
bool Property() {
return true;
}
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
public override IToken NextToken() {
if (!(Interpreter is PositionAdjustingLexerATNSimulator)) {
Interpreter = new PositionAdjustingLexerATNSimulator(this, _ATN);
}
return base.NextToken();
}
public override IToken Emit() {
switch (Type) {
case TOKENS:
HandleAcceptPositionForKeyword("tokens");
break;
case LABEL:
HandleAcceptPositionForIdentifier();
break;
default:
break;
}
return base.Emit();
}
private bool HandleAcceptPositionForIdentifier() {
string tokenText = this.Text;
int identifierLength = 0;
while (identifierLength \< tokenText.Length && IsIdentifierChar(tokenText[identifierLength])) {
identifierLength++;
}
if (InputStream.Index > TokenStartCharIndex + identifierLength) {
int offset = identifierLength - 1;
getInterpreter().ResetAcceptPosition((ICharStream)InputStream, TokenStartCharIndex + offset, TokenStartLine, TokenStartColumn + offset);
return true;
}
return false;
}
private bool HandleAcceptPositionForKeyword(string keyword) {
if (InputStream.Index > TokenStartCharIndex + keyword.Length) {
int offset = keyword.Length - 1;
getInterpreter().ResetAcceptPosition((ICharStream)InputStream, TokenStartCharIndex + offset, TokenStartLine, TokenStartColumn + offset);
return true;
}
return false;
}
public PositionAdjustingLexerATNSimulator getInterpreter() {
return (PositionAdjustingLexerATNSimulator)base.Interpreter;
}
private static bool IsIdentifierChar(char c) {
return Char.IsLetterOrDigit(c) || c == '_';
}
public class PositionAdjustingLexerATNSimulator : LexerATNSimulator {
public PositionAdjustingLexerATNSimulator(Lexer recog, ATN atn)
: base(recog, atn)
{
}
public void ResetAcceptPosition(ICharStream input, int index, int line, int column) {
input.Seek(index);
this.Line = line;
this.Column = column;
Consume(input);
}
}
>>
BasicListener(X) ::= <<
@parser::members {
public class LeafListener : TBaseListener {
public override void VisitTerminal(ITerminalNode node) {
Console.WriteLine(node.Symbol.Text);
}
}
}
>>
WalkListener(s) ::= <<
ParseTreeWalker walker = new ParseTreeWalker();
walker.Walk(new LeafListener(), <s>);
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::members {
public class MyRuleNode : ParserRuleContext {
public int altNum;
public MyRuleNode(ParserRuleContext parent, int invokingStateNumber): base(parent, invokingStateNumber)
{
}
public override int getAltNumber() { return altNum; }
public override void setAltNumber(int altNum) { this.altNum = altNum; }
}
}
>>
TokenGetterListener(X) ::= <<
@parser::members {
public class LeafListener : TBaseListener {
public override void ExitA(TParser.AContext ctx) {
if (ctx.ChildCount==2)
{
StringBuilder sb = new StringBuilder ("[");
foreach (ITerminalNode node in ctx.INT ()) {
sb.Append (node.ToString ());
sb.Append (", ");
}
sb.Length = sb.Length - 2;
sb.Append ("]");
Console.Write ("{0} {1} {2}", ctx.INT (0).Symbol.Text,
ctx.INT (1).Symbol.Text, sb.ToString());
}
else
Console.WriteLine(ctx.ID().Symbol);
}
}
}
>>
RuleGetterListener(X) ::= <<
@parser::members {
public class LeafListener : TBaseListener {
public override void ExitA(TParser.AContext ctx) {
if (ctx.ChildCount==2) {
Console.Write("{0} {1} {2}",ctx.b(0).Start.Text,
ctx.b(1).Start.Text,ctx.b()[0].Start.Text);
} else
Console.WriteLine(ctx.b(0).Start.Text);
}
}
}
>>
LRListener(X) ::= <<
@parser::members {
public class LeafListener : TBaseListener {
public override void ExitE(TParser.EContext ctx) {
if (ctx.ChildCount==3) {
Console.Write("{0} {1} {2}\n",ctx.e(0).Start.Text,
ctx.e(1).Start.Text, ctx.e()[0].Start.Text);
} else
Console.WriteLine(ctx.INT().Symbol.Text);
}
}
}
>>
LRWithLabelsListener(X) ::= <<
@parser::members {
public class LeafListener : TBaseListener {
public override void ExitCall(TParser.CallContext ctx) {
Console.Write("{0} {1}",ctx.e().Start.Text,ctx.eList());
}
public override void ExitInt(TParser.IntContext ctx) {
Console.WriteLine(ctx.INT().Symbol.Text);
}
}
}
>>
ImportVisitor(X) ::= ""
BasicVisitor(X) ::= ""
WalkVisitor(s) ::= ""
LRWithLabelsVisitor(X) ::= ""
RuleGetterVisitor(X) ::= ""
LRVisitor(x) ::= ""
TokenGetterVisitor(x) ::= ""
DeclareContextListGettersFunction() ::= <<
void foo() {
SContext s = null;
AContext[] a = s.a();
BContext[] b = s.b();
}
>>
Declare_foo() ::= <<public void foo() {Console.WriteLine("foo");}>>
Invoke_foo() ::= "this.foo();"
Declare_pred() ::= <<bool pred(bool v) {
Console.WriteLine("eval="+v.ToString().ToLower());
return v;
}
>>
Invoke_pred(v) ::= <<this.pred(<v>)>>
ParserTokenType(t) ::= "Parser.<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"

View File

@ -1,338 +0,0 @@
writeln(s) ::= <<fmt.Println(<s>)>>
write(s) ::= <<fmt.Print(<s>)>>
writeList(s) ::= <<fmt.Print(<s; separator="+">);>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= ""
Cast(t,v) ::= "(<v>)"
Append(a,b) ::= "<a> + fmt.Sprint(<b>)"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s, v) ::= "var <s> = <v>"
AssertIsList(v) ::= ""
AssignLocal(s, v) ::= "<s> = <v>;"
InitIntMember(n, v) ::= <%var <n> int = <v>; var _ int = <n>; %>
InitBooleanMember(n, v) ::= <%var <n> bool = <v>; var _ bool = <n>; %>
GetMember(n) ::= <%<n>%>
SetMember(n, v) ::= <%<n> = <v>;%>
AddMember(n, v) ::= <%<n> += <v>;%>
PlusMember(v, n) ::= <%<v> + fmt.Sprint(<n>)%>
MemberEquals(n, v) ::= <%<n> == <v>%>
ModMemberEquals(n, m, v) ::= <%<n> % <m> == <v>%>
ModMemberNotEquals(n, m, v) ::= <%<n> % <m> != <v>%>
DumpDFA() ::= "p.DumpDFA()"
Pass() ::= ""
StringList() ::= "[]string"
BuildParseTrees() ::= "p.BuildParseTrees = true"
BailErrorStrategy() ::= <%p.SetErrorHandler(antlr.NewBailErrorStrategy())%>
ToStringTree(s) ::= <%<s>.ToStringTree(nil, p)%>
Column() ::= "p.GetCharPositionInLine()"
Text() ::= "l.GetText()"
ValEquals(a, b) ::= <%<a> == <b>%>
TextEquals(a) ::= <%p.GetText() == "<a>"%>
PlusText(a) ::= <%"<a>" + l.GetText()%>
InputText() ::= "p.GetTokenStream().GetAllText()"
LTEquals(i, v) ::= <%p.GetTokenStream().LT(<i>).GetText() == <v>%>
LANotEquals(i, v) ::= <%p.GetTokenStream().LA(<i>) != <v>%>
TokenStartColumnEquals(i) ::= <%p.TokenStartColumn == <i>%>
ImportListener(X) ::= ""
GetExpectedTokenNames() ::= "p.GetExpectedTokens().StringVerbose(p.GetTokenNames(), nil, false)"
RuleInvocationStack() ::= "antlr.PrintArrayJavaStyle(p.GetRuleInvocationStack(nil))"
LL_EXACT_AMBIG_DETECTION() ::= <<p.Interpreter.SetPredictionMode(antlr.PredictionModeLLExactAmbigDetection);>>
ParserToken(parser, token) ::= <%<parser><token>%>
Production(p) ::= <%<p; format="cap">%>
Result(r) ::= <%Get<r; format="cap">()%>
ParserPropertyMember() ::= <<
@parser::members {
func (p *TParser) Property() bool {
return true
}
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
func (p *PositionAdjustingLexer) NextToken() antlr.Token {
if _, ok := p.Interpreter.(*PositionAdjustingLexerATNSimulator); !ok {
p.Interpreter = NewPositionAdjustingLexerATNSimulator(p, lexerAtn, p.Interpreter.DecisionToDFA(), p.Interpreter.SharedContextCache())
p.Virt = p
}
return p.BaseLexer.NextToken()
}
func (p *PositionAdjustingLexer) Emit() antlr.Token {
switch p.GetType() {
case PositionAdjustingLexerTOKENS:
p.HandleAcceptPositionForKeyword("tokens")
case PositionAdjustingLexerLABEL:
p.HandleAcceptPositionForIdentifier()
}
return p.BaseLexer.Emit()
}
func isIdentifierChar(c rune) bool {
return unicode.IsLetter(c) || unicode.IsDigit(c) || c == '_'
}
func (p *PositionAdjustingLexer) HandleAcceptPositionForIdentifier() bool {
var tokenText = p.GetText()
var identifierLength int
for identifierLength \< len(tokenText) && isIdentifierChar([]rune(tokenText)[identifierLength]) {
identifierLength++
}
if p.GetInputStream().Index() \<= p.TokenStartCharIndex + identifierLength {
return false
}
var offset = identifierLength - 1
p.GetInterpreter().(*PositionAdjustingLexerATNSimulator).ResetAcceptPosition(p.GetInputStream(), p.TokenStartCharIndex + offset, p.TokenStartLine, p.TokenStartColumn + offset)
return true
}
func (p *PositionAdjustingLexer) HandleAcceptPositionForKeyword(keyword string) bool {
if p.GetInputStream().Index() \<= p.TokenStartCharIndex + len(keyword) {
return false
}
var offset = len(keyword) - 1
p.GetInterpreter().(*PositionAdjustingLexerATNSimulator).ResetAcceptPosition(p.GetInputStream(), p.TokenStartCharIndex + offset, p.TokenStartLine, p.TokenStartColumn + offset)
return true
}
type PositionAdjustingLexerATNSimulator struct {
*antlr.LexerATNSimulator
}
func NewPositionAdjustingLexerATNSimulator(recog antlr.Lexer, atn *antlr.ATN, decisionToDFA []*antlr.DFA, sharedContextCache *antlr.PredictionContextCache) *PositionAdjustingLexerATNSimulator {
return &PositionAdjustingLexerATNSimulator{
LexerATNSimulator: antlr.NewLexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache),
}
}
func (p *PositionAdjustingLexerATNSimulator) ResetAcceptPosition(input antlr.CharStream, index, line, charPositionInLine int) {
input.Seek(index)
p.Line = line
p.CharPositionInLine = charPositionInLine
p.Consume(input)
}
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::members {
type MyRuleNode struct {
*antlr.BaseParserRuleContext
altNum int
}
func NewMyRuleNode(parent antlr.ParserRuleContext, invokingStateNumber int) *MyRuleNode {
return &MyRuleNode{
BaseParserRuleContext : antlr.NewBaseParserRuleContext(parent, invokingStateNumber),
}
}
func (m *MyRuleNode) GetAltNumber() int {
return m.altNum
}
func (m *MyRuleNode) SetAltNumber(altNum int) {
m.altNum = altNum
}
}
>>
BasicListener(notused) ::= <<
@parser::members {
type LeafListener struct {
*BaseTListener
}
func NewLeafListener() *LeafListener {
return &LeafListener{BaseTListener: &BaseTListener{}}
}
func (*LeafListener) VisitTerminal(node antlr.TerminalNode) {
fmt.Println(node.GetSymbol().GetText())
}
}
>>
WalkListener(s) ::= <<
var walker = antlr.NewParseTreeWalker()
walker.Walk(NewLeafListener(), <s>)
>>
TokenGetterListener(notused) ::= <<
@parser::members {
type LeafListener struct {
*BaseTListener
}
func NewLeafListener() *LeafListener {
return &LeafListener{BaseTListener: &BaseTListener{}}
}
func (*LeafListener) ExitA(ctx *AContext) {
if ctx.GetChildCount() == 2 {
fmt.Printf("%s %s %s", ctx.INT(0).GetSymbol().GetText(), ctx.INT(1).GetSymbol().GetText(), antlr.PrintArrayJavaStyle(antlr.TerminalNodeToStringArray(ctx.AllINT())))
} else {
fmt.Println(ctx.ID().GetSymbol())
}
}
}
>>
RuleGetterListener(notused) ::= <<
@parser::members {
type LeafListener struct {
*BaseTListener
}
func NewLeafListener() *LeafListener {
return &LeafListener{BaseTListener: &BaseTListener{}}
}
func (*LeafListener) ExitA(ctx *AContext) {
if ctx.GetChildCount() == 2 {
fmt.Printf("%s %s %s", ctx.B(0).GetStart().GetText(), ctx.B(1).GetStart().GetText(), ctx.AllB()[0].GetStart().GetText())
} else {
fmt.Println(ctx.B(0).GetStart().GetText())
}
}
}
>>
LRListener(notused) ::= <<
@parser::members {
type LeafListener struct {
*BaseTListener
}
func NewLeafListener() *LeafListener {
return &LeafListener{BaseTListener: &BaseTListener{}}
}
func (*LeafListener) ExitE(ctx *EContext) {
if ctx.GetChildCount() == 3 {
fmt.Printf("%s %s %s\n", ctx.E(0).GetStart().GetText(), ctx.E(1).GetStart().GetText(), ctx.AllE()[0].GetStart().GetText())
} else {
fmt.Println(ctx.INT().GetSymbol().GetText())
}
}
}
>>
LRWithLabelsListener(notused) ::= <<
@parser::members {
type LeafListener struct {
*BaseTListener
}
func NewLeafListener() *LeafListener {
return &LeafListener{BaseTListener: &BaseTListener{}}
}
func (*LeafListener) ExitCall(ctx *CallContext) {
fmt.Printf("%s %s", ctx.E().GetStart().GetText(), ctx.EList().String(nil, nil))
}
func (*LeafListener) ExitInt(ctx *IntContext) {
fmt.Println(ctx.INT().GetSymbol().GetText())
}
}
>>
ImportVisitor(X) ::= ""
BasicVisitor(X) ::= ""
WalkVisitor(s) ::= ""
LRWithLabelsVisitor(X) ::= ""
RuleGetterVisitor(X) ::= ""
LRVisitor(x) ::= ""
TokenGetterVisitor(x) ::= ""
DeclareContextListGettersFunction() ::= <<
func foo() {
// TODO
// var s SContext
// var a = s.A()
// var b = s.B()
}
>>
Declare_foo() ::= <<
func foo() {
fmt.Println("foo")
}
>>
Invoke_foo() ::= "foo()"
Declare_pred() ::= <<
func pred(v bool) bool {
fmt.Println("eval=" + fmt.Sprint(v))
return v
}
>>
Invoke_pred(v) ::= <<pred(<v>)>>
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member; format={cap}>"

View File

@ -1,298 +0,0 @@
writeln(s) ::= <<System.out.println(<s>);>>
write(s) ::= <<System.out.print(<s>);>>
writeList(s) ::= <<System.out.println(<s; separator="+">);>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= <<assert(<s>);>>
Cast(t,v) ::= "((<t>)<v>)"
Append(a,b) ::= "<a> + <b>"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "Object <s> = <v>;"
AssertIsList(v) ::= "List\<?> __ttt__ = <v>;" // just use static type system
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= <%int <n> = <v>;%>
InitBooleanMember(n,v) ::= <%boolean <n> = <v>;%>
GetMember(n) ::= <%this.<n>%>
SetMember(n,v) ::= <%this.<n> = <v>;%>
AddMember(n,v) ::= <%this.<n> += <v>;%>
PlusMember(v,n) ::= <%<v> + this.<n>%>
MemberEquals(n,v) ::= <%this.<n> == <v>%>
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> == <v>%>
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
DumpDFA() ::= "this.dumpDFA();"
Pass() ::= ""
StringList() ::= "List\<String>"
BuildParseTrees() ::= "setBuildParseTree(true);"
BailErrorStrategy() ::= <%setErrorHandler(new BailErrorStrategy());%>
ToStringTree(s) ::= <%<s>.toStringTree(this)%>
Column() ::= "this.getCharPositionInLine()"
Text() ::= "this.getText()"
ValEquals(a,b) ::= <%<a>==<b>%>
TextEquals(a) ::= <%this.getText().equals("<a>")%>
PlusText(a) ::= <%"<a>" + this.getText()%>
InputText() ::= "this._input.getText()"
LTEquals(i, v) ::= <%this._input.LT(<i>).getText().equals(<v>)%>
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%this._tokenStartCharPositionInLine==<i>%>
ImportListener(X) ::= ""
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.tokenNames)"
RuleInvocationStack() ::= "getRuleInvocationStack()"
LL_EXACT_AMBIG_DETECTION() ::= <<_interp.setPredictionMode(PredictionMode.LL_EXACT_AMBIG_DETECTION);>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
boolean Property() {
return true;
}
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
@Override
public Token nextToken() {
if (!(_interp instanceof PositionAdjustingLexerATNSimulator)) {
_interp = new PositionAdjustingLexerATNSimulator(this, _ATN, _decisionToDFA, _sharedContextCache);
}
return super.nextToken();
}
@Override
public Token emit() {
switch (_type) {
case TOKENS:
handleAcceptPositionForKeyword("tokens");
break;
case LABEL:
handleAcceptPositionForIdentifier();
break;
default:
break;
}
return super.emit();
}
private boolean handleAcceptPositionForIdentifier() {
String tokenText = getText();
int identifierLength = 0;
while (identifierLength \< tokenText.length() && isIdentifierChar(tokenText.charAt(identifierLength))) {
identifierLength++;
}
if (getInputStream().index() > _tokenStartCharIndex + identifierLength) {
int offset = identifierLength - 1;
getInterpreter().resetAcceptPosition(getInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);
return true;
}
return false;
}
private boolean handleAcceptPositionForKeyword(String keyword) {
if (getInputStream().index() > _tokenStartCharIndex + keyword.length()) {
int offset = keyword.length() - 1;
getInterpreter().resetAcceptPosition(getInputStream(), _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset);
return true;
}
return false;
}
@Override
public PositionAdjustingLexerATNSimulator getInterpreter() {
return (PositionAdjustingLexerATNSimulator)super.getInterpreter();
}
private static boolean isIdentifierChar(char c) {
return Character.isLetterOrDigit(c) || c == '_';
}
protected static class PositionAdjustingLexerATNSimulator extends LexerATNSimulator {
public PositionAdjustingLexerATNSimulator(Lexer recog, ATN atn,
DFA[] decisionToDFA,
PredictionContextCache sharedContextCache)
{
super(recog, atn, decisionToDFA, sharedContextCache);
}
protected void resetAcceptPosition(CharStream input, int index, int line, int charPositionInLine) {
input.seek(index);
this.line = line;
this.charPositionInLine = charPositionInLine;
consume(input);
}
}
>>
BasicListener(X) ::= <<
@parser::members {
public static class LeafListener extends TBaseListener {
public void visitTerminal(TerminalNode node) {
System.out.println(node.getSymbol().getText());
}
}
}
>>
WalkListener(s) ::= <<
ParseTreeWalker walker = new ParseTreeWalker();
walker.walk(new LeafListener(), <s>);
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::members {
public static class MyRuleNode extends ParserRuleContext {
public int altNum;
public MyRuleNode(ParserRuleContext parent, int invokingStateNumber) {
super(parent, invokingStateNumber);
}
@Override public int getAltNumber() { return altNum; }
@Override public void setAltNumber(int altNum) { this.altNum = altNum; }
}
}
>>
TokenGetterListener(X) ::= <<
@parser::members {
public static class LeafListener extends TBaseListener {
public void exitA(TParser.AContext ctx) {
if (ctx.getChildCount()==2)
System.out.printf("%s %s %s",ctx.INT(0).getSymbol().getText(),
ctx.INT(1).getSymbol().getText(),ctx.INT());
else
System.out.println(ctx.ID().getSymbol());
}
}
}
>>
RuleGetterListener(X) ::= <<
@parser::members {
public static class LeafListener extends TBaseListener {
public void exitA(TParser.AContext ctx) {
if (ctx.getChildCount()==2) {
System.out.printf("%s %s %s",ctx.b(0).start.getText(),
ctx.b(1).start.getText(),ctx.b().get(0).start.getText());
} else
System.out.println(ctx.b(0).start.getText());
}
}
}
>>
LRListener(X) ::= <<
@parser::members {
public static class LeafListener extends TBaseListener {
public void exitE(TParser.EContext ctx) {
if (ctx.getChildCount()==3) {
System.out.printf("%s %s %s\n",ctx.e(0).start.getText(),
ctx.e(1).start.getText(), ctx.e().get(0).start.getText());
} else
System.out.println(ctx.INT().getSymbol().getText());
}
}
}
>>
LRWithLabelsListener(X) ::= <<
@parser::members {
public static class LeafListener extends TBaseListener {
public void exitCall(TParser.CallContext ctx) {
System.out.printf("%s %s",ctx.e().start.getText(),ctx.eList());
}
public void exitInt(TParser.IntContext ctx) {
System.out.println(ctx.INT().getSymbol().getText());
}
}
}
>>
ImportVisitor(X) ::= ""
BasicVisitor(X) ::= ""
WalkVisitor(s) ::= ""
LRWithLabelsVisitor(X) ::= ""
RuleGetterVisitor(X) ::= ""
LRVisitor(x) ::= ""
TokenGetterVisitor(x) ::= ""
DeclareContextListGettersFunction() ::= <<
void foo() {
SContext s = null;
List\<? extends AContext> a = s.a();
List\<? extends BContext> b = s.b();
}
>>
Declare_foo() ::= <<
public void foo() {System.out.println("foo");}
>>
Invoke_foo() ::= "foo();"
Declare_pred() ::= <<boolean pred(boolean v) {
System.out.println("eval="+v);
return v;
}
>>
Invoke_pred(v) ::= <<this.pred(<v>)>>
ParserTokenType(t) ::= "Parser.<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"

View File

@ -1,285 +0,0 @@
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
write(s) ::= <<document.getElementById('output').value += <s>;>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= ""
Cast(t,v) ::= "<v>"
Append(a,b) ::= "<a> + <b>"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "var <s> = <v>;"
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
GetMember(n) ::= <%this.<n>%>
SetMember(n,v) ::= <%this.<n> = <v>;%>
AddMember(n,v) ::= <%this.<n> += <v>;%>
PlusMember(v,n) ::= <%<v> + this.<n>%>
MemberEquals(n,v) ::= <%this.<n> === <v>%>
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
DumpDFA() ::= "this.dumpDFA();"
Pass() ::= ""
StringList() ::= "list"
BuildParseTrees() ::= "this.buildParseTrees = true;"
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
Column() ::= "this.column"
Text() ::= "this.text"
ValEquals(a,b) ::= <%<a>===<b>%>
TextEquals(a) ::= <%this.text==="<a>"%>
PlusText(a) ::= <%"<a>" + this.text%>
InputText() ::= "this._input.getText()"
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
ImportListener(X) ::= <<var <X>Listener = require('./<X>Listener').<X>Listener;>>
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
this.Property = function() {
return true;
}
}
>>
PositionAdjustingLexer() ::= <<
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
this._input.seek(index);
this.line = line;
this.column = column;
this._interp.consume(this._input);
};
PositionAdjustingLexer.prototype.nextToken = function() {
if (!("resetAcceptPosition" in this._interp)) {
var lexer = this;
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
}
return antlr4.Lexer.prototype.nextToken.call(this);
};
PositionAdjustingLexer.prototype.emit = function() {
switch(this._type) {
case PositionAdjustingLexer.TOKENS:
this.handleAcceptPositionForKeyword("tokens");
break;
case PositionAdjustingLexer.LABEL:
this.handleAcceptPositionForIdentifier();
break;
}
return antlr4.Lexer.prototype.emit.call(this);
};
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
var tokenText = this.text;
var identifierLength = 0;
while (identifierLength \< tokenText.length &&
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
) {
identifierLength += 1;
}
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
var offset = identifierLength - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
var offset = keyword.length - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.isIdentifierChar = function(c) {
return c.match(/^[0-9a-zA-Z_]+$/);
}
>>
BasicListener(X) ::= <<
this.LeafListener = function() {
this.visitTerminal = function(node) {
document.getElementById('output').value += node.symbol.text + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
>>
WalkListener(s) ::= <<
var walker = new antlr4.tree.ParseTreeWalker();
walker.walk(new this.LeafListener(), <s>);
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::header {
MyRuleNode = function(parent, invokingState) {
antlr4.ParserRuleContext.call(this, parent, invokingState);
this.altNum = 0;
return this;
};
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
MyRuleNode.prototype.constructor = MyRuleNode;
}
>>
TokenGetterListener(X) ::= <<
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
} else {
str = ctx.ID().symbol.toString();
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
>>
RuleGetterListener(X) ::= <<
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
} else {
str = ctx.b(0).start.text;
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
>>
LRListener(X) ::= <<
this.LeafListener = function() {
this.exitE = function(ctx) {
var str;
if(ctx.getChildCount()===3) {
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
} else {
str = ctx.INT().symbol.text;
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
>>
LRWithLabelsListener(X) ::= <<
this.LeafListener = function() {
this.exitCall = function(ctx) {
var str = ctx.e().start.text + ' ' + ctx.eList();
document.getElementById('output').value += str + '\\n';
};
this.exitInt = function(ctx) {
var str = ctx.INT().symbol.text;
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
>>
DeclareContextListGettersFunction() ::= <<
function foo() {
var s = new SContext();
var a = s.a();
var b = s.b();
};
>>
Declare_foo() ::= "this.foo = function() {document.getElementById('output').value += 'foo' + '\\n';};"
Invoke_foo() ::= "this.foo();"
Declare_pred() ::= <<this.pred = function(v) {
document.getElementById('output').value += 'eval=' + v.toString() + '\\n';
return v;
};
>>
Invoke_pred(v) ::= <<this.pred(<v>)>>
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"
ParserPropertyCall(p, call) ::= "<p>.<call>"

View File

@ -1,294 +0,0 @@
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
write(s) ::= <<document.getElementById('output').value += <s>;>>
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= ""
Cast(t,v) ::= "<v>"
Append(a,b) ::= "<a> + <b>"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "var <s> = <v>;"
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
GetMember(n) ::= <%this.<n>%>
SetMember(n,v) ::= <%this.<n> = <v>;%>
AddMember(n,v) ::= <%this.<n> += <v>;%>
PlusMember(v,n) ::= <%<v> + this.<n>%>
MemberEquals(n,v) ::= <%this.<n> === <v>%>
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
DumpDFA() ::= "this.dumpDFA();"
Pass() ::= ""
StringList() ::= "list"
BuildParseTrees() ::= "this.buildParseTrees = true;"
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
Column() ::= "this.column"
Text() ::= "this.text"
ValEquals(a,b) ::= <%<a>===<b>%>
TextEquals(a) ::= <%this.text==="<a>"%>
PlusText(a) ::= <%"<a>" + this.text%>
InputText() ::= "this._input.getText()"
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
ImportListener(X) ::= <<
@parser::header {
var <X>Listener = require('./<X>Listener').<X>Listener;
}
>>
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
this.Property = function() {
return true;
}
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
this._input.seek(index);
this.line = line;
this.column = column;
this._interp.consume(this._input);
};
PositionAdjustingLexer.prototype.nextToken = function() {
if (!("resetAcceptPosition" in this._interp)) {
var lexer = this;
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
}
return antlr4.Lexer.prototype.nextToken.call(this);
};
PositionAdjustingLexer.prototype.emit = function() {
switch(this._type) {
case PositionAdjustingLexer.TOKENS:
this.handleAcceptPositionForKeyword("tokens");
break;
case PositionAdjustingLexer.LABEL:
this.handleAcceptPositionForIdentifier();
break;
}
return antlr4.Lexer.prototype.emit.call(this);
};
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
var tokenText = this.text;
var identifierLength = 0;
while (identifierLength \< tokenText.length &&
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
) {
identifierLength += 1;
}
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
var offset = identifierLength - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
var offset = keyword.length - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.isIdentifierChar = function(c) {
return c.match(/^[0-9a-zA-Z_]+$/);
}
>>
BasicListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.visitTerminal = function(node) {
document.getElementById('output').value += node.symbol.text + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
WalkListener(s) ::= <<
var walker = new antlr4.tree.ParseTreeWalker();
walker.walk(new this.LeafListener(), <s>);
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::header {
MyRuleNode = function(parent, invokingState) {
antlr4.ParserRuleContext.call(this, parent, invokingState);
this.altNum = 0;
return this;
};
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
MyRuleNode.prototype.constructor = MyRuleNode;
}
>>
TokenGetterListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
} else {
str = ctx.ID().symbol.toString();
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
RuleGetterListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
} else {
str = ctx.b(0).start.text;
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
LRListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitE = function(ctx) {
var str;
if(ctx.getChildCount()===3) {
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
} else {
str = ctx.INT().symbol.text;
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
LRWithLabelsListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitCall = function(ctx) {
var str = ctx.e().start.text + ' ' + ctx.eList();
document.getElementById('output').value += str + '\\n';
};
this.exitInt = function(ctx) {
var str = ctx.INT().symbol.text;
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
DeclareContextListGettersFunction() ::= <<
function foo() {
var s = new SContext();
var a = s.a();
var b = s.b();
};
>>
Declare_foo() ::= "this.foo = function() {document.getElementById('output').value += 'foo' + '\\n';};"
Invoke_foo() ::= "this.foo();"
Declare_pred() ::= <<this.pred = function(v) {
document.getElementById('output').value += 'eval=' + v.toString() + '\\n';
return v;
};
>>
Invoke_pred(v) ::= <<this.pred(<v>)>>
ParserTokenType(t) ::= "Parser.<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"

View File

@ -1,296 +0,0 @@
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
write(s) ::= <<document.getElementById('output').value += <s>;>>
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= ""
Cast(t,v) ::= "<v>"
Append(a,b) ::= "<a> + <b>"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "var <s> = <v>;"
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array"}>>
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
GetMember(n) ::= <%this.<n>%>
SetMember(n,v) ::= <%this.<n> = <v>;%>
AddMember(n,v) ::= <%this.<n> += <v>;%>
PlusMember(v,n) ::= <%<v> + this.<n>%>
MemberEquals(n,v) ::= <%this.<n> === <v>%>
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
CheckVectorContext(s,v) ::= "<s> = [].concat(<v>);"
DumpDFA() ::= "this.dumpDFA();"
Pass() ::= ""
StringList() ::= "list"
BuildParseTrees() ::= "this.buildParseTrees = true;"
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
Column() ::= "this.column"
Text() ::= "this.text"
ValEquals(a,b) ::= <%<a>===<b>%>
TextEquals(a) ::= <%this.text==="<a>"%>
PlusText(a) ::= <%"<a>" + this.text%>
InputText() ::= "this._input.getText()"
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
ImportListener(X) ::= <<
@parser::header {
var <X>Listener = require('./<X>Listener').<X>Listener;
}
>>
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
this.Property = function() {
return true;
}
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
this._input.seek(index);
this.line = line;
this.column = column;
this._interp.consume(this._input);
};
PositionAdjustingLexer.prototype.nextToken = function() {
if (!("resetAcceptPosition" in this._interp)) {
var lexer = this;
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
}
return antlr4.Lexer.prototype.nextToken.call(this);
};
PositionAdjustingLexer.prototype.emit = function() {
switch(this._type) {
case PositionAdjustingLexer.TOKENS:
this.handleAcceptPositionForKeyword("tokens");
break;
case PositionAdjustingLexer.LABEL:
this.handleAcceptPositionForIdentifier();
break;
}
return antlr4.Lexer.prototype.emit.call(this);
};
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
var tokenText = this.text;
var identifierLength = 0;
while (identifierLength \< tokenText.length &&
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
) {
identifierLength += 1;
}
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
var offset = identifierLength - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
var offset = keyword.length - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.isIdentifierChar = function(c) {
return c.match(/^[0-9a-zA-Z_]+$/);
}
>>
BasicListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.visitTerminal = function(node) {
document.getElementById('output').value += node.symbol.text + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
WalkListener(s) ::= <<
var walker = new antlr4.tree.ParseTreeWalker();
walker.walk(new this.LeafListener(), <s>);
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::header {
MyRuleNode = function(parent, invokingState) {
antlr4.ParserRuleContext.call(this, parent, invokingState);
this.altNum = 0;
return this;
};
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
MyRuleNode.prototype.constructor = MyRuleNode;
}
>>
TokenGetterListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
} else {
str = ctx.ID().symbol.toString();
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
RuleGetterListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
} else {
str = ctx.b(0).start.text;
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
LRListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitE = function(ctx) {
var str;
if(ctx.getChildCount()===3) {
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
} else {
str = ctx.INT().symbol.text;
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
LRWithLabelsListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitCall = function(ctx) {
var str = ctx.e().start.text + ' ' + ctx.eList();
document.getElementById('output').value += str + '\\n';
};
this.exitInt = function(ctx) {
var str = ctx.INT().symbol.text;
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
DeclareContextListGettersFunction() ::= <<
function foo() {
var s = new SContext();
var a = s.a();
var b = s.b();
};
>>
Declare_foo() ::= "this.foo = function() {document.getElementById('output').value += 'foo' + '\\n';};"
Invoke_foo() ::= "this.foo();"
Declare_pred() ::= <<this.pred = function(v) {
document.getElementById('output').value += 'eval=' + v.toString() + '\\n';
return v;
};
>>
Invoke_pred(v) ::= <<this.pred(<v>)>>
ParserTokenType(t) ::= "Parser.<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"

View File

@ -1,389 +0,0 @@
writeln(s) ::= <<console.log(<s>);>>
write(s) ::= <<process.stdout.write(<s>);>>
writeList(s) ::= <<console.log(<s; separator="+">);>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= <<console.assert(<s>);>>
Cast(t,v) ::= "<v>"
Append(a,b) ::= "<a> + <b>"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "var <s> = <v>;"
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
GetMember(n) ::= <%this.<n>%>
SetMember(n,v) ::= <%this.<n> = <v>;%>
AddMember(n,v) ::= <%this.<n> += <v>;%>
PlusMember(v,n) ::= <%<v> + this.<n>%>
MemberEquals(n,v) ::= <%this.<n> === <v>%>
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
DumpDFA() ::= "this.dumpDFA();"
Pass() ::= ""
StringList() ::= "list"
BuildParseTrees() ::= "this.buildParseTrees = true;"
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
Column() ::= "this.column"
Text() ::= "this.text"
ValEquals(a,b) ::= <%<a>===<b>%>
TextEquals(a) ::= <%this.text==="<a>"%>
PlusText(a) ::= <%"<a>" + this.text%>
InputText() ::= "this._input.getText()"
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
ImportListener(X) ::= <<
@parser::header {
var <X>Listener = require('./<X>Listener').<X>Listener;
}
>>
ImportVisitor(X) ::= <<var <X>Visitor = require('./<X>Visitor').<X>Visitor;>>
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
this.Property = function() {
return true;
}
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
this._input.seek(index);
this.line = line;
this.column = column;
this._interp.consume(this._input);
};
PositionAdjustingLexer.prototype.nextToken = function() {
if (!("resetAcceptPosition" in this._interp)) {
var lexer = this;
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
}
return antlr4.Lexer.prototype.nextToken.call(this);
};
PositionAdjustingLexer.prototype.emit = function() {
switch(this._type) {
case PositionAdjustingLexer.TOKENS:
this.handleAcceptPositionForKeyword("tokens");
break;
case PositionAdjustingLexer.LABEL:
this.handleAcceptPositionForIdentifier();
break;
}
return antlr4.Lexer.prototype.emit.call(this);
};
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
var tokenText = this.text;
var identifierLength = 0;
while (identifierLength \< tokenText.length &&
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
) {
identifierLength += 1;
}
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
var offset = identifierLength - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
var offset = keyword.length - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.isIdentifierChar = function(c) {
return c.match(/^[0-9a-zA-Z_]+$/);
}
>>
BasicListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.visitTerminal = function(node) {
console.log(node.symbol.text);
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
WalkListener(s) ::= <<
var walker = new antlr4.tree.ParseTreeWalker();
walker.walk(new this.LeafListener(), <s>);
>>
BasicVisitor(X) ::= <<
this.LeafVisitor = function() {
this.visitTerminal = function(node) {
return node.symbol.text;
};
return this;
};
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
>>
WalkVisitor(s) ::= <<
var visitor = new this.LeafVisitor();
console.log(<s>.accept(visitor));
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::header {
MyRuleNode = function(parent, invokingState) {
antlr4.ParserRuleContext.call(this, parent, invokingState);
this.altNum = 0;
return this;
};
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
MyRuleNode.prototype.constructor = MyRuleNode;
MyRuleNode.prototype.getAltNumber = function() { return this.altNum; }
MyRuleNode.prototype.setAltNumber = function(altNumber) { this.altNum = altNumber; }
}
>>
TokenGetterListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
} else {
str = ctx.ID().symbol.toString();
}
console.log(str);
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
TokenGetterVisitor(X) ::= <<
this.LeafVisitor = function() {
this.visitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
} else {
str = ctx.ID().symbol.toString();
}
return this.visitChildren(ctx) + str;
};
return this;
};
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
>>
RuleGetterListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
} else {
str = ctx.b(0).start.text;
}
console.log(str);
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
RuleGetterVisitor(X) ::= <<
this.LeafVisitor = function() {
this.visitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
} else {
str = ctx.b(0).start.text;
}
return this.visitChildren(ctx) + str;
};
return this;
};
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
>>
LRListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitE = function(ctx) {
var str;
if(ctx.getChildCount()===3) {
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
} else {
str = ctx.INT().symbol.text;
}
console.log(str);
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
LRVisitor(X) ::= <<
this.LeafVisitor = function() {
this.visitE = function(ctx) {
var str;
if(ctx.getChildCount()===3) {
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
} else {
str = ctx.INT().symbol.text;
}
return this.visitChildren(ctx) + str;
};
return this;
};
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
>>
LRWithLabelsListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitCall = function(ctx) {
var str = ctx.e().start.text + ' ' + ctx.eList();
console.log(str);
};
this.exitInt = function(ctx) {
var str = ctx.INT().symbol.text;
console.log(str);
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
LRWithLabelsVisitor(X) ::= <<
this.LeafVisitor = function() {
this.visitCall = function(ctx) {
var str = ctx.e().start.text + ' ' + ctx.eList();
return this.visitChildren(ctx) + str;
};
this.visitInt = function(ctx) {
var str = ctx.INT().symbol.text;
return this.visitChildren(ctx) + str;
};
return this;
};
this.LeafVisitor.prototype = Object.create(<X>Visitor.prototype);
this.LeafVisitor.prototype.constructor = this.LeafVisitor;
>>
DeclareContextListGettersFunction() ::= <<
function foo() {
var s = new SContext();
var a = s.a();
var b = s.b();
};
>>
Declare_foo() ::= "this.foo = function() {console.log('foo');};"
Invoke_foo() ::= "this.foo();"
Declare_pred() ::= <<this.pred = function(v) {
console.log("eval=" + v.toString());
return v;
};
>>
Invoke_pred(v) ::= <<this.pred(<v>)>>
ParserTokenType(t) ::= "Parser.<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"

View File

@ -1,295 +0,0 @@
writeln(s) ::= <<document.getElementById('output').value += <s> + '\\n';>>
write(s) ::= <<document.getElementById('output').value += <s>;>>
writeList(s) ::= <<document.getElementById('output').value += <s; separator="+">;>>
False() ::= "false"
True() ::= "true"
Not(v) ::= "!<v>"
Assert(s) ::= ""
Cast(t,v) ::= "<v>"
Append(a,b) ::= "<a> + <b>"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "var <s> = <v>;"
AssertIsList(v) ::= <<if ( !(v instanceof Array) ) {throw "value is not an array";}>>
AssignLocal(s,v) ::= "<s> = <v>;"
InitIntMember(n,v) ::= <%this.<n> = <v>;%>
InitBooleanMember(n,v) ::= <%this.<n> = <v>;%>
GetMember(n) ::= <%this.<n>%>
SetMember(n,v) ::= <%this.<n> = <v>;%>
AddMember(n,v) ::= <%this.<n> += <v>;%>
PlusMember(v,n) ::= <%<v> + this.<n>%>
MemberEquals(n,v) ::= <%this.<n> === <v>%>
ModMemberEquals(n,m,v) ::= <%this.<n> % <m> === <v>%>
ModMemberNotEquals(n,m,v) ::= <%this.<n> % <m> != <v>%>
DumpDFA() ::= "this.dumpDFA();"
Pass() ::= ""
StringList() ::= "list"
BuildParseTrees() ::= "this.buildParseTrees = true;"
BailErrorStrategy() ::= <%this._errHandler = new antlr4.error.BailErrorStrategy();%>
ToStringTree(s) ::= <%<s>.toStringTree(null, this)%>
Column() ::= "this.column"
Text() ::= "this.text"
ValEquals(a,b) ::= <%<a>===<b>%>
TextEquals(a) ::= <%this.text==="<a>"%>
PlusText(a) ::= <%"<a>" + this.text%>
InputText() ::= "this._input.getText()"
LTEquals(i, v) ::= <%this._input.LT(<i>).text===<v>%>
LANotEquals(i, v) ::= <%this._input.LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%this._tokenStartColumn===<i>%>
ImportListener(X) ::= <<
@parser::header {
var <X>Listener = require('./<X>Listener').<X>Listener;
}
>>
GetExpectedTokenNames() ::= "this.getExpectedTokens().toString(this.literalNames)"
RuleInvocationStack() ::= "antlr4.Utils.arrayToString(this.getRuleInvocationStack())"
LL_EXACT_AMBIG_DETECTION() ::= <<this._interp.predictionMode = antlr4.atn.PredictionMode.LL_EXACT_AMBIG_DETECTION;>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
this.Property = function() {
return true;
}
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
PositionAdjustingLexer.prototype.resetAcceptPosition = function(index, line, column) {
this._input.seek(index);
this.line = line;
this.column = column;
this._interp.consume(this._input);
};
PositionAdjustingLexer.prototype.nextToken = function() {
if (!("resetAcceptPosition" in this._interp)) {
var lexer = this;
this._interp.resetAcceptPosition = function(index, line, column) { lexer.resetAcceptPosition(index, line, column); };
}
return antlr4.Lexer.prototype.nextToken.call(this);
};
PositionAdjustingLexer.prototype.emit = function() {
switch(this._type) {
case PositionAdjustingLexer.TOKENS:
this.handleAcceptPositionForKeyword("tokens");
break;
case PositionAdjustingLexer.LABEL:
this.handleAcceptPositionForIdentifier();
break;
}
return antlr4.Lexer.prototype.emit.call(this);
};
PositionAdjustingLexer.prototype.handleAcceptPositionForIdentifier = function() {
var tokenText = this.text;
var identifierLength = 0;
while (identifierLength \< tokenText.length &&
PositionAdjustingLexer.isIdentifierChar(tokenText[identifierLength])
) {
identifierLength += 1;
}
if (this._input.index > this._tokenStartCharIndex + identifierLength) {
var offset = identifierLength - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.prototype.handleAcceptPositionForKeyword = function(keyword) {
if (this._input.index > this._tokenStartCharIndex + keyword.length) {
var offset = keyword.length - 1;
this._interp.resetAcceptPosition(this._tokenStartCharIndex + offset,
this._tokenStartLine, this._tokenStartColumn + offset);
return true;
} else {
return false;
}
};
PositionAdjustingLexer.isIdentifierChar = function(c) {
return c.match(/^[0-9a-zA-Z_]+$/);
}
>>
BasicListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.visitTerminal = function(node) {
document.getElementById('output').value += node.symbol.text + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
WalkListener(s) ::= <<
var walker = new antlr4.tree.ParseTreeWalker();
walker.walk(new this.LeafListener(), <s>);
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::header {
MyRuleNode = function(parent, invokingState) {
antlr4.ParserRuleContext.call(this, parent, invokingState);
this.altNum = 0;
return this;
};
MyRuleNode.prototype = Object.create(antlr4.ParserRuleContext.prototype);
MyRuleNode.prototype.constructor = MyRuleNode;
}
>>
TokenGetterListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + antlr4.Utils.arrayToString(ctx.INT());
} else {
str = ctx.ID().symbol.toString();
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
RuleGetterListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitA = function(ctx) {
var str;
if(ctx.getChildCount()===2) {
str = ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text;
} else {
str = ctx.b(0).start.text;
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
LRListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitE = function(ctx) {
var str;
if(ctx.getChildCount()===3) {
str = ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text;
} else {
str = ctx.INT().symbol.text;
}
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
LRWithLabelsListener(X) ::= <<
@parser::members {
this.LeafListener = function() {
this.exitCall = function(ctx) {
var str = ctx.e().start.text + ' ' + ctx.eList();
document.getElementById('output').value += str + '\\n';
};
this.exitInt = function(ctx) {
var str = ctx.INT().symbol.text;
document.getElementById('output').value += str + '\\n';
};
return this;
};
this.LeafListener.prototype = Object.create(<X>Listener.prototype);
this.LeafListener.prototype.constructor = this.LeafListener;
}
>>
DeclareContextListGettersFunction() ::= <<
function foo() {
var s = new SContext();
var a = s.a();
var b = s.b();
};
>>
Declare_foo() ::= "this.foo = function() {document.getElementById('output').value += 'foo' + '\\n';};"
Invoke_foo() ::= "this.foo();"
Declare_pred() ::= <<this.pred = function(v) {
document.getElementById('output').value += 'eval=' + v.toString() + '\\n';
return v;
};
>>
Invoke_pred(v) ::= <<this.pred(<v>)>>
ParserTokenType(t) ::= "Parser.<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"

View File

@ -1,273 +0,0 @@
writeln(s) ::= <<print(<s>)>>
write(s) ::= <<print(<s>,end='')>>
writeList(s) ::= <<print(<s: {v | str(<v>)}; separator="+">)>>
False() ::= "False"
True() ::= "True"
Not(v) ::= "not <v>"
Assert(s) ::= ""
Cast(t,v) ::= "<v>"
Append(a,b) ::= "<a> + str(<b>)"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "<s> = <v>"
AssertIsList(v) ::= "assert isinstance(v, (list, tuple))"
AssignLocal(s,v) ::= "<s> = <v>"
InitIntMember(n,v) ::= <%<n> = <v>%>
InitBooleanMember(n,v) ::= <%<n> = <v>%>
GetMember(n) ::= <%self.<n>%>
SetMember(n,v) ::= <%self.<n> = <v>%>
AddMember(n,v) ::= <%self.<n> += <v>%>
PlusMember(v,n) ::= <%<v> + str(self.<n>)%>
MemberEquals(n,v) ::= <%self.<n> == <v>%>
ModMemberEquals(n,m,v) ::= <%self.<n> % <m> == <v>%>
ModMemberNotEquals(n,m,v) ::= <%self.<n> % <m> != <v>%>
DumpDFA() ::= "self.dumpDFA()"
Pass() ::= "pass"
StringList() ::= ""
BuildParseTrees() ::= "self._buildParseTrees = True"
BailErrorStrategy() ::= <%self._errHandler = BailErrorStrategy()%>
ToStringTree(s) ::= <%<s>.toStringTree(recog=self)%>
Column() ::= "self.column"
Text() ::= "self.text"
ValEquals(a,b) ::= <%<a>==<b>%>
TextEquals(a) ::= <%self.text=="<a>"%>
PlusText(a) ::= <%"<a>" + self.text%>
InputText() ::= "self._input.getText()"
LTEquals(i, v) ::= <%self._input.LT(<i>).text==<v>%>
LANotEquals(i, v) ::= <%self._input.LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%self._tokenStartColumn==<i>%>
ImportListener(X) ::= ""
GetExpectedTokenNames() ::= "self.getExpectedTokens().toString(self.literalNames, self.symbolicNames)"
RuleInvocationStack() ::= "str_list(self.getRuleInvocationStack())"
LL_EXACT_AMBIG_DETECTION() ::= <<self._interp.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
def Property(self):
return True
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
def resetAcceptPosition(self, index, line, column):
self._input.seek(index)
self.line = line
self.column = column
self._interp.consume(self._input)
def nextToken(self):
if self._interp.__dict__.get("resetAcceptPosition", None) is None:
self._interp.__dict__["resetAcceptPosition"] = self.resetAcceptPosition
return super(type(self),self).nextToken()
def emit(self):
if self._type==PositionAdjustingLexer.TOKENS:
self.handleAcceptPositionForKeyword("tokens")
elif self._type==PositionAdjustingLexer.LABEL:
self.handleAcceptPositionForIdentifier()
return super(type(self),self).emit()
def handleAcceptPositionForIdentifier(self):
tokenText = self.text
identifierLength = 0
while identifierLength \< len(tokenText) and self.isIdentifierChar(tokenText[identifierLength]):
identifierLength += 1
if self._input.index > self._tokenStartCharIndex + identifierLength:
offset = identifierLength - 1
self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset,
self._tokenStartLine, self._tokenStartColumn + offset)
return True
else:
return False
def handleAcceptPositionForKeyword(self, keyword):
if self._input.index > self._tokenStartCharIndex + len(keyword):
offset = len(keyword) - 1
self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset,
self._tokenStartLine, self._tokenStartColumn + offset)
return True
else:
return False
@staticmethod
def isIdentifierChar(c):
return c.isalnum() or c == '_'
>>
BasicListener(X) ::= <<
@parser::members {
if __name__ is not None and "." in __name__:
from .<X>Listener import <X>Listener
else:
from <X>Listener import <X>Listener
class LeafListener(TListener):
def visitTerminal(self, node):
print(node.symbol.text)
}
>>
WalkListener(s) ::= <<
walker = ParseTreeWalker()
walker.walk(TParser.LeafListener(), <s>)
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::members {
class MyRuleNode(ParserRuleContext):
def __init__(self, parent = None, invokingStateNumber = None ):
super(<X>Parser.MyRuleNode, self).__init__(parent, invokingStateNumber)
self.altNum = 0;
def getAltNumber(self):
return self.altNum
def setAltNumber(self, altNum):
self.altNum = altNum
}
>>
TokenGetterListener(X) ::= <<
@parser::members {
if __name__ is not None and "." in __name__:
from .<X>Listener import <X>Listener
else:
from <X>Listener import <X>Listener
class LeafListener(TListener):
def exitA(self, ctx):
if ctx.getChildCount()==2:
print(ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + str_list(ctx.INT()))
else:
print(str(ctx.ID().symbol))
}
>>
RuleGetterListener(X) ::= <<
@parser::members {
if __name__ is not None and "." in __name__:
from .<X>Listener import <X>Listener
else:
from <X>Listener import <X>Listener
class LeafListener(TListener):
def exitA(self, ctx):
if ctx.getChildCount()==2:
print(ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text)
else:
print(ctx.b(0).start.text)
}
>>
LRListener(X) ::= <<
@parser::members {
if __name__ is not None and "." in __name__:
from .<X>Listener import <X>Listener
else:
from <X>Listener import <X>Listener
class LeafListener(TListener):
def exitE(self, ctx):
if ctx.getChildCount()==3:
print(ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text)
else:
print(ctx.INT().symbol.text)
}
>>
LRWithLabelsListener(X) ::= <<
@parser::members {
if __name__ is not None and "." in __name__:
from .<X>Listener import <X>Listener
else:
from <X>Listener import <X>Listener
class LeafListener(TListener):
def exitCall(self, ctx):
print(ctx.e().start.text + ' ' + str(ctx.eList()))
def exitInt(self, ctx):
print(ctx.INT().symbol.text)
}
>>
ImportVisitor(X) ::= ""
BasicVisitor(X) ::= ""
WalkVisitor(s) ::= ""
LRWithLabelsVisitor(X) ::= ""
RuleGetterVisitor(X) ::= ""
LRVisitor(x) ::= ""
TokenGetterVisitor(x) ::= ""
DeclareContextListGettersFunction() ::= <<
def foo():
s = SContext()
a = s.a()
b = s.b()
>>
Declare_foo() ::= <<def foo(self):
print('foo')
>>
Invoke_foo() ::= "self.foo()"
Declare_pred() ::= <<def pred(self, v):
print('eval=' + str(v).lower())
return v
>>
Invoke_pred(v) ::= <<self.pred(<v>)>>
ParserTokenType(t) ::= "Parser.<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"

View File

@ -1,258 +0,0 @@
writeln(s) ::= <<print(<s>)>>
write(s) ::= <<print(<s>,end='')>>
writeList(s) ::= <<print(<s: {v | str(<v>)}; separator="+">)>>
False() ::= "False"
True() ::= "True"
Not(v) ::= "not <v>"
Assert(s) ::= ""
Cast(t,v) ::= "<v>"
Append(a,b) ::= "<a> + str(<b>)"
Concat(a,b) ::= "<a><b>"
DeclareLocal(s,v) ::= "<s> = <v>"
AssertIsList(v) ::= "assert isinstance(v, (list, tuple))"
AssignLocal(s,v) ::= "<s> = <v>"
InitIntMember(n,v) ::= <%<n> = <v>%>
InitBooleanMember(n,v) ::= <%<n> = <v>%>
GetMember(n) ::= <%self.<n>%>
SetMember(n,v) ::= <%self.<n> = <v>%>
AddMember(n,v) ::= <%self.<n> += <v>%>
PlusMember(v,n) ::= <%<v> + str(self.<n>)%>
MemberEquals(n,v) ::= <%self.<n> == <v>%>
ModMemberEquals(n,m,v) ::= <%self.<n> % <m> == <v>%>
ModMemberNotEquals(n,m,v) ::= <%self.<n> % <m> != <v>%>
DumpDFA() ::= "self.dumpDFA()"
Pass() ::= "pass"
StringList() ::= ""
BuildParseTrees() ::= "self._buildParseTrees = True"
BailErrorStrategy() ::= <%self._errHandler = BailErrorStrategy()%>
ToStringTree(s) ::= <%<s>.toStringTree(recog=self)%>
Column() ::= "self.column"
Text() ::= "self.text"
ValEquals(a,b) ::= <%<a>==<b>%>
TextEquals(a) ::= <%self.text=="<a>"%>
PlusText(a) ::= <%"<a>" + self.text%>
InputText() ::= "self._input.getText()"
LTEquals(i, v) ::= <%self._input.LT(<i>).text==<v>%>
LANotEquals(i, v) ::= <%self._input.LA(<i>)!=<v>%>
TokenStartColumnEquals(i) ::= <%self._tokenStartColumn==<i>%>
ImportListener(X) ::= <<
@parser::header {
class MockListener:
pass
}
>>
GetExpectedTokenNames() ::= "self.getExpectedTokens().toString(self.literalNames, self.symbolicNames)"
RuleInvocationStack() ::= "str_list(self.getRuleInvocationStack())"
LL_EXACT_AMBIG_DETECTION() ::= <<self._interp.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION>>
ParserToken(parser, token) ::= <%<parser>.<token>%>
Production(p) ::= <%<p>%>
Result(r) ::= <%<r>%>
ParserPropertyMember() ::= <<
@members {
def Property(self):
return True
}
>>
ParserPropertyCall(p, call) ::= "<p>.<call>"
PositionAdjustingLexer() ::= <<
def resetAcceptPosition(self, index, line, column):
self._input.seek(index)
self.line = line
self.column = column
self._interp.consume(self._input)
def nextToken(self):
if self._interp.__dict__.get("resetAcceptPosition", None) is None:
self._interp.__dict__["resetAcceptPosition"] = self.resetAcceptPosition
return super(type(self),self).nextToken()
def emit(self):
if self._type==PositionAdjustingLexer.TOKENS:
self.handleAcceptPositionForKeyword("tokens")
elif self._type==PositionAdjustingLexer.LABEL:
self.handleAcceptPositionForIdentifier()
return super(type(self),self).emit()
def handleAcceptPositionForIdentifier(self):
tokenText = self.text
identifierLength = 0
while identifierLength \< len(tokenText) and self.isIdentifierChar(tokenText[identifierLength]):
identifierLength += 1
if self._input.index > self._tokenStartCharIndex + identifierLength:
offset = identifierLength - 1
self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset,
self._tokenStartLine, self._tokenStartColumn + offset)
return True
else:
return False
def handleAcceptPositionForKeyword(self, keyword):
if self._input.index > self._tokenStartCharIndex + len(keyword):
offset = len(keyword) - 1
self._interp.resetAcceptPosition(self._tokenStartCharIndex + offset,
self._tokenStartLine, self._tokenStartColumn + offset)
return True
else:
return False
@staticmethod
def isIdentifierChar(c):
return c.isalnum() or c == '_'
>>
BasicListener(X) ::= <<
@parser::members {
class LeafListener(MockListener):
def visitTerminal(self, node):
print(node.symbol.text)
}
>>
WalkListener(s) ::= <<
if __name__ is not None and "." in __name__:
from .TListener import TListener
else:
from TListener import TListener
TParser.LeafListener.__bases__ = (TListener,)
walker = ParseTreeWalker()
walker.walk(TParser.LeafListener(), <s>)
>>
TreeNodeWithAltNumField(X) ::= <<
@parser::members {
class MyRuleNode(ParserRuleContext):
def __init__(self, parent:ParserRuleContext = None, invokingStateNumber:int = None ):
super(<X>Parser.MyRuleNode, self).__init__(parent, invokingStateNumber)
self.altNum = 0;
def getAltNumber(self):
return self.altNum
def setAltNumber(self, altNum):
self.altNum = altNum
}
>>
TokenGetterListener(X) ::= <<
@parser::members {
class LeafListener(MockListener):
def exitA(self, ctx):
if ctx.getChildCount()==2:
print(ctx.INT(0).symbol.text + ' ' + ctx.INT(1).symbol.text + ' ' + str_list(ctx.INT()))
else:
print(str(ctx.ID().symbol))
}
>>
RuleGetterListener(X) ::= <<
@parser::members {
class LeafListener(MockListener):
def exitA(self, ctx):
if ctx.getChildCount()==2:
print(ctx.b(0).start.text + ' ' + ctx.b(1).start.text + ' ' + ctx.b()[0].start.text)
else:
print(ctx.b(0).start.text)
}
>>
LRListener(X) ::= <<
@parser::members {
class LeafListener(MockListener):
def exitE(self, ctx):
if ctx.getChildCount()==3:
print(ctx.e(0).start.text + ' ' + ctx.e(1).start.text + ' ' + ctx.e()[0].start.text)
else:
print(ctx.INT().symbol.text)
}
>>
LRWithLabelsListener(X) ::= <<
@parser::members {
class LeafListener(MockListener):
def exitCall(self, ctx):
print(ctx.e().start.text + ' ' + str(ctx.eList()))
def exitInt(self, ctx):
print(ctx.INT().symbol.text)
}
>>
ImportVisitor(X) ::= ""
BasicVisitor(X) ::= ""
WalkVisitor(s) ::= ""
LRWithLabelsVisitor(X) ::= ""
RuleGetterVisitor(X) ::= ""
LRVisitor(x) ::= ""
TokenGetterVisitor(x) ::= ""
DeclareContextListGettersFunction() ::= <<
def foo():
s = SContext()
a = s.a()
b = s.b()
>>
Declare_foo() ::= <<def foo(self):
print('foo')
>>
Invoke_foo() ::= "self.foo()"
Declare_pred() ::= <<def pred(self, v):
print('eval=' + str(v).lower())
return v
>>
Invoke_pred(v) ::= <<self.pred(<v>)>>
ParserTokenType(t) ::= "Parser.<t>"
ContextRuleFunction(ctx, rule) ::= "<ctx>.<rule>"
StringType() ::= "String"
ContextMember(ctx, subctx, member) ::= "<ctx>.<subctx>.<member>"

View File

@ -1,34 +0,0 @@
TestType() ::= "CompositeLexer"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Input() ::= "abc"
Output() ::= <<
S.A
[@0,0:0='a',\<3>,1:0]
[@1,1:1='b',\<1>,1:1]
[@2,2:2='c',\<4>,1:2]
[@3,3:2='\<EOF>',\<-1>,1:3]<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
lexer grammar <grammarName>;
import S;
B : 'b';
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
lexer grammar <grammarName>;
A : 'a' {<writeln("\"S.A\"")>};
C : 'c' ;
>>

View File

@ -1,32 +0,0 @@
TestType() ::= "CompositeLexer"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Input() ::= "ab"
Output() ::= <<
M.A
[@0,0:1='ab',\<1>,1:0]
[@1,2:1='\<EOF>',\<-1>,1:2]<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
lexer grammar <grammarName>;
import S;
A : 'a' B {<writeln("\"M.A\"")>} ;
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
lexer grammar <grammarName>;
A : 'a' {<writeln("\"S.A\"")>} ;
B : 'b' {<writeln("\"S.B\"")>} ;
>>

View File

@ -1,31 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "s"
Input() ::= "=a"
Output() ::= <<
S.a<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
s : a ;
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
a : '=' 'a' {<write("\"S.a\"")>};
>>

View File

@ -1,40 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
AfterGrammar() ::= <<
writeFile(tmpdir, "M.g4", grammar);
ErrorQueue equeue = new ErrorQueue();
new Grammar(tmpdir+"/M.g4", grammar, equeue);
assertEquals("unexpected errors: " + equeue, 0, equeue.errors.size());<\n>
>>
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "s"
Input() ::= "x 34 9"
Output() ::= <<
S.x<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
s : x INT;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
tokens { A, B, C }
x : 'x' INT {<writeln("\"S.x\"")>};
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -1,66 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", ["S", "T"])>}
]
AfterGrammar() ::= <<
writeFile(tmpdir, "M.g4", grammar);
ErrorQueue equeue = new ErrorQueue();
Grammar g = new Grammar(tmpdir+"/M.g4", grammar, equeue);
String expectedTokenIDToTypeMap = "{EOF=-1, B=1, A=2, C=3, WS=4}";
String expectedStringLiteralToTypeMap = "{'a'=2, 'b'=1, 'c'=3}";
String expectedTypeToTokenList = "[B, A, C, WS]";
assertEquals(expectedTokenIDToTypeMap, g.tokenNameToTypeMap.toString());
assertEquals(expectedStringLiteralToTypeMap, sort(g.stringLiteralToTypeMap).toString());
assertEquals(expectedTypeToTokenList, realElements(g.typeToTokenList).toString());
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());<\n>
>>
SlaveGrammars ::= [
"S": {<slaveGrammarS("S")>},
"T": {<slaveGrammarT("T")>}
]
Rule() ::= "s"
Input() ::= "aa"
Output() ::= <<
S.x
T.y<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
// The lexer will create rules to match letters a, b, c.
// The associated token types A, B, C must have the same value
// and all import'd parsers. Since ANTLR regenerates all imports
// for use with the delegator M, it can generate the same token type
// mapping in each parser:
// public static final int C=6;
// public static final int EOF=-1;
// public static final int B=5;
// public static final int WS=7;
// public static final int A=4;
grammar M;
import S,T;
s : x y ; // matches AA, which should be 'aa'
B : 'b' ; // another order: B, A, C
A : 'a' ;
C : 'c' ;
WS : (' '|'\n') -> skip ;
>>
slaveGrammarS(grammarName) ::= <<
parser grammar S;
tokens { A, B, C }
x : A {<writeln("\"S.x\"")>};
>>
slaveGrammarT(grammarName) ::= <<
parser grammar T;
tokens { C, B, A } // reverse order
y : A {<writeln("\"T.y\"")>};
>>

View File

@ -1,34 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "s"
Input() ::= "b"
Output() ::= <<
foo<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M; // uses no rules from the import
import S;
s : 'b' {<Invoke_foo()>} ; // gS is import pointer
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
@parser::members {
<Declare_foo()>
}
a : B;
>>

View File

@ -1,32 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "s"
Input() ::= "b"
Output() ::= <<
S.a<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
s : a ;
B : 'b' ; // defines B from inherited token space
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
a : B {<writeln("\"S.a\"")>};
>>

View File

@ -1,32 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "s"
Input() ::= "b"
Output() ::= <<
S.a1000<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
s : label=a[3] {<writeln("$label.y")>} ;
B : 'b' ; // defines B from inherited token space
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
a[int x] returns [int y] : B {<write("\"S.a\"")>} {$y=1000;} ;
>>

View File

@ -1,32 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "s"
Input() ::= "b"
Output() ::= <<
S.ab<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
s : a {<write("$a.text")>} ;
B : 'b' ; // defines B from inherited token space
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
a : B {<write("\"S.a\"")>} ;
>>

View File

@ -1,39 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", ["S", "T"])>}
]
SlaveGrammars ::= [
"S": {<slaveGrammarS("S")>},
"T": {<slaveGrammarT("T")>}
]
Rule() ::= "s"
Input() ::= "b"
Output() ::= <<
S.a<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S,T;
s : a ;
B : 'b' ; // defines B from inherited token space
WS : (' '|'\n') -> skip ;
>>
slaveGrammarS(grammarName) ::= <<
parser grammar S;
a : b {<writeln("\"S.a\"")>};
b : B;
>>
slaveGrammarT(grammarName) ::= <<
parser grammar T;
a : B {<writeln("\"T.a\"")>};<! hidden by S.a !>
>>

View File

@ -1,32 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "a"
Input() ::= "c"
Output() ::= <<
S.a<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
b : 'b'|'c';
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
a : b {<write("\"S.a\"")>};
b : B ;
>>

View File

@ -1,40 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammarS("S")>},
"T": {<slaveGrammarT("T")>}
]
Rule() ::= "a"
Input() ::= "c"
Output() ::= <<
M.b
S.a<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S, T;
b : 'b'|'c' {<writeln("\"M.b\"")>}|B|A;
WS : (' '|'\n') -> skip ;
>>
slaveGrammarS(grammarName) ::= <<
parser grammar S;
a : b {<writeln("\"S.a\"")>};
b : 'b' ;
>>
slaveGrammarT(grammarName) ::= <<
parser grammar T;
tokens { A }
b : 'b' {<writeln("\"T.b\"")>};
>>

View File

@ -1,38 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "prog"
Input() ::= "float x = 3;"
Output() ::= <<
JavaDecl: floatx=3;<\n>
>>
Errors() ::= ""
// for float to work in decl, type must be overridden
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
prog : decl ;
type_ : 'int' | 'float' ;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
type_ : 'int' ;
decl : type_ ID ';'
| type_ ID init_ ';' {<write("\"JavaDecl: \" + $text")>};
init_ : '=' INT;
>>

View File

@ -1,45 +0,0 @@
/*
* This is a regression test for antlr/antlr4#248 "Including grammar with only
* fragments breaks generated lexer".
* https://github.com/antlr/antlr4/issues/248
*/
TestType() ::= "CompositeParser"
Grammar ::= [
"Test": {<masterGrammar("Test", "Unicode")>}
]
SlaveGrammars ::= [
"Unicode": {<slaveGrammar("Unicode")>}
]
Rule() ::= "program"
Input() ::= "test test"
Output() ::= <<
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar <grammarName>;
import Unicode;
program : 'test' 'test';
WS : (UNICODE_CLASS_Zs)+ -> skip;
>>
slaveGrammar(grammarName) ::= <<
lexer grammar <grammarName>;
fragment
UNICODE_CLASS_Zs : '\u0020' | '\u00A0' | '\u1680' | '\u180E'
| '\u2000'..'\u200A'
| '\u202F' | '\u205F' | '\u3000'
;
>>

View File

@ -1,32 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "s"
Input() ::= "b"
Output() ::= <<
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
s : a ;
B : 'b' ;
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
parser grammar S;
options {}
a : B ;
>>

View File

@ -1,32 +0,0 @@
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "s"
Input() ::= "b"
Output() ::= <<
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
s : a;
B : 'b';
WS : (' '|'\n') -> skip ;
>>
// wasn't terminating. @after was injected into M as if it were @members
slaveGrammar(grammarName) ::= <<
parser grammar S;
a @after {<InitIntMember("x","0")>} : B;
>>

View File

@ -1,37 +0,0 @@
// rules in lexer are imported at END so rules in master override
// *and* get priority over imported rules. So importing ID doesn't
// mess up keywords in master grammar
TestType() ::= "CompositeParser"
Grammar ::= [
"M": {<masterGrammar("M", "S")>}
]
SlaveGrammars ::= [
"S": {<slaveGrammar("S")>}
]
Rule() ::= "a"
Input() ::= "abc"
Output() ::= <<
M.A
M.a: [@0,0:2='abc',\<1>,1:0]<\n>
>>
Errors() ::= ""
masterGrammar(grammarName, slaveGrammarName) ::= <<
grammar M;
import S;
a : A {<Append("\"M.a: \"","$A"):writeln()>};
A : 'abc' {<writeln("\"M.A\"")>};
WS : (' '|'\n') -> skip ;
>>
slaveGrammar(grammarName) ::= <<
lexer grammar S;
ID : 'a'..'z'+;
>>

View File

@ -1,30 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "abc"
Rule() ::= "s"
Output() ::= <<
Decision 0:
s0-ID->:s1^=>1<\n>
>>
Errors() ::= <<
line 1:0 reportAttemptingFullContext d=0 (s), input='abc'<\n>
>>
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<DumpDFA()>}
: ID | ID {} ;
ID : 'a'..'z'+;
WS : (' '|'\t'|'\n')+ -> skip ;
>>

View File

@ -1,39 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "a@"
Rule() ::= "prog"
Output() ::= <<
alt 1<\n>
>>
Errors() ::= <<
line 1:2 reportAttemptingFullContext d=0 (prog), input='a@'
line 1:2 reportAmbiguity d=0 (prog): ambigAlts={1, 2}, input='a@'
line 1:2 reportAttemptingFullContext d=1 (expr), input='a@'
line 1:2 reportContextSensitivity d=1 (expr), input='a@'<\n>
>>
grammar(grammarName) ::= <<
grammar <grammarName>;
prog
@init {<LL_EXACT_AMBIG_DETECTION()>}
: expr expr {<writeln("\"alt 1\"")>}
| expr
;
expr: '@'
| ID '@'
| ID
;
ID : [a-z]+ ;
WS : [ \r\n\t]+ -> skip ;
>>

View File

@ -1,23 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<DumpDFA()>}
: '$' a | '@' b ;
a : e ID ;
b : e INT ID ;
e : INT | ;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
WS : (' '|'\t'|'\n')+ -> skip ;
>>

View File

@ -1,39 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "$ 34 abc @ 34 abc"
Rule() ::= "s"
Output() ::= <<
Decision 2:
s0-INT->s1
s1-ID->:s2^=>1<\n>
>>
Errors() ::= <<
line 1:5 reportAttemptingFullContext d=2 (e), input='34abc'
line 1:2 reportContextSensitivity d=2 (e), input='34'
line 1:14 reportAttemptingFullContext d=2 (e), input='34abc'
line 1:14 reportContextSensitivity d=2 (e), input='34abc'<\n>
>>
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<DumpDFA()>}
: ('$' a | '@' b)+ ;
a : e ID ;
b : e INT ID ;
e : INT | ;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
WS : (' '|'\t'|'\n')+ -> skip ;
>>

View File

@ -1,14 +0,0 @@
import "CtxSensitiveDFA.stg"
Input() ::= "$ 34 abc"
Output() ::= <<
Decision 1:
s0-INT->s1
s1-ID->:s2^=>1<\n>
>>
Errors() ::= <<
line 1:5 reportAttemptingFullContext d=1 (e), input='34abc'
line 1:2 reportContextSensitivity d=1 (e), input='34'<\n>
>>

View File

@ -1,14 +0,0 @@
import "CtxSensitiveDFA.stg"
Input() ::= "@ 34 abc"
Output() ::= <<
Decision 1:
s0-INT->s1
s1-ID->:s2^=>1<\n>
>>
Errors() ::= <<
line 1:5 reportAttemptingFullContext d=1 (e), input='34abc'
line 1:5 reportContextSensitivity d=1 (e), input='34abc'<\n>
>>

View File

@ -1,28 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s
@init {<LL_EXACT_AMBIG_DETECTION()>}
: expr[0] {<ToStringTree("$expr.ctx"):writeln()>};
expr[int _p]
: ID
(
{5 >= $_p}? '*' expr[6]
| {4 >= $_p}? '+' expr[5]
)*
;
ID : [a-zA-Z]+ ;
WS : [ \r\n\t]+ -> skip ;
>>

View File

@ -1,12 +0,0 @@
import "ExprAmbiguity.stg"
Input() ::= "a+b"
Output() ::= <<
(expr a + (expr b))<\n>
>>
Errors() ::= <<
line 1:1 reportAttemptingFullContext d=1 (expr), input='+'
line 1:2 reportContextSensitivity d=1 (expr), input='+b'<\n>
>>

View File

@ -1,14 +0,0 @@
import "ExprAmbiguity.stg"
Input() ::= "a+b*c"
Output() ::= <<
(expr a + (expr b * (expr c)))<\n>
>>
Errors() ::= <<
line 1:1 reportAttemptingFullContext d=1 (expr), input='+'
line 1:2 reportContextSensitivity d=1 (expr), input='+b'
line 1:3 reportAttemptingFullContext d=1 (expr), input='*'
line 1:5 reportAmbiguity d=1 (expr): ambigAlts={1, 2}, input='*c'<\n>
>>

View File

@ -1,24 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s
@init {<LL_EXACT_AMBIG_DETECTION()>}
@after {<DumpDFA()>}
: '{' stat* '}' ;
stat: 'if' ID 'then' stat ('else' ID)?
| 'return'
;
ID : 'a'..'z'+ ;
WS : (' '|'\t'|'\n')+ -> skip ;
>>

View File

@ -1,10 +0,0 @@
import "FullContextIF_THEN_ELSEParse.stg"
Input() ::= "{ if x then return }"
Output() ::= <<
Decision 1:
s0-'}'->:s1=>2<\n>
>>
Errors() ::= ""

View File

@ -1,20 +0,0 @@
import "FullContextIF_THEN_ELSEParse.stg"
Input() ::= "{ if x then return else foo }"
Output() ::= <<
Decision 1:
s0-'else'->:s1^=>1<\n>
>>
// Technically, this input sequence is not ambiguous because else
// uniquely predicts going into the optional subrule. else cannot
// be matched by exiting stat since that would only match '}' or
// the start of a stat. But, we are using the theory that
// SLL(1)=LL(1) and so we are avoiding full context parsing
// by declaring all else clause parsing to be ambiguous.
Errors() ::= <<
line 1:19 reportAttemptingFullContext d=1 (stat), input='else'
line 1:19 reportContextSensitivity d=1 (stat), input='else'<\n>
>>

View File

@ -1,14 +0,0 @@
import "FullContextIF_THEN_ELSEParse.stg"
Input() ::= "{ if x then if y then return else foo }"
Output() ::= <<
Decision 1:
s0-'}'->:s2=>2
s0-'else'->:s1^=>1<\n>
>>
Errors() ::= <<
line 1:29 reportAttemptingFullContext d=1 (stat), input='else'
line 1:38 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'<\n>
>>

View File

@ -1,19 +0,0 @@
import "FullContextIF_THEN_ELSEParse.stg"
// should not be ambiguous because the second 'else bar' clearly
// indicates that the first else should match to the innermost if.
// LL_EXACT_AMBIG_DETECTION makes us keep going to resolve
Input() ::= "{ if x then if y then return else foo else bar }"
Output() ::= <<
Decision 1:
s0-'else'->:s1^=>1<\n>
>>
Errors() ::= <<
line 1:29 reportAttemptingFullContext d=1 (stat), input='else'
line 1:38 reportContextSensitivity d=1 (stat), input='elsefooelse'
line 1:38 reportAttemptingFullContext d=1 (stat), input='else'
line 1:38 reportContextSensitivity d=1 (stat), input='else'<\n>
>>

View File

@ -1,19 +0,0 @@
import "FullContextIF_THEN_ELSEParse.stg"
Input() ::= <<
{ if x then return else foo
if x then if y then return else foo }
>>
Output() ::= <<
Decision 1:
s0-'}'->:s2=>2
s0-'else'->:s1^=>1<\n>
>>
Errors() ::= <<
line 1:19 reportAttemptingFullContext d=1 (stat), input='else'
line 1:19 reportContextSensitivity d=1 (stat), input='else'
line 2:27 reportAttemptingFullContext d=1 (stat), input='else'
line 2:36 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'<\n>
>>

View File

@ -1,19 +0,0 @@
import "FullContextIF_THEN_ELSEParse.stg"
Input() ::= <<
{ if x then return else foo
if x then if y then return else foo }
>>
Output() ::= <<
Decision 1:
s0-'}'->:s2=>2
s0-'else'->:s1^=>1<\n>
>>
Errors() ::= <<
line 1:19 reportAttemptingFullContext d=1 (stat), input='else'
line 1:19 reportContextSensitivity d=1 (stat), input='else'
line 2:27 reportAttemptingFullContext d=1 (stat), input='else'
line 2:36 reportAmbiguity d=1 (stat): ambigAlts={1, 2}, input='elsefoo}'<\n>
>>

View File

@ -1,44 +0,0 @@
/*
* Tests predictions for the following case involving closures.
* http://www.antlr.org/wiki/display/~admin/2011/12/29/Flaw+in+ANTLR+v3+LL(*)+analysis+algorithm
*/
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "a(i)\<-x"
Rule() ::= "prog"
Output() ::= <<
pass: a(i)\<-x<\n>
>>
Errors() ::= <<
line 1:3 reportAttemptingFullContext d=3 (expr_primary), input='a(i)'
line 1:7 reportAmbiguity d=3 (expr_primary): ambigAlts={2, 3}, input='a(i)\<-x'<\n>
>>
grammar(grammarName) ::= <<
grammar <grammarName>;
prog
@init {<LL_EXACT_AMBIG_DETECTION()>}
: expr_or_assign*;
expr_or_assign
: expr '++' {<writeln("\"fail.\"")>}
| expr {<writeln("\"pass: \"+$expr.text")>}
;
expr: expr_primary ('\<-' ID)?;
expr_primary
: '(' ID ')'
| ID '(' ID ')'
| ID
;
ID : [a-z]+ ;
>>

View File

@ -1,36 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"T": {<grammar("T")>}
]
Input() ::= "34 abc"
Rule() ::= "s"
Output() ::= <<
Decision 0:
s0-INT->s1
s1-ID->:s2^=>1<\n>
>>
Errors() ::= <<
line 1:3 reportAttemptingFullContext d=0 (e), input='34abc'
line 1:0 reportContextSensitivity d=0 (e), input='34'<\n>
>>
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<DumpDFA()>}
: a;
a : e ID ;
b : e INT ID ;
e : INT | ;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
WS : (' '|'\t'|'\n')+ -> skip ;
>>

View File

@ -1,156 +0,0 @@
TestFile(file) ::= <<
/* This file is generated by TestGenerator, any edits will be overwritten by the next generation. */
package org.antlr.v4.test.runtime.<if(file.targetSubdir)><file.targetSubdir>.<endif><file.target; format="lower">;
import org.junit.Ignore;
import org.junit.Test;
import static org.junit.Assert.*;
import org.antlr.v4.test.runtime.java.ErrorQueue;
import org.antlr.v4.tool.Grammar;
@SuppressWarnings("unused")
public class Test<file.name> extends Base<file.target>Test {
<file.tests:{test | <test>}; separator="\n", wrap, anchor>
}
>>
LexerTestMethod(test) ::= <<
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void test<test.name>() throws Exception {
mkdir(tmpdir);
<test.SlaveGrammars:{grammar |
String slave_<grammar> = <writeStringLiteral(test.SlaveGrammars.(grammar))>;
writeFile(tmpdir, "<grammar>.g4", slave_<grammar>);
}; separator="\n">
<test.Grammar:{grammar |
<buildStringLiteral(test.Grammar.(grammar), "grammar")>
<if(test.AfterGrammar)>
<test.AfterGrammar>
<endif>
String input =<writeStringLiteral(test.Input)>;
String found = execLexer("<grammar>.g4", grammar, "<grammar><if(test.Options.("CombinedGrammar"))>Lexer<endif>", input, <writeBoolean(test.Options.("ShowDFA"))>);
assertEquals(<writeStringLiteral(test.Output)>, found);
<if(!isEmpty.(test.Errors))>
assertEquals(<writeStringLiteral(test.Errors)>, this.stderrDuringParse);
<else>
assertNull(this.stderrDuringParse);
<endif>
}>
}
>>
CompositeLexerTestMethod(test) ::= <<
<LexerTestMethod(test)>
>>
ParserTestMethod(test) ::= <<
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
public void test<test.name>() throws Exception {
mkdir(tmpdir);
<test.SlaveGrammars:{grammar |
String slave_<grammar> =<writeStringLiteral(test.SlaveGrammars.(grammar))>;
<if(test.Options.("SlaveIsLexer"))>
rawGenerateAndBuildRecognizer("<grammar>.g4", slave_<grammar>, null, "<grammar>");
<else>
writeFile(tmpdir, "<grammar>.g4", slave_<grammar>);
<endif>
}; separator="\n">
<test.Grammar:{grammar |
<buildStringLiteral(test.Grammar.(grammar), "grammar")>
<test.AfterGrammar>
String input =<writeStringLiteral(test.Input)>;
String found = execParser("<grammar>.g4", grammar, "<grammar><if(!test.SlaveIsLexer)>Parser<endif>", "<if(test.SlaveIsLexer)><first(test.SlaveGrammars).grammarName><else><grammar>Lexer<endif>", "<grammar>Listener", "<grammar>Visitor", "<test.Rule>", input, <writeBoolean(test.Options.("Debug"))>);
assertEquals(<writeStringLiteral(test.Output)>, found);
<if(!isEmpty.(test.Errors))>
assertEquals(<writeStringLiteral(test.Errors)>, this.stderrDuringParse);
<else>
assertNull(this.stderrDuringParse);
<endif>
}>
}
>>
IgnoredTestMethod(test) ::= <<
/* This file and method are generated by TestGenerator, any edits will be overwritten by the next generation. */
@Test
@Ignore("true")
public void test<test.name>() throws Exception {
}
>>
CompositeParserTestMethod(test) ::= <<
<ParserTestMethod(test)>
>>
AbstractParserTestMethod(test) ::= <<
/* this file and method are generated, any edit will be overwritten by the next generation */
String test<test.name>(String input) throws Exception {
String grammar = <test.grammar.lines:{ line | "<line>};separator="\\n\" +\n", wrap, anchor>";
return execParser("<test.grammar.grammarName>.g4", grammar, "<test.grammar.grammarName>Parser", "<test.grammar.grammarName>Lexer", "<test.startRule>", input, <test.debug>);
}
>>
ConcreteParserTestMethod(test) ::= <<
/* this file and method are generated, any edit will be overwritten by the next generation */
@Test
public void test<test.name>() throws Exception {
String found = test<test.baseName>("<test.input>");
assertEquals("<test.expectedOutput>", found);
<if(test.expectedErrors)>
assertEquals("<test.expectedErrors>", this.stderrDuringParse);
<else>
assertNull(this.stderrDuringParse);
<endif>
}
>>
buildStringLiteral(text, variable) ::= <<
StringBuilder <variable>Builder = new StringBuilder(<strlen.(text)>);
<lines.(text):{line|<variable>Builder.append("<escape.(line)>");}; separator="\n">
String <variable> = <variable>Builder.toString();
>>
writeStringLiteral(text) ::= <%
<if(isEmpty.(text))>
""
<else>
<writeLines(lines.(text))>
<endif>
%>
writeLines(textLines) ::= <%
<if(rest(textLines))>
<textLines:{line|
<\n> "<escape.(line)>}; separator="\" +">"
<else>
"<escape.(first(textLines))>"
<endif>
%>
writeBoolean(o) ::= "<if(o && !isEmpty.(o))>true<else>false<endif>"
string(text) ::= <<
"<escape.(text)>"
>>
isEmpty ::= [
"": true,
default: false
]

View File

@ -1,35 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": true
]
Grammar ::= [
"Expr": {<grammar("Expr")>}
]
Rule() ::= "prog"
grammar(grammarName) ::= <<
grammar <grammarName>;
prog: stat ;
stat: expr NEWLINE # printExpr
| ID '=' expr NEWLINE # assign
| NEWLINE # blank
;
expr: expr ('*'|'/') expr # MulDiv
| expr ('+'|'-') expr # AddSub
| INT # int
| ID # id
| '(' expr ')' # parens
;
MUL : '*' ; // assigns token name to '*' used above in grammar
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
ID : [a-zA-Z]+ ; // match identifiers
INT : [0-9]+ ; // match integers
NEWLINE:'\r'? '\n' ; // return newlines to parser (is end-statement signal)
WS : [ \t]+ -> skip ; // toss out whitespace
>>

View File

@ -1,7 +0,0 @@
import "AmbigLR.stg"
Input() ::= "1<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -1,7 +0,0 @@
import "AmbigLR.stg"
Input() ::= "a = 5<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -1,7 +0,0 @@
import "AmbigLR.stg"
Input() ::= "b = 6<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -1,7 +0,0 @@
import "AmbigLR.stg"
Input() ::= "a+b*2<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -1,7 +0,0 @@
import "AmbigLR.stg"
Input() ::= "(1+2)*3<\n>"
Output() ::= ""
Errors() ::= ""

View File

@ -1,28 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : declarator EOF ; // must indicate EOF can follow
declarator
: declarator '[' e ']'
| declarator '[' ']'
| declarator '(' ')'
| '*' declarator // binds less tight than suffixes
| '(' declarator ')'
| ID
;
e : INT ;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "a"
Output() ::= <<
(s (declarator a) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "(*a)[]"
Output() ::= <<
(s (declarator (declarator ( (declarator * (declarator a)) )) [ ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "*a"
Output() ::= <<
(s (declarator * (declarator a)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "**a"
Output() ::= <<
(s (declarator * (declarator * (declarator a))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "a[3]"
Output() ::= <<
(s (declarator (declarator a) [ (e 3) ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "b[]"
Output() ::= <<
(s (declarator (declarator b) [ ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "(a)"
Output() ::= <<
(s (declarator ( (declarator a) )) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "a[]()"
Output() ::= <<
(s (declarator (declarator (declarator a) [ ]) ( )) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "a[][]"
Output() ::= <<
(s (declarator (declarator (declarator a) [ ]) [ ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Declarations.stg"
Input() ::= "*a[]"
Output() ::= <<
(s (declarator * (declarator (declarator a) [ ])) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,26 +0,0 @@
/*
* This is a regression test for "Support direct calls to left-recursive
* rules".
* https://github.com/antlr/antlr4/issues/161
*/
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "a"
grammar(grammarName) ::= <<
grammar <grammarName>;
a @after {<ToStringTree("$ctx"):writeln()>} : a ID
| ID
;
ID : 'a'..'z'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -1,9 +0,0 @@
import "DirectCallToLeftRecursiveRule.stg"
Input() ::= "x"
Output() ::= <<
(a x)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "DirectCallToLeftRecursiveRule.stg"
Input() ::= "x y"
Output() ::= <<
(a (a x) y)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "DirectCallToLeftRecursiveRule.stg"
Input() ::= "x y z"
Output() ::= <<
(a (a (a x) y) z)<\n>
>>
Errors() ::= ""

View File

@ -1,27 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow
e : e '.' ID
| e '.' 'this'
| '-' e
| e '*' e
| e ('+'|'-') e
| INT
| ID
;
ID : 'a'..'z'+ ;
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -1,9 +0,0 @@
import "Expressions.stg"
Input() ::= "a"
Output() ::= <<
(s (e a) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Expressions.stg"
Input() ::= "1"
Output() ::= <<
(s (e 1) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Expressions.stg"
Input() ::= "a-1"
Output() ::= <<
(s (e (e a) - (e 1)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Expressions.stg"
Input() ::= "a.b"
Output() ::= <<
(s (e (e a) . b) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Expressions.stg"
Input() ::= "a.this"
Output() ::= <<
(s (e (e a) . this) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Expressions.stg"
Input() ::= "-a"
Output() ::= <<
(s (e - (e a)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "Expressions.stg"
Input() ::= "-a+b"
Output() ::= <<
(s (e (e - (e a)) + (e b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,71 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e EOF ; // must indicate EOF can follow
expressionList
: e (',' e)*
;
e : '(' e ')'
| 'this'
| 'super'
| INT
| ID
| typespec '.' 'class'
| e '.' ID
| e '.' 'this'
| e '.' 'super' '(' expressionList? ')'
| e '.' 'new' ID '(' expressionList? ')'
| 'new' typespec ( '(' expressionList? ')' | ('[' e ']')+)
| e '[' e ']'
| '(' typespec ')' e
| e ('++' | '--')
| e '(' expressionList? ')'
| ('+'|'-'|'++'|'--') e
| ('~'|'!') e
| e ('*'|'/'|'%') e
| e ('+'|'-') e
| e ('\<\<' | '>\>>' | '\>>') e
| e ('\<=' | '>=' | '>' | '\<') e
| e 'instanceof' e
| e ('==' | '!=') e
| e '&' e
|\<assoc=right> e '^' e
| e '|' e
| e '&&' e
| e '||' e
| e '?' e ':' e
|\<assoc=right>
e ('='
|'+='
|'-='
|'*='
|'/='
|'&='
|'|='
|'^='
|'\>>='
|'>\>>='
|'\<\<='
|'%=') e
;
typespec
: ID
| ID '[' ']'
| 'int'
| 'int' '[' ']'
;
ID : ('a'..'z'|'A'..'Z'|'_'|'$')+;
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "a|b&c"
Output() ::= <<
(s (e (e a) | (e (e b) & (e c))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "a.f(x)==T.c"
Output() ::= <<
(s (e (e (e (e a) . f) ( (expressionList (e x)) )) == (e (e T) . c)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "a.f().g(x,1)"
Output() ::= <<
(s (e (e (e (e (e a) . f) ( )) . g) ( (expressionList (e x) , (e 1)) )) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "new T[((n-1) * x) + 1]"
Output() ::= <<
(s (e new (typespec T) [ (e (e ( (e (e ( (e (e n) - (e 1)) )) * (e x)) )) + (e 1)) ]) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "(a|b)&c"
Output() ::= <<
(s (e (e ( (e (e a) | (e b)) )) & (e c)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "a > b"
Output() ::= <<
(s (e (e a) > (e b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "a >> b"
Output() ::= <<
(s (e (e a) \>> (e b)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "a=b=c"
Output() ::= <<
(s (e (e a) = (e (e b) = (e c))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "a^b^c"
Output() ::= <<
(s (e (e a) ^ (e (e b) ^ (e c))) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "(T)x"
Output() ::= <<
(s (e ( (typespec T) ) (e x)) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "new A().b"
Output() ::= <<
(s (e (e new (typespec A) ( )) . b) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "JavaExpressions.stg"
Input() ::= "(T)t.f()"
Output() ::= <<
(s (e (e ( (typespec T) ) (e (e t) . f)) ( )) \<EOF>)<\n>
>>
Errors() ::= ""

View File

@ -1,22 +0,0 @@
TestType() ::= "Parser"
Options ::= [
"Debug": false
]
Grammar ::= [
"T": {<grammar("T")>}
]
Rule() ::= "s"
grammar(grammarName) ::= <<
grammar <grammarName>;
s @after {<ToStringTree("$ctx"):writeln()>} : e;
e : a=e op=('*'|'/') b=e {}
| INT {}
| '(' x=e ')' {}
;
INT : '0'..'9'+ ;
WS : (' '|'\n') -> skip ;
>>

View File

@ -1,9 +0,0 @@
import "LabelsOnOpSubrule.stg"
Input() ::= "4"
Output() ::= <<
(s (e 4))<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "LabelsOnOpSubrule.stg"
Input() ::= "1*2/3"
Output() ::= <<
(s (e (e (e 1) * (e 2)) / (e 3)))<\n>
>>
Errors() ::= ""

View File

@ -1,9 +0,0 @@
import "LabelsOnOpSubrule.stg"
Input() ::= "(1/2)*3"
Output() ::= <<
(s (e (e ( (e (e 1) / (e 2)) )) * (e 3)))<\n>
>>
Errors() ::= ""

Some files were not shown because too many files have changed in this diff Show More