-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Pegen grammar for reading Python3 grammar.
- Loading branch information
Showing
11 changed files
with
3,575 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using Antlr4.Runtime; | ||
using Antlr4.Runtime.Misc; | ||
using System; | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
public abstract class Adaptor : Lexer | ||
{ | ||
readonly ICharStream stream; | ||
readonly FieldInfo tokenInput = typeof(CommonToken).GetField("_type", BindingFlags.NonPublic | BindingFlags.Instance); | ||
protected Adaptor(ICharStream input) | ||
: base(input, Console.Out, Console.Error) | ||
{ | ||
stream = input; | ||
} | ||
|
||
protected Adaptor(ICharStream input, TextWriter output, TextWriter errorOutput) | ||
: base(input, output, errorOutput) | ||
{ | ||
stream = input; | ||
} | ||
|
||
private int CurrentRuleType { get; set; } = TokenConstants.InvalidType; | ||
|
||
public bool AtEnd() | ||
{ | ||
return CurrentMode == pegen_v3_10Lexer.ACTION_MODE; | ||
} | ||
|
||
protected void handleEndAction() | ||
{ | ||
int oldMode = CurrentMode; | ||
int newMode = PopMode(); | ||
bool isActionWithinAction = ModeStack.Count > 0 | ||
&& newMode == pegen_v3_10Lexer.ACTION_MODE | ||
&& oldMode == newMode; | ||
|
||
if (isActionWithinAction) | ||
{ | ||
CurrentRuleType = (pegen_v3_10Lexer.ACTION); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import org.antlr.v4.runtime.CharStream; | ||
import org.antlr.v4.runtime.Lexer; | ||
import org.antlr.v4.runtime.Token; | ||
|
||
public abstract class Adaptor extends Lexer { | ||
|
||
protected Adaptor(CharStream input) { | ||
super(input); | ||
} | ||
|
||
private int CurrentRuleType = Token.INVALID_TYPE; | ||
|
||
public boolean AtEnd() | ||
{ | ||
return this._mode == pegen_v3_10Lexer.ACTION_MODE; | ||
} | ||
|
||
protected void handleEndAction() | ||
{ | ||
int oldMode = this._mode; | ||
int newMode = this.popMode(); | ||
boolean isActionWithinAction = !this._modeStack.isEmpty() | ||
&& newMode == pegen_v3_10Lexer.ACTION_MODE | ||
&& oldMode == newMode; | ||
|
||
if (isActionWithinAction) | ||
{ | ||
CurrentRuleType = (pegen_v3_10Lexer.ACTION); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<desc xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../_scripts/desc.xsd"> | ||
<targets>CSharp;Java</targets> | ||
</desc> |
Oops, something went wrong.