Skip to content

Commit

Permalink
Merge pull request #27 from dhakehurst/performance
Browse files Browse the repository at this point in the history
Performance
  • Loading branch information
dhakehurst authored Aug 11, 2021
2 parents d018978 + 4d65d22 commit 87a569f
Show file tree
Hide file tree
Showing 326 changed files with 1,396 additions and 1,652 deletions.
3 changes: 1 addition & 2 deletions examples/js/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"dependencies": {
"kotlin": "1.3.71",
"net.akehurst.language-agl-processor": "file:../../../net.akehurst.language/.gradle-build/agl-processor/libs/agl-processor-js-3.5.0"
"net.akehurst.language-agl-processor": "file:../../../net.akehurst.language/.gradle-build/agl-processor/productionLibrary"
}
}
33 changes: 29 additions & 4 deletions examples/js/node/src/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const agl_module = require('net.akehurst.language-agl-processor');
const Agl = agl_module.net.akehurst.language.agl.processor.Agl;

const AsmElementSimple = agl_module.net.akehurst.language.api.syntaxAnalyser.AsmElementSimple;

const grammarStr = `
namespace test
Expand Down Expand Up @@ -41,7 +41,32 @@ class class {
}
`;
const sppt = proc.parse(sentence);
console.info(sppt);
console.info(sppt.toStringAllWithIndent(' '));

const asm = proc.process(null, sentence);

function asmToString(indent, asm) {
const newIndent = ' '+indent;
if (typeof(asm)==='string') {
return asm;
} else if (asm instanceof AsmElementSimple) {
var str = ':'+asm.typeName + ' {\n';
const props = asm.properties.toArray();
for (const p of props) {
str += indent + p.name+' = '+asmToString(newIndent, p.value) +'\n';
}
str += indent+'}';
return str;
} else { // assume a List
var str = '[\n';
const arr = asm.toArray();
for (const el of arr) {
str += indent + asmToString(newIndent, el) + '\n';
}
str += indent+']';
return str;
}
}


const asm = proc.process(sentence).toArray();
console.info(asm);
console.info(asmToString('',asm));
2 changes: 1 addition & 1 deletion net.akehurst.language.comparisons/agl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("multiplatform") version ("1.4.32")
kotlin("multiplatform") version ("1.5.20")
}

val version_agl:String by project
Expand Down
2 changes: 1 addition & 1 deletion net.akehurst.language.comparisons/common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("multiplatform") version ("1.4.32")
kotlin("multiplatform") version ("1.5.20")
}

kotlin {
Expand Down
2 changes: 1 addition & 1 deletion net.akehurst.language.comparisons/iguana/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
kotlin("multiplatform") version ("1.4.32")
kotlin("multiplatform") version ("1.5.20")
}

val version_agl:String by project
Expand Down
12 changes: 9 additions & 3 deletions net.akehurst.language/agl-processor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
//id("net.akehurst.kotlin.kt2ts") version "1.7.0"
//jacoco
id("net.akehurst.kotlin.gradle.plugin.exportPublic") version("1.2.0")
}

kotlin {
Expand All @@ -19,8 +19,15 @@ kotlin {
}
}
}

/*
tasks.named<Copy>("jsProductionLibraryCompileSync") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
tasks.named<Copy>("jsDevelopmentLibraryCompileSync") {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}
kt2ts {
jvmTargetName.set("jvm8")
jsTargetName.set("js")
Expand All @@ -36,7 +43,6 @@ kt2ts {
))
}
*/

/*
jacoco {
toolVersion = "0.8.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,9 @@
package net.akehurst.language.agl.ast


import net.akehurst.language.api.grammar.Choice
import net.akehurst.language.api.grammar.Terminal
import net.akehurst.language.api.grammar.NonTerminal
import net.akehurst.language.api.grammar.Rule
import net.akehurst.language.api.grammar.RuleItem
import net.akehurst.language.api.grammar.Concatenation

abstract class ChoiceAbstract(override val alternative: List<Concatenation>) : RuleItemAbstract(), Choice {
import net.akehurst.language.api.grammar.*

internal abstract class ChoiceAbstract(override val alternative: List<Concatenation>) : RuleItemAbstract(), Choice {

override fun setOwningRule(rule: Rule, indices: List<Int>) {
this._owningRule = rule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ package net.akehurst.language.agl.ast

import net.akehurst.language.api.grammar.ChoiceAmbiguous
import net.akehurst.language.api.grammar.Concatenation
import net.akehurst.language.api.grammar.GrammarVisitor

class ChoiceAmbiguousDefault(override val alternative: List<Concatenation>) : ChoiceAbstract(alternative), ChoiceAmbiguous {

// --- GrammarVisitable ---

override fun <T,A> accept(visitor: GrammarVisitor<T, A>, arg: A): T {
return visitor.visit(this, arg);
}
internal class ChoiceAmbiguousDefault(override val alternative: List<Concatenation>) : ChoiceAbstract(alternative), ChoiceAmbiguous {

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ package net.akehurst.language.agl.ast

import net.akehurst.language.api.grammar.ChoiceEqual
import net.akehurst.language.api.grammar.Concatenation
import net.akehurst.language.api.grammar.GrammarVisitor

class ChoiceLongestDefault(override val alternative: List<Concatenation>) : ChoiceAbstract(alternative), ChoiceEqual {

// --- GrammarVisitable ---

override fun <T,A> accept(visitor: GrammarVisitor<T, A>, arg: A): T {
return visitor.visit(this, arg);
}
internal class ChoiceLongestDefault(override val alternative: List<Concatenation>) : ChoiceAbstract(alternative), ChoiceEqual {

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ package net.akehurst.language.agl.ast

import net.akehurst.language.api.grammar.ChoicePriority
import net.akehurst.language.api.grammar.Concatenation
import net.akehurst.language.api.grammar.GrammarVisitor

class ChoicePriorityDefault(override val alternative: List<Concatenation>) : ChoiceAbstract(alternative), ChoicePriority {
internal class ChoicePriorityDefault(override val alternative: List<Concatenation>) : ChoiceAbstract(alternative), ChoicePriority {

// --- GrammarVisitable ---

override fun <T,A> accept(visitor: GrammarVisitor<T, A>, arg: A): T {
return visitor.visit(this, arg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,9 @@

package net.akehurst.language.agl.ast

import net.akehurst.language.api.grammar.Concatenation;
import net.akehurst.language.api.grammar.ConcatenationItem;
import net.akehurst.language.api.grammar.NonTerminal;
import net.akehurst.language.api.grammar.RuleItem;
import net.akehurst.language.api.grammar.Terminal;
import net.akehurst.language.api.grammar.Rule;
import net.akehurst.language.api.grammar.GrammarVisitor;
import net.akehurst.language.api.grammar.*

class ConcatenationDefault(override val items: List<ConcatenationItem>) : RuleItemAbstract(), Concatenation {
internal class ConcatenationDefault(override val items: List<ConcatenationItem>) : RuleItemAbstract(), Concatenation {

override fun setOwningRule(rule: Rule, indices: List<Int>) {
this._owningRule = rule
Expand All @@ -48,10 +42,4 @@ class ConcatenationDefault(override val items: List<ConcatenationItem>) : RuleIt
this.items.flatMap { it.allNonTerminal }.toSet()
}

// --- GrammarVisitable ---

override fun <T,A> accept(visitor: GrammarVisitor<T, A>, arg: A): T {
return visitor.visit(this, arg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package net.akehurst.language.agl.ast;

import net.akehurst.language.api.grammar.ConcatenationItem;

abstract class ConcatenationItemAbstract : RuleItemAbstract(), ConcatenationItem {
internal abstract class ConcatenationItemAbstract : RuleItemAbstract(), ConcatenationItem {


}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package net.akehurst.language.agl.ast;

import net.akehurst.language.api.grammar.*

class EmptyRuleDefault : RuleItemAbstract(), EmptyRule {
internal class EmptyRuleDefault : RuleItemAbstract(), EmptyRule {

override val name : String by lazy {
"<empty>"
Expand All @@ -40,9 +40,4 @@ class EmptyRuleDefault : RuleItemAbstract(), EmptyRule {
throw GrammarRuleItemNotFoundException("subitem ${index} not found")
}

// --- GrammarVisitable ---

override fun <T,A> accept(visitor: GrammarVisitor<T, A>, arg: A): T {
return visitor.visit(this, arg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package net.akehurst.language.agl.ast
import net.akehurst.language.api.grammar.*
import net.akehurst.language.collections.lazyMapNonNull

class GrammarBuilderDefault(val namespace: Namespace, val name: String) {
internal class GrammarBuilderDefault(val namespace: Namespace, val name: String) {

private val _literals = lazyMapNonNull<String, Terminal>() {
TerminalDefault(it, false)
Expand Down Expand Up @@ -74,12 +74,12 @@ class GrammarBuilderDefault(val namespace: Namespace, val name: String) {
this.rule.rhs = ChoiceLongestDefault(listOf(ConcatenationDefault(sequence.toList())));
}

fun choiceLongest(vararg alternative: Concatenation) {
fun choiceLongestFromConcatenation(vararg alternative: Concatenation) {
//val alternativeConcats = alternative.map { ChoiceLongestDefault(listOf(it)) }
this.rule.rhs = ChoiceLongestDefault(alternative.asList());
}

fun choiceLongest(vararg alternative: ConcatenationItem) {
fun choiceLongestFromConcatenationItem(vararg alternative: ConcatenationItem) {
val alternativeConcats = alternative.map { ConcatenationDefault(listOf(it)) }
this.rule.rhs = ChoiceLongestDefault(alternativeConcats);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,17 @@

package net.akehurst.language.agl.ast

import net.akehurst.language.api.grammar.Grammar
import net.akehurst.language.api.grammar.GrammarRuleNotFoundException
import net.akehurst.language.api.grammar.Namespace
import net.akehurst.language.api.grammar.NodeType
import net.akehurst.language.api.grammar.Rule
import net.akehurst.language.api.grammar.RuleItem
import net.akehurst.language.api.grammar.Terminal
import net.akehurst.language.api.grammar.*

class GrammarDefault(
internal class GrammarDefault(
override val namespace: Namespace,
override val name: String,
override val rule: MutableList<Rule>
) : GrammarAbstract(namespace, name, rule) {

}

abstract class GrammarAbstract(
internal abstract class GrammarAbstract(
override val namespace: Namespace,
override val name: String,
override val rule: List<Rule>
Expand Down Expand Up @@ -82,4 +76,5 @@ abstract class GrammarAbstract(
}
return all.first()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (C) 2021 Dr. David H. Akehurst (http://dr.david.h.akehurst.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.akehurst.language.agl.ast

import net.akehurst.language.api.grammar.*

internal abstract class GrammarVisitorAbstract<R, A> : GrammarVisitor<R, A> {

protected fun visitConcatenationItem(target: ConcatenationItem, arg: A): R = when (target) {
is Multi -> this.visitMulti(target, arg)
is SeparatedList -> this.visitSeparatedList(target, arg)
is SimpleItem -> this.visitSimpleItem(target, arg)
else -> error("${target::class} is not a supported subtype of ConcatenationItem")
}

protected fun visitChoice(target: Choice, arg: A): R = when (target) {
is ChoiceEqual -> this.visitChoiceEqual(target, arg)
is ChoicePriority -> this.visitChoicePriority(target, arg)
is ChoiceAmbiguous -> this.visitChoiceAmbiguous(target, arg)
else -> error("${target::class} is not a supported subtype of Choice")
}

protected fun visitSimpleItem(target: SimpleItem, arg: A): R = when (target) {
is Group -> this.visitGroup(target, arg)
is TangibleItem -> this.visitTangibleItem(target, arg)
else -> error("${target::class} is not a supported subtype of SimpleItem")
}

protected fun visitTangibleItem(target: TangibleItem, arg: A): R = when (target) {
is EmptyRule -> this.visitEmptyRule(target, arg)
is NonTerminal -> this.visitNonTerminal(target, arg)
is Terminal -> this.visitTerminal(target, arg)
else -> error("${target::class} is not a supported subtype of TangibleItem")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package net.akehurst.language.agl.ast

import net.akehurst.language.api.grammar.*

class GroupDefault(override val choice: Choice) : SimpleItemAbstract(), Group {
internal class GroupDefault(override val choice: Choice) : SimpleItemAbstract(), Group {

override val name: String = "${'$'}group"

Expand All @@ -40,11 +40,5 @@ class GroupDefault(override val choice: Choice) : SimpleItemAbstract(), Group {
override val allNonTerminal: Set<NonTerminal> by lazy {
this.choice.allNonTerminal
}

// --- GrammarVisitable ---

override fun <T,A> accept(visitor: GrammarVisitor<T, A>, arg: A): T {
return visitor.visit(this, arg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,9 @@

package net.akehurst.language.agl.ast

import net.akehurst.language.api.grammar.SimpleItem
import net.akehurst.language.api.grammar.Multi
import net.akehurst.language.api.grammar.Rule
import net.akehurst.language.api.grammar.RuleItem
import net.akehurst.language.api.grammar.Terminal
import net.akehurst.language.api.grammar.NonTerminal
import net.akehurst.language.api.grammar.GrammarVisitor
import net.akehurst.language.api.grammar.GrammarRuleItemNotFoundException
import net.akehurst.language.api.grammar.*

class MultiDefault(override val min: Int, override val max: Int, override val item: SimpleItem) : RuleItemAbstract(), Multi {
internal class MultiDefault(override val min: Int, override val max: Int, override val item: SimpleItem) : RuleItemAbstract(), Multi {

override fun setOwningRule(rule: Rule, indices: List<Int>) {
this._owningRule = rule
Expand All @@ -45,11 +38,5 @@ class MultiDefault(override val min: Int, override val max: Int, override val it
override val allNonTerminal: Set<NonTerminal> by lazy {
this.item.allNonTerminal
}

// --- GrammarVisitable ---

override fun <T,A> accept(visitor: GrammarVisitor<T, A>, arg: A): T {
return visitor.visit(this, arg);
}

}
Loading

0 comments on commit 87a569f

Please sign in to comment.