Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into catch-import-statem…
Browse files Browse the repository at this point in the history
…ent-missing-file
  • Loading branch information
TwitchBronBron committed Jul 8, 2020
2 parents e715e9f + 19e14bd commit d968863
Show file tree
Hide file tree
Showing 53 changed files with 2,051 additions and 271 deletions.
1 change: 1 addition & 0 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: benchmark
on: repository_dispatch #only run manually for now...something is wrong with the benchmark

jobs:
ci:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [0.11.0] - 2020-07-06
### Added
- [Source literals feature](https://github.com/rokucommunity/brighterscript/blob/master/docs/source-literals.md) which adds new literals such as `SOURCE_FILE_PATH`, `SOURCE_LINE_NUM`, `FUNCTION_NAME`, and more. ([#13](https://github.com/rokucommunity/brighterscript/issues/13))
- `sourceRoot` config option to fix sourcemap paths for projects that use a temporary staging folder before calling the BrighterScript compiler. ([#134](https://github.com/rokucommunity/brighterscript/commit/e5b73ca37016d5015a389257fb259573c4721e7a))
- [Template string feature](https://github.com/rokucommunity/brighterscript/blob/master/docs/template-strings.md) which brings template string support to BrighterScript. ([#98](https://github.com/rokucommunity/brighterscript/issues/98))
### Fixed
- Do not show BS1010 diagnostic `hint`s for the same script imported for parent and child. ([#113](https://github.com/rokucommunity/brighterscript/issues/113))

## [0.10.11] - 2020-07-05
- Fix bug that would fail to copy files to staging without explicitly specifying `stagingFolderpath`. [#129](https://github.com/rokucommunity/brighterscript/issues/129)
Expand Down Expand Up @@ -368,6 +375,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0



[0.11.0]: https://github.com/rokucommunity/brighterscript/compare/v0.10.10...v0.11.0
[0.10.10]: https://github.com/rokucommunity/brighterscript/compare/v0.10.9...v0.10.10
[0.10.9]: https://github.com/rokucommunity/brighterscript/compare/v0.10.8...v0.10.9
[0.10.7]: https://github.com/rokucommunity/brighterscript/compare/v0.10.6...v0.10.7
Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ A superset of Roku's BrightScript language. Compiles to standard BrightScript.

The BrighterScript language provides new features and syntax enhancements to Roku's BrightScript language. Because the language is a superset of BrightScript, the parser and associated tools (VSCode integration, cli, etc...) work with standard BrightScript (.brs) files. This means you will get benefits (as described in the following section) from using the BrighterScript compiler, whether your project contains BrighterScript (.bs) files or not. The BrighterScript language transpiles to standard BrightScript, so your code is fully compatible with all roku devices.

## Features
BrighterScript adds several new features to the BrightScript language such as Namespaces, classes, import statements, and more. Take a look at the language specification docs for more information.

[BrighterScript Language Specification](https://github.com/rokucommunity/BrighterScript/blob/master/docs/index.md)

## Why use the BrighterScript compiler/CLI?

- Check the entire project for syntax and program errors without needing to run on an actual Roku device.
Expand Down Expand Up @@ -64,12 +69,6 @@ The name BrighterScript is a compliment to everything that is great about Roku's

We want to honor BrightScript, the language that BrighterScript is based off of, and could think of no better way than to use _most_ of its name in our name.

## Features
BrighterScript adds several new features to the BrightScript language such as Namespaces, classes, import statements, and more. Take a look at the language specification docs for more information.

[BrighterScript Language Specification](https://github.com/rokucommunity/BrighterScript/blob/master/docs/index.md)


## Installation

### npm
Expand Down Expand Up @@ -180,6 +179,8 @@ These are the options available in the `bsconfig.json` file.
```
- **autoImportComponentScript**: `bool` - BrighterScript only: will automatically import a script at transpile-time for a component with the same name if it exists.

- **sourceRoot*: `string` - Override the root directory path where debugger should locate the source files. The location will be embedded in the source map to help debuggers locate the original source files. This only applies to files found within rootDir. This is useful when you want to preprocess files before passing them to BrighterScript, and want a debugger to open the original files. This option also affects the `SOURCE_FILE_PATH` and `SOURCE_LOCATION` source literals.


## Ignore errors and warnings on a per-line basis
In addition to disabling an entire class of errors in `bsconfig.json` by using `ignoreErrorCodes`, you may also disable errors for a subset of the complier rules within a file with the following comment flags:
Expand Down
4 changes: 4 additions & 0 deletions bsconfig.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@
"debug",
"trace"
]
},
"sourceRoot": {
"description": "Override the root directory path where debugger should locate the source files. The location will be embedded in the source map to help debuggers locate the original source files. This only applies to files found within rootDir. This is useful when you want to preprocess files before passing them to BrighterScript, and want a debugger to open the original files. This option also affects the `SOURCE_FILE_PATH` and `SOURCE_LOCATION` source literals.",
"type": "string"
}
}
}
25 changes: 24 additions & 1 deletion bslib.brs
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
' Utility functions for the BrighterScript language
' Utility functions for the BrighterScript language

'
' Convert a value into a string. For non-primitive values, this will return the type instead of its value in most cases.
' @param dynamic value - the value to be turned into a string.
' @return string - the string representation of `value`
'
function bslib_toString(value)
valueType = type(value)
'if the var supports `toStr()`
if valueType = "<uninitialized>" then
return valueType
else if value = invalid then
return "<invalid>"
else if GetInterface(value, "ifToStr") <> invalid then
return value.toStr()
else if valueType = "roSGNode"
return "Node(" + value.subType() + ")"
end if
'TODO add class name for objects once we have reflection implemented

'when all else fails, just return the type
return "<" + valueType + ">"
end function
4 changes: 3 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ BrighterScript is a superset of Roku's BrightScript language. Its goal is to pro

See the following pages for more information

- [Callfunc Operator](callfunc-operator.md)
- [Classes](classes.md)
- [Imports](imports.md)
- [Namespaces](namespaces.md)
- [callfunc operator](callfunc-operator.md)
- [Source Literals](source-literals.md)
- [Template Strings (Template Literals)](template-strings.md)
186 changes: 186 additions & 0 deletions docs/source-literals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# Source Literals
BrightScript provides the `LINE_NUM` literal, which represents the runtime 1-based line number of the current line of code. In a similar fashion, BrighterScript provides several more source literals.

These source literals are converted into inline variables at transpile-time, so keep in mind that any post-processing to the transpiled files could cause these values to be incorrect.

## SOURCE_FILE_PATH
The absolute path to the source file, including a leading `file:/` scheme indicator. i.e. `"file:/C:/projects/RokuApp/source/main.bs"`.

```BrighterScript
print SOURCE_FILE_PATH
```

transpiles to:

```BrightScript
print "file:/c:\projects\roku\brighterscript\scripts\rootDir\source\main.bs"
```

## SOURCE_LINE_NUM
The 1-based line number of the source file.

```BrighterScript
'I am line 1
print SOURCE_LINE_NUM 'I am line 2
```

transpiles to:

```BrightScript
'I am line 1
print 2 'I am line 2
```

## FUNCTION_NAME
### Basic
The name of the current function
```BrighterScript
function RunFromZombie()
print FUNCTION_NAME
end function
```

transpiles to:

```BrightScript
function RunFromZombie()
print "RunFromZombie"
end function
```

### Namespaced
if the function is contained in a namespace, that name will be included in the function name
```BrighterScript
namespace Human.Versus.Zombie
function RunFromZombie()
print FUNCTION_NAME
end function
end namespace
```

transpiles to:

```BrightScript
function Human_Versus_Zombie_RunFromZombie()
print "Human_Versus_Zombie_RunFromZombie"
end function
```
### Anonymous Functions
For anonymous functions, FUNCTION_NAME will include the enclosing function name, followed by `anon` and the index of the function in its parent. If there are multiple nested anonymous functions, each level will have its own `anon[index]` in the name. Function indexes start at 0 within each enclosing function.

```BrighterScript
function main()
zombieAttack = function()
print FUNCTION_NAME
end function
humanAttack = function()
useSword = function()
print FUNCTION_NAME
end function
useSword()
end function
end function
namespace Human.Versus.Zombie
function Eat()
print SOURCE_FUNCTION_NAME
findFood = function()
print FUNCTION_NAME
end function
end function
end namespace
```

transpiles to:

```BrightScript
function main()
zombieAttack = function()
print "main$anon0"
end function
humanAttack = function()
useSword = function()
print "main$anon1$anon0"
end function
useSword()
end function
end function
function Human_Versus_Zombie_Eat()
print "Human.Versus.Zombie.Eat"
findFood = function()
print "Human_Versus_Zombie_Eat$anon0"
end function
end function
```

## SOURCE_FUNCTION_NAME
This works the same as FUNCTION_NAME except that it will use a dot in namespace names instead of the transpiled underscores.


```BrighterScript
namespace Human.Versus.Zombie
function Eat()
print SOURCE_FUNCTION_NAME
findFood = function()
print SOURCE_FUNCTION_NAME
end function
end function
end namespace
```

transpiles to:

```BrightScript
function Human_Versus_Zombie_Eat()
print "Human.Versus.Zombie.Eat"
findFood = function()
print "Human.Versus.Zombie.Eat$anon0"
end function
end function
```

## SOURCE_LOCATION
A combination of SOURCE_FILE_PATH and SOURCE_LINE_NUM.

```BrighterScript
function main()
print SOURCE_LOCATION
end function
```

transpiles to:

```BrightScript
function main()
print "file:/c:\projects\roku\brighterscript\scripts\rootDir\source\main.bs:2"
end function
```

## PKG_PATH
The pkg path of the file.

```BrighterScript
function main()
print PKG_PATH
end function
```

transpiles to:

```BrightScript
function main()
print "pkg:/source/main.brs"
end function
```

## PKG_LOCATION
A combination of PKG_PATH and LINE_NUM. Keep in mind, LINE_NUM is a runtime variable provided by Roku.
```BrighterScript
print PKG_LOCATION
```

transpiles to:

```BrightScript
print "pkg:/source/main.brs:" + str(LINE_NUM)
```
Loading

0 comments on commit d968863

Please sign in to comment.