Code Monkey home page Code Monkey logo

antlr-swift-runtime's People

Contributors

artyom-razinov avatar janyou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

antlr-swift-runtime's Issues

Grammar with semantic predicates produces parser that won't compile

Steps to reproduce:

  1. Get ANTLRv4 grammars: https://github.com/antlr/grammars-v4
  2. Run antlr for Swift.g4: java -cp antlr4-4.5.1.jar org.antlr.v4.Tool -Dlanguage=Swift -o gen Swift.g4

Actutal result:

  1. Swift parser has compilation errors

Expected result:

  1. Swift parser can be compiled

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.

any progress?

hi. are you any closer to finishing this? Need help?

Spit out AST - Json

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

screen shot 2016-11-06 at 18 23 15

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")
    }
}

}

Sample test project - seems out of sync with Antlr-Swift-Target

screen shot 2016-11-06 at 15 58 48

screen shot 2016-11-06 at 15 58 10

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("&lt;ID&gt;+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.
screen shot 2016-11-06 at 16 33 27

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.

screen shot 2016-11-06 at 16 45 15

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.