Giter Site home page Giter Site logo

strumenta / kolasu Goto Github PK

View Code? Open in Web Editor NEW
104.0 104.0 11.0 3.03 MB

Kotlin Language Support – AST Library

License: Apache License 2.0

Kotlin 98.19% ANTLR 0.65% Java 1.16%
antlr antlr4 ast compilers interpreters kotlin language languages parsing starlasu transpilers

kolasu's People

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kolasu's Issues

Handle null collections

Kolasu assumes lists and other collections are never null when mapping to EMF. However, nothing prevents the AST from containing null collections.

"isInterface" not recorded in EMF metamodel

This causes issues when importing a metamodel with interfaces from a language that doesn't allow multiple inheritance, because interfaces are recorded as abstract classes.

Collection usage

I see LinkedList and HashMap and such. Why not use the Kotlin collections?

Point/Position naming

"Position" sounds like something that is in 1 place. In Kolasu it is more of a range from one point to another.

And of course, Point should be Position as it is in JavaParser :-)

The operation lambda for Node.transform can process same node more than once

Please consider this test from the Minicalc project:

    @test
    fun transformVarName() {
        val startTree = MiniCalcFile(listOf(
            VarDeclaration("A", IntLit("10")),
            Assignment(ReferenceByName("A"), IntLit("11")),
            Print(ValueReference(ReferenceByName("A")))))

        val expectedTransformedTree = MiniCalcFile(listOf(
            VarDeclaration("B", IntLit("10")),
            Assignment(ReferenceByName("B"), IntLit("11")),
            Print(ValueReference(ReferenceByName("B")))))

        assertEquals(expectedTransformedTree, startTree.transform {
            println("Hashcode: ${it.hashCode()}")
            when (it) {
                is VarDeclaration -> VarDeclaration("B", it.value)
                is ValueReference -> ValueReference(ReferenceByName("B"))
                is Assignment -> Assignment(ReferenceByName("B"), it.value)
                else -> it
            }
        })
    }

Note the println("Hashcode: ${it.hashCode()}") line that I added.

This is what's being printed if we run this test with the original implementation of the Node.transform function:

  • Hashcode: 1422860865
  • Hashcode: 1568352
  • Hashcode: 48577
  • Hashcode: 48577
  • Hashcode: 1568352
  • Hashcode: 2006568
  • Hashcode: 48608
  • Hashcode: 48608
  • Hashcode: 2006568
  • Hashcode: 499720
  • Hashcode: 16120
  • Hashcode: 16120
  • Hashcode: 507408
  • Hashcode: 1459116512

As you can see, some of the nodes are processed twice.

Now please see what's printed in the case I comment out the operation(this) at https://github.com/Strumenta/kolasu/blob/master/core/src/main/kotlin/com/strumenta/kolasu/model/Processing.kt#L318:

  • Hashcode: 48577
  • Hashcode: 1568352
  • Hashcode: 48608
  • Hashcode: 2006568
  • Hashcode: 16120
  • Hashcode: 507408
  • Hashcode: 1459116512

We don't see duplicates anymore, however, the test passes in either case.

P.S. I first noticed this behavior in the 0.1.1 version. I tried to use the newest version but it seemed to behave similarly.

CLI support

Provide optional tools to build a command-line interface for your parser.

Marker for synthetic/generated nodes

Some nodes are calculated, for example the CharacterType node in the RPG parser. We could mark them appropriately to indicate they have a reason for not having a position

Printing AST: shorter format for empty arrays

See for examples:

CompilationUnit {
  _allDataDefinitions = [
  ]
  allDataDefinitions = [
    DataDefinition {
      fields = [
      ]
      initializationValue = null
      name = Msg§
      type = StringType(length=12)
      muteAnnotations = [
      ]
      parseTreeNode = null
    } // DataDefinition
  ]
  compileTimeArrays = [
  ]
  dataDefinitions = [
    DataDefinition {
      fields = [
      ]
      initializationValue = null
      name = Msg§
      type = StringType(length=12)
      muteAnnotations = [
      ]
      parseTreeNode = null
    } // DataDefinition
  ]
  databaseInterface = com.smeup.rpgparser.interpreter.DummyDBInterface@6ad43d70
  directives = [
  ]
  entryPlist = null
  fileDefinitions = [
  ]
  inStatementsDataDefinitions = []
  main = [
    MainBody {
      stmts = [
        EvalStmt {
          expression = [
            StringLiteral {
              value = Hello World!
              parseTreeNode = null
            } // StringLiteral
          ]
          flags = EvalFlags(halfAdjust=false, maximumNumberOfDigitsRule=false, resultDecimalPositionRule=false)
          operator = NORMAL_ASSIGNMENT
          target = [
            DataRefExpr {
              variable = Ref(Msg§)[Unsolved]
              parseTreeNode = null
            } // DataRefExpr
          ]
          muteAnnotations = [
          ]
          parseTreeNode = null
        } // EvalStmt
        DisplayStmt {
          factor1 = null
          response = [
            DataRefExpr {
              variable = Ref(Msg§)[Unsolved]
              parseTreeNode = null
            } // DataRefExpr
          ]
          muteAnnotations = [
          ]
          parseTreeNode = null
        } // DisplayStmt
        SetOnStmt {
          muteAnnotations = [
          ]
          parseTreeNode = null
        } // SetOnStmt
      ]
      parseTreeNode = null
    } // MainBody
  ]
  minTimeOut = null
  subroutines = [
  ]
  timeouts = [
  ]
  parseTreeNode = null
} // CompilationUnit

Create transformDescendants(InPlace)

Since transformChildren only transforms the direct children in the node, there is not really a full-tree transformation function. That should be easy to make.

mapTree and transformTree don't recurse

It seems like these two only look at their direct children and don't recurse deeper. I assume that's a bug? Or maybe you need to do the recursion in the "operation" you pass?

Add operator Point + String

    operator fun plus(text: String) : Point {
        return when {
            text.isEmpty() -> this
            text.startsWith("\r\n") -> Point(line + 1, 0) + text.substring(2)
            text.startsWith("\n") || text.startsWith("\r") -> Point(line + 1, 0) + text.substring(1)
            else -> Point(line, charPositionInLine + 1) + text.substring(1)
        }
    }

Documentation

Improve documentation, ensure every class/method has KDoc comments attached.

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.