本文整理汇总了C#中antlr类的典型用法代码示例。如果您正苦于以下问题:C# antlr类的具体用法?C# antlr怎么用?C# antlr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
antlr类属于命名空间,在下文中一共展示了antlr类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseIntegerLiteralExpression
public static IntegerLiteralExpression ParseIntegerLiteralExpression(antlr.IToken token, string s, bool asLong)
{
const string HEX_PREFIX = "0x";
NumberStyles style = NumberStyles.Integer | NumberStyles.AllowExponent;
int hex_start = s.IndexOf(HEX_PREFIX);
bool negative = false;
if (hex_start >= 0)
{
if (s.StartsWith("-"))
{
negative = true;
}
s = s.Substring(hex_start + HEX_PREFIX.Length);
style = NumberStyles.HexNumber;
}
long value = long.Parse(s, style, CultureInfo.InvariantCulture);
if (negative) //negative hex number
{
value *= -1;
}
return new IntegerLiteralExpression(SourceLocationFactory.ToLexicalInfo(token), value, asLong || (value > int.MaxValue || value < int.MinValue));
}
示例2: ResolveBooTokenStartAndEndIndex
public void ResolveBooTokenStartAndEndIndex(antlr.CommonToken token, TokenInfo tokenInfo)
{
int oneCharBack = token.getColumn() - 1;
int lengthOfTokenText = token.getText() == null ? 0 : token.getText().Length;
int oneCharAfterToken = token.getColumn() + lengthOfTokenText;
// single quoted string
if (token.Type == BooLexer.SINGLE_QUOTED_STRING || token.Type == BooLexer.DOUBLE_QUOTED_STRING)
{
tokenInfo.StartIndex = oneCharBack;
tokenInfo.EndIndex = oneCharAfterToken;
}
else if (token.Type == BooLexer.TRIPLE_QUOTED_STRING)
{
tokenInfo.StartIndex = oneCharBack;
tokenInfo.EndIndex = oneCharBack+ 5 + token.getText().Length;
}
else if (token.Type == 1)
{
return;
}
else
{
tokenInfo.StartIndex = oneCharBack;
tokenInfo.EndIndex = oneCharBack + (token.getText().Length - 1);
}
}
示例3: ToLexicalInfo
protected LexicalInfo ToLexicalInfo(antlr.IToken token)
{
int line = token.getLine();
int startColumn = token.getColumn();
int endColumn = token.getColumn() + token.getText().Length;
String filename = token.getFilename();
return new LexicalInfo(filename, line, startColumn, endColumn);
}
示例4: OnParserError
void OnParserError(antlr.RecognitionException error)
{
var location = new LexicalInfo(error.getFilename(), error.getLine(), error.getColumn());
var nvae = error as antlr.NoViableAltException;
if (null != nvae)
ParserError(location, nvae);
else
GenericParserError(location, error);
}
示例5: ParseDouble
public static double ParseDouble(antlr.IToken token, string s, bool isSingle)
{
try
{
return TryParseDouble(isSingle, s);
}
catch (Exception x)
{
LexicalInfo sourceLocation = ToLexicalInfo(token);
GenericParserError(sourceLocation, x);
// let the parser continue
return double.NaN;
}
}
示例6: ParseTimeSpan
public static TimeSpan ParseTimeSpan(antlr.IToken token, string text)
{
try
{
return TryParseTimeSpan(token, text);
}
catch (System.OverflowException x)
{
LexicalInfo sourceLocation = ToLexicalInfo(token);
GenericParserError(sourceLocation, x);
// let the parser continue
return TimeSpan.Zero;
}
}
示例7: IndentTokenStreamFilter
public IndentTokenStreamFilter(antlr.TokenStream istream, int wsTokenType, int indentTokenType, int dedentTokenType, int eosTokenType)
{
if (null == istream)
{
throw new ArgumentNullException("istream");
}
_istream = istream;
_wsTokenType = wsTokenType;
_indentTokenType = indentTokenType;
_dedentTokenType = dedentTokenType;
_eosTokenType = eosTokenType;
_indentStack = new Stack();
_pendingTokens = new Queue();
_indentStack.Push(0); // current indent level is zero
}
示例8: TryParseTimeSpan
private static TimeSpan TryParseTimeSpan(antlr.IToken token, string text)
{
if (text.EndsWith("ms"))
{
return TimeSpan.FromMilliseconds(
ParseDouble(token, text.Substring(0, text.Length - 2)));
}
char last = text[text.Length - 1];
double value = ParseDouble(token, text.Substring(0, text.Length - 1));
switch (last)
{
case 's': return TimeSpan.FromSeconds(value);
case 'h': return TimeSpan.FromHours(value);
case 'm': return TimeSpan.FromMinutes(value);
case 'd': return TimeSpan.FromDays(value);
}
throw new ArgumentException(text, "text");
}
示例9: Enqueue
void Enqueue(antlr.IToken token, string text)
{
token.setText(text);
EnqueueInterpolatedToken(token);
}
示例10: reportError
override public void reportError(antlr.RecognitionException x)
{
if (null != Error)
Error(x);
else
base.reportError(x);
}
示例11: ToSourceLocation
public static SourceLocation ToSourceLocation(antlr.IToken token)
{
return new SourceLocation(token.getLine(), token.getColumn());
}
示例12: ToEndSourceLocation
public static SourceLocation ToEndSourceLocation(antlr.IToken token)
{
return new SourceLocation(token.getLine(), token.getColumn() + token.getText().Length - 1);
}
示例13: ToEndSourceLocation
public static SourceLocation ToEndSourceLocation(antlr.IToken token)
{
string text = token.getText() ?? "";
return new SourceLocation(token.getLine(), token.getColumn() + text.Length - 1);
}
示例14: CreateToken
antlr.IToken CreateToken(antlr.IToken prototype, int newTokenType, string newTokenText)
{
return new BooToken(newTokenType, newTokenText,
prototype.getFilename(),
prototype.getLine(),
prototype.getColumn()+SafeGetLength(prototype.getText()));
}
示例15: CheckForEOF
void CheckForEOF(antlr.IToken token)
{
if (antlr.Token.EOF_TYPE != token.Type) return;
EnqueueEOS(token);
while (CurrentIndentLevel > 0)
{
EnqueueDedent();
_indentStack.Pop();
}
}