weixin_39831001
weixin_39831001
2020-12-30 03:20

Line number followed by multiple statement : parse error


Version 2.4.1.4729
OS: Microsoft Windows NT 10.0.17134.0, x64
Host Product: Microsoft Office x86
Host Version: 16.0.11629.20196
Host Executable: EXCEL.EXE

Code to reproduce


Sub ParseError()
1    DoEvents:
End Sub

"No viable alternative at input "DoEvents"

Expected behavior No error


2019-06-04 15:49:58.2464;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (91) is invoking StateChanged (Started);
2019-06-04 15:49:58.6214;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (92) is invoking StateChanged (LoadingReference);
2019-06-04 15:49:58.9874;INFO-2.4.1.4729;Rubberduck.Parsing.Common.ParsingStageTimer;Loaded and unloaded referenced libraries in 31ms.;
2019-06-04 15:49:58.9934;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (93) is invoking StateChanged (Parsing);
2019-06-04 15:49:59.3384;WARN-2.4.1.4729;Rubberduck.Parsing.VBA.Parsing.TokenStreamParserBase;SLL mode failed while parsing the CodePaneCode version of module Module1 at symbol DoEvents at L8C10. Retrying using LL.;
2019-06-04 15:49:59.3384;ERROR-2.4.1.4729;Rubberduck.Parsing.VBA.Parsing.ModuleParser;Syntax error; offending token 'DoEvents' at line 8, column 10 in the CodePaneCode version of module Module1.;
2019-06-04 15:49:59.3384;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (94) is invoking StateChanged (Error);
2019-06-04 15:49:59.7174;INFO-2.4.1.4729;Rubberduck.Parsing.Common.ParsingStageTimer;Parsed user modules in 385ms.;
2019-06-04 15:49:59.7174;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.ParseCoordinator;Parsing run finished after 1.4732416s. (thread 46).;
2019-06-04 15:50:09.9580;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (95) is invoking StateChanged (Started);
2019-06-04 15:50:10.3510;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (96) is invoking StateChanged (LoadingReference);
2019-06-04 15:50:10.7250;INFO-2.4.1.4729;Rubberduck.Parsing.Common.ParsingStageTimer;Loaded and unloaded referenced libraries in 31ms.;
2019-06-04 15:50:10.7250;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (97) is invoking StateChanged (Parsing);
2019-06-04 15:50:11.0790;WARN-2.4.1.4729;Rubberduck.Parsing.VBA.Parsing.TokenStreamParserBase;SLL mode failed while parsing the CodePaneCode version of module Module1 at symbol DoEvents at L8C6. Retrying using LL.;
2019-06-04 15:50:11.0830;ERROR-2.4.1.4729;Rubberduck.Parsing.VBA.Parsing.ModuleParser;Syntax error; offending token 'DoEvents' at line 8, column 6 in the CodePaneCode version of module Module1.;
2019-06-04 15:50:11.0830;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.RubberduckParserState;RubberduckParserState (98) is invoking StateChanged (Error);
2019-06-04 15:50:11.4460;INFO-2.4.1.4729;Rubberduck.Parsing.Common.ParsingStageTimer;Parsed user modules in 372ms.;
2019-06-04 15:50:11.4460;INFO-2.4.1.4729;Rubberduck.Parsing.VBA.ParseCoordinator;Parsing run finished after 1.4892918s. (thread 33).;

该提问来源于开源项目:rubberduck-vba/Rubberduck

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • weixin_39629093 weixin_39629093 4月前

    Did you know this DoEvents isn't an executable instruction, but a line label? turns out it is executable.... just one of a bunch of obviously special-cased tokens

    Rubberduck failing to parse a line with a line number and a line label is a blessing of a bug, IMO. Almost like not fixing it would be a better thing than fixing it and then implementing an inspection to locate line labels that look like they are intended to be executable statements.

    vb
    Public Sub test()
    10 foo:    foo
    End Sub
    
    Private Sub foo()
        Debug.Print "foo!"
    End Sub
    

    Output: a single foo!.

    点赞 评论 复制链接分享
  • weixin_39831001 weixin_39831001 4月前

    Interesting. the "foo:" is indented left so it is seen as a label. And not executed. Thanks for that ! But DoEvents is recognised executed, as is, say, "Stop" and I guess other one-word statements.

    点赞 评论 复制链接分享
  • weixin_39827034 weixin_39827034 4月前

    Ref #3175 -- Thunderframe listed some keywords that can't be line labels. #FunTimes

    点赞 评论 复制链接分享
  • weixin_39831001 weixin_39831001 4月前

    And for more detail: This code raises the parse error finding at L2C6 (line label 1). Comment the DoEvents line out or delete the line and the other two are not reported as parse errors.

    
    Sub ParseError()
    1    DoEvents: ' is executed
    2 foo:   bar ' foo is seen as a label and not executed
    3  Stop: bar   ' Stop is executed
    
    End Sub
    
    Sub foo()
    
    End Sub
    
    Sub bar()
    
    End Sub
    
    点赞 评论 复制链接分享

相关推荐