bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 13 forks source link

@bmk Pragma broken since 0.139 #656

Open Scaremonger opened 3 months ago

Scaremonger commented 3 months ago

Bug Report

Consider the following code that includes simple Pragmas: `SuperStrict

' @bmk echo ' @bmk echo * ?Debug ' @bmk echo DEBUG MODE ?Not Debug ' @bmk echo RELEASE MODE ? ' @bmk echo *

Print "Hello World"`

Expected Behavior

In version 0.138 this would print "DEBUG MODE" or "RELEASE MODE" during compilation, but since 0.139 this no longer works.

Actual Behavior

Compile Error: Expecting expression but encountered '' @bmk echo

[/home/si/dev/Blitzmax-Language-Server/bls-test.bmx;3;0]
Build Error: failed to compile (65280) /home/si/dev/Blitzmax-Language-Server/bls-test.bmx
Process complete

Environment

Investigation

In file parser.bmx within method TParser.ParseMain(): Existing Code in 0.143

        'Parse header - imports etc.
        While _toke
            SetErr
            Select _toke.ToLower()
...
            Case "moduleinfo"
                NextToke
                Local info:String = ParseStringLit()
                _module.modInfo.AddLast(info)
            Default
                Exit
            End Select

            If _tokeType = TOKE_PRAGMA Then
                ParsePragmaStmt()
                NextToke
            End If
        Wend

The Default at the end of the select..case, exits before it gets to the PRAGMA parser. I fixed it by moving the pragma parser into the default like this: Potential fix

        'Parse header - imports etc.
        While _toke
            SetErr
            Select _toke.ToLower()
...
            Case "moduleinfo"
                NextToke
                Local info:String = ParseStringLit()
                _module.modInfo.AddLast(info)
            Default
                If _tokeType = TOKE_PRAGMA Then
                    ParsePragmaStmt()
                    NextToke
                Else
                    Exit
                End If
            End Select
        Wend