Skip to content
Chris Lowth edited this page Sep 21, 2022 · 3 revisions

The Otto Interpreter

TbScript (and TbUtil) are based on the open-source "Otto" interpreter - a JavaScript parser and interpreter written natively in Go.

Otto source and documentation can be found at..

Our implementation..

Caveat Emptor (from the OTTO web site)..

The following are some limitations with otto:

  • "use strict" will parse, but does nothing.
  • The regular expression engine (re2/regexp) is not fully compatible with the ECMA5 specification.
  • Otto targets ES5. ES6 features (eg: Typed Arrays) are not supported.

Regular Expression Incompatibility (from the OTTO web site)..

Go translates JavaScript-style regular expressions into something that is "regexp" compatible via parser.TransformRegExp. Unfortunately, RegExp requires backtracking for some patterns, and backtracking is not supported by the standard Go engine: https://code.google.com/p/re2/wiki/Syntax

Therefore, the following syntax is incompatible:

  • (?=) // Lookahead (positive), currently a parsing error
  • (?!) // Lookahead (backhead), currently a parsing error
  • \1 // Backreference (\1, \2, \3, ...), currently a parsing error

A brief discussion of these limitations: "Regexp (?!re)" https://groups.google.com/forum/?fromgroups=#%21topic/golang-nuts/7qgSDWPIh_E

More information about re2: https://code.google.com/p/re2/

In addition to the above, re2 (Go) has a different definition for \s: [\t\n\f\r ]. The JavaScript definition, on the other hand, also includes \v, Unicode "Separator, Space", etc.

Clone this wiki locally