/* Cycript - The Truly Universal Scripting Language
* Copyright (C) 2009-2016 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 YYSTACKEXPANDABLE 1
}
%code requires {
#include "Driver.hpp"
#include "Parser.hpp"
#include "Stack.hpp"
#include "Syntax.hpp"
#define CYNew new(driver.pool_)
@begin ObjectiveC
#include "ObjectiveC/Syntax.hpp"
@end
@begin E4X
#include "E4X/Syntax.hpp"
@end
#include "Highlight.hpp"
}
%union { bool bool_; }
%union { CYMember *access_; }
%union { CYArgument *argument_; }
%union { CYAssignment *assignment_; }
%union { CYBinding *binding_; }
%union { CYBindings *bindings_; }
%union { CYBoolean *boolean_; }
%union { CYBraced *braced_; }
%union { CYClause *clause_; }
%union { cy::Syntax::Catch *catch_; }
%union { CYClassTail *classTail_; }
%union { CYComprehension *comprehension_; }
%union { CYElement *element_; }
%union { CYEnumConstant *constant_; }
%union { CYExpression *expression_; }
%union { CYFalse *false_; }
%union { CYVariable *variable_; }
%union { CYFinally *finally_; }
%union { CYForInitializer *for_; }
%union { CYForInInitializer *forin_; }
%union { CYFunctionParameter *functionParameter_; }
%union { CYIdentifier *identifier_; }
%union { CYImportSpecifier *import_; }
%union { CYInfix *infix_; }
%union { CYLiteral *literal_; }
%union { CYMethod *method_; }
%union { CYModule *module_; }
%union { CYNull *null_; }
%union { CYNumber *number_; }
%union { CYParenthetical *parenthetical_; }
%union { CYProperty *property_; }
%union { CYPropertyName *propertyName_; }
%union { CYTypeSigning signing_; }
%union { CYSpan *span_; }
%union { CYStatement *statement_; }
%union { CYString *string_; }
%union { CYTarget *target_; }
%union { CYThis *this_; }
%union { CYTrue *true_; }
%union { CYWord *word_; }
@begin C
%union { CYTypeIntegral *integral_; }
%union { CYTypeStructField *structField_; }
%union { CYTypeModifier *modifier_; }
%union { CYTypeSpecifier *specifier_; }
%union { CYTypedFormal *typedFormal_; }
%union { CYTypedLocation *typedLocation_; }
%union { CYTypedName *typedName_; }
%union { CYTypedParameter *typedParameter_; }
%union { CYType *typedThing_; }
@end
@begin ObjectiveC
%union { CYObjCKeyValue *keyValue_; }
%union { CYImplementationField *implementationField_; }
%union { CYMessage *message_; }
%union { CYMessageParameter *messageParameter_; }
%union { CYProtocol *protocol_; }
%union { CYSelectorPart *selector_; }
@end
@begin E4X
%union { CYAttribute *attribute_; }
%union { CYPropertyIdentifier *propertyIdentifier_; }
%union { CYSelector *selector_; }
@end
%code provides {
struct YYSTYPE {
cy::parser::semantic_type semantic_;
hi::Value highlight_;
};
int cylex(YYSTYPE *, CYLocation *, void *);
}
%code {
#undef yylex
typedef cy::parser::token tk;
_finline int cylex_(cy::parser::semantic_type *semantic, CYLocation *location, CYDriver &driver) {
driver.newline_ = false;
lex:
YYSTYPE data;
int token(cylex(&data, location, driver.scanner_));
*semantic = data.semantic_;
switch (token) {
case tk::OpenBrace:
case tk::OpenBracket:
case tk::OpenParen:
driver.in_.push(false);
break;
case tk::_in_:
if (driver.in_.top())
token = tk::_in__;
break;
case tk::CloseBrace:
case tk::CloseBracket:
case tk::CloseParen:
driver.in_.pop();
break;
case tk::_yield_:
if (driver.yield_.top())
token = tk::_yield__;
break;
case tk::NewLine:
driver.newline_ = true;
goto lex;
break;
}
return token;
}
#define yylex_(semantic, location, driver) ({ \
int type; \
if (driver.hold_ == cy::parser::empty_symbol) \
type = yytranslate_(cylex_(semantic, location, driver)); \
else { \
type = driver.hold_; \
driver.hold_ = cy::parser::empty_symbol; \
} \
type; })
#define CYLEX() do if (yyla.empty()) { \
YYCDEBUG << "Mapping a token: "; \
yyla.type = yylex_(&yyla.value, &yyla.location, driver); \
YY_SYMBOL_PRINT("Next token is", yyla); \
} while (false)
#define CYMAP(to, from) do { \
CYLEX(); \
if (yyla.type == yytranslate_(token::from)) \
yyla.type = yytranslate_(token::to); \
} while (false)
#define CYHLD(location, token) do { \
if (driver.hold_ != empty_symbol) \
CYERR(location, "unexpected hold"); \
driver.hold_ = yyla.type; \
yyla.type = yytranslate_(token); \
} while (false)
#define CYERR(location, message) do { \
error(location, message); \
YYABORT; \
} while (false)
#define CYEOK() do { \
yyerrok; \
driver.errors_.pop_back(); \
} while (false)
#define CYNOT(location) \
CYERR(location, "unimplemented feature")
#define CYMPT(location) do { \
if (!yyla.empty() && yyla.type_get() != yyeof_) \
CYERR(location, "unexpected lookahead"); \
} while (false)
}
%name-prefix "cy"
%language "C++"
%initial-action {
@$.begin.filename = @$.end.filename = &driver.filename_;
switch (driver.mark_) {
case CYMarkScript:
driver.hold_ = yytranslate_(token::MarkScript);
break;
case CYMarkModule:
driver.hold_ = yytranslate_(token::MarkModule);
break;
case CYMarkExpression:
driver.hold_ = yytranslate_(token::MarkExpression);
break;
}
};
%locations
%defines
%define api.location.type { CYLocation }
//%glr-parser
//%expect 1
%error-verbose
%param { CYDriver &driver }
/* 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 PeriodPeriod ".."
@end
@begin E4X ObjectiveC
%token At "@"
@end
%token Ampersand "&"
%token AmpersandAmpersand "&&"
%token AmpersandEqual "&="
%token Carrot "^"
%token CarrotEqual "^="
%token Equal "="
%token EqualEqual "=="
%token EqualEqualEqual "==="
%token EqualRight "=>"
%token Exclamation "!"
%token ExclamationEqual "!="
%token ExclamationEqualEqual "!=="
%token Hyphen "-"
%token HyphenEqual "-="
%token HyphenHyphen "--"
%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 Right ">"
%token RightEqual ">="
%token RightRight ">>"
%token RightRightEqual ">>="
%token RightRightRight ">>>"
%token RightRightRightEqual ">>>="
%token Slash "/"
%token SlashEqual "/="
%token Star "*"
%token StarEqual "*="
%token Tilde "~"
%token Colon ":"
%token ColonColon "::"
%token Comma ","
%token Question "?"
%token SemiColon ";"
%token Pound "#"
%token NewLine "\n"
%token __ ""
%token Comment
%token OpenParen "("
%token CloseParen ")"
%token OpenBrace "{"
%token OpenBrace_ ";{"
%token OpenBrace_let "let {"
%token CloseBrace "}"
%token OpenBracket "["
%token OpenBracket_let "let ["
%token CloseBracket "]"
%token At_error_ "@error"
@begin Java
%token At_class_ "@class"
@end
@begin C
%token _typedef_ "typedef"
%token _unsigned_ "unsigned"
%token _signed_ "signed"
%token _struct_ "struct"
%token _extern_ "extern"
@end
@begin C
%token At_encode_ "@encode"
@end
@begin ObjectiveC
%token At_implementation_ "@implementation"
%token At_import_ "@import"
%token At_end_ "@end"
%token At_selector_ "@selector"
%token At_null_ "@null"
%token At_YES_ "@YES"
%token At_NO_ "@NO"
%token At_true_ "@true"
%token At_false_ "@false"
%token _YES_ "YES"
%token _NO_ "NO"
@end
%token _false_ "false"
%token _null_ "null"
%token _true_ "true"
%token _as_ "as"
%token _break_ "break"
%token _case_ "case"
%token _catch_ "catch"
%token _class_ "class"
%token _class__ ";class"
%token _const_ "const"
%token _continue_ "continue"
%token _debugger_ "debugger"
%token _default_ "default"
%token _delete_ "delete"
%token _do_ "do"
%token _else_ "else"
%token _enum_ "enum"
%token _export_ "export"
%token _extends_ "extends"
%token _finally_ "finally"
%token _for_ "for"
%token _function_ "function"
%token _function__ ";function"
%token _if_ "if"
%token _import_ "import"
%token _in_ "in"
%token _in__ "!in"
%token _Infinity_ "Infinity"
%token _instanceof_ "instanceof"
%token _new_ "new"
%token _return_ "return"
%token _super_ "super"
%token _switch_ "switch"
%token _target_ "target"
%token _this_ "this"
%token _throw_ "throw"
%token _try_ "try"
%token _typeof_ "typeof"
%token _var_ "var"
%token _void_ "void"
%token _while_ "while"
%token _with_ "with"
%token _abstract_ "abstract"
%token _await_ "await"
%token _boolean_ "boolean"
%token _byte_ "byte"
%token _char_ "char"
%token _constructor_ "constructor"
%token _double_ "double"
%token _eval_ "eval"
%token _final_ "final"
%token _float_ "float"
%token _from_ "from"
%token _get_ "get"
%token _goto_ "goto"
%token _implements_ "implements"
%token _int_ "int"
%token ___int128_ "__int128"
%token _interface_ "interface"
%token _let_ "let"
%token _let__ "!let"
%token _long_ "long"
%token _native_ "native"
%token _package_ "package"
%token _private_ "private"
%token _protected_ "protected"
%token ___proto___ "__proto__"
%token _prototype_ "prototype"
%token _public_ "public"
%token _set_ "set"
%token _short_ "short"
%token _static_ "static"
%token _synchronized_ "synchronized"
%token _throws_ "throws"
%token _transient_ "transient"
%token _typeid_ "typeid"
%token _volatile_ "volatile"
%token _yield_ "yield"
%token _yield__ "!yield"
%token _undefined_ "undefined"
@begin ObjectiveC
%token _bool_ "bool"
%token _BOOL_ "BOOL"
%token _id_ "id"
%token _nil_ "nil"
%token _NULL_ "NULL"
%token _SEL_ "SEL"
@end
%token _each_ "each"
%token _of_ "of"
%token _of__ "!of"
@begin E4X
%token _namespace_ "namespace"
%token _xml_ "xml"
@end
%token AutoComplete
%token YieldStar "yield *"
%token Identifier_
%token NumericLiteral
%token StringLiteral
%token RegularExpressionLiteral_
%token NoSubstitutionTemplate
%token TemplateHead
%token TemplateMiddle
%token TemplateTail
%type AccessExpression
%type AdditiveExpression
%type ArgumentList_
%type ArgumentList
%type ArgumentListOpt
%type Arguments
%type ArrayComprehension
%type ArrayElement
%type ArrayLiteral
%type ArrowFunction
%type ArrowParameters
%type AssignmentExpression
%type BindingIdentifier
%type BindingIdentifierOpt
%type BindingList_
%type BindingList
%type BitwiseANDExpression
%type Block
%type BlockStatement
%type BooleanLiteral
%type BindingElement
%type BitwiseORExpression
%type BitwiseXORExpression
%type BracedExpression_
%type BracedExpression
%type BreakStatement
%type BreakableStatement
%type CallExpression_
%type CallExpression
%type CaseBlock
%type CaseClause
%type CaseClausesOpt
%type Catch
%type CatchParameter
%type ClassDeclaration
%type ClassExpression
%type ClassHeritage
%type ClassHeritageOpt
%type ClassTail
%type Comprehension
%type ComprehensionFor
%type ComprehensionIf
%type ComprehensionTail
%type ComputedPropertyName
%type ConditionalExpression
%type ContinueStatement
%type ConciseBody
%type CoverParenthesizedExpressionAndArrowParameterList
%type DebuggerStatement
%type Declaration_
%type Declaration
%type DefaultClause
%type ElementList_
%type ElementList
%type ElementListOpt
%type ElseStatementOpt
%type EmptyStatement
%type EqualityExpression
%type Expression
%type ExpressionOpt
%type ExpressionStatement_
%type ExpressionStatement
%type ExternC
%type ExternCStatement
%type ExternCStatementListOpt
%type Finally
%type ForBinding
%type ForDeclaration
%type ForInStatementInitializer
%type ForStatementInitializer
%type FormalParameter
%type FormalParameterList_
%type FormalParameterList
%type FormalParameters
%type FromClause
%type FunctionBody
%type FunctionDeclaration
%type FunctionExpression
%type FunctionStatementList
%type GeneratorBody
%type GeneratorDeclaration
%type GeneratorExpression
%type GeneratorMethod
%type HoistableDeclaration
%type Identifier
%type IdentifierNoOf
%type IdentifierType
%type IdentifierTypeNoOf
%type IdentifierTypeOpt
%type IdentifierName
%type IdentifierReference
%type IfStatement
%type ImportClause
%type ImportDeclaration
%type ImportSpecifier
%type ImportedBinding
%type ImportedDefaultBinding
%type ImportsList_
%type ImportsList
%type ImportsListOpt
%type IndirectExpression
%type Initializer
%type InitializerOpt
%type IterationStatement
%type LabelIdentifier
%type LabelledItem
%type LabelledStatement
%type LeftHandSideAssignment
%type LeftHandSideExpression
%type LetOrConst
%type LexicalBinding
%type LexicalDeclaration_
%type LexicalDeclaration
%type Literal
%type LiteralPropertyName
%type LogicalANDExpression
%type LogicalORExpression
%type MemberAccess
%type MemberExpression
%type MethodDefinition
%type ModuleBody
%type ModuleBodyOpt
%type ModuleItem
%type ModuleItemList
%type ModuleItemListOpt
%type ModulePath
%type ModuleSpecifier
%type MultiplicativeExpression
%type NameSpaceImport
%type NamedImports
%type NewExpression
%type NullLiteral
%type ObjectLiteral
%type PostfixExpression
%type PrimaryExpression
%type PropertyName
%type PropertyDefinition
%type PropertyDefinitionList_
%type PropertyDefinitionList
%type PropertyDefinitionListOpt
%type PropertySetParameterList
%type RegularExpressionLiteral
%type RegularExpressionSlash
%type RelationalExpression
%type ReturnStatement
%type BracedParameter
%type RubyProcParameterList_
%type RubyProcParameterList
%type RubyProcParameters
%type RubyProcParametersOpt
%type Script
%type ScriptBody
%type ScriptBodyOpt
%type ShiftExpression
%type SingleNameBinding
%type Statement__
%type Statement_
%type Statement
%type StatementList
%type StatementListOpt
%type StatementListItem
%type StrictFormalParameters
%type SuperCall
%type SuperProperty
%type SwitchStatement
%type TemplateLiteral
%type TemplateSpans
%type ThrowStatement
%type TryStatement
%type TypeDefinition
%type UnaryExpression_
%type UnaryExpression
%type VariableDeclaration
%type VariableDeclarationList_
%type VariableDeclarationList
%type VariableStatement_
%type VariableStatement
%type WithStatement
%type Word
%type WordNoUnary
@begin ObjectiveC
%type WordOpt
@end
%type YieldExpression
@begin C
%type EnumConstantListOpt_
%type EnumConstantListOpt
%type IntegerNumber
%type IntegerType
%type IntegerTypeOpt
%type PrefixedType
%type PrimitiveReference
%type PrimitiveType
%type StructFieldListOpt
%type SuffixedType
%type SuffixedTypeOpt
%type TypeSignifier
%type TypeSignifierNone
%type TypeSignifierOpt
%type TypeSigning
%type ParameterTail
%type TypeQualifierLeft
%type TypeQualifierLeftOpt
%type TypeQualifierRight
%type TypeQualifierRightOpt
%type TypedIdentifierDefinition
%type TypedIdentifierEncoding
%type TypedIdentifierField
%type TypedIdentifierMaybe
%type TypedIdentifierNo
%type TypedIdentifierTagged
%type TypedIdentifierYes
%type TypedParameterList_
%type TypedParameterList
%type TypedParameterListOpt
%type TypedParameters
@end
@begin ObjectiveC
%type AssignmentExpressionClassic
%type BoxableExpression
%type CategoryStatement
%type ClassSuperOpt
%type ConditionalExpressionClassic
%type ClassMessageDeclaration
%type ClassMessageDeclarationListOpt
%type ClassProtocolListOpt
%type ClassProtocols
%type ClassProtocolsOpt
%type ImplementationFieldListOpt
%type ImplementationStatement
%type KeyValuePairList_
%type KeyValuePairList
%type KeyValuePairListOpt
%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