# Copyright 2005-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ --- SourceSpan ? def makeSourceSpan := # value: ? def span := makeSourceSpan("http://example.org/t", true, 1, 0, 1, 9) # value: ? span :PassByCopy # value: ? span :(makeSourceSpan.asType()) # value: ? 1 :(makeSourceSpan.asType()) # problem: the int 1 doesn't coerce to a SourceSpan ? span.__optUncall() # value: [, "run", ["http://example.org/t", true, 1, 0, 1, 9]] ? span.getUri() # value: "http://example.org/t" ? span.isOneToOne() # value: true ? span.getStartCol() # value: 0 ? span.getEndCol() # value: 9 ? span.getStartLine() # value: 1 ? span.getEndLine() # value: 1 ? {[def x := span.notOneToOne(), x.__optUncall()]} # value: [, [, "run", ["http://example.org/t", false, 1, 0, 1, 9]]] ? makeSourceSpan("a", true, 1, 0, 2, 7) # problem: one-to-one span must be on a single line --- Twine construction Twine that is a String ? __makeTwine # value: ? def twine := __makeTwine.fromValuesOf('a'..'z') # value: "abcdefghijklmnopqrstuvwxyz" ? twine.isBare() # value: true Other fromValuesOf ? __makeTwine.fromValuesOf("abc") # value: "abc" ? __makeTwine.fromValuesOf(['a', 'b', 'c']) # value: "abc" ? def f > def twine := __makeTwine.fromValuesOf(def _ { to iterate(bind f) {} }) # value: "" ? f(0, '1') # problem: vector accumulation iterator called too late ? twine # value: "" Error cases ? __makeTwine.fromString("", span) # problem: an empty twine may not have a source span Complex Twine ? def twine := __makeTwine.fromString("aardvark", span) # problem: the source span, , must match the size of the string, 8, or be not one-to-one ? def twine := __makeTwine.fromString("/aardvark/", span) # value: "/aardvark/" ? twine :String # value: "/aardvark/" ? twine.isBare() # value: false ? twine.getOptSpan() # value: ? twine.getParts() == [twine] # value: true Non-homogenous composite twine ? def span2 := makeSourceSpan("http://example.org/u", true, 1, 0, 1, 9) # value: ? def twine2 := __makeTwine.fromString("!aardvark!", span2) # value: "!aardvark!" ? def multiTwine := twine + twine2 # value: "/aardvark/!aardvark!" ? [multiTwine.getOptSpan()] # value: [null] ? multiTwine.isBare() # value: false ? multiTwine.__optUncall() # value: [, "fromParts", [["/aardvark/", "!aardvark!"]]] ? multiTwine.getParts() # value: ["/aardvark/", "!aardvark!"] Matching composite twine ? (twine + __makeTwine.fromString("$aardvark$", makeSourceSpan("http://example.org/t", true, 1, 10, 1, 19))).getOptSpan() # value: --- asFrom Tests derived from some poking at the E-on-Java repl ? "abc\ndef".asFrom("foo:bar").getOptSpan() # value: ? "abcdef".asFrom("foo:bar").getOptSpan() # value: ? "abcdef\n".asFrom("foo:bar").getOptSpan() # value: ? "abcdef\nghijkl".asFrom("foo:bar").getOptSpan() # value: ? "abcdef\nghijkl".asFrom("foo:bar")(0, 6).getOptSpan() # value: ? ["".asFrom("foo:bar").getOptSpan()] # value: [null] ? "\n".asFrom("foo:bar").getOptSpan() # value: ? "\n\n".asFrom("foo:bar").getOptSpan() # value: ? "abcdef\n\n".asFrom("foo:bar").getOptSpan() # value: ? "abcdef\ng\n".asFrom("foo:bar").getOptSpan() # value: ? "abcdef\ng".asFrom("foo:bar").getOptSpan() # value: --- run ? "abc\ndef\n\nghij\n\n".asFrom("foo:bar").run(0, 3).getOptSpan() # value: --- split ? "abc\ndef".asFrom("foo:bar").split("\n")[0].getOptSpan() # value: ? for x in "abc\ndef\n\nghij\n\n".asFrom("foo:bar").split("\n") { println(x.getOptSpan()) } # stdout: # # null # # null # null #