Skip to content

Commit

Permalink
Encourage better statement error locations by adding cuts in grammar
Browse files Browse the repository at this point in the history
Signed-off-by: reidspencer <reid.spencer@yoppworks.com>
  • Loading branch information
reid-spencer committed Sep 14, 2023
1 parent 44da59b commit ce687ed
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,40 @@ private[parsing] trait StatementParser {

private def errorStatement[u: P]: P[ErrorStatement] = {
P(
location ~ Keywords.error ~ literalString
location ~ Keywords.error ~/ literalString
)./.map { tpl => (ErrorStatement.apply _).tupled(tpl) }
}

private def setStatement[u: P]: P[SetStatement] = {
P(
location ~ Keywords.set ~ fieldRef ~ Readability.to ~ literalString
location ~ Keywords.set ~/ fieldRef ~/ Readability.to ~ literalString
)./.map { tpl => (SetStatement.apply _).tupled(tpl) }
}

private def sendStatement[u: P]: P[SendStatement] = {
P(
location ~ Keywords.send ~/ messageRef ~
location ~ Keywords.send ~/ messageRef ~/
Readability.to ~ (outletRef | inletRef)
)./.map { t => (SendStatement.apply _).tupled(t) }
}

private def tellStatement[u: P]: P[TellStatement] = {
P(
location ~ Keywords.tell ~/ messageRef ~ Readability.to ~ processorRef
location ~ Keywords.tell ~/ messageRef ~/ Readability.to ~ processorRef
)./.map { t => (TellStatement.apply _).tupled(t) }
}

private def forEachStatement[u: P](set: StatementsSet): P[ForEachStatement] = {
P(
location ~ Keywords.foreach ~ pathIdentifier ~ Keywords.do_ ~ pseudoCodeBlock(set) ~ Keywords.end_
location ~ Keywords.foreach ~/ pathIdentifier ~ Keywords.do_ ~/ pseudoCodeBlock(set) ~ Keywords.end_
)./.map { case (loc, pid, statements) =>
ForEachStatement(loc, pid, statements)
}
}

private def ifThenElseStatement[u: P](set: StatementsSet): P[IfThenElseStatement] = {
P(
location ~ Keywords.if_ ~ literalString ~ Keywords.then_ ~ pseudoCodeBlock(set) ~ (
location ~ Keywords.if_ ~/ literalString ~ Keywords.then_ ~/ pseudoCodeBlock(set) ~ (
Keywords.else_ ~ pseudoCodeBlock(set)
).?
)./.map { case (loc, cond, thens, maybeElses) =>
Expand All @@ -66,7 +66,7 @@ private[parsing] trait StatementParser {
}

private def callStatement[u: P]: P[CallStatement] = {
P(location ~ Keywords.call ~ functionRef)./.map { tpl => (CallStatement.apply _).tupled(tpl) }
P(location ~ Keywords.call ~/ functionRef)./.map { tpl => (CallStatement.apply _).tupled(tpl) }
}

private def anyDefStatements[u: P](set: StatementsSet): P[Statement] = {
Expand Down Expand Up @@ -117,8 +117,9 @@ private[parsing] trait StatementParser {
case StatementsSet.AdaptorStatements => anyDefStatements(set) | replyStatement
case StatementsSet.ApplicationStatements => anyDefStatements(set) | replyStatement
case StatementsSet.ContextStatements => anyDefStatements(set) | replyStatement
case StatementsSet.EntityStatements => anyDefStatements(set) | morphStatement | becomeStatement | replyStatement
case StatementsSet.FunctionStatements => anyDefStatements(set) | returnStatement
case StatementsSet.EntityStatements =>
anyDefStatements(set) | morphStatement | becomeStatement | replyStatement
case StatementsSet.FunctionStatements => anyDefStatements(set) | returnStatement
case StatementsSet.ProjectorStatements => anyDefStatements(set) | replyStatement
case StatementsSet.RepositoryStatements => anyDefStatements(set) | replyStatement
case StatementsSet.SagaStatements => anyDefStatements(set) | returnStatement
Expand Down

0 comments on commit ce687ed

Please sign in to comment.