antlr / antlr/antlr4

Swift: Provide ANTLRURLStream similar to ANTLRFileStream

Open
#4,264 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
19k
Forks
3.5k
PR merge metrics
No merged PRs in 30d

Description

- [x] I have reproduced my issue using the latest version of ANTLR
- [ ] I have asked at [stackoverflow](http://stackoverflow.com/questions/tagged/antlr4)
- [ ] Responses from the above seem to indicate that my issue could be an ANTLR bug
- [x] I have done a search of the existing issues to make sure I'm not sending in a duplicate

Please include the following information:
- target information: Swift

I would like to create an ANTLRInputStream from a URL. ANTLR provides an ANTLRFileStream, which is very similar to what I need. Unfortunately, ANTLRInputStream is not an open class. Thus I cannot inherit from it.

The ANTLRURLStream I have in mind looks as follows:

```
import Foundation

import Antlr4

public class ANTLRURLStream: ANTLRInputStream {
private let url: URL

public init(_ url: URL, _ encoding: String.Encoding? = nil) throws {
self.url = url
let fileContents = try String(contentsOf: url, encoding: encoding ?? .utf8)
let data = Array(fileContents.unicodeScalars)
super.init(data, data.count)
}

override
public func getSourceName() -> String {
return url.relativePath
}
}

```

It would be great, if ANTLRInputStream could be declared `open` or Antlr would provide the respective url input stream

Contributor guide

Open the contributing guide

Research direction

Start by inspecting the Swift ANTLRInputStream and ANTLRFileStream entry points and the proposed ANTLRURLStream example. Determine whether the supported approach should be opening ANTLRInputStream for subclassing or adding a URL stream, then verify that URL contents and the source name are handled as requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.