janyou / antlr-swift-runtime Goto Github PK
View Code? Open in Web Editor NEWANTLR v4.5.3 Swift Runtime
ANTLR v4.5.3 Swift Runtime
Search "try!". Every of 21 cases in this project can crash application. It is not expected behavior. There should be no unsafe "try!".
Steps to reproduce:
java -cp antlr4-4.5.1.jar org.antlr.v4.Tool -Dlanguage=Swift -o gen Swift.g4
Actutal result:
Expected result:
The cause of problem is this rule for that grammar:
operator
: operator_head ({_input.get(_input.index()-1).getType()!=WS}? operator_character)*
| dot_operator_head ({_input.get(_input.index()-1).getType()!=WS}? dot_operator_character)*
;
Swift treat "!=" as implicit unwrapping operator "!". Parser generator should replace binary operators with those that would be compiled in Swift with Antlr-Swift-Runtime.
This regex will fix issue: "([^ ])!=([^ ])" -> "$1 != $2", other binary operators can be compiled, because Swift Reference defines binary operator as operator surrounded with spaces on both sides or on neither side. I don't know why "!=" isn't tokenized as a binary operator. Maybe it's even a compiler bug.
I also don't know if it is necessary to fix this issue.
hi. are you any closer to finishing this? Need help?
http://stackoverflow.com/questions/32428108/convert-python-ast-to-json-and-back
I want to do this. Any ideas?
my sample is here
https://github.com/johndpope/Antlr-Swift-Runtime/tree/master/Test/Test
I'm trying to get into the
service MasterService node
import Cocoa
import Antlr4
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
@IBAction func runHelloWalker(_ sender: AnyObject) {
do {
let textFileName = "master_service.proto"
if let textFilePath = Bundle.main.path(forResource: textFileName, ofType: nil) {
let lexer = ProtoLexer(ANTLRFileStream(textFilePath))
//print("lexer:",lexer.getATN())
let tokens = CommonTokenStream(lexer)
let parser = try ProtoParser(tokens)
//print("parser:",parser.getATN())
let tree = try parser.serviceName()
let walker = ParseTreeWalker()
try walker.walk(ProtoWalker(),tree)
} else {
print("error occur: can not open \(textFileName)")
}
}catch ANTLRException.cannotInvokeStartRule {
print("error occur: CannotInvokeStartRule")
}catch ANTLRException.recognition(let e ) {
print("error occur\(e)")
}catch {
print("error occur")
}
}
}
the methods enterR + .r don't seem to connect.
To recreate - I have this script to spit out proto parsers.
https://gist.github.com/johndpope/ec1855edd1e51888a25a1751a2614838
maybe - this updated syntax will suffice. will try
I want to walk the ast. If I get it working will open PR. https://github.com/SwiftTools/SwiftGrammar/blob/eb1b075b4d09d28a815fdc34768ed0c02e050141/SwiftGrammarTests/SwiftGrammarTests.swift
Parser.swif - may also be out of date.
/**
* The preferred method of getting a tree pattern. For example, here's a
* sample use:
*
* <pre>
* ParseTree t = parser.expr(); <- this
* ParseTreePattern p = parser.compileParseTreePattern("<ID>+0", MyParser.RULE_expr);
* ParseTreeMatch m = p.match(t);
* String id = m.get("ID");
* </pre>
fyi - it's not clear how to get the parsetree.
It's not clear where the sample Hello.g4 came from. (might be good idea to include in library)
https://github.com/search?utf8=%E2%9C%93&q=filename%3AHello.g4&type=Code&ref=searchresults
Might be good (popular + protocol buffers + grpc + swift etc ) to replace with Proto.g4 grammar file. Ok - found the Hello grammar file - now the .r call makes sense.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.