本文整理汇总了C#中VBAParser.startRule方法的典型用法代码示例。如果您正苦于以下问题:C# VBAParser.startRule方法的具体用法?C# VBAParser.startRule怎么用?C# VBAParser.startRule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VBAParser
的用法示例。
在下文中一共展示了VBAParser.startRule方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParsesEmptyForm
public void ParsesEmptyForm()
{
var code = @"
VERSION 5.00
Begin {C62A69F0-16DC-11CE-9E98-00AA00574A4F} Form1
Caption = ""Form1""
ClientHeight = 2640
ClientLeft = 45
ClientTop = 375
ClientWidth = 4710
OleObjectBlob = ""Form1.frx"":0000
StartUpPosition = 1 'CenterOwner
End
Attribute VB_Name = ""Form1""
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
";
var stream = new AntlrInputStream(code);
var lexer = new VBALexer(stream);
var tokens = new CommonTokenStream(lexer);
var parser = new VBAParser(tokens);
parser.ErrorListeners.Clear();
parser.ErrorListeners.Add(new ExceptionErrorListener());
var tree = parser.startRule();
Assert.IsNotNull(tree);
}
示例2: Parse
/// <summary>
/// Exports the specified component to a temporary file, loads, and then parses the exported file.
/// </summary>
/// <param name="component"></param>
public IDictionary<Tuple<string, DeclarationType>, Attributes> Parse(VBComponent component)
{
var path = _exporter.Export(component);
if (!File.Exists(path))
{
// a document component without any code wouldn't be exported (file would be empty anyway).
return new Dictionary<Tuple<string, DeclarationType>, Attributes>();
}
var code = File.ReadAllText(path);
File.Delete(path);
var type = component.Type == vbext_ComponentType.vbext_ct_StdModule
? DeclarationType.Module
: DeclarationType.Class;
var listener = new AttributeListener(Tuple.Create(component.Name, type));
var stream = new AntlrInputStream(code);
var lexer = new VBALexer(stream);
var tokens = new CommonTokenStream(lexer);
var parser = new VBAParser(tokens);
// parse tree isn't usable for declarations because
// line numbers are offset due to module header and attributes
// (these don't show up in the VBE, that's why we're parsing an exported file)
var tree = parser.startRule();
ParseTreeWalker.Default.Walk(listener, tree);
return listener.Attributes;
}
示例3: Parse
private Tuple<VBAParser, ParserRuleContext> Parse(string code)
{
var stream = new AntlrInputStream(code);
var lexer = new VBALexer(stream);
var tokens = new CommonTokenStream(lexer);
var parser = new VBAParser(tokens);
//parser.AddErrorListener(new ExceptionErrorListener());
var root = parser.startRule();
// Useful for figuring out what XPath to use for querying the parse tree.
var str = root.ToStringTree(parser);
return Tuple.Create<VBAParser, ParserRuleContext>(parser, root);
}
示例4: Parse
public IParseTree Parse(string code, out ITokenStream outStream)
{
var input = new AntlrInputStream(code);
var lexer = new VBALexer(input);
var tokens = new CommonTokenStream(lexer);
var parser = new VBAParser(tokens);
parser.AddErrorListener(new ExceptionErrorListener());
outStream = tokens;
var result = parser.startRule();
return result;
}
示例5: ParseInternal
private static IParseTree ParseInternal(string code, IParseTreeListener[] listeners, out ITokenStream outStream)
{
var stream = new AntlrInputStream(code);
var lexer = new VBALexer(stream);
var tokens = new CommonTokenStream(lexer);
var parser = new VBAParser(tokens);
parser.AddErrorListener(new ExceptionErrorListener());
foreach (var l in listeners)
{
parser.AddParseListener(l);
}
outStream = tokens;
return parser.startRule();
}