本文整理汇总了C#中antlr类的典型用法代码示例。如果您正苦于以下问题:C# antlr类的具体用法?C# antlr怎么用?C# antlr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
antlr类属于命名空间,在下文中一共展示了antlr类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:boo,项目名称:boo-lang,代码行数:25,代码来源:PrimitiveParser.cs
示例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);
}
}
开发者ID:w4x,项目名称:boolangstudio,代码行数:27,代码来源:BooScannerResolvers.cs
示例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);
}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:8,代码来源:AspectLanguageParser.cs
示例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);
}
开发者ID:Qorpent,项目名称:comdiv.oldcore,代码行数:9,代码来源:WSAIgnoranceParsingStep.cs
示例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;
}
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:14,代码来源:PrimitiveParser.cs
示例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;
}
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:14,代码来源:PrimitiveParser.cs
示例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
}
开发者ID:HaKDMoDz,项目名称:GNet,代码行数:17,代码来源:IndentTokenStreamFilter.cs
示例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");
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:19,代码来源:PrimitiveParser.cs
示例9: Enqueue
void Enqueue(antlr.IToken token, string text)
{
token.setText(text);
EnqueueInterpolatedToken(token);
}
开发者ID:leylena,项目名称:boo,代码行数:5,代码来源:WSABooLexer.cs
示例10: reportError
override public void reportError(antlr.RecognitionException x)
{
if (null != Error)
Error(x);
else
base.reportError(x);
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:7,代码来源:WSABooParser.cs
示例11: ToSourceLocation
public static SourceLocation ToSourceLocation(antlr.IToken token)
{
return new SourceLocation(token.getLine(), token.getColumn());
}
开发者ID:boo,项目名称:boo-lang,代码行数:4,代码来源:SourceLocationFactory.cs
示例12: ToEndSourceLocation
public static SourceLocation ToEndSourceLocation(antlr.IToken token)
{
return new SourceLocation(token.getLine(), token.getColumn() + token.getText().Length - 1);
}
开发者ID:boo,项目名称:boo-lang,代码行数:4,代码来源:SourceLocationFactory.cs
示例13: ToEndSourceLocation
public static SourceLocation ToEndSourceLocation(antlr.IToken token)
{
string text = token.getText() ?? "";
return new SourceLocation(token.getLine(), token.getColumn() + text.Length - 1);
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:5,代码来源:SourceLocationFactory.cs
示例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()));
}
开发者ID:w4x,项目名称:boolangstudio,代码行数:7,代码来源:IndentTokenStreamFilter.cs
示例15: CheckForEOF
void CheckForEOF(antlr.IToken token)
{
if (antlr.Token.EOF_TYPE != token.Type) return;
EnqueueEOS(token);
while (CurrentIndentLevel > 0)
{
EnqueueDedent();
_indentStack.Pop();
}
}
开发者ID:w4x,项目名称:boolangstudio,代码行数:11,代码来源:IndentTokenStreamFilter.cs
示例16: GetTokenType
public static BooTokenType GetTokenType(antlr.IToken token)
{
switch (token.Type)
{
case BooLexer.TRIPLE_QUOTED_STRING: return BooTokenType.DocumentString;
case BooLexer.DOUBLE_QUOTED_STRING:
case BooLexer.SINGLE_QUOTED_STRING:
return BooTokenType.String;
case BooLexer.DOT: return BooTokenType.MemberSelector;
case BooLexer.WS: return BooTokenType.WhiteSpace;
case BooLexer.ID: return BooTokenType.Identifier;
case BooLexer.ABSTRACT:
case BooLexer.AS:
case BooLexer.BREAK:
case BooLexer.CLASS:
case BooLexer.CONSTRUCTOR:
case BooLexer.CONTINUE:
case BooLexer.DEF:
case BooLexer.DO:
case BooLexer.ELIF:
case BooLexer.ELSE:
case BooLexer.ENUM:
case BooLexer.EVENT:
case BooLexer.EXCEPT:
case BooLexer.FALSE:
case BooLexer.FINAL:
case BooLexer.FOR:
case BooLexer.FROM:
case BooLexer.GET:
case BooLexer.GOTO:
case BooLexer.IF:
case BooLexer.IMPORT:
case BooLexer.IN:
case BooLexer.INTERFACE:
case BooLexer.INTERNAL:
case BooLexer.IS:
case BooLexer.LONG:
case BooLexer.NAMESPACE:
case BooLexer.NULL:
case BooLexer.OF:
case BooLexer.OVERRIDE:
case BooLexer.PARTIAL:
case BooLexer.PASS:
case BooLexer.PRIVATE:
case BooLexer.PROTECTED:
case BooLexer.PUBLIC:
case BooLexer.RAISE:
case BooLexer.REF:
case BooLexer.RETURN:
case BooLexer.SELF:
case BooLexer.SET:
case BooLexer.STATIC:
case BooLexer.STRUCT:
case BooLexer.SUPER:
case BooLexer.THEN:
case BooLexer.TRUE:
case BooLexer.TRY:
case BooLexer.TYPEOF:
case BooLexer.UNLESS:
case BooLexer.VIRTUAL:
case BooLexer.WHILE:
case BooLexer.YIELD:
return BooTokenType.Keyword;
default: return BooTokenType.Other;
}
}
开发者ID:Rfvgyhn,项目名称:Boo-Plugin,代码行数:72,代码来源:Scanner.cs
示例17: ParserError
void ParserError(LexicalInfo data, antlr.NoViableAltException error)
{
_context.Errors.Add(CompilerErrorFactory.UnexpectedToken(data, error, error.token.getText()));
}
开发者ID:0xb1dd1e,项目名称:boo,代码行数:4,代码来源:BooParsingStep.cs
示例18: Enqueue
void Enqueue(antlr.IToken token)
{
_pendingTokens.Enqueue(token);
}
开发者ID:w4x,项目名称:boolangstudio,代码行数:4,代码来源:IndentTokenStreamFilter.cs
示例19: reportError
public override void reportError(antlr.RecognitionException x)
{
if (null != Error)
{
Error(x);
}
else
{
base.reportError(x);
}
}
开发者ID:boo,项目名称:boo-lang,代码行数:11,代码来源:WSABooParser.cs
示例20: EnqueueEOS
void EnqueueEOS(antlr.IToken prototype)
{
_pendingTokens.Enqueue(CreateToken(prototype, _eosTokenType, "<EOL>"));
}
开发者ID:w4x,项目名称:boolangstudio,代码行数:4,代码来源:IndentTokenStreamFilter.cs
注:本文中的antlr类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论