-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic regex literal lexer support. * Add lexer support for escaped regexp chars * Add parser and transpile functionality * Add very basic docs about regex literals * Verify lexer handles quotemark properly * Escape quotemarks
- Loading branch information
1 parent
1818c36
commit 22c8a30
Showing
8 changed files
with
235 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Regular Expression Literals | ||
You can create a regular expression literal in brighterscript. This simplifies pattern writing and improves readability. | ||
|
||
Example: | ||
```BrighterScript | ||
print /hello world/ig | ||
``` | ||
|
||
transpiles to: | ||
|
||
```BrightScript | ||
print CreateObject("roRegex","hello world","ig") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/parser/tests/expression/RegexLiteralExpression.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Program } from '../../../Program'; | ||
import { standardizePath as s } from '../../../util'; | ||
import { getTestTranspile } from '../../../testHelpers.spec'; | ||
|
||
describe('RegexLiteralExpression', () => { | ||
let rootDir = s`${process.cwd()}/rootDir`; | ||
let program: Program; | ||
let testTranspile = getTestTranspile(() => [program, rootDir]); | ||
|
||
beforeEach(() => { | ||
program = new Program({ rootDir: rootDir }); | ||
}); | ||
afterEach(() => { | ||
program.dispose(); | ||
}); | ||
|
||
describe('transpile', () => { | ||
it('captures flags', () => { | ||
testTranspile(` | ||
sub main() | ||
print /hello/gi | ||
end sub | ||
`, ` | ||
sub main() | ||
print CreateObject("roRegex", "hello", "gi") | ||
end sub | ||
`); | ||
}); | ||
|
||
it('handles when no flags', () => { | ||
testTranspile(` | ||
sub main() | ||
print /hello/ | ||
end sub | ||
`, ` | ||
sub main() | ||
print CreateObject("roRegex", "hello", "") | ||
end sub | ||
`); | ||
}); | ||
|
||
it('handles weird escapes', () => { | ||
testTranspile(` | ||
sub main() | ||
print /\\r\\n\\// | ||
end sub | ||
`, ` | ||
sub main() | ||
print CreateObject("roRegex", "\\r\\n\\/", "") | ||
end sub | ||
`); | ||
}); | ||
|
||
it('escapes quotemark', () => { | ||
testTranspile(` | ||
sub main() | ||
print /"/ | ||
end sub | ||
`, ` | ||
sub main() | ||
print CreateObject("roRegex", "" + chr(34) + "", "") | ||
end sub | ||
`); | ||
}); | ||
|
||
}); | ||
}); |