# JAS :: JavaScript Alternative Syntax # Test the JASPA Parser at http://timwhitlock.info/plug/examples/JASPA/Parser/JASParser.php # # Similar to ActionScript in many ways, but much stripped down: # - No interfaces; # - No native XML support; # - No namespaces. # - No meta data # # AS2 features included: # - type declaration # - super calls # - import statements # - include statements # - public, private, static accessors # - get/set function accessors # # AS3 features included: # - constants # - "each" iterator # - "as" "is" operators # - bodyless function expressions # - "..." rest parameter # - function parameter initializers # - additional accessors, protected, internal, etc.. # # Syntax tightening: # - no procedural code following a package block # - no procedural code inside classes or packages # - no package-level members # # Syntax loosening: # - literal and numeric property names allowed in object literals # # Syntax differing # - classes private to a class file are inside the package not following the package block # - no ":*" type declarations # # Terminal symbols shared with ECMAScript maintain a "J_" prefix. # JAS-specific symbols have their own "JAS_" prefix. # Top-level program is either procedural code or a single package definition # : | ; # Packages may not be empty, but may be unamed # : J_PACKAGE "{" "}" | J_PACKAGE "{" "}" ; : J_IDENTIFIER | "." J_IDENTIFIER ; : | ; : | ; : J_CLASS J_IDENTIFIER "{" "}" | J_CLASS J_IDENTIFIER "{" "}" | J_CLASS J_IDENTIFIER "{" "}" | J_CLASS J_IDENTIFIER "{" "}" ; : P_EPSILON | J_EXTENDS ; : | ; : | | | ; : | ; : | ; # Function, and Method definitions # -------------------------------------- : J_FUNCTION J_IDENTIFIER "(" ")" ; : J_FUNCTION J_IDENTIFIER "(" ")" | J_FUNCTION J_IDENTIFIER "(" ")" ; : J_FUNCTION J_IDENTIFIER "(" ")" ";" | J_FUNCTION J_IDENTIFIER "(" ")" ";" ; : P_EPSILON | JAS_GET | JAS_SET ; # A function expression is allowed to have no body # : J_FUNCTION J_IDENTIFIER "(" ")" | J_FUNCTION J_IDENTIFIER "(" ")" | J_FUNCTION "(" ")" | J_FUNCTION "(" ")" ; : P_EPSILON | | | "," ; : | "," ; : J_IDENTIFIER ; : P_EPSILON | "=" ; : "{" "}" | "{" "}" ; # : P_EPSILON | ":" | ":" J_VOID ; : | ; : J_PRIVATE | J_PUBLIC | J_STATIC | J_FINAL | J_PROTECTED | J_NATIVE | JAS_INTERNAL | JAS_DYNAMIC | JAS_OVERRIDE ; # Statements # : | | | | | | | | | | | | | | | ; : J_IMPORT "*" ";" | J_IMPORT ";" | J_IMPORT "." "*" ";" ; : JAS_INCLUDE J_STRING_LITERAL ";" ; : "{" "}" | "{" "}" ; : | ; # Variable Statements - # Extended for class and package properties # : | ; : J_VAR ";" | J_CONST ";" ; : | "," ; : | "," ; : J_IDENTIFIER | J_IDENTIFIER ; : J_IDENTIFIER | J_IDENTIFIER ; : "=" ; : "=" ; # 12.3 - Empty Statement : ";" ; # 12.4 - Expression Statement # - Cannot start with "{" or J_FUNCTION # - Special Rule Processing, see Grammar::exclude_terminal : ";" ; # 12.5 - The IF Statement # - Conflicts here on J_ELSE symbol but seems to work with a default shift : J_IF "(" ")" J_ELSE | J_IF "(" ")" ; # 12.6 - Iterations Statements : J_DO J_WHILE "(" ")" ";" | J_WHILE "(" ")" | J_FOR "(" ";" ";" ")" | J_FOR "(" ";" ";" ")" | J_FOR "(" ";" ";" ")" | J_FOR "(" ";" ";" ")" | J_FOR "(" ";" ";" ")" | J_FOR "(" ";" ";" ")" | J_FOR "(" ";" ";" ")" | J_FOR "(" ";" ";" ")" | J_FOR "(" J_VAR ";" ";" ")" | J_FOR "(" J_VAR ";" ";" ")" | J_FOR "(" J_VAR ";" ";" ")" | J_FOR "(" J_VAR ";" ";" ")" | J_FOR "(" J_IN ")" | J_FOR "(" J_VAR J_IN ")" | J_FOR JAS_EACH "(" J_VAR J_IN ")" | J_FOR JAS_EACH "(" J_IN ")" ; # 12.7 - Continue Statement # ( No line terminator after J_CONTINUE ) : J_CONTINUE ";" | J_CONTINUE J_IDENTIFIER ";" ; # 12.8 - Break Statement # ( No line terminator after J_BREAK ) : J_BREAK ";" | J_BREAK J_IDENTIFIER ";" ; # 12.9 - Return Statement # ( No line terminator after J_RETURN ) : J_RETURN ";" | J_RETURN ";" ; # 12.10 - With Statement : J_WITH "(" ")" ; # 12.11 - Switch Statement : J_SWITCH "(" ")" ; : "{" "}" | "{" "}" | "{" "}" | "{" "}" | "{" "}" | "{" "}" ; : | ; : J_CASE ":" | J_CASE ":" ; : J_DEFAULT ":" | J_DEFAULT ":" ; # 12.12 - Labelled Statements : J_IDENTIFIER ":" ; # 12.13 - The "throw" Statement # ( No line terminator after J_THROW ) : J_THROW ";" ; # 12.14 - The "try" Statement : J_TRY | J_TRY | J_TRY ; : J_CATCH "(" J_IDENTIFIER ")" ; : J_FINALLY ; # 11 - Expressions # ---------------- # 11.1 : J_THIS | J_IDENTIFIER | J_STRING_LITERAL | J_NUMERIC_LITERAL | J_TRUE | J_FALSE | J_NULL | J_REGEX | | | "(" ")" ; # 11.1.4 # ( As per the spec, but extra commas are odd, as it is in the elision rule too ) : "[" "]" | "[" "]" | "[" "]" | "[" "," "]" | "[" "," "]" ; : | | "," | "," ; # Elision is permitted empty elements, e.g. ",,," : "," | "," ; # 11.1.5 : "{" "}" | "{" "}" ; : ":" | "," ":" ; : J_IDENTIFIER | J_STRING_LITERAL | J_NUMERIC_LITERAL ; # 11.2 - Left Hand Side Expressions : J_SUPER | | | | J_NEW ; : | J_NEW ; : | | ; : "." J_IDENTIFIER | "[" "]" ; : "(" ")" | "(" ")" ; : | "," ; : | ; # 11.3 - Postfix Expressions # (No line terminator before operators) : | "++" | "--" ; # 11.4 - Unary Operators : | J_DELETE | J_VOID | J_TYPEOF | "++" | "--" | "+" | "-" | "~" | "!" ; # 11.5 - Multiplicative Operators & 11.6 - Additive Operators & 11.7 - Bitwise Shift Operators : | ; : "*" | "/" | "%" | "+" | "-" | "<<" | ">>" | ">>>" ; # AS3-style "as" operator : | JAS_AS ; : | JAS_AS ; # 11.8 - Relational Operators & Equality Operators : | | J_IN ; # NOTE - # The "NoIn" variants are needed to to avoid confusing the J_IN operator in a relational expression with the J_IN operator in a for statement : | ; : ">" | "<" | ">=" | "<=" | ">=" | "==" | "!=" | "===" | "!==" | J_INSTANCEOF | JAS_IS ; # Binary Bitwise Operations : | ; : | ; : "&" | "|" | "^" ; # Binary Logical Operators : | ; : | ; : "&&" | "||" ; # 11.12 - Conditional Operator ( ? : ) : | "?" ":" ; : | "?" ":" ; # 11.13 - Assignment Operators : | ; : | ; : "=" | "*=" | "/=" | "%=" | "+=" | "-=" | "<<=" | ">>=" | ">>>=" | "&=" | "|=" | "^=" ; # 11.14 - Comma Operator : | "," ; : | "," ; # AS3-style Rest Args operator : "..." J_IDENTIFIER ; # Extra symbols not in any grammar rules but required to be in the lex # : J_COMMENT | J_WHITESPACE | J_LINE_TERMINATOR ; # Extra symbols that are reserved to remain compatible with ECMA 262 Edition 3 # Or are reserved for future compatibility with ActionScript 3 # Also ECMAScript reserved words that are not reserved in AS3 are removed from here # : J_ABSTRACT | J_ENUM | J_SHORT | J_BOOLEAN | J_EXPORT | J_BYTE | J_LONG | J_CHAR | J_SYNCHRONIZED | J_FLOAT | J_THROWS | J_GOTO | J_TRANSIENT | J_DEBUGGER | J_VOLATILE | J_DOUBLE | J_INTERFACE | J_IMPLEMENTS | JAS_USE | JAS_NAMESPACE ;