Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
Merge pull request #63 from willowtreeapps/feature/conditionalCompila…
Browse files Browse the repository at this point in the history
…tion

Support for Conditional Compilation
  • Loading branch information
nishtahir authored Feb 6, 2018
2 parents 7752ae2 + 20043dd commit d62291f
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
50 changes: 47 additions & 3 deletions grammar/BrightScript.g4
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@ startRule
;

component
: endOfLine* libraryStatement* endOfLine* componentBody
: componentHead componentBody
;

componentHead
: endOfLine* componentHeadElement (endOfLine+ componentHeadElement)* endOfLine*
;

componentHeadElement
: libraryStatement
| conditionalCompilationStatement
| comment
;

componentBody
: componentBodyElement (endOfLine+ componentBodyElement)* endOfLine*
: endOfLine* componentBodyElement (endOfLine+ componentBodyElement)* endOfLine*
;

componentBodyElement
Expand All @@ -23,6 +33,7 @@ block

blockStatement
: comment
| conditionalCompilationStatement
| dimStatement
| exitStatement
| forStatement
Expand Down Expand Up @@ -50,6 +61,15 @@ associativeElementInitializer
: (identifier | reservedWord | stringLiteral) COLON assignableExpression
;

conditionalCompilationStatement
: CONDITIONAL_CONST untypedIdentifier EQUALS expression
| CONDITIONAL_ERROR .*?
| CONDITIONAL_IF expression
| CONDITIONAL_ELSEIF expression
| CONDITIONAL_ELSE
| CONDITIONAL_ENDIF
;

dimStatement
: DIM identifier OPEN_BRACKET parameterList CLOSE_BRACKET
;
Expand Down Expand Up @@ -547,7 +567,7 @@ IDENTIFIER_TYPE_DECLARATION
;
COMMENT
: (SINGLE_QUOTE | (REM (WS | NEWLINE))) ~[\r\n\u2028\u2029]* -> channel(HIDDEN)
: (SINGLE_QUOTE | (REM (WS | NEWLINE))) ~[\r\n\u2028\u2029]* -> channel(HIDDEN)
;
NEWLINE
Expand All @@ -558,6 +578,30 @@ WS
: [ \t]+ -> skip
;
CONDITIONAL_CONST
: '#' C O N S T
;
CONDITIONAL_ELSE
: '#' ELSE
;
CONDITIONAL_ELSEIF
: '#' (ELSE WS IF | ELSEIF)
;
CONDITIONAL_ENDIF
: '#' (END WS IF | ENDIF)
;
CONDITIONAL_ERROR
: '#' E R R O R
;
CONDITIONAL_IF
: '#' IF
;
SINGLE_QUOTE
: '\''
;
Expand Down
9 changes: 9 additions & 0 deletions sample-project/source/GoodSyntax.brs
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
' This is a sample file containing syntax that compiles properly

#const debug = true

REM Although the file compiles,
REM
REM Not all linting rules pass

sub DefaultMain()
#if debug = true
print "debug mode enabled"
#else
print "debug mode disabled"
#end if

print "in showChannelSGScreen"

'Indicate this is a Roku SceneGraph application'
screen = CreateObject("roSGScreen")
m.port = CreateObject("roMessagePort")
Expand Down

0 comments on commit d62291f

Please sign in to comment.