use .evaluated instead of .value for InputTasks

This commit is contained in:
Mark Harrah 2013-03-08 14:23:31 -05:00
parent 114cf2dbd8
commit 5b80e8c941
3 changed files with 15 additions and 11 deletions

View File

@ -50,7 +50,7 @@ object Def extends Init[Scope] with TaskMacroExtra
import language.experimental.macros
import std.TaskMacro.{inputTaskMacroImpl, inputTaskDynMacroImpl, taskDynMacroImpl, taskMacroImpl}
import std.SettingMacro.{settingDynMacroImpl,settingMacroImpl}
import std.{MacroValue, ParserInput}
import std.{InputEvaluated, MacroValue, ParserInput}
def task[T](t: T): Def.Initialize[Task[T]] = macro taskMacroImpl[T]
def taskDyn[T](t: Def.Initialize[Task[T]]): Def.Initialize[Task[T]] = macro taskDynMacroImpl[T]
@ -64,7 +64,7 @@ object Def extends Init[Scope] with TaskMacroExtra
implicit def macroValueI[T](in: Initialize[T]): MacroValue[T] = ???
implicit def macroValueIT[T](in: Initialize[Task[T]]): MacroValue[T] = ???
implicit def macroValueIInT[T](in: Initialize[InputTask[T]]): MacroValue[T] = ???
implicit def macroValueIInT[T](in: Initialize[InputTask[T]]): InputEvaluated[T] = ???
// The following conversions enable the types Parser[T], Initialize[Parser[T]], and Initialize[State => Parser[T]] to
// be used in the inputTask macro as an input with an ultimate result of type T
@ -80,7 +80,7 @@ object Def extends Init[Scope] with TaskMacroExtra
trait TaskMacroExtra
{
implicit def macroValueT[T](in: Task[T]): std.MacroValue[T] = ???
implicit def macroValueIn[T](in: InputTask[T]): std.MacroValue[T] = ???
implicit def macroValueIn[T](in: InputTask[T]): std.InputEvaluated[T] = ???
implicit def parserToInput[T](in: Parser[T]): std.ParserInput[T] = ???
implicit def stateParserToInput[T](in: State => Parser[T]): std.ParserInput[T] = ???
}

View File

@ -98,6 +98,10 @@ sealed abstract class ParserInput[T] {
@compileTimeOnly("`parsed` can only be used within an input task macro, such as := or Def.inputTask.")
def parsed: T = macro ParserInput.parsedMacroImpl[T]
}
sealed abstract class InputEvaluated[T] {
@compileTimeOnly("`evaluated` can only be used within an input task macro, such as := or Def.inputTask.")
def evaluated: T = macro InputWrapper.valueMacroImpl[T]
}
sealed abstract class ParserInputTask[T] {
@compileTimeOnly("`parsed` can only be used within an input task macro, such as := or Def.inputTask.")
def parsed: Task[T] = macro ParserInput.parsedInputMacroImpl[T]

View File

@ -151,13 +151,13 @@ Using other input tasks
=======================
The types involved in an input task are composable, so it is possible to reuse input tasks.
The ``.parsed`` and ``.value`` methods are defined on InputTasks to make this more convenient in common situations:
The ``.parsed`` and ``.`` methods are defined on InputTasks to make this more convenient in common situations:
* Call ``.parsed`` on an ``InputTask[T]`` or ``Initialize[InputTask[T]]`` to get the ``Task[T]`` created by that input task
* Call ``.value`` on an ``InputTask[T]`` or ``Initialize[InputTask[T]]`` to get the final value of type ``T`` for that input task
* Call ``.parsed`` on an ``InputTask[T]`` or ``Initialize[InputTask[T]]`` to get the ``Task[T]`` created after parsing the command line
* Call ``.evaluated`` on an ``InputTask[T]`` or ``Initialize[InputTask[T]]`` to get the value of type ``T`` from evaluating that task
In both situations, the underlying ``Parser`` is sequenced with other parsers in the input task definition.
In the case of ``.value``, the generated task is evaluated.
In the case of ``.evaluated``, the generated task is evaluated.
The following example applies the ``run`` input task, a literal separator parser ``--``, and ``run`` again.
The parsers are sequenced in order of syntactic appearance,
@ -171,9 +171,9 @@ so that the arguments before ``--`` are passed to the first ``run`` and the ones
val separator: Parser[String] = "--"
run2 := {
val one = (run in Compile).value
val one = (run in Compile).evaluated
val sep = separator.parsed
val two = (run in Compile).value
val two = (run in Compile).evaluated
}
For a main class Demo that echoes its arguments, this looks like:
@ -226,8 +226,8 @@ NOTE: the current implementation of ``:=`` doesn't actually support applying inp
val separator: Parser[String] = "--"
run2 := {
val one = (run in Compile).fullInput(firstInput.value).value
val two = (run in Compile).partialInput(secondInput).value
val one = (run in Compile).fullInput(firstInput.value).evaluated
val two = (run in Compile).partialInput(secondInput).evaluated
}
For a main class Demo that echoes its arguments, this looks like: