# Copyright 2005-2007 Kevin Reid, under the terms of the MIT X license # found at http://www.opensource.org/licenses/mit-license.html ................ # NOTE: The TermLexer in E-on-Java is under Mozilla license. This file has been written purely by examining the interface as used in other files, and examples of the Term language. pragma.syntax("0.9") def InStream :DeepFrozen := def makeTermLexer implements DeepFrozen, ExitViaHere { # from Term.y # = new TermLexer(lineFeeder, # input # false, # what? # builder.doesQuasis(), # false, # what? # builder); # why? to run(quasi :boolean) { def termLexer implements DeepFrozen { to run(textIn :InStream) { # kpreid's Standard Cheap Ugly Lexer Style var text := EIO.takeAll(textIn) #traceln(`text: $text`) def tokens := [].diverge() while (!(text <=> "")) { #traceln(`looping; text: $text`) switch (text) { match rx`\s+(@r.*)` { text := r } match rx`(@t[][\(\){}:,*+?])(@r.*)` { text := r tokens.push([t]) } match rx`(@n-?[0-9]+)(@r.*)` { text := r tokens.push(["Integer", __makeInt(n)]) } match rx`"(@strbody(?:\\.|[^"])*)"(@r.*)` { text := r tokens.push(["String", e__quasiParser(`"$strbody"`).getValue()]) # XXX horrible but correct kludge to get escape parsing. } match rx`(@t[$$@@])\{(@n[0-9]+)\}(@r.*)` { text := r tokens.push(["Quasi" + t, __makeInt(n)]) } match rx`(@t.?[a-zA-Z_$$][a-zA-Z_$$0-9.-]*)(@r.*)` { # XXX Unicode character categories #traceln(`pushing tag token into $tokens | $t:$r`) text := r tokens.push(["Tag", [["Ident", t]]]) } match _ { return Ref.broken(`unexpected term token: $text`) } } } #traceln(E.toQuote(tokens)) #traceln(E.toQuote(tokens.snapshot())) #traceln(E.toQuote(tokens.snapshot().asStream())) return tokens.snapshot().asStream() } } return termLexer } }