Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bump version 1.5.0 -> 1.6.0: refactor syntax: default record from #15

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class CsvProcessorTest {
}
process main {
params {
row from source
row = default_record from source
}
products {
1 kWh electricity
Expand Down Expand Up @@ -95,7 +95,7 @@ class CsvProcessorTest {
}
process main {
params {
row from source
row = default_record from source
}
products {
1 kWh electricity
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ javaVersion=17
gradleVersion=7.6
org.gradle.jvmargs=-Xmx4096m
lcaacGroup=ch.kleis.lcaac
lcaacVersion=1.5.0
lcaacVersion=1.6.0
3 changes: 2 additions & 1 deletion grammar/src/main/antlr/LcaLang.g4
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ variables

assignment
: dataRef sep=EQUAL dataExpression
| dataRef sep=FROM_KEYWORD dataSourceRef
;

/*
Expand Down Expand Up @@ -239,6 +238,7 @@ dataExpression
| stringExpression # baseGroup
| dataRef slice? # baseGroup
| op=LOOKUP dataSourceExpression # recordGroup
| op=DEFAULT_RECORD FROM_KEYWORD dataSourceExpression # recordGroup
| op=SUM LPAREN dataSourceExpression COMMA columnRef (STAR columnRef)* RPAREN # colGroup
;
slice
Expand Down Expand Up @@ -376,6 +376,7 @@ FOR_EACH_KEYWORD : 'for_each' ;

SUM : 'sum' ;
LOOKUP : 'lookup' ;
DEFAULT_RECORD : 'default_record' ;


EQUAL : '=' ;
Expand Down
8 changes: 5 additions & 3 deletions grammar/src/main/kotlin/ch/kleis/lcaac/grammar/CoreMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ class CoreMapper<Q>(
fun assignment(ctx: LcaLangParser.AssignmentContext): Pair<String, DataExpression<Q>> {
return when (ctx.sep.text) {
ctx.EQUAL()?.innerText() -> ctx.dataRef().innerText() to dataExpression(ctx.dataExpression())
ctx.FROM_KEYWORD()?.innerText() -> ctx.dataRef().innerText() to EDefaultRecordOf(EDataSourceRef(ctx.dataSourceRef().innerText()))

else -> throw IllegalStateException("parsing error: invalid assignment '${ctx.text}'")
}
}
Expand Down Expand Up @@ -231,10 +229,14 @@ class CoreMapper<Q>(
return when (ctx) {
is LcaLangParser.RecordGroupContext -> {
when (ctx.op.text) {
ctx.LOOKUP().innerText() -> {
ctx.LOOKUP()?.innerText() -> {
val dataSource = dataSource(ctx.dataSourceExpression())
EFirstRecordOf(dataSource)
}
ctx.DEFAULT_RECORD()?.innerText() -> {
val dataSource = dataSource(ctx.dataSourceExpression())
EDefaultRecordOf(dataSource)
}
else -> throw IllegalStateException("parsing error: invalid primitive '${ctx.op.text}'")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class CoreMapperTest {
fun assignment_defaultRecordOf() {
// given
val ctx = LcaLangFixture.parser("""
x from inventory
x = default_record from inventory
""".trimIndent()).assignment()
val mapper = CoreMapper(ops)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class EvaluatorTest {

process p {
params {
row from source
row = default_record from source
}
products {
1 kg carrot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LoaderTest {

process p {
params {
row from source
row = default_record from source
}
}
""".trimIndent()).lcaFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ process server {
// You can define a parameter as a row from inventory.
// The default value for this parameter is given by the schema.
params {
row from inventory
row = default_record from inventory
}
products {
1 p server
Expand Down
2 changes: 1 addition & 1 deletion tutorials/03-advanced/01-relational-modeling/01-main.lca
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ process datacenter {

process datacenter_component {
params {
dc_component from datacenter_components
dc_component = default_record from datacenter_components
}
products {
1 p component
Expand Down
Loading