git @ Cat's Eye Technologies Tamsin / master lib / tamsin_scanner.tamsin
master

Tree @master (Download .tar.gz)

tamsin_scanner.tamsin @masterraw · history · blame

# Scanner for Tamsin tokens, written in Tamsin.
# Distributed under a BSD-style license; see LICENSE.

tamsin_scanner {
  scanner = scan using $:utf8.
  scan = skippable &
         (symbol | str('\'', '\'') | str('"', '"') | str('“', '”') | word).
  symbol = "&" & "&" & '&&'
         | "|" & "|" & '||'
         | "-" & ">" & '->'
         | "<" & "-" & '<-'
         | "<" & "<" & '<<'
         | ">" & ">" & '>>'
         | "=" | "(" | ")" | "[" | "]" | "{" | "}" | "!" | "|" | "&" | ":"
         | "/" | "," | "." | "@" | "+" | "$" | "→" | "←" | "«" | "»".
  str(O, C) = «O»  T & {("\\" & escape | !«C» & any)  S & T  T + S} & «C» &
           return T + C.
  escape = "n" & '\n'
         | "r" & '\r'
         | "t" & '\t'
         | "x" & hexdigit  H & hexdigit  L & $:hexbyte(H, L)
         | "\\" & '\\'
         | "'" & '\''
         | "\"" & '"'.
  hexdigit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" |
             "a" | "b" | "c" | "d" | "e" | "f".
  word = $:alnum  T & { ($:alnum | "_")  S & T  T + S } & T.
  skippable = {whitespace | comment}.
  whitespace = " " | "\t" | "\r" | "\n".
  comment = "#" & {!"\n" & any} & ("\n" | eof).
}