Module lang

This module provides language services like tokenizing JavaScript code or converting JavaScript objects to and from JSON.
To customize JSON serialization of Objects just overwrite the toJSON method in your class.

public members:

JSONParser()

A class for parsing JSON.
  • JSONParser::addLib(obj,name,exports)
    Adds a lib object for converting application specific JSON-Objects.
    This is an extension to the default JSON behavior to allow class hinitng.
  • JSONParser::jsonToObj(data)
    Turns JSON code into JavaScript objects.
    data is a String containing the JSON code.
  • JSONParser::objToJson(obj)
    Turns an object into JSON.
    This is the same as calling obj.toJSON();

parser

A JSONParser object used for jsonToObj and objToJson.

jsonToObj(src)

Turns JSON code into JavaScript objects.
src is a String containing the JSON code.

objToJson(obj)

Turns an object into JSON.
This is the same as calling obj.toJSON();

tokens

Token type constants for the tokenizer.
  • tokens.WSP WhiteSpace
  • tokens.OP Operator
  • tokens.STR String
  • tokens.NAME Name
  • tokens.NUM Number
  • tokens.ERR Error
  • tokens.NL NewLine
  • tokens.COMMENT Comment
  • tokens.DOCCOMMENT Documentation comment
  • tokens.REGEXP Regular Expression

Tokenizer(source)

Tokenizer Class which incrementally parses JavaScript code(source) and returns the language tokens.
  • Tokenizer::next()
    Returns the next Token object.
  • Tokenizer::nextNonWS(nlIsWS)
    Returns the next non whitespace token.
    If nlIsWS is true then a NewLine token is interpreted as whitespace.
  • Tokenizer::finished()
    Returns true if the Tokenizer has finished the parsing.

Token(type, value, pos, err)

Token class for token objects returned by the Tokenizer.
  • Token::typeThe type of the token(see the tokens constants).
  • Token::valueA String containing the token value.
  • Token::posThe starting position of the token in the source .
  • Token::errThe error object for Error tokens.