Yate
JsParser Class Reference

Javascript parser. More...

#include <yatescript.h>

Inheritance diagram for JsParser:
ScriptParser GenObject

Public Member Functions

 JsParser (bool allowLink=true, bool allowTrace=false)
 
virtual bool parse (const char *text, bool fragment=false, const char *file=0, int len=-1)
 
virtual ScriptContextcreateContext () const
 
virtual ScriptRuncreateRunner (ScriptCode *code, ScriptContext *context=0, const char *title=0) const
 
ScriptRuncreateRunner (ScriptContext *context=0, const char *title=0) const
 
virtual bool callable (const String &name)
 
void adjustPath (String &script, bool extraInc=false) const
 
const StringbasePath () const
 
const StringincludePath () const
 
void basePath (const char *path, const char *incPath=0)
 
const StringparsedFile () const
 
bool scriptChanged (const char *file) const
 
bool scriptChanged (const char *file, const String &path, const String &incPath=String::empty()) const
 
void link (bool allowed=true)
 
void trace (bool allowed=true)
 
- Public Member Functions inherited from ScriptParser
virtual ~ScriptParser ()
 
virtual bool parseFile (const char *name, bool fragment=false)
 
void clear ()
 
ScriptCodecode () const
 
void setMaxFileLen (unsigned int len)
 
unsigned int maxFileLen () const
 
ScriptRuncreateRunner (ScriptContext *context=0, const char *title=0) const
 
- Public Member Functions inherited from GenObject
 GenObject ()
 
virtual ~GenObject ()
 
virtual bool alive () const
 
virtual void destruct ()
 
virtual const StringtoString () const
 
virtual const StringtraceId () const
 
virtual void * getObject (const String &name) const
 
NamedCountergetObjCounter () const
 
NamedCountersetObjCounter (NamedCounter *counter)
 

Static Public Member Functions

static ScriptRun::Status eval (const String &text, ExpOperation **result=0, ScriptContext *context=0)
 
static ExpOperationparseJSON (const char *text, ScriptMutex *mtx=0, ObjList *stack=0, GenObject *context=0, const ExpOperation *op=0)
 
static ExpOperationnullClone (const char *name=0)
 
static JsObjectnullObject ()
 
static bool isNull (const ExpOperation &oper)
 
static bool isUndefined (const ExpOperation &oper)
 
static bool isMissing (const ExpOperation &oper)
 
static bool isMissing (const ExpOperation *oper)
 
static bool isPresent (const ExpOperation &oper)
 
static bool isPresent (const ExpOperation *oper)
 
static bool isEmpty (const ExpOperation &oper)
 
static bool isEmpty (const ExpOperation *oper)
 
static bool isFilled (const ExpOperation &oper)
 
static bool isFilled (const ExpOperation *oper)
 
- Static Public Member Functions inherited from GenObject
static void * getObject (const String &name, const GenObject *obj)
 
static bool getObjCounting ()
 
static void setObjCounting (bool enable)
 
static NamedCountergetObjCounter (const String &name, bool create=true)
 
static ObjListgetObjCounters ()
 

Additional Inherited Members

- Protected Member Functions inherited from ScriptParser
 ScriptParser ()
 
void setCode (ScriptCode *code)
 

Detailed Description

Javascript parser.

Javascript parser, takes source code and generates preparsed code

Constructor & Destructor Documentation

◆ JsParser()

JsParser ( bool allowLink = true,
bool allowTrace = false )
inline

Constructor

Parameters
allowLinkTrue to allow linking of the code, false otherwise.
allowTraceTrue to allow the script to enable performance tracing

Member Function Documentation

◆ adjustPath()

void adjustPath ( String & script,
bool extraInc = false ) const

Adjust a file script path to include default if needed

Parameters
scriptFile path to adjust
extraIncTrue to check the extra include path first

◆ basePath() [1/2]

const String & basePath ( ) const
inline

Retrieve the base script path

Returns
Base path added to relative script paths

◆ basePath() [2/2]

void basePath ( const char * path,
const char * incPath = 0 )
inline

Set the base script path

Parameters
pathBase path to add to relative script paths
incPathExtra include path to add to relative script paths

◆ callable()

virtual bool callable ( const String & name)
virtual

Check if a script has a certain function or method

Parameters
nameName of the function to check
Returns
True if function exists in code

Reimplemented from ScriptParser.

◆ createContext()

virtual ScriptContext * createContext ( ) const
virtual

Create a context adequate for Javascript code

Returns
A new Javascript context

Reimplemented from ScriptParser.

◆ createRunner() [1/2]

virtual ScriptRun * createRunner ( ScriptCode * code,
ScriptContext * context = 0,
const char * title = 0 ) const
virtual

Create a runner adequate for a block of parsed Javascript code

Parameters
codeParsed code block
contextJavascript context, an empty one will be allocated if NULL
titleAn optional name for the runner
Returns
A new Javascript runner, NULL if code is NULL

Reimplemented from ScriptParser.

References ScriptParser::code().

Referenced by createRunner().

◆ createRunner() [2/2]

ScriptRun * createRunner ( ScriptContext * context = 0,
const char * title = 0 ) const
inline

Create a runner adequate for the parsed Javascript code

Parameters
contextJavascript context, an empty one will be allocated if NULL
titleAn optional name for the runner
Returns
A new Javascript runner, NULL if code is not yet parsed

References ScriptParser::code(), and createRunner().

◆ eval()

static ScriptRun::Status eval ( const String & text,
ExpOperation ** result = 0,
ScriptContext * context = 0 )
static

Parse and run a piece of Javascript code

Parameters
textSource code fragment to execute
resultPointer to an optional pointer to store returned value
contextScript context, an empty one will be allocated if NULL
Returns
Status of the runtime after code execution

◆ includePath()

const String & includePath ( ) const
inline

Retrieve the extra include script path

Returns
Include path added to relative script paths

◆ isEmpty() [1/2]

static bool isEmpty ( const ExpOperation & oper)
inlinestatic

Check if an operation holds a null or undefined value or empty string

Returns
True if the operation is an undefined value or a null object or empty string

References isMissing(), and String::null().

Referenced by isFilled().

◆ isEmpty() [2/2]

static bool isEmpty ( const ExpOperation * oper)
inlinestatic

Check if an operation is missing, holds a null or undefined value or empty string

Returns
True if the operation is an undefined value or a null object or empty string

References isMissing().

◆ isFilled() [1/2]

static bool isFilled ( const ExpOperation & oper)
inlinestatic

Check if an operation is not null or undefined or empty string

Returns
True if the operation holds a non-empty value or non-null object

References isMissing().

◆ isFilled() [2/2]

static bool isFilled ( const ExpOperation * oper)
inlinestatic

Check if an operation is not null or undefined or empty string

Returns
True if the operation holds a non-empty value or non-null object

References isEmpty().

◆ isMissing() [1/2]

static bool isMissing ( const ExpOperation & oper)
static

Check if an operation is null or undefined

Returns
True if the operation holds an undefined value or a null object

Referenced by isEmpty(), isEmpty(), isFilled(), isMissing(), isPresent(), and isPresent().

◆ isMissing() [2/2]

static bool isMissing ( const ExpOperation * oper)
inlinestatic

Check if an operation is missing, holds a null or undefined

Returns
True if the operation is null or holds an undefined value or a null object

References isMissing().

◆ isNull()

static bool isNull ( const ExpOperation & oper)
static

Check if an operation holds a null value

Returns
True if the operation holds a null object

◆ isPresent() [1/2]

static bool isPresent ( const ExpOperation & oper)
inlinestatic

Check if an operation is not null or undefined

Returns
True if the operation holds a value or non-null object

References isMissing().

◆ isPresent() [2/2]

static bool isPresent ( const ExpOperation * oper)
inlinestatic

Check if an operation is present and not null or undefined

Returns
True if the operation holds a value or non-null object

References isMissing().

◆ isUndefined()

static bool isUndefined ( const ExpOperation & oper)
static

Check if an operation holds an undefined value

Returns
True if the operation holds an undefined value

◆ link()

void link ( bool allowed = true)
inline

Set whether the Javascript code should be linked or not

Parameters
allowedTrue to allow linking, false otherwise

◆ nullClone()

static ExpOperation * nullClone ( const char * name = 0)
static

Get a "null" object wrapper that will identity match another "null"

Parameters
nameName of the new wrapper, "null" if empty
Returns
ExpWrapper for the "null" object

◆ nullObject()

static JsObject * nullObject ( )
static

Obtain the "null" object

Returns
Referenced "null" object (0 if ref() fails)

◆ parse()

virtual bool parse ( const char * text,
bool fragment = false,
const char * file = 0,
int len = -1 )
virtual

Parse a string as Javascript source code

Parameters
textSource code text
fragmentTrue if the code is just an included fragment
fileName of the file that is being parsed
lenLength of text, negative if unknown
Returns
True if the text was successfully parsed

Implements ScriptParser.

◆ parsedFile()

const String & parsedFile ( ) const
inline

Retrieve the last parsed file name

Returns
Name of the successfully parsed file or an empty String

◆ parseJSON()

static ExpOperation * parseJSON ( const char * text,
ScriptMutex * mtx = 0,
ObjList * stack = 0,
GenObject * context = 0,
const ExpOperation * op = 0 )
static

Parse a complete block of JSON text

Parameters
textJSON text to parse
mtxPointer to the mutex that serializes this object
stackPointer to an execution stack, required for adding prototypes
contextPointer to an execution context, required for adding prototypes
opExpOperation that determined calling of this method
Returns
ExpOperation holding the content of JSON, must be dereferenced after use, NULL if parse error

References GenObject::GenObject().

◆ scriptChanged() [1/2]

bool scriptChanged ( const char * file) const

Check if the script or any includes have changed

Parameters
fileName of the file to check
Returns
True if the script may have changed, false if not changed

Referenced by scriptChanged().

◆ scriptChanged() [2/2]

bool scriptChanged ( const char * file,
const String & path,
const String & incPath = String::empty() ) const
inline

Check if the script or any includes have changed

Parameters
fileName of the file to check
pathNew base path to check
incPathNew extra include path to check
Returns
True if the script may have changed, false if not changed

References String::empty(), and scriptChanged().

◆ trace()

void trace ( bool allowed = true)
inline

Set whether the Javascript code can be traced or not

Parameters
allowedTrue to allow tracing, false otherwise

The documentation for this class was generated from the following file: