/* Cycript - Optimizing JavaScript Compiler/Runtime
* Copyright (C) 2009-2015 Jay Freeman (saurik)
*/
/* GNU Affero General Public License, Version 3 {{{ */
/*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
**/
/* }}} */
%code top {
#define cyscanner driver.scanner_
#define YYSTACKEXPANDABLE 1
}
%code requires {
#include "Driver.hpp"
#include "Parser.hpp"
#include "Stack.hpp"
#define CYNew new($pool)
@begin ObjectiveC
#include "ObjectiveC/Syntax.hpp"
@end
@begin E4X
#include "E4X/Syntax.hpp"
@end
#include "Highlight.hpp"
typedef struct {
bool newline_;
hi::Value highlight_;
union {
bool bool_;
CYDriver::Condition condition_;
CYArgument *argument_;
CYAssignment *assignment_;
CYBoolean *boolean_;
CYClause *clause_;
cy::Syntax::Catch *catch_;
CYComment *comment_;
CYComprehension *comprehension_;
CYDeclaration *declaration_;
CYDeclarations *declarations_;
CYElement *element_;
CYExpression *expression_;
CYFalse *false_;
CYFinally *finally_;
CYForInitialiser *for_;
CYForInInitialiser *forin_;
CYFunctionParameter *functionParameter_;
CYIdentifier *identifier_;
CYInfix *infix_;
CYLiteral *literal_;
CYMember *member_;
CYModule *module_;
CYNull *null_;
CYNumber *number_;
CYParenthetical *parenthetical_;
CYProgram *program_;
CYProperty *property_;
CYPropertyName *propertyName_;
CYRubyProc *rubyProc_;
CYStatement *statement_;
CYString *string_;
CYThis *this_;
CYTrue *true_;
CYWord *word_;
@begin C
CYTypeModifier *modifier_;
CYTypeSpecifier *specifier_;
CYTypedIdentifier *typedIdentifier_;
CYTypedParameter *typedParameter_;
@end
@begin ObjectiveC
CYClassName *className_;
CYClassField *classField_;
CYMessage *message_;
CYMessageParameter *messageParameter_;
CYProtocol *protocol_;
CYSelectorPart *selector_;
@end
@begin E4X
CYAttribute *attribute_;
CYPropertyIdentifier *propertyIdentifier_;
CYSelector *selector_;
@end
};
} YYSTYPE;
#define YYSTYPE YYSTYPE
}
%code provides {
int cylex(YYSTYPE *, CYLocation *, void *);
}
%name-prefix "cy"
%language "C++"
%initial-action {
@$.begin.filename = @$.end.filename = &driver.filename_;
};
%locations
%defines
%define api.location.type { CYLocation }
//%glr-parser
//%expect 1
%error-verbose
%parse-param { CYDriver &driver }
%lex-param { void *cyscanner }
/* Token Declarations {{{ */
@begin E4X
%token XMLCDATA
%token XMLComment
%token XMLPI
%token XMLAttributeValue
%token XMLName
%token XMLTagCharacters
%token XMLText
%token XMLWhitespace
@end
@begin E4X
%token LeftRight "<>"
%token LeftSlashRight ">"
%token SlashRight "/>"
%token LeftSlash ""
%token ColonColon "::"
%token PeriodPeriod ".."
@end
@begin E4X ObjectiveC
%token At "@"
%token Pound "#"
@end
%token Ampersand "&"
%token AmpersandAmpersand "&&"
%token AmpersandEqual "&="
%token Carrot "^"
%token CarrotEqual "^="
%token Equal "="
%token EqualEqual "=="
%token EqualEqualEqual "==="
%token EqualRight "=>"
%token EqualRight_ "\n=>"
%token Exclamation "!"
%token ExclamationEqual "!="
%token ExclamationEqualEqual "!=="
%token Hyphen "-"
%token HyphenEqual "-="
%token HyphenHyphen "--"
%token HyphenHyphen_ "\n--"
%token HyphenRight "->"
%token Left "<"
%token LeftEqual "<="
%token LeftLeft "<<"
%token LeftLeftEqual "<<="
%token Percent "%"
%token PercentEqual "%="
%token Period "."
%token PeriodPeriodPeriod "..."
%token Pipe "|"
%token PipeEqual "|="
%token PipePipe "||"
%token Plus "+"
%token PlusEqual "+="
%token PlusPlus "++"
%token PlusPlus_ "\n++"
%token Right ">"
%token RightEqual ">="
%token RightRight ">>"
%token RightRightEqual ">>="
%token RightRightRight ">>>"
%token RightRightRightEqual ">>>="
%token Slash "/"
%token SlashEqual "/="
%token Star "*"
%token StarEqual "*="
%token Tilde "~"
%token Colon ":"
%token Comma ","
%token Question "?"
%token SemiColon ";"
%token NewLine "\n"
%token Comment
%token OpenParen "("
%token CloseParen ")"
%token OpenBrace "{"
%token OpenBrace_ "\n{"
%token OpenBrace__ ";{"
%token CloseBrace "}"
%token OpenBracket "["
%token CloseBracket "]"
%token AtError "@error"
@begin Java
%token AtClass "@class"
@end
@begin C
%token Typedef "typedef"
%token Unsigned "unsigned"
%token Signed "signed"
%token Extern "extern"
@end
@begin C
%token AtEncode "@encode"
@end
@begin ObjectiveC
%token AtImplementation "@implementation"
%token AtImplementation_ ";@implementation"
%token AtImport "@import"
%token AtEnd "@end"
%token AtSelector "@selector"
%token AtNull "@null"
%token AtYes "@YES"
%token AtNo "@NO"
%token AtTrue "@true"
%token AtFalse "@false"
%token Yes "YES"
%token No "NO"
@end
%token False "false"
%token Null "null"
%token True "true"
// ES3/ES5/WIE/JSC Reserved
%token Auto "auto"
%token Break "break"
%token Case "case"
%token Catch "catch"
%token Continue "continue"
%token Default "default"
%token Delete "delete"
%token Do "do"
%token Else "else"
%token Finally "finally"
%token For "for"
%token Function "function"
%token Function_ ";function"
%token If "if"
%token In "in"
%token In_ "!in"
%token InstanceOf "instanceof"
%token New "new"
%token Return "return"
%token Switch "switch"
%token This "this"
%token Throw "throw"
%token Try "try"
%token TypeOf "typeof"
%token Var "var"
%token Void "void"
%token While "while"
%token With "with"
// ES3/IE6 Future, ES5/JSC Reserved
%token Debugger "debugger"
// ES3/ES5/IE6 Future, JSC Reserved
%token Const "const"
// ES3/ES5/IE6/JSC Future
%token Class "class"
%token Enum "enum"
%token Export "export"
%token Extends "extends"
%token Import "import"
%token Super "super"
// ES3 Future, ES5 Strict Future
%token Implements "implements"
%token Interface "interface"
%token Package "package"
%token Private "private"
%token Protected "protected"
%token Public "public"
%token Static "static"
// ES3 Future
%token Abstract "abstract"
%token Boolean "boolean"
%token Byte "byte"
%token Char "char"
%token Double "double"
%token Final "final"
%token Float "float"
%token Goto "goto"
%token Int "int"
%token Long "long"
%token Native "native"
%token Short "short"
%token Synchronized "synchronized"
%token Throws "throws"
%token Transient "transient"
%token Volatile "volatile"
// ES5 Strict
%token Let "let"
%token Yield "yield"
// Woah?!
%token Each "each"
%token Of "of"
@begin E4X
// E4X Conditional
%token Namespace "namespace"
%token XML "xml"
@end
%token AutoComplete
%token Identifier_
%token NumericLiteral
%token StringLiteral
%token RegularExpressionLiteral
%type AdditiveExpression
%type ArgumentList_
%type ArgumentList
%type ArgumentListOpt
%type Arguments
%type ArrayComprehension
%type ArrayInitialiser
%type ArrayLiteral
%type ArrowFunction
%type ArrowParameters
%type AssignmentExpression
%type Binding
%type BindingIdentifier
%type BitwiseANDExpression
%type Block_
%type Block
%type BooleanLiteral
%type BindingElement
%type BitwiseORExpression
%type BitwiseXORExpression
%type BreakStatement
%type BreakableStatement
%type CallExpression_
%type CallExpression
%type CaseBlock
%type CaseClause
%type CaseClausesOpt
%type CatchOpt
%type Comprehension
%type ComprehensionFor
%type ComprehensionIf
%type ComprehensionTail
%type ConditionalExpression
%type ContinueStatement
%type ConciseBody
%type DebuggerStatement
%type Declaration__
%type Declaration_
%type Declaration
%type DefaultClause
%type Element
%type ElementOpt
%type ElementList
%type ElementListOpt
%type ElseStatementOpt
%type EmptyStatement
%type EqualityExpression
%type Expression
%type ExpressionOpt
%type ExpressionStatement
%type FinallyOpt
%type ForStatementInitialiser
%type ForInStatementInitialiser
%type FormalParameter
%type FormalParameterList_
%type FormalParameterList
%type FormalParameterListOpt
%type FunctionBody
%type FunctionDeclaration
%type FunctionExpression
%type Identifier
%type IdentifierOpt
%type IdentifierType
%type IdentifierName
%type IfStatement
%type Initialiser
%type InitialiserOpt
%type IterationStatement
%type LabelledStatement
%type LeftHandSideExpression
%type LetStatement
%type LexicalDeclaration
%type Literal
%type ValueLiteral
%type LogicalANDExpression
%type LogicalORExpression
%type MemberAccess
%type MemberExpression_
%type MemberExpression
%type Module
%type MultiplicativeExpression
%type NewExpression
%type NullLiteral
%type ObjectLiteral
%type Parenthetical
%type PostfixExpression
%type PrimaryExpression
%type Program
%type ProgramBody
%type ProgramBodyOpt
%type PropertyName_
%type PropertyName
%type PropertyDefinition
%type PropertyDefinitionList_
%type PropertyDefinitionList
%type PropertyDefinitionListOpt
%type RelationalExpression
%type ReturnStatement
%type RubyProcExpression
%type RubyProcParameterList_
%type RubyProcParameterList
%type RubyProcParameters
%type RubyProcParametersOpt
%type ShiftExpression
%type SingleNameBinding
%type Statement__
%type Statement_
%type Statement
%type StatementList
%type StatementListOpt
%type StatementListItem
%type SwitchStatement
%type ThrowStatement
%type TryStatement
%type UnaryExpression_
%type UnaryExpression
%type VariableDeclaration
%type VariableDeclarationList_
%type VariableDeclarationList
%type VariableStatement
%type WithStatement
%type Word
@begin ObjectiveC
%type WordOpt
@end
%type Variable
@begin C
%type IntegerType
%type IntegerTypeOpt
%type PrefixedType
%type PrimitiveType
%type SuffixedType
%type TypeSignifier
%type TypeQualifierLeft
%type TypeQualifierRight
%type TypedIdentifier
%type TypedParameterList_
%type TypedParameterList
%type TypedParameterListOpt
@end
@begin ObjectiveC
%type BoxableExpression
%type CategoryStatement
%type ClassExpression
%type ClassFieldListOpt
%type ClassFields
%type ClassStatement
%type ClassSuperOpt
%type ClassMessageDeclaration
%type ClassMessageDeclarationListOpt
%type ClassName
%type ClassNameOpt
%type ClassProtocolListOpt
%type ClassProtocols
%type ClassProtocolsOpt
%type MessageExpression
%type MessageParameter
%type MessageParameters
%type MessageParameterList
%type MessageParameterListOpt
%type MessageScope
%type SelectorCall_
%type SelectorCall
%type SelectorExpression_
%type SelectorExpression
%type SelectorExpressionOpt
%type SelectorList
%type SelectorWordOpt
%type TypeOpt
%type VariadicCall
@end
@begin E4X
%type PropertyIdentifier_
%type PropertySelector_
%type PropertySelector
%type QualifiedIdentifier_
%type QualifiedIdentifier
%type WildcardIdentifier
%type XMLComment
%type XMLCDATA
%type XMLElement
%type XMLElementContent
%type