strumenta / kolasu Goto Github PK
View Code? Open in Web Editor NEWKotlin Language Support – AST Library
License: Apache License 2.0
Kotlin Language Support – AST Library
License: Apache License 2.0
There's a TODO there.
This method should navigate the tree considering the position and the fact that a child should be contained in the parent also w.r.t. positions
Also see #10
Kolasu assumes lists and other collections are never null when mapping to EMF. However, nothing prevents the AST from containing null collections.
Is the error lexical, syntactic or semantic?
Otherwise we risk having the root without a position, which causes problems
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.
Lately I've been using assertj a lot, and I must say that once you get over the "this is slightly longer syntax" phase, it offers a lot more ways to check stuff.
fun ParserRuleContext.toPosition(considerPosition: Boolean = true)
There's a TODO there.
We could pass an object of type "IgnoreChildren" and the comparison could take that in account
There's a TODO there.
So that it can be used more easily
I see LinkedList and HashMap and such. Why not use the Kotlin collections?
Navigation, Processing, and Traversing do more or less the same. Should we put some stuff together?
"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 :-)
It is useful for documentation, debugging, and presentations
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:
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:
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.
Provide optional tools to build a command-line interface for your parser.
To do that we need to ask the authorization to Sonatype
This is useful to handle inclusions or transformations with nodes coming from multiple files
Issues could be errors, warnings, notes, ...
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
For backward compatibility, the default is to include the Kolasu metamodel. However, when exporting to Parser Bench or other software that is already aware of Kolasu, it doesn't make sense to include it.
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
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.
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?
Also, adapt references to support this
@JvmOverloads
, remapping of useful constants, extension methods, etc.
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)
}
}
Improve documentation, ensure every class/method has KDoc comments attached.
There's a TODO there.
When loading the project all fresh, intellij does not set the source path to the generated test parser. It is in a rather peculiar location if you ask me...
I guess these will be useful eventually.
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.