summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Token.h
AgeCommit message (Collapse)Author
2020-10-26LibJS: Add message string to TokenLinus Groh
This allows us to communicate details about invalid tokens to the parser without having to invent a bunch of specific invalid tokens like TokenType::InvalidNumericLiteral.
2020-10-24LibJS: Support LegacyOctalEscapeSequence in string literalsLinus Groh
https://tc39.es/ecma262/#sec-additional-syntax-string-literals The syntax and semantics of 11.8.4 is extended as follows except that this extension is not allowed for strict mode code: Syntax EscapeSequence:: CharacterEscapeSequence LegacyOctalEscapeSequence NonOctalDecimalEscapeSequence HexEscapeSequence UnicodeEscapeSequence LegacyOctalEscapeSequence:: OctalDigit [lookahead ∉ OctalDigit] ZeroToThree OctalDigit [lookahead ∉ OctalDigit] FourToSeven OctalDigit ZeroToThree OctalDigit OctalDigit ZeroToThree :: one of 0 1 2 3 FourToSeven :: one of 4 5 6 7 NonOctalDecimalEscapeSequence :: one of 8 9 This definition of EscapeSequence is not used in strict mode or when parsing TemplateCharacter. Note It is possible for string literals to precede a Use Strict Directive that places the enclosing code in strict mode, and implementations must take care to not use this extended definition of EscapeSequence with such literals. For example, attempting to parse the following source text must fail: function invalid() { "\7"; "use strict"; }
2020-10-22LibJS: Support all line terminators (LF, CR, LS, PS)Linus Groh
https://tc39.es/ecma262/#sec-line-terminators
2020-10-05LibJS: Implement logical assignment operators (&&=, ||=, ??=)Linus Groh
TC39 proposal, stage 4 as of 2020-07. https://tc39.es/proposal-logical-assignment/
2020-10-04LibJS: Unify syntax highlightingLinus Groh
So far we have three different syntax highlighters for LibJS: - js's Line::Editor stylization - JS::MarkupGenerator - GUI::JSSyntaxHighlighter This not only caused repetition of most token types in each highlighter but also a lot of inconsistency regarding the styling of certain tokens: - JSSyntaxHighlighter was considering TokenType::Period to be an operator whereas MarkupGenerator categorized it as punctuation. - MarkupGenerator was considering TokenType::{Break,Case,Continue, Default,Switch,With} control keywords whereas JSSyntaxHighlighter just disregarded them - MarkupGenerator considered some future reserved keywords invalid and others not. JSSyntaxHighlighter and js disregarded most Adding a new token type meant adding it to ENUMERATE_JS_TOKENS as well as each individual highlighter's switch/case construct. I added a TokenCategory enum, and each TokenType is now associated to a certain category, which the syntax highlighters then can use for styling rather than operating on the token type directly. This also makes changing a token's category everywhere easier, should we need to do that (e.g. I decided to make TokenType::{Period,QuestionMarkPeriod} TokenCategory::Operator for now, but we might want to change them to Punctuation.
2020-08-21LibJS: Parser refactored to use constexpr precedence tableMuhammad Zahalqa
Replaced implementation dependent on HashMap with a constexpr PrecedenceTable based on array lookup.
2020-06-07LibJS: Add BigIntLinus Groh
2020-06-07LibJS: Lex and parse regex literals, add RegExp objectsMatthew Olsson
This adds regex parsing/lexing, as well as a relatively empty RegExpObject. The purpose of this patch is to allow the engine to not get hung up on parsing regexes. This will aid in finding new syntax errors (say, from google or twitter) without having to replace all of their regexes first!
2020-05-18LibJS: Handle hex and unicode escape sequences in string literalsMatthew Olsson
Introduces the following syntax: '\x55' '\u26a0' '\u{1f41e}'
2020-05-12LibJS: Add missing keywords/tokensLinus Groh
Some of these are required for syntax we have not implemented yet, some are future reserved words in strict mode.
2020-05-05LibJS: Implement exponentiation assignment operator (**=)Linus Groh
2020-05-05LibJS: Implement bitwise assignment operators (&=, |=, ^=)Linus Groh
2020-05-04LibJS: Add template literalsmattco98
Adds fully functioning template literals. Because template literals contain expressions, most of the work has to be done in the Lexer rather than the Parser. And because of the complexity of template literals (expressions, nesting, escapes, etc), the Lexer needs to have some template-related state. When entering a new template literal, a TemplateLiteralStart token is emitted. When inside a literal, all text will be parsed up until a '${' or '`' (or EOF, but that's a syntax error) is seen, and then a TemplateLiteralExprStart token is emitted. At this point, the Lexer proceeds as normal, however it keeps track of the number of opening and closing curly braces it has seen in order to determine the close of the expression. Once it finds a matching curly brace for the '${', a TemplateLiteralExprEnd token is emitted and the state is updated accordingly. When the Lexer is inside of a template literal, but not an expression, and sees a '`', this must be the closing grave: a TemplateLiteralEnd token is emitted. The state required to correctly parse template strings consists of a vector (for nesting) of two pieces of information: whether or not we are in a template expression (as opposed to a template string); and the count of the number of unmatched open curly braces we have seen (only applicable if the Lexer is currently in a template expression). TODO: Add support for template literal newlines in the JS REPL (this will cause a syntax error currently): > `foo > bar` 'foo bar'
2020-05-01LibJS: Implement (no-op) debugger statementLinus Groh
2020-04-27LibJS: Add spreading in array literalsmattco98
Implement the syntax and behavor necessary to support array literals such as [...[1, 2, 3]]. A type error is thrown if the target of the spread operator does not evaluate to an array (though it should eventually just check for an iterable). Note that the spread token's name is TripleDot, since the '...' token is used for two features: spread and rest. Calling it anything involving 'spread' or 'rest' would be a bit confusing.
2020-04-24LibJS: Add TokenType::TemplateLiteralLinus Groh
This is required for template literals - we're not quite there yet, but at least the parser can now tell us when this token is encountered - currently this yields "Unexpected token Invalid". Not really helpful. The character is a "backtick", but as we already have TokenType::{StringLiteral,RegexLiteral} this seemed like a fitting name. This also enables syntax highlighting for template literals in the js REPL and LibGUI's JSSyntaxHighlighter.
2020-04-18LibJS: Allow reserved words as keys in object expressions.Stephan Unverwerth
2020-04-13LibJS: Parse "this" as ThisExpressionStephan Unverwerth
2020-04-05LibJS: Plumb line and column information through Lexer / ParserBrian Gianforcaro
While debugging test failures, it's pretty frustrating to have to go do printf debugging to figure out what test is failing right now. While watching your JS Raytracer stream it seemed like this was pretty furstrating as well. So I wanted to start working on improving the diagnostics here. In the future I hope we can eventually be able to plumb the info down to the Error classes so any thrown exceptions will contain enough metadata to know where they came from.
2020-04-05LibJS: Add support for "continue" inside "for" statements :^)Andreas Kling
2020-04-03LibJS: Remove UndefinedLiteral, add undefined to global objectLinus Groh
There is no such thing as a "undefined literal" in JS - undefined is just a property on the global object with a value of undefined. This is pretty similar to NaN. var undefined = "foo"; is a perfectly fine AssignmentExpression :^)
2020-03-30LibJS: Add support for arrow functionsJack Karamanian
2020-03-30LibJS: Use some macro magic to avoid duplicating all the token typesAndreas Kling
2020-03-29LibJS: Lexer and parser support for "switch" statementsAndreas Kling
2020-03-24LibJS: Implement "throw"Andreas Kling
You can now throw an expression to the nearest catcher! :^) To support throwing arbitrary values, I added an Exception class that sits as a wrapper around whatever is thrown. In the future it will be a logical place to store a call stack.
2020-03-21LibJS: Parse object expressions0xtechnobabble
2020-03-16LibJS: Implement null and undefined literals0xtechnobabble
2020-03-14LibJS: Lex single quote strings, escaped chars and unterminated stringsStephan Unverwerth
2020-03-14LibJS: Add operator precedence parsingStephan Unverwerth
Obey precedence and associativity rules when parsing expressions with chained operators.
2020-03-12LibJS: Implement for statementConrad Pankoff
2020-03-12LibJS: Parse === and !== binary operatorsConrad Pankoff
2020-03-12LibJS: Implement <= and >= binary operatorsConrad Pankoff
2020-03-12LibJS: Add Javascript lexer and parserStephan Unverwerth
This adds a basic Javascript lexer and parser. It can parse the currently existing demo programs. More work needs to be done to turn it into a complete parser than can parse arbitrary JS Code. The lexer outputs tokens with preceeding whitespace and comments in the trivia member. This should allow us to generate the exact source code by concatenating the generated tokens. The parser is written in a way that it always returns a complete syntax tree. Error conditions are represented as nodes in the tree. This simplifies the code and allows it to be used as an early stage parser, e.g for parsing JS documents in an IDE while editing the source code.: