Merge pull request #1979 from hanjoes/swift-wiki

Updated swift-target.md.
This commit is contained in:
Terence Parr 2017-08-06 08:13:47 -07:00 committed by GitHub
commit 1203794259
1 changed files with 9 additions and 26 deletions

View File

@ -1,9 +1,16 @@
# ANTLR4 Language Target, Runtime for Swift
## Performance Note
To use ANTLR4 Swift target in production environment, make sure to turn on compiler optimizations by following [these instructions](https://github.com/apple/swift-package-manager/blob/master/Documentation/Usage.md#build-configurations) if you use SwiftPM to build your project. If you are using Xcode to build your project, it's unlikely you will not use `release` build for production build.
Conclusion is, you need to turn on `release` mode (which will have all the optimization pre configured for you) so the ANTLR4 Swift target can have reasonable parsing speed.
## Install ANTLR4
Make sure you have the ANTLR
installed.[The getting started guide](getting-started.md) should get
installed. [The getting started guide](getting-started.md) should get
you started.
## Create a Swift lexer or parser
@ -72,28 +79,4 @@ Dependencies__" and "__Link Binary With Libraries__" sections, as
shown below. After correctly added dependencies, the error message for
importing library will be gone.
<img src=images/xcodedep.png width="800">
## Example playground
The Swift runtime includes an Xcode playground to get started with.
First go to the ANTLR4 repository, and open
`runtime/Swift/Antlr4.xcworkspace` in Xcode. Select "Antlr4 OSX > My
Mac" as the build target, and build the project as normal. The
playground should then be active.
The playground includes a simple grammar called "Hello", and an
example for walking the parse tree. You should see in the playground
output that it is printing messages for each node in the parse tree as
it walks.
The grammar is defined in the playground's `Resources/Hello.g4`. The
parser was generated from the grammar using ANTLR like this:
```
antlr4 -Dlanguage=Swift -visitor -o ../Sources/Autogen Hello.g4
```
The example tree walker is in Sources/HelloWalker.swift.
<img src=images/xcodedep.png width="800">