From a2164213a49b51bbc72e5729db97ca692e583083 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 4 Aug 2020 23:34:47 +0100 Subject: [PATCH 001/103] lex any elm program! --- src/Stage/Parse/Lexer.elm | 432 +++++++++++++++ tests/LexerTest.elm | 1058 +++++++++++++++++++++++++++++++++++++ 2 files changed, 1490 insertions(+) create mode 100644 src/Stage/Parse/Lexer.elm create mode 100644 tests/LexerTest.elm diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm new file mode 100644 index 00000000..3827875a --- /dev/null +++ b/src/Stage/Parse/Lexer.elm @@ -0,0 +1,432 @@ +module Stage.Parse.Lexer exposing (..) + +import Elm.Data.Located as Located exposing (Located) +import Parser.Advanced as P exposing ((|.), (|=), Parser) +import Set + + +type LexItem + = Sigil LexSigil + | Token String + | NumericLiteral String + | TextLiteral LexLiteralType String + | Whitespace Int + | Newline Int + | Comment LexCommentType String + | Invalid String + + +type LexSigil + = Bracket BracketType BracketTodoNameMe + | Assign + | Pipe + | Comma + | SingleDot + | DoubleDot + | ThinArrow + | Backslash + | Underscore + | Colon + | BinaryOperator LexBinaryOperator + + +type LexCommentType + = LineComment + | MutlilineComment + | DocComment + + +type LexBinaryOperator + = Add + | Subtract + | Multiply + | Divide + | Exponentiate + | And + | Or + | Equals + | GreaterThan + | GreaterThanEquals + | LessThan + | LessThanEquals + | Append + + +type BracketType + = Round + | Square + | Curly + + +type BracketTodoNameMe + = Open + | Close + + +type LexLiteralType + = StringL StringType + | CharL + + +type StringType + = Single + | Triple + + +type LexProblem + = ExpectingToken + | ExpectingSigil + | ExpectingLiteralStart LexLiteralType + | ExpectingLiteralEnd LexLiteralType + | ExpectingBackslash + | ExpectingAnything + | ExpectingWhitespace + | ExpectingNewline + | ExpectingLineComment + | ExpectingNumericLiteral + | ExpectingEscape + | ExpectingEnd + + +type alias Parser_ a = + Parser Never LexProblem a + + +toString : LexItem -> String +toString item = + case item of + Sigil (Bracket Round Open) -> + "(" + + Sigil (Bracket Round Close) -> + ")" + + Sigil (Bracket Square Open) -> + "[" + + Sigil (Bracket Square Close) -> + "]" + + Sigil (Bracket Curly Open) -> + "{" + + Sigil (Bracket Curly Close) -> + "}" + + Sigil Assign -> + "=" + + Sigil Pipe -> + "|" + + Sigil Comma -> + "," + + Sigil SingleDot -> + "." + + Sigil DoubleDot -> + ".." + + Sigil ThinArrow -> + "->" + + Sigil Backslash -> + "\\" + + Sigil Colon -> + ":" + + Sigil Underscore -> + "_" + + Sigil (BinaryOperator Add) -> + "+" + + Sigil (BinaryOperator Subtract) -> + "-" + + Sigil (BinaryOperator Multiply) -> + "*" + + Sigil (BinaryOperator Divide) -> + "/" + + Sigil (BinaryOperator Exponentiate) -> + "^" + + Sigil (BinaryOperator And) -> + "&&" + + Sigil (BinaryOperator Or) -> + "||" + + Sigil (BinaryOperator Equals) -> + "==" + + Sigil (BinaryOperator GreaterThan) -> + ">" + + Sigil (BinaryOperator GreaterThanEquals) -> + ">=" + + Sigil (BinaryOperator LessThan) -> + "<" + + Sigil (BinaryOperator LessThanEquals) -> + "<=" + + Sigil (BinaryOperator Append) -> + "++" + + Token s -> + s + + NumericLiteral s -> + s + + TextLiteral ty s -> + delimiterFor ty ++ s ++ delimiterFor ty + + Whitespace i -> + String.repeat i " " + + Newline i -> + "\n" ++ String.repeat i " " + + Comment LineComment s -> + "//" ++ s + + Comment MutlilineComment s -> + "{-" ++ s ++ "-}" + + Comment DocComment s -> + "{-|" ++ s ++ "-}" + + Invalid s -> + s + + +located : Parser_ p -> Parser_ (Located p) +located p = + P.succeed + (\( startRow, startCol ) value ( endRow, endCol ) -> + Located.located + { start = { row = startRow, col = startCol } + , end = { row = endRow, col = endCol } + } + value + ) + |= P.getPosition + |= p + |= P.getPosition + + +parser : Parser_ (List (Located LexItem)) +parser = + P.loop + [] + (\reversed -> + P.oneOf + [ P.oneOf + ([ -- commentParser must come before sigil parser as the sigil + -- parser will try to interpret "--" as a sigil + P.variable + { start = Char.isAlphaNum + , inner = \c -> Char.isAlphaNum c || c == '_' + , reserved = Set.empty + , expecting = ExpectingToken + } + |> P.map Token + , numericLiteralParser + |> P.map NumericLiteral + , textLiteralParser + |> P.map + (\( ty, terminates, literalBody ) -> + if terminates then + TextLiteral ty literalBody + + else + Invalid (delimiterFor ty ++ literalBody) + ) + , commentParser + |> P.map (\( ty, commentBody ) -> Comment ty commentBody) + , sigilParser + |> P.map Sigil + , P.symbol (P.Token " " ExpectingWhitespace) + |> P.andThen (\() -> chompSpacesAndCount) + |> P.map (\count -> Whitespace (count + 1)) + , P.oneOf + [ P.symbol (P.Token "\n\u{000D}" ExpectingNewline) + , P.symbol (P.Token "\n" ExpectingNewline) + ] + |> P.andThen (\() -> chompSpacesAndCount) + |> P.map Newline + ] + |> List.map (located >> P.map (\t -> P.Loop (t :: reversed))) + ) + , P.end ExpectingEnd + |> P.map (\() -> P.Done (List.reverse reversed)) + ] + ) + + +chompSpacesAndCount : Parser_ Int +chompSpacesAndCount = + P.chompWhile (\c -> c == ' ') + |> P.getChompedString + |> P.map String.length + + +alphaOrNumOr_ : Char -> Bool +alphaOrNumOr_ c = + Char.isAlphaNum c || c == '_' + + +textLiteralParser : Parser_ ( LexLiteralType, Bool, String ) +textLiteralParser = + P.oneOf + [ -- order matters! We must try parsing a tripple delimited string first! + delimitedLiteral (StringL Triple) + , delimitedLiteral (StringL Single) + , delimitedLiteral CharL + ] + + +delimiterFor : LexLiteralType -> String +delimiterFor ty = + case ty of + StringL Single -> + "\"" + + StringL Triple -> + "\"\"\"" + + CharL -> + "'" + + +commentParser : Parser_ ( LexCommentType, String ) +commentParser = + P.oneOf + [ P.symbol (P.Token "--" ExpectingLineComment) + |> P.andThen (\() -> P.chompWhile (\c -> c /= '\n') |> P.getChompedString) + |> P.map (Tuple.pair LineComment) + ] + + +delimitedLiteral : LexLiteralType -> Parser_ ( LexLiteralType, Bool, String ) +delimitedLiteral ty = + let + delimiter = + delimiterFor ty + in + P.succeed + (\( body, terminates ) -> + ( ty + , terminates + , if terminates then + String.dropRight (String.length (delimiterFor ty)) body + + else + body + ) + ) + |. P.symbol (P.Token delimiter (ExpectingLiteralStart ty)) + |= P.mapChompedString + Tuple.pair + (P.loop () + (\() -> + P.oneOf + [ P.token (P.Token delimiter (ExpectingLiteralEnd ty)) + |> P.map (\() -> P.Done True) + , P.token (P.Token "\\" ExpectingEscape) + |> P.andThen + (\() -> P.chompIf (\c -> True) ExpectingAnything) + |> P.map P.Loop + , P.chompIf (\_ -> True) ExpectingAnything + |> P.map P.Loop + , P.end ExpectingEnd + |> P.map (\() -> P.Done False) + ] + ) + ) + + +numericLiteralParser : Parser_ String +numericLiteralParser = + P.getChompedString + (P.oneOf + [ P.chompIf Char.isDigit ExpectingNumericLiteral + |> P.andThen (\() -> P.chompWhile (\c -> Char.isAlphaNum c || c == '_')) + , P.backtrackable + (P.succeed () + |. P.chompIf (\c -> c == '-') ExpectingNumericLiteral + |. P.chompIf Char.isDigit ExpectingNumericLiteral + |. P.chompWhile (\c -> Char.isAlphaNum c || c == '_') + ) + ] + ) + + +sigilParser : Parser_ LexSigil +sigilParser = + P.oneOf + [ -- Two character sigils (must come first) + P.symbol (P.Token "&&" ExpectingSigil) + |> P.map (\() -> BinaryOperator And) + , P.symbol (P.Token "++" ExpectingSigil) + |> P.map (\() -> BinaryOperator Append) + , P.symbol (P.Token "==" ExpectingSigil) + |> P.map (\() -> BinaryOperator Equals) + , P.symbol (P.Token "||" ExpectingSigil) + |> P.map (\() -> BinaryOperator Or) + , P.symbol (P.Token ".." ExpectingSigil) + |> P.map (\() -> DoubleDot) + + -- Single character sigils + , P.symbol (P.Token "^" ExpectingSigil) + |> P.map (\() -> BinaryOperator Exponentiate) + , P.symbol (P.Token "\\" ExpectingSigil) + |> P.map (\() -> Backslash) + , P.symbol (P.Token "_" ExpectingSigil) + |> P.map (\() -> Underscore) + , P.symbol (P.Token "(" ExpectingSigil) + |> P.map (\() -> Bracket Round Open) + , P.symbol (P.Token ")" ExpectingSigil) + |> P.map (\() -> Bracket Round Close) + , P.symbol (P.Token ">" ExpectingSigil) + |> P.map (\() -> BinaryOperator GreaterThan) + , P.symbol (P.Token "<" ExpectingSigil) + |> P.map (\() -> BinaryOperator LessThan) + , P.symbol (P.Token ">=" ExpectingSigil) + |> P.map (\() -> BinaryOperator GreaterThanEquals) + , P.symbol (P.Token "<=" ExpectingSigil) + |> P.map (\() -> BinaryOperator LessThanEquals) + , P.symbol (P.Token "-" ExpectingSigil) + |> P.map (\() -> BinaryOperator Subtract) + , P.symbol (P.Token "+" ExpectingSigil) + |> P.map (\() -> BinaryOperator Add) + , P.symbol (P.Token "=" ExpectingSigil) + |> P.map (\() -> Assign) + , P.symbol (P.Token "/" ExpectingSigil) + |> P.map (\() -> BinaryOperator Divide) + , P.symbol (P.Token "*" ExpectingSigil) + |> P.map (\() -> BinaryOperator Multiply) + , P.symbol (P.Token "{" ExpectingSigil) + |> P.map (\() -> Bracket Curly Open) + , P.symbol (P.Token "[" ExpectingSigil) + |> P.map (\() -> Bracket Square Open) + , P.symbol (P.Token "}" ExpectingSigil) + |> P.map (\() -> Bracket Curly Close) + , P.symbol (P.Token "]" ExpectingSigil) + |> P.map (\() -> Bracket Square Close) + , P.symbol (P.Token ":" ExpectingSigil) + |> P.map (\() -> Colon) + , P.symbol (P.Token "," ExpectingSigil) + |> P.map (\() -> Comma) + , P.symbol (P.Token "." ExpectingSigil) + |> P.map (\() -> SingleDot) + , P.symbol (P.Token "|" ExpectingSigil) + |> P.map (\() -> Pipe) + ] diff --git a/tests/LexerTest.elm b/tests/LexerTest.elm new file mode 100644 index 00000000..afd5370c --- /dev/null +++ b/tests/LexerTest.elm @@ -0,0 +1,1058 @@ +module LexerTest exposing (..) + +import Dict +import Elm.AST.Frontend as Frontend +import Elm.AST.Frontend.Unwrapped exposing (Expr(..), Pattern(..)) +import Elm.Data.Declaration as Declaration exposing (DeclarationBody) +import Elm.Data.Exposing exposing (ExposedItem(..), Exposing(..)) +import Elm.Data.Located as Located +import Elm.Data.Module exposing (ModuleType(..)) +import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) +import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) +import Elm.Data.TypeAnnotation exposing (TypeAnnotation) +import Expect exposing (Expectation) +import OurExtras.String as String +import Parser.Advanced as P +import Stage.Parse.Lexer exposing (..) +import String.Extra as String +import Test exposing (Test, describe, test) + + +runTest ( description, input ) = + test description <| + \() -> + input + -- |> P.run ((located (Stage.Parse.Lexer.literalParser + -- |> P.map (\( ty, literalBody ) -> Literal ty literalBody ))) + -- |> P.map List.singleton) + |> P.run Stage.Parse.Lexer.parser + |> Expect.all + [ Result.map (List.map (Located.unwrap >> toString) >> String.join "") + >> Expect.equal (Ok input) + , Result.map + (List.filterMap + (\item -> + case Located.unwrap item of + Invalid s -> + Just s + + _ -> + Nothing + ) + ) + >> Expect.equal (Ok []) + ] + + +moduleDeclaration : Test +moduleDeclaration = + describe "Stage.Parse.Parser.moduleDeclaration" + [ describe "general" + (List.map runTest + [ ( "works with simple module name" + , "module Foo exposing (..)" + -- , [ Token "module" + -- , Whitespace 1 + -- , Token "Foo" + -- , Whitespace 1 + -- , Token "exposing" + -- , Whitespace 1 + -- , Sigil (Bracket Round Open) + -- , Sigil DoubleDot + -- , Sigil (Bracket Round Close) + -- ] + ) + , ( "works with nested module name" + , "module Foo.Bar exposing (..)" + ) + , ( "works with even more nested module name" + , "module Foo.Bar.Baz.Quux exposing (..)" + ) + , ( "allows multiple spaces between the `module` keyword and the module name" + , "module Foo exposing (..)" + ) + , ( "doesn't allow a newline between the `module` keyword and the module name" + , """ + module + Foo exposing (..) + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "allows a newline and space between the `module` keyword and the module name" + , """ + module + Foo exposing (..) + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "allows multiple spaces between the module name and the `exposing` keyword" + , "module Foo exposing (..)" + ) + , ( "doesn't allow a newline between the module name and the `exposing` keyword" + , """ + module Foo + exposing (..) + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "allows newline and space between the module name and the `exposing` keyword" + , """ + module Foo + exposing (..) + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "allows multiple spaces between the `exposing` keyword and the exposing list" + , "module Foo exposing (..)" + ) + , ( "doesn't allow a newline between the `exposing` keyword and the exposing list" + , """ + module Foo exposing + (..) + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "allows a newline and space between the `exposing` keyword and the exposing list" + , """ + module Foo exposing + (..) + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "doesn't work without something after the `exposing` keyword" + , "module Foo exposing" + ) + ] + ) + , describe "plain module" + (List.map runTest + [ ( "simply works" + , "module Foo exposing (..)" + ) + ] + ) + , describe "port module" + (List.map runTest + [ ( "simply works" + , "port module Foo exposing (..)" + ) + ] + ) + ] + + +exposingList : Test +exposingList = + describe "Stage.Parse.Parser.exposingList" + [ describe "exposing all" + (List.map runTest + [ ( "simply works" + , "(..)" + ) + , ( "doesn't work with spaces inside the parens" + , "( .. )" + ) + ] + ) + , describe "exposing some" + [ describe "general" + (List.map runTest + [ ( "can't be empty" + , "()" + ) + , ( "works with spaces between items" + , "(foo, bar)" + ) + , ( "works with even more spaces between items" + , "(foo , bar)" + ) + , ( "works with mixed values" + , "(foo, Bar, Baz(..))" + ) + , ( "allows for newline" + , "(foo\n,bar)" + ) + ] + ) + , describe "values" + (List.map runTest + [ ( "works with a value" + , "(foo)" + ) + ] + ) + , describe "types" + (List.map runTest + [ ( "works with exposed type" + , "(Foo)" + ) + ] + ) + , describe "types with all constructors" + (List.map runTest + [ ( "works with exposed type and all constructors" + , "(Foo(..))" + ) + , ( "doesn't allow spaces between the module name and the double period list" + , "(Foo (..))" + ) + , ( "doesn't allow spaces inside the double period list" + , "(Foo( .. ))" + ) + , ( "doesn't allow only some constructors exposed" + , "(Foo(Bar))" + ) + ] + ) + ] + ] + + +imports : Test +imports = + describe "Stage.Parse.Parser.imports" + [ describe "general" + (List.map runTest + [ ( "allows for multiple modifiers" + , "import Foo as F exposing (..)" + ) + , ( "allows for multiple spaces" + , "import Foo as F exposing (..)" + ) + , ( "allows for multiple imports" + , "import Foo\nimport Bar" + ) + , ( "allows for multiple newlines between imports" + , "import Foo\n\nimport Bar" + ) + , ( "doesn't allow for lower-case import" + , "import foo" + ) + ] + ) + , describe "simple" + (List.map runTest + [ ( "simply works" + , "import Foo" + ) + ] + ) + , describe "as" + (List.map runTest + [ ( "simply works" + , "import Foo as F" + ) + , ( "doesn't work with lowercase alias" + , "import Foo as f" + ) + , ( "doesn't work with dot-separated alias" + , "import Foo as X.B" + ) + ] + ) + , describe "exposing" + (List.map runTest + [ ( "simply works" + , "import Foo exposing (bar, Baz, Quux(..))" + ) + , ( "doesn't work without something after the `exposing` keyword" + , "import Foo exposing" + ) + ] + ) + ] + + +moduleName : Test +moduleName = + describe "Stage.Parse.Parser.moduleName" + (List.map runTest + [ ( "works with simple module name" + , "Foo" + ) + , ( "doesn't work with lower-case name" + , "foo" + ) + , ( "doesn't work with dot at the end" + , "Foo." + ) + , ( "works with dotted module name" + , "Foo.Bar" + ) + , ( "works with doubly-dotted module name" + , "Foo.Bar.Baz" + ) + , ( "doesn't work with lower-case letter after the dot" + , "Foo.bar" + ) + ] + ) + + +singleQuote : String -> String +singleQuote txt = + "'" ++ txt ++ "'" + + +doubleQuote : String -> String +doubleQuote txt = + "\"" ++ txt ++ "\"" + + +tripleQuote : String -> String +tripleQuote txt = + "\"\"\"" ++ txt ++ "\"\"\"" + + +expr : Test +expr = + let + runSection ( description, tests ) = + describe description + (List.map runTest tests) + in + describe "Stage.Parse.Parser.expr" + (List.map runSection + [ ( "lambda" + , [ ( "works with single argument" + , "\\x -> x + 1" + ) + , ( "multiline" + , """ + \\x -> + x + 1 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "works with multiple arguments" + , "\\x y -> x + y" + ) + ] + ) + , ( "call" + , [ ( "simple" + , "fn 1" + ) + , ( "with var" + , "fn arg" + ) + , ( "multiple" + , "fn arg1 arg2" + ) + , ( "space not needed if parenthesized arg" + , "fn(arg1)" + ) + , ( "multiline" + , """ + fn + arg1 + arg2 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + ] + ) + , ( "if" + , [ ( "with one space" + , "if 1 then 2 else 3" + ) + , ( "with multiple spaces" + , "if 1 then 2 else 3" + ) + , ( "multiline" + , """ + if 1 then + 2 + else + 3 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + ] + ) + , ( "literal int" + , [ ( "positive" + , "123" + ) + , ( "zero" + , "0" + ) + , ( "negative zero" + , "-0" + ) + , ( "hexadecimal int" + , "0x123abc" + ) + , ( "hexadecimal int - uppercase" + , "0x789DEF" + ) + , ( "hexadecimal int - mixed case" + , "0x789dEf" + ) + , ( "negative int" + , "-42" + ) + , ( "negative hexadecimal" + , "-0x123abc" + ) + , ( "starting with zero disallowed" + , "0123" + ) + , ( "e is interpreted as hex 14, not scientific notation" + , "0xABCe5" + ) + ] + ) + , ( "literal float" + , [ ( "positive" + , "12.3" + ) + , ( "zero" + , "0.0" + ) + , ( "negative zero" + , "-0.0" + ) + , ( "negative float" + , "-4.2" + ) + , ( "Scientific notation" + , "5e2" + ) + , ( "Scientific notation with dot" + , "5.12e2" + ) + , ( "Uppercase scientific notation" + , "5.12E2" + ) + , ( "Negative scientific notation" + , "-5.12e2" + ) + , ( "Exponent with explicit plus sign" + , "5e+2" + ) + , ( "Uppercase E and exponent with explicit plus sign" + , "5E+2" + ) + , ( "Negative exponent" + , "5e-2" + ) + , ( "Zero - exhibit 1" + , "0.0e5" + ) + , ( "Zero - exhibit 2" + , "0e5" + ) + , ( "starting with dot disallowed" + , ".123" + ) + , ( "ending with dot disallowed" + , "123." + ) + ] + ) + , ( "literal char" + , [ ( "number" + , "'1'" + ) + , ( "space" + , "' '" + ) + , ( "newline shouldn't work" + , "'\n'" + ) + , ( "letter lowercase" + , "'a'" + ) + , ( "letter uppercase" + , "'A'" + ) + + -- https://github.com/elm/compiler/blob/dcbe51fa22879f83b5d94642e117440cb5249bb1/compiler/src/Parse/String.hs#L279-L285 + , ( "escape backslash" + , singleQuote "\\\\" + ) + , ( "escape n" + , singleQuote "\\n" + ) + , ( "escape r" + , singleQuote "\\r" + ) + , ( "escape t" + , singleQuote "\\t" + ) + , ( "double quote" + , singleQuote "\"" + ) + , ( "single quote" + , singleQuote "\\'" + ) + , ( "emoji" + , singleQuote "😃" + ) + , ( "escaped unicode code point" + , singleQuote "\\u{1F648}" + ) + ] + ) + , ( "literal string" + , [ ( "empty" + , doubleQuote "" + ) + , ( "one space" + , doubleQuote " " + ) + , ( "newline shouldn't work" + , doubleQuote "\n" + ) + , ( "two numbers" + , doubleQuote "42" + ) + , ( "single quote" + , doubleQuote "'" + ) + , ( "double quote" + , doubleQuote "\\\"" + ) + , ( "escape backslash" + , doubleQuote "\\\\" + ) + , ( "escape n" + , doubleQuote "\\n" + ) + , ( "escape r" + , doubleQuote "\\r" + ) + , ( "escape t" + , doubleQuote "\\t" + ) + , ( "emoji" + , doubleQuote "😃" + ) + , ( "escaped unicode code point" + , doubleQuote "\\u{1F648}" + ) + , ( "combo of escapes and chars" + , doubleQuote "\\u{1F648}\\n\\r\\t\\\\abc123" + ) + ] + ) + , ( "literal multiline string" + , [ ( "empty" + , tripleQuote "" + ) + , ( "one space" + , tripleQuote " " + ) + , ( "newline" + , tripleQuote "\n" + ) + , ( "two numbers" + , tripleQuote "42" + ) + , ( "single quote" + , tripleQuote "'" + ) + , ( "double quote" + , tripleQuote " \" " + ) + , ( "escape backslash" + , tripleQuote "\\\\" + ) + , ( "escape n" + , tripleQuote "\\n" + ) + , ( "escape r" + , tripleQuote "\\r" + ) + , ( "escape t" + , tripleQuote "\\t" + ) + , ( "emoji" + , tripleQuote "😃" + ) + , ( "escaped unicode code point" + , tripleQuote "\\u{1F648}" + ) + , ( "combo of escapes, newlines, and chars" + , tripleQuote "\\u{1F648}\\n\n\n\\r\\t\\\\abc123" + ) + ] + ) + , ( "literal bool" + , [ ( "True" + , "True" + ) + , ( "False" + , "False" + ) + ] + ) + , ( "let" + , [ ( "one liner" + , "let x = 1 in 2" + ) + , ( "one binding, generous whitespace" + , """ + let + x = + 1 + in + 2 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "doesn't allow bindings on the same indentation level as `let`" + , """ + let + x = 1 + in + 2 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "allows result expr on the same indentation level as `let`" + , """ + let + x = 1 + in + 2 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "multiple bindings" + , """ + let + x = 1 + y = 2 + in + 3 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "doesn't allow bindings to have different indentation from each other" + , """ + let + x = 1 + y = 2 + in + 3 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "doesn't allow bindings to have different indentation from each other - the other way" + , """ + let + x = 1 + y = 2 + in + 3 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "one binding that's used in the body" + , """ + let + x = 2 + in + 1 + x + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "two bindings where one is dependent on the other" + , """ + let + x = 2 + y = x + 1 + in + 42 + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + ] + ) + , ( "list" + , [ ( "empty list" + , "[]" + ) + , ( "empty list with inner spaces" + , "[ ]" + ) + , ( "single item in list" + , "[1]" + ) + , ( "single item in list with inner spaces" + , "[ 1 ]" + ) + , ( "simple list" + , "[1,2,3]" + ) + , ( "simple list with inner spaces" + , "[ 1, 2 , 3 ]" + ) + , ( "list concat" + , "[] ++ []" + ) + , ( "multiline" + , """ + [ 1 + , 2 + , 3 + ] + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + ] + ) + , ( "unit" + , [ ( "simple case" + , "()" + ) + ] + ) + , ( "tuple" + , [ ( "without spaces" + , "(1,2)" + ) + , ( "with inner spaces" + , "( 3 , 4 )" + ) + , ( "nested tuple" + , "(5,(6,7))" + ) + ] + ) + , ( "tuple3" + , [ ( "without spaces" + , "(1,2,3)" + ) + , ( "with inner spaces" + , "( 4 , 5 , 6 )" + ) + ] + ) + , ( "cons" + , [ ( "simple case" + , "1 :: []" + ) + , ( "multiple values case" + , "1 :: 2 :: []" + ) + , ( "no spaces" + , "1::[]" + ) + , ( "multiple spaces" + , "1 :: []" + ) + ] + ) + , ( "record" + , [ ( "empty record" + , "{}" + ) + , ( "empty record with spaces" + , "{ }" + ) + , ( "one field record" + , "{ a = 42 }" + ) + , ( "one field record without spaces" + , "{a=42}" + ) + , ( "two fields record" + , """{ a = 42, b = "hello" }""" + ) + , ( "multiline" + , """ + { a = 42 + , b = "hello" + } + """ + ) + ] + ) + , ( "case" + , [ ( "simple case" + , "case True of _->True" + ) + , ( "multiline case" + , """ + case 21 of + 31 -> True + 5 -> True + 0xABC -> True + _ -> False + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "complex case" + , """ + case arg of + ('c', 23) -> + True + ("string") -> + True + ((arg1, arg2), 435.4) -> + False + [_, 45, (67.7)] -> + False + fst :: snd :: tail -> + False + ({ count } as alias1) as alias2 -> + False + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + ] + ) + ] + ) + + +expectEqualParseResult : + String + -> a + -> Result (List (P.DeadEnd Never LexProblem)) a + -> Expectation +expectEqualParseResult input expected actual = + case actual of + Err deadEnds -> + Expect.fail + (String.join "\n" + (input + :: "===>" + :: "Err" + :: List.map deadEndToString deadEnds + ) + ) + + Ok actual_ -> + actual_ + |> Expect.equal expected + + +deadEndToString : P.DeadEnd Never LexProblem -> String +deadEndToString deadEnd = + "\n(" + ++ String.fromInt (deadEnd.row - 1) + ++ "," + ++ String.fromInt (deadEnd.col - 1) + ++ ") " + ++ Debug.toString deadEnd.problem + + + +type_ : Test +type_ = + describe "Stage.Parse.Parser.type_" + (List.map runTest + [ ( "int", "Int") + , ( "unit", "()") + , ( "type var a", "a") + , ( "function" + , "Int -> ()" + ) + , ( "multiple-arg function" + , "Int -> () -> Char" + ) + , ( "float", "Float") + , ( "char", "Char") + , ( "string", "String") + , ( "bool", "Bool") + , ( "list", "List ()") + , ( "tuple" + , "(Int, String)" + ) + , ( "tuple with different whitespace" + , "( Int,String )" + ) + , ( "tuple with yet different whitespace" + , "( Int , String )" + ) + , ( "tuple3" + , "(Int, String, Bool)" + ) + , ( "custom type or alias" + , "NonemptyList" + ) + , ( "parametric type" + , "Maybe a" + ) + , ( "qualified custom type" + , "Foo.Bar" + ) + , ( "qualified custom type with params" + , "Foo.Bar a Int" + ) + , ( "empty record" + , "{}" + ) + , ( "empty record with whitespace" + , "{ }" + ) + , ( "record with one field" + , "{ x : Int }" + ) + , ( "record with two fields" + , "{ x : Int, y : String }" + ) + , ( "multiline record" + , """ + { x : Int + , y : String + } + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "parenthesized type" + , "(Int)" + ) + , ( "parenthesized type with whitespace" + , "( Int )" + ) + ] + ) +valueDeclaration : Test +valueDeclaration = + -- TODO add various whitespace behavior tests + describe "Stage.Parse.Parser.valueDeclaration" <| + List.map runTest + [ ( "simple without annotation" + , "x = ()" + ) + , ( "simple with annotation" + , """ + y : () + y = () + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "user defined type with argument - newline+space" + , """ + x : Foo + () + x = () + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "user defined type with argument - newline only" + , """ + x : Foo + () + x = () + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "type on a newline+space" + , """ + x : + () + x = () + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + , ( "type on a newline without space" + , """ + x : + () + x = () + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + ] +typeAliasDeclaration : Test +typeAliasDeclaration = + describe "Stage.Parse.Parser.typeAliasDeclaration" <| + List.map runTest <| + [ ( "simple" + , "type alias Foo = ()" + ) + , ( "with params" + , "type alias Bar a = ()" + ) + , ( "a bit more advanced" + , "type alias Foo = Maybe Int" + ) + , {- TODO create integration test that this fails + (`a` on right must be present on the left too) + -} + ( "to something that itself has params" + , "type alias Foo = Maybe a" + ) + , ( "params on both sides" + , "type alias Foo a = Maybe a" + ) + ] +customTypeDeclaration : Test +customTypeDeclaration = + describe "Stage.Parse.Parser.customTypeDeclaration" <| + List.map runTest <| + [ ( "simple" + , "type Foo = Bar" + ) + , ( "with params" + , "type Bar a = Baz" + ) + , ( "a bit more advanced" + , "type Foo = Bar Int" + ) + , {- TODO create integration test that this fails + (`a` on right must be present on the left too) + -} + ( "to something that itself has parameters" + , "type Foo = Bar a" + ) + , ( "params on both sides" + , "type Foo a = Bar (Maybe a)" + ) + , ( "multiple constructors" + , "type Foo = Bar | Baz" + ) + ] +portDeclaration : Test +portDeclaration = + describe "Stage.Parse.Parser.portDeclaration" <| + List.map runTest <| + [ ( "outgoing" + , "port foo : String -> Cmd msg" + ) + , ( "incoming" + , "port bar : (String -> msg) -> Sub msg" + ) + , ( "wacky multiline" + , """ + port + foo + : + String -> Cmd msg + """ + |> String.unindent + |> String.removeNewlinesAtEnds + ) + ] From 1dacf19c1d9d5dfd5a5842f638314d40969fcbbb Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Wed, 5 Aug 2020 20:39:20 +0100 Subject: [PATCH 002/103] add some operator tests --- tests/LexerTest.elm | 48 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 38 insertions(+), 10 deletions(-) diff --git a/tests/LexerTest.elm b/tests/LexerTest.elm index afd5370c..a3f7457f 100644 --- a/tests/LexerTest.elm +++ b/tests/LexerTest.elm @@ -825,6 +825,27 @@ expr = ) ] ) + , ( "operators" + , [ ( "add" + , "5 + 5" + ) + , ( "sub" + , """ + 6 - 10 + """ + ) + , ( "unary subtract" + , """ + - hello + """ + ) + , ( "chained" + , """ + 5 *5 + 8 + 1 - (4 + 7) ^ 2 + """ + ) + ] + ) ] ) @@ -861,28 +882,27 @@ deadEndToString deadEnd = ++ Debug.toString deadEnd.problem - type_ : Test type_ = describe "Stage.Parse.Parser.type_" (List.map runTest - [ ( "int", "Int") - , ( "unit", "()") - , ( "type var a", "a") + [ ( "int", "Int" ) + , ( "unit", "()" ) + , ( "type var a", "a" ) , ( "function" , "Int -> ()" ) , ( "multiple-arg function" , "Int -> () -> Char" ) - , ( "float", "Float") - , ( "char", "Char") - , ( "string", "String") - , ( "bool", "Bool") - , ( "list", "List ()") + , ( "float", "Float" ) + , ( "char", "Char" ) + , ( "string", "String" ) + , ( "bool", "Bool" ) + , ( "list", "List ()" ) , ( "tuple" , "(Int, String)" - ) + ) , ( "tuple with different whitespace" , "( Int,String )" ) @@ -933,6 +953,8 @@ type_ = ) ] ) + + valueDeclaration : Test valueDeclaration = -- TODO add various whitespace behavior tests @@ -986,6 +1008,8 @@ valueDeclaration = |> String.removeNewlinesAtEnds ) ] + + typeAliasDeclaration : Test typeAliasDeclaration = describe "Stage.Parse.Parser.typeAliasDeclaration" <| @@ -1009,6 +1033,8 @@ typeAliasDeclaration = , "type alias Foo a = Maybe a" ) ] + + customTypeDeclaration : Test customTypeDeclaration = describe "Stage.Parse.Parser.customTypeDeclaration" <| @@ -1035,6 +1061,8 @@ customTypeDeclaration = , "type Foo = Bar | Baz" ) ] + + portDeclaration : Test portDeclaration = describe "Stage.Parse.Parser.portDeclaration" <| From 39d05271183d03a4366374a07737e201fb916fde Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Wed, 5 Aug 2020 21:26:08 +0100 Subject: [PATCH 003/103] drop the Binary from BinaryOperator The lexer has no idea whether an operator is binary or not! Let's not pretend it does --- src/Stage/Parse/Lexer.elm | 56 +++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 3827875a..ec0c021f 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -27,7 +27,7 @@ type LexSigil | Backslash | Underscore | Colon - | BinaryOperator LexBinaryOperator + | Operator LexOperator type LexCommentType @@ -36,7 +36,7 @@ type LexCommentType | DocComment -type LexBinaryOperator +type LexOperator = Add | Subtract | Multiply @@ -140,43 +140,43 @@ toString item = Sigil Underscore -> "_" - Sigil (BinaryOperator Add) -> + Sigil (Operator Add) -> "+" - Sigil (BinaryOperator Subtract) -> + Sigil (Operator Subtract) -> "-" - Sigil (BinaryOperator Multiply) -> + Sigil (Operator Multiply) -> "*" - Sigil (BinaryOperator Divide) -> + Sigil (Operator Divide) -> "/" - Sigil (BinaryOperator Exponentiate) -> + Sigil (Operator Exponentiate) -> "^" - Sigil (BinaryOperator And) -> + Sigil (Operator And) -> "&&" - Sigil (BinaryOperator Or) -> + Sigil (Operator Or) -> "||" - Sigil (BinaryOperator Equals) -> + Sigil (Operator Equals) -> "==" - Sigil (BinaryOperator GreaterThan) -> + Sigil (Operator GreaterThan) -> ">" - Sigil (BinaryOperator GreaterThanEquals) -> + Sigil (Operator GreaterThanEquals) -> ">=" - Sigil (BinaryOperator LessThan) -> + Sigil (Operator LessThan) -> "<" - Sigil (BinaryOperator LessThanEquals) -> + Sigil (Operator LessThanEquals) -> "<=" - Sigil (BinaryOperator Append) -> + Sigil (Operator Append) -> "++" Token s -> @@ -374,19 +374,19 @@ sigilParser = P.oneOf [ -- Two character sigils (must come first) P.symbol (P.Token "&&" ExpectingSigil) - |> P.map (\() -> BinaryOperator And) + |> P.map (\() -> Operator And) , P.symbol (P.Token "++" ExpectingSigil) - |> P.map (\() -> BinaryOperator Append) + |> P.map (\() -> Operator Append) , P.symbol (P.Token "==" ExpectingSigil) - |> P.map (\() -> BinaryOperator Equals) + |> P.map (\() -> Operator Equals) , P.symbol (P.Token "||" ExpectingSigil) - |> P.map (\() -> BinaryOperator Or) + |> P.map (\() -> Operator Or) , P.symbol (P.Token ".." ExpectingSigil) |> P.map (\() -> DoubleDot) -- Single character sigils , P.symbol (P.Token "^" ExpectingSigil) - |> P.map (\() -> BinaryOperator Exponentiate) + |> P.map (\() -> Operator Exponentiate) , P.symbol (P.Token "\\" ExpectingSigil) |> P.map (\() -> Backslash) , P.symbol (P.Token "_" ExpectingSigil) @@ -396,23 +396,23 @@ sigilParser = , P.symbol (P.Token ")" ExpectingSigil) |> P.map (\() -> Bracket Round Close) , P.symbol (P.Token ">" ExpectingSigil) - |> P.map (\() -> BinaryOperator GreaterThan) + |> P.map (\() -> Operator GreaterThan) , P.symbol (P.Token "<" ExpectingSigil) - |> P.map (\() -> BinaryOperator LessThan) + |> P.map (\() -> Operator LessThan) , P.symbol (P.Token ">=" ExpectingSigil) - |> P.map (\() -> BinaryOperator GreaterThanEquals) + |> P.map (\() -> Operator GreaterThanEquals) , P.symbol (P.Token "<=" ExpectingSigil) - |> P.map (\() -> BinaryOperator LessThanEquals) + |> P.map (\() -> Operator LessThanEquals) , P.symbol (P.Token "-" ExpectingSigil) - |> P.map (\() -> BinaryOperator Subtract) + |> P.map (\() -> Operator Subtract) , P.symbol (P.Token "+" ExpectingSigil) - |> P.map (\() -> BinaryOperator Add) + |> P.map (\() -> Operator Add) , P.symbol (P.Token "=" ExpectingSigil) |> P.map (\() -> Assign) , P.symbol (P.Token "/" ExpectingSigil) - |> P.map (\() -> BinaryOperator Divide) + |> P.map (\() -> Operator Divide) , P.symbol (P.Token "*" ExpectingSigil) - |> P.map (\() -> BinaryOperator Multiply) + |> P.map (\() -> Operator Multiply) , P.symbol (P.Token "{" ExpectingSigil) |> P.map (\() -> Bracket Curly Open) , P.symbol (P.Token "[" ExpectingSigil) From 1e094575089647fa89626971d1957e2aedf4eb73 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 24 Sep 2020 08:22:48 +0100 Subject: [PATCH 004/103] sketch of contextualising --- src/Stage/Parse/Contextualize.elm | 244 ++++++++++++++++++++++++++++++ src/Stage/Parse/Lexer.elm | 52 +++++-- src/Stage/Parse/Token.elm | 103 +++++++++++++ 3 files changed, 390 insertions(+), 9 deletions(-) create mode 100644 src/Stage/Parse/Contextualize.elm create mode 100644 src/Stage/Parse/Token.elm diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm new file mode 100644 index 00000000..5eb32959 --- /dev/null +++ b/src/Stage/Parse/Contextualize.elm @@ -0,0 +1,244 @@ +module Stage.Parse.Contextualize exposing (..) + +import Elm.AST.Frontend as Frontend exposing (Expr(..), LocatedExpr, LocatedPattern, Pattern(..)) +import Elm.Data.Declaration +import Elm.Data.Exposing +import Elm.Data.Located as Located exposing (Located) +import Elm.Data.Module exposing (Module, ModuleType(..)) +import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) +import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) +import Elm.Data.TypeAnnotation exposing (TypeAnnotation) +import Elm.Data.VarName exposing (VarName) +import Stage.Parse.Lexer as Lexer exposing (LexItem) +import Stage.Parse.Token as Token exposing (Keyword) + + +{-| An 'block' starts with an unindented line and continues until the next +unindented line. + +In the following Program + + module Main exposing (..) + + -- 0 + + import Dict + + + -- 1 + type + A + -- 2 + = A -- 2 + + a : A + + -- 3 + a = + -- 4 + A + + -- 4 + +There are five blocks. + +-} +type Block + = Module + { ty : Elm.Data.Module.ModuleType + , name : Elm.Data.ModuleName.ModuleName + , exposingList : Elm.Data.Exposing.Exposing + } + | CustomType + { ty : VarName + , constructors : List (Elm.Data.Declaration.Constructor PossiblyQualified) + } + + +type State + = StateBlockStart + | StateErrorRecovery + | StateBlockFirstItem BlockFirstItem + | StateBlockSecondItem BlockSecondItem + + +type alias State_ = + { previousBlocks : List (Result ( State, Error ) Block) + , state : State + } + + +type BlockFirstItem + = BlockFirstItemType + | BlockFirstItemModule + | BlockFirstItemName Token.ValueOrFunction + + +type BlockSecondItem + = BlockSecondItemTypeAlias + | BlockSecondItemCustomTypeNamed Token.TypeOrConstructor + + +type Error + = ErrorInvalidToken LexItem + | ErrorMisplacedKeyword Keyword + | BlockStartsWithTypeOrConstructor Token.TypeOrConstructor + | TypeNameStartsWithLowerCase Token.ValueOrFunction + | Panic String + + +parser : List LexItem -> List (Result ( State, Error ) Block) +parser items = + parserHelp + items + { previousBlocks = [] + , state = StateBlockStart + } + + +parserHelp : List LexItem -> State_ -> List (Result ( State, Error ) Block) +parserHelp items state = + case items of + item :: rest -> + let + newState = + case state.state of + StateErrorRecovery -> + parseBlockStart item + |> Result.withDefault StateErrorRecovery + |> Ok + + StateBlockStart -> + parseBlockStart item + + StateBlockFirstItem BlockFirstItemType -> + parseTypeBlock item + + StateBlockFirstItem BlockFirstItemModule -> + Debug.todo "" + + StateBlockFirstItem (BlockFirstItemName name) -> + Debug.todo "" + + StateBlockSecondItem BlockSecondItemTypeAlias -> + Debug.todo "" + + StateBlockSecondItem (BlockSecondItemCustomTypeNamed name) -> + Debug.todo "" + in + case newState of + Ok newState_ -> + parserHelp rest { previousBlocks = state.previousBlocks, state = newState_ } + + Err error -> + parserHelp + rest + { previousBlocks = Err ( state.state, error ) :: state.previousBlocks + , state = StateErrorRecovery + } + + [] -> + List.reverse state.previousBlocks + + +{-| + + +### Panics + +If the LexItem is `Newlines`. + +-} +parseBlockStart : LexItem -> Result Error State +parseBlockStart item = + case item of + Lexer.Token str -> + case Token.classifyToken str of + Token.TokenKeyword Token.Type -> + Ok (StateBlockFirstItem BlockFirstItemType) + + Token.TokenKeyword Token.Module -> + Ok (StateBlockFirstItem BlockFirstItemModule) + + Token.TokenKeyword other -> + Err (ErrorMisplacedKeyword other) + + Token.TokenValueOrFunction valOrFunc -> + Ok (StateBlockFirstItem (BlockFirstItemName valOrFunc)) + + Token.TokenTypeOrConstructor typeOrConstructor -> + Err (BlockStartsWithTypeOrConstructor typeOrConstructor) + + Lexer.Newlines _ _ -> + Ok StateBlockStart + + _ -> + Err (ErrorInvalidToken item) + + +parseTypeBlock : LexItem -> Result Error State +parseTypeBlock item = + case item of + Lexer.Token str -> + case Token.classifyToken str of + Token.TokenKeyword Token.Alias -> + Ok (StateBlockSecondItem BlockSecondItemTypeAlias) + + Token.TokenKeyword other -> + Err (ErrorMisplacedKeyword other) + + Token.TokenTypeOrConstructor typeOrConstructor -> + Ok (StateBlockSecondItem (BlockSecondItemCustomTypeNamed typeOrConstructor)) + + Token.TokenValueOrFunction valOrFunc -> + Err (TypeNameStartsWithLowerCase valOrFunc) + + Lexer.Newlines _ 0 -> + Ok StateBlockStart + + Lexer.Newlines _ _ -> + Ok (StateBlockFirstItem BlockFirstItemType) + + _ -> + Err (ErrorInvalidToken item) + + +parserTypeAlias : LexItem -> Result Error State +parserTypeAlias item = + case item of + Lexer.Token str -> + case Token.classifyToken str of + Token.TokenKeyword other -> + Err (ErrorMisplacedKeyword other) + + Token.TokenTypeOrConstructor typeOrConstructor -> + Ok (StateBlockSecondItem (BlockSecondItemCustomTypeNamed typeOrConstructor)) + + Token.TokenValueOrFunction valOrFunc -> + Err (TypeNameStartsWithLowerCase valOrFunc) + + Lexer.Newlines _ 0 -> + Ok StateBlockStart + + Lexer.Newlines _ _ -> + Ok (StateBlockSecondItem BlockSecondItemTypeAlias) + + _ -> + Err (ErrorInvalidToken item) + + +blockFromState : State -> Result Error (Maybe Block) +blockFromState state = + case state of + StateErrorRecovery -> + Ok Nothing + + StateBlockStart -> + Ok Nothing + + StateBlockFirstItem firstItem -> + Debug.todo "handle incomplete block" + + StateBlockSecondItem firstItem -> + Debug.todo "handle incomplete block" diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index ec0c021f..29996b7e 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -11,7 +11,7 @@ type LexItem | NumericLiteral String | TextLiteral LexLiteralType String | Whitespace Int - | Newline Int + | Newlines (List Int) Int | Comment LexCommentType String | Invalid String @@ -191,8 +191,13 @@ toString item = Whitespace i -> String.repeat i " " - Newline i -> - "\n" ++ String.repeat i " " + Newlines empties identationSpaces -> + (empties + |> List.map (\spacesInEmptyLine -> "\n" ++ String.repeat spacesInEmptyLine " ") + |> String.join "" + ) + ++ "\n" + ++ String.repeat identationSpaces " " Comment LineComment s -> "//" ++ s @@ -256,12 +261,8 @@ parser = , P.symbol (P.Token " " ExpectingWhitespace) |> P.andThen (\() -> chompSpacesAndCount) |> P.map (\count -> Whitespace (count + 1)) - , P.oneOf - [ P.symbol (P.Token "\n\u{000D}" ExpectingNewline) - , P.symbol (P.Token "\n" ExpectingNewline) - ] - |> P.andThen (\() -> chompSpacesAndCount) - |> P.map Newline + , newlinesParser + |> P.map (\( emptyLines, indentation ) -> Newlines emptyLines indentation) ] |> List.map (located >> P.map (\t -> P.Loop (t :: reversed))) ) @@ -271,6 +272,39 @@ parser = ) +newlinesParser : Parser_ ( List Int, Int ) +newlinesParser = + let + eolParser = + P.oneOf + [ P.symbol (P.Token "\n\u{000D}" ExpectingNewline) + , P.symbol (P.Token "\n" ExpectingNewline) + ] + in + eolParser + |> P.andThen + (\() -> + P.loop + [] + (\reversed -> + P.succeed + (\spacesOnThisLine isThisLineEmpty -> + if isThisLineEmpty then + P.Loop (spacesOnThisLine :: reversed) + + else + P.Done ( List.reverse reversed, spacesOnThisLine ) + ) + |= chompSpacesAndCount + |= P.oneOf + [ eolParser + |> P.map (\() -> True) + , P.succeed False + ] + ) + ) + + chompSpacesAndCount : Parser_ Int chompSpacesAndCount = P.chompWhile (\c -> c == ' ') diff --git a/src/Stage/Parse/Token.elm b/src/Stage/Parse/Token.elm new file mode 100644 index 00000000..b3c5fa33 --- /dev/null +++ b/src/Stage/Parse/Token.elm @@ -0,0 +1,103 @@ +module Stage.Parse.Token exposing (..) + + +type Keyword + = Module + | Type + | Alias + | Exposing + | Case + | Of + | If + | Then + | Else + + +type TypeOrConstructor + = TypeOrConstructor String + + +type ValueOrFunction + = ValueOrFunction String + + +type Token + = TokenTypeOrConstructor TypeOrConstructor + | TokenValueOrFunction ValueOrFunction + | TokenKeyword Keyword + + +keywordToString : Keyword -> String +keywordToString keyword = + case keyword of + Module -> + "module" + + Type -> + "type" + + Alias -> + "alias" + + Exposing -> + "exposing" + + Case -> + "case" + + Of -> + "of" + + If -> + "if" + + Then -> + "then" + + Else -> + "else" + + +{-| Note: empty strings become `ValueOrFunction`s +-} +classifyToken : String -> Token +classifyToken token = + case token of + "module" -> + TokenKeyword Module + + "type" -> + TokenKeyword Type + + "alias" -> + TokenKeyword Alias + + "exposing" -> + TokenKeyword Exposing + + "case" -> + TokenKeyword Case + + "of" -> + TokenKeyword Of + + "if" -> + TokenKeyword If + + "then" -> + TokenKeyword Then + + "else" -> + TokenKeyword Else + + _ -> + case String.uncons token of + Just ( first, _ ) -> + if Char.isUpper first then + TokenTypeOrConstructor (TypeOrConstructor token) + + else + TokenValueOrFunction (ValueOrFunction token) + + Nothing -> + TokenValueOrFunction (ValueOrFunction token) From 664bc01a4afe11e754ccf4761591713e824d1286 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 24 Sep 2020 08:27:18 +0100 Subject: [PATCH 005/103] prefix constructors with custom type name We will have a lot of constructors and this namespacing will help tell them apart. --- src/Stage/Parse/Contextualize.elm | 96 +++++++++++++++---------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 5eb32959..bfbb05c4 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -57,10 +57,10 @@ type Block type State - = StateBlockStart - | StateErrorRecovery - | StateBlockFirstItem BlockFirstItem - | StateBlockSecondItem BlockSecondItem + = State_BlockStart + | State_Error_Recovery + | State_BlockFirstItem BlockFirstItem + | State_BlockSecondItem BlockSecondItem type alias State_ = @@ -70,22 +70,22 @@ type alias State_ = type BlockFirstItem - = BlockFirstItemType - | BlockFirstItemModule - | BlockFirstItemName Token.ValueOrFunction + = BlockFirstItem_Type + | BlockFirstItem_Module + | BlockFirstItem_Name Token.ValueOrFunction type BlockSecondItem - = BlockSecondItemTypeAlias - | BlockSecondItemCustomTypeNamed Token.TypeOrConstructor + = BlockSecondItem_TypeAlias + | BlockSecondItem_CustomTypeNamed Token.TypeOrConstructor type Error - = ErrorInvalidToken LexItem - | ErrorMisplacedKeyword Keyword - | BlockStartsWithTypeOrConstructor Token.TypeOrConstructor - | TypeNameStartsWithLowerCase Token.ValueOrFunction - | Panic String + = Error_InvalidToken LexItem + | Error_MisplacedKeyword Keyword + | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor + | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction + | Error_Panic String parser : List LexItem -> List (Result ( State, Error ) Block) @@ -93,7 +93,7 @@ parser items = parserHelp items { previousBlocks = [] - , state = StateBlockStart + , state = State_BlockStart } @@ -104,27 +104,27 @@ parserHelp items state = let newState = case state.state of - StateErrorRecovery -> + State_Error_Recovery -> parseBlockStart item - |> Result.withDefault StateErrorRecovery + |> Result.withDefault State_Error_Recovery |> Ok - StateBlockStart -> + State_BlockStart -> parseBlockStart item - StateBlockFirstItem BlockFirstItemType -> + State_BlockFirstItem BlockFirstItem_Type -> parseTypeBlock item - StateBlockFirstItem BlockFirstItemModule -> + State_BlockFirstItem BlockFirstItem_Module -> Debug.todo "" - StateBlockFirstItem (BlockFirstItemName name) -> + State_BlockFirstItem (BlockFirstItem_Name name) -> Debug.todo "" - StateBlockSecondItem BlockSecondItemTypeAlias -> + State_BlockSecondItem BlockSecondItem_TypeAlias -> Debug.todo "" - StateBlockSecondItem (BlockSecondItemCustomTypeNamed name) -> + State_BlockSecondItem (BlockSecondItem_CustomTypeNamed name) -> Debug.todo "" in case newState of @@ -135,7 +135,7 @@ parserHelp items state = parserHelp rest { previousBlocks = Err ( state.state, error ) :: state.previousBlocks - , state = StateErrorRecovery + , state = State_Error_Recovery } [] -> @@ -156,25 +156,25 @@ parseBlockStart item = Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword Token.Type -> - Ok (StateBlockFirstItem BlockFirstItemType) + Ok (State_BlockFirstItem BlockFirstItem_Type) Token.TokenKeyword Token.Module -> - Ok (StateBlockFirstItem BlockFirstItemModule) + Ok (State_BlockFirstItem BlockFirstItem_Module) Token.TokenKeyword other -> - Err (ErrorMisplacedKeyword other) + Err (Error_MisplacedKeyword other) Token.TokenValueOrFunction valOrFunc -> - Ok (StateBlockFirstItem (BlockFirstItemName valOrFunc)) + Ok (State_BlockFirstItem (BlockFirstItem_Name valOrFunc)) Token.TokenTypeOrConstructor typeOrConstructor -> - Err (BlockStartsWithTypeOrConstructor typeOrConstructor) + Err (Error_BlockStartsWithTypeOrConstructor typeOrConstructor) Lexer.Newlines _ _ -> - Ok StateBlockStart + Ok State_BlockStart _ -> - Err (ErrorInvalidToken item) + Err (Error_InvalidToken item) parseTypeBlock : LexItem -> Result Error State @@ -183,25 +183,25 @@ parseTypeBlock item = Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword Token.Alias -> - Ok (StateBlockSecondItem BlockSecondItemTypeAlias) + Ok (State_BlockSecondItem BlockSecondItem_TypeAlias) Token.TokenKeyword other -> - Err (ErrorMisplacedKeyword other) + Err (Error_MisplacedKeyword other) Token.TokenTypeOrConstructor typeOrConstructor -> - Ok (StateBlockSecondItem (BlockSecondItemCustomTypeNamed typeOrConstructor)) + Ok (State_BlockSecondItem (BlockSecondItem_CustomTypeNamed typeOrConstructor)) Token.TokenValueOrFunction valOrFunc -> - Err (TypeNameStartsWithLowerCase valOrFunc) + Err (Error_TypeNameStartsWithLowerCase valOrFunc) Lexer.Newlines _ 0 -> - Ok StateBlockStart + Ok State_BlockStart Lexer.Newlines _ _ -> - Ok (StateBlockFirstItem BlockFirstItemType) + Ok (State_BlockFirstItem BlockFirstItem_Type) _ -> - Err (ErrorInvalidToken item) + Err (Error_InvalidToken item) parserTypeAlias : LexItem -> Result Error State @@ -210,35 +210,35 @@ parserTypeAlias item = Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword other -> - Err (ErrorMisplacedKeyword other) + Err (Error_MisplacedKeyword other) Token.TokenTypeOrConstructor typeOrConstructor -> - Ok (StateBlockSecondItem (BlockSecondItemCustomTypeNamed typeOrConstructor)) + Ok (State_BlockSecondItem (BlockSecondItem_CustomTypeNamed typeOrConstructor)) Token.TokenValueOrFunction valOrFunc -> - Err (TypeNameStartsWithLowerCase valOrFunc) + Err (Error_TypeNameStartsWithLowerCase valOrFunc) Lexer.Newlines _ 0 -> - Ok StateBlockStart + Ok State_BlockStart Lexer.Newlines _ _ -> - Ok (StateBlockSecondItem BlockSecondItemTypeAlias) + Ok (State_BlockSecondItem BlockSecondItem_TypeAlias) _ -> - Err (ErrorInvalidToken item) + Err (Error_InvalidToken item) blockFromState : State -> Result Error (Maybe Block) blockFromState state = case state of - StateErrorRecovery -> + State_Error_Recovery -> Ok Nothing - StateBlockStart -> + State_BlockStart -> Ok Nothing - StateBlockFirstItem firstItem -> + State_BlockFirstItem firstItem -> Debug.todo "handle incomplete block" - StateBlockSecondItem firstItem -> + State_BlockSecondItem firstItem -> Debug.todo "handle incomplete block" From f926996312a336c2d06ba3b42991f631606b7a14 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 24 Sep 2020 14:09:36 +0100 Subject: [PATCH 006/103] we can parse "type alias Model = List Int"! --- src/Stage/Parse/Contextualize.elm | 533 +++++++++++++++++++++++++++--- src/Stage/Parse/Lexer.elm | 6 +- 2 files changed, 482 insertions(+), 57 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index bfbb05c4..981f1134 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -6,11 +6,11 @@ import Elm.Data.Exposing import Elm.Data.Located as Located exposing (Located) import Elm.Data.Module exposing (Module, ModuleType(..)) import Elm.Data.ModuleName exposing (ModuleName) -import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) +import Elm.Data.Qualifiedness as Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) import Elm.Data.TypeAnnotation exposing (TypeAnnotation) import Elm.Data.VarName exposing (VarName) -import Stage.Parse.Lexer as Lexer exposing (LexItem) +import Stage.Parse.Lexer as Lexer exposing (LexItem(..)) import Stage.Parse.Token as Token exposing (Keyword) @@ -50,6 +50,10 @@ type Block , name : Elm.Data.ModuleName.ModuleName , exposingList : Elm.Data.Exposing.Exposing } + | TypeAlias + { ty : Token.TypeOrConstructor + , expr : ConcreteType PossiblyQualified + } | CustomType { ty : VarName , constructors : List (Elm.Data.Declaration.Constructor PossiblyQualified) @@ -60,7 +64,8 @@ type State = State_BlockStart | State_Error_Recovery | State_BlockFirstItem BlockFirstItem - | State_BlockSecondItem BlockSecondItem + | State_BlockTypeAlias BlockTypeAlias + | State_BlockCustomType BlockCustomType type alias State_ = @@ -75,19 +80,84 @@ type BlockFirstItem | BlockFirstItem_Name Token.ValueOrFunction -type BlockSecondItem - = BlockSecondItem_TypeAlias - | BlockSecondItem_CustomTypeNamed Token.TypeOrConstructor +type BlockTypeAlias + = BlockTypeAlias_Keywords + | BlockTypeAlias_Named Token.TypeOrConstructor + | BlockTypeAlias_NamedAssigns Token.TypeOrConstructor + | BlockTypeAlias_Completish Token.TypeOrConstructor PartialTypeExpression2 + | BlockTypeAlias_Complete Token.TypeOrConstructor PartialTypeExpression + + +type BlockCustomType + = BlockCustomType_Named Token.TypeOrConstructor + | BlockCustomType_NamedAssigns Token.TypeOrConstructor + + +{-| Notes: + + - Type names can start with a lower case character as it may be generic. If + it is generic there should be no args (we do not check this currently + though :(). + +-} +type PartialTypeExpression + = TypeExpression_NamedType + { name : String + , args : Stack PartialTypeExpression + } + | TypeExpression_Unit + + +partialTypeExpressionToConcreteType : PartialTypeExpression -> ConcreteType PossiblyQualified +partialTypeExpressionToConcreteType pte = + case pte of + TypeExpression_NamedType { name, args } -> + ConcreteType.UserDefinedType + { qualifiedness = Qualifiedness.PossiblyQualified Nothing + , name = name + , args = + args + |> toList partialTypeExpressionToConcreteType + } + + TypeExpression_Unit -> + ConcreteType.Unit + + +type TypeExpressionContext + = TypeExpressionContext_Bracket Lexer.BracketType + | TypeExpressionContext_Alias + + +type alias PartialTypeExpression2 = + { stack : Stack ( TypeExpressionContext, Maybe PartialTypeExpression ) + , current : ( TypeExpressionContext, Maybe PartialTypeExpression ) + } + + +type TypeExpressionResult + = TypeExpressionResult_Progress PartialTypeExpression2 + | TypeExpressionResult_Done PartialTypeExpression + | TypeExpressionResult_Empty type Error - = Error_InvalidToken LexItem + = Error_InvalidToken LexItem Expecting | Error_MisplacedKeyword Keyword | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction + | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole + | Error_UnitTypeDoesTakeArgs PartialTypeExpression + | Error_PartwayThroughTypeAlias | Error_Panic String +type Expecting + = Expecting_Sigil Lexer.LexSigil + | Expecting_Block + | Expecting_TypeName + + parser : List LexItem -> List (Result ( State, Error ) Block) parser items = parserHelp @@ -99,47 +169,103 @@ parser items = parserHelp : List LexItem -> State_ -> List (Result ( State, Error ) Block) parserHelp items state = - case items of - item :: rest -> - let - newState = - case state.state of - State_Error_Recovery -> - parseBlockStart item - |> Result.withDefault State_Error_Recovery - |> Ok + let + newState = + case state.state of + State_Error_Recovery -> + parseBlockStart + >> Result.withDefault State_Error_Recovery + >> Ok + >> Just + + State_BlockStart -> + parseBlockStart + >> Just + + State_BlockFirstItem BlockFirstItem_Type -> + parseTypeBlock + + State_BlockFirstItem BlockFirstItem_Module -> + Debug.todo "" + + State_BlockFirstItem (BlockFirstItem_Name name) -> + Debug.todo "" + + State_BlockTypeAlias BlockTypeAlias_Keywords -> + parseTypeAliasName + + State_BlockTypeAlias (BlockTypeAlias_Named name) -> + parseAssignment + (State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name)) + + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name) -> + parserTypeExpr + (\res -> + case res of + TypeExpressionResult_Progress expr -> + State_BlockTypeAlias (BlockTypeAlias_Completish name expr) + + TypeExpressionResult_Done expr -> + State_BlockTypeAlias (BlockTypeAlias_Complete name expr) + + TypeExpressionResult_Empty -> + Debug.todo "" + ) + { current = ( TypeExpressionContext_Alias, Nothing ) + , stack = empty + } - State_BlockStart -> - parseBlockStart item + State_BlockTypeAlias (BlockTypeAlias_Completish name exprSoFar) -> + parserTypeExpr + (\res -> + case res of + TypeExpressionResult_Progress expr -> + State_BlockTypeAlias (BlockTypeAlias_Completish name expr) - State_BlockFirstItem BlockFirstItem_Type -> - parseTypeBlock item + TypeExpressionResult_Done expr -> + State_BlockTypeAlias (BlockTypeAlias_Complete name expr) - State_BlockFirstItem BlockFirstItem_Module -> - Debug.todo "" + TypeExpressionResult_Empty -> + Debug.todo "" + ) + exprSoFar - State_BlockFirstItem (BlockFirstItem_Name name) -> - Debug.todo "" + State_BlockTypeAlias (BlockTypeAlias_Complete name expr) -> + Debug.todo "" - State_BlockSecondItem BlockSecondItem_TypeAlias -> - Debug.todo "" + State_BlockCustomType (BlockCustomType_Named name) -> + parseAssignment + (State_BlockCustomType (BlockCustomType_NamedAssigns name)) - State_BlockSecondItem (BlockSecondItem_CustomTypeNamed name) -> - Debug.todo "" - in - case newState of - Ok newState_ -> + State_BlockCustomType (BlockCustomType_NamedAssigns name) -> + Debug.todo "" + in + case items of + item :: rest -> + case newState item of + Just (Ok newState_) -> parserHelp rest { previousBlocks = state.previousBlocks, state = newState_ } - Err error -> + Just (Err error) -> parserHelp rest { previousBlocks = Err ( state.state, error ) :: state.previousBlocks , state = State_Error_Recovery } + Nothing -> + parserHelp rest state + [] -> - List.reverse state.previousBlocks + List.reverse + (case blockFromState state.state of + Nothing -> + state.previousBlocks + + Just newBlock -> + (newBlock |> Result.mapError (\err -> ( state.state, err ))) + :: state.previousBlocks + ) {-| @@ -174,71 +300,370 @@ parseBlockStart item = Ok State_BlockStart _ -> - Err (Error_InvalidToken item) + Err (Error_InvalidToken item Expecting_Block) -parseTypeBlock : LexItem -> Result Error State +parseTypeBlock : LexItem -> Maybe (Result Error State) parseTypeBlock item = case item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword Token.Alias -> - Ok (State_BlockSecondItem BlockSecondItem_TypeAlias) + State_BlockTypeAlias BlockTypeAlias_Keywords + |> Ok + |> Just Token.TokenKeyword other -> - Err (Error_MisplacedKeyword other) + Error_MisplacedKeyword other + |> Err + |> Just Token.TokenTypeOrConstructor typeOrConstructor -> - Ok (State_BlockSecondItem (BlockSecondItem_CustomTypeNamed typeOrConstructor)) + State_BlockCustomType (BlockCustomType_Named typeOrConstructor) + |> Ok + |> Just Token.TokenValueOrFunction valOrFunc -> - Err (Error_TypeNameStartsWithLowerCase valOrFunc) + Error_TypeNameStartsWithLowerCase valOrFunc + |> Err + |> Just Lexer.Newlines _ 0 -> - Ok State_BlockStart + State_BlockStart + |> Ok + |> Just Lexer.Newlines _ _ -> - Ok (State_BlockFirstItem BlockFirstItem_Type) + State_BlockFirstItem BlockFirstItem_Type + |> Ok + |> Just + + Whitespace _ -> + Nothing _ -> - Err (Error_InvalidToken item) + -- TODO(harry) indicate that we could also be expecting the `alias` + -- keyword. + Error_InvalidToken item Expecting_TypeName + |> Err + |> Just -parserTypeAlias : LexItem -> Result Error State -parserTypeAlias item = +parseTypeAliasName : LexItem -> Maybe (Result Error State) +parseTypeAliasName item = case item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword other -> - Err (Error_MisplacedKeyword other) + Error_MisplacedKeyword other + |> Err + |> Just Token.TokenTypeOrConstructor typeOrConstructor -> - Ok (State_BlockSecondItem (BlockSecondItem_CustomTypeNamed typeOrConstructor)) + State_BlockTypeAlias (BlockTypeAlias_Named typeOrConstructor) + |> Ok + |> Just Token.TokenValueOrFunction valOrFunc -> - Err (Error_TypeNameStartsWithLowerCase valOrFunc) + Error_TypeNameStartsWithLowerCase valOrFunc + |> Err + |> Just Lexer.Newlines _ 0 -> - Ok State_BlockStart + State_BlockStart + |> Ok + |> Just Lexer.Newlines _ _ -> - Ok (State_BlockSecondItem BlockSecondItem_TypeAlias) + Nothing + + Lexer.Whitespace _ -> + Nothing _ -> - Err (Error_InvalidToken item) + Error_InvalidToken item Expecting_TypeName + |> Err + |> Just + +parseAssignment : State -> LexItem -> Maybe (Result Error State) +parseAssignment newState item = + case item of + Lexer.Sigil Lexer.Assign -> + newState + |> Ok + |> Just + + Lexer.Newlines _ 0 -> + State_BlockStart + |> Ok + |> Just -blockFromState : State -> Result Error (Maybe Block) + Lexer.Newlines _ _ -> + Nothing + + Lexer.Whitespace _ -> + Nothing + + _ -> + Error_InvalidToken item (Expecting_Sigil Lexer.Assign) + |> Err + |> Just + + +parserTypeExpr : + (TypeExpressionResult -> State) + -> PartialTypeExpression2 + -> LexItem + -> Maybe (Result Error State) +parserTypeExpr newState { stack, current } item = + case item of + Lexer.Token str -> + case current of + ( context, Nothing ) -> + newState + ({ stack = stack + , current = + ( context + , Just + (TypeExpression_NamedType + { name = str + , args = empty + } + ) + ) + } + |> TypeExpressionResult_Progress + ) + |> Ok + |> Just + + ( context, Just (TypeExpression_NamedType { name, args }) ) -> + -- TODO(harry): think about how this is fundamentally + -- similar to the definition of custom type constructors. + -- The value of `_context` is key I think. + newState + ({ stack = stack + , current = + ( context + , Just + (TypeExpression_NamedType + { name = name + , args = + TypeExpression_NamedType { name = str, args = empty } + |> pushOnto args + } + ) + ) + } + |> TypeExpressionResult_Progress + ) + |> Ok + |> Just + + ( context, Just TypeExpression_Unit ) -> + Error_UnitTypeDoesTakeArgs + (TypeExpression_NamedType + { name = str + , args = empty + } + ) + |> Err + |> Just + + Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> + case role of + Lexer.Open -> + newState + ({ stack = + current + |> pushOnto stack + , current = ( TypeExpressionContext_Bracket Lexer.Round, Nothing ) + } + |> TypeExpressionResult_Progress + ) + |> Ok + |> Just + + Lexer.Close -> + case current of + ( TypeExpressionContext_Bracket Lexer.Round, mexpr ) -> + case mexpr of + Nothing -> + (case pop stack of + Just ( ( newContext, newExprToAddTo ), newStack ) -> + let + rnewExpr = + case newExprToAddTo of + Nothing -> + Just TypeExpression_Unit + |> Ok + + Just (TypeExpression_NamedType { name, args }) -> + Just + (TypeExpression_NamedType + { name = name + , args = + TypeExpression_Unit + |> pushOnto args + } + ) + |> Ok + + Just TypeExpression_Unit -> + Error_UnitTypeDoesTakeArgs TypeExpression_Unit + |> Err + in + rnewExpr + |> Result.map + (\newExpr -> + { stack = newStack + , current = ( newContext, newExpr ) + } + |> TypeExpressionResult_Progress + ) + + Nothing -> + TypeExpressionResult_Done TypeExpression_Unit + |> Ok + ) + |> Result.map newState + |> Just + + Just expr -> + newState + (case pop stack of + Just ( newCurrent, newStack ) -> + { stack = newStack + , current = Debug.todo "newCurrent" + } + |> TypeExpressionResult_Progress + + Nothing -> + TypeExpressionResult_Done expr + ) + |> Ok + |> Just + + _ -> + -- TODO(harry): can we add information about the + -- bracket we are expecting here? + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> Err + |> Just + + Lexer.Newlines _ 0 -> + State_BlockStart + |> Ok + |> Just + + Lexer.Newlines _ _ -> + Nothing + + Lexer.Whitespace _ -> + Nothing + + _ -> + Error_InvalidToken item (Expecting_Sigil Lexer.Assign) + |> Err + |> Just + + +blockFromState : State -> Maybe (Result Error Block) blockFromState state = case state of State_Error_Recovery -> - Ok Nothing + Nothing State_BlockStart -> - Ok Nothing + Nothing State_BlockFirstItem firstItem -> Debug.todo "handle incomplete block" - State_BlockSecondItem firstItem -> + State_BlockTypeAlias BlockTypeAlias_Keywords -> + Error_PartwayThroughTypeAlias + |> Err + |> Just + + State_BlockTypeAlias (BlockTypeAlias_Named _) -> + Error_PartwayThroughTypeAlias + |> Err + |> Just + + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns _) -> + Error_PartwayThroughTypeAlias + |> Err + |> Just + + State_BlockTypeAlias (BlockTypeAlias_Completish name { stack, current }) -> + let + -- _ = + -- Debug.log "part" partialExpr + ( context, mexpr ) = + current + in + -- TODO(harry): handle maybe incomplete block + case ( pop stack, context, mexpr ) of + ( Nothing, TypeExpressionContext_Alias, Just expr ) -> + { ty = name + , expr = partialTypeExpressionToConcreteType expr + } + |> TypeAlias + |> Ok + |> Just + + _ -> + Debug.todo "handle maybe incomplete block" + + State_BlockTypeAlias (BlockTypeAlias_Complete name expr) -> + { ty = name + , expr = partialTypeExpressionToConcreteType expr + } + |> TypeAlias + |> Ok + |> Just + + State_BlockCustomType firstItem -> Debug.todo "handle incomplete block" + + + +-- HELPERS + + +type Stack a + = Stack (List a) + + +empty : Stack a +empty = + Stack [] + + +singleton : a -> Stack a +singleton val = + Stack [ val ] + + +pushOnto : Stack a -> a -> Stack a +pushOnto (Stack ls) val = + Stack (val :: ls) + + +pop : Stack a -> Maybe ( a, Stack a ) +pop (Stack ls) = + case ls of + last :: preceding -> + Just ( last, Stack preceding ) + + [] -> + Nothing + + +toList : (a -> b) -> Stack a -> List b +toList mapper (Stack ls) = + List.foldl + (\curr prev -> mapper curr :: prev) + [] + ls diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 29996b7e..24e493d1 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -17,7 +17,7 @@ type LexItem type LexSigil - = Bracket BracketType BracketTodoNameMe + = Bracket BracketType BracketRole | Assign | Pipe | Comma @@ -58,7 +58,7 @@ type BracketType | Curly -type BracketTodoNameMe +type BracketRole = Open | Close @@ -192,7 +192,7 @@ toString item = String.repeat i " " Newlines empties identationSpaces -> - (empties + (Debug.log "empties" empties |> List.map (\spacesInEmptyLine -> "\n" ++ String.repeat spacesInEmptyLine " ") |> String.join "" ) From ec5ca01ead1a2a43a64eb1a0989f6788b594eb77 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 24 Sep 2020 14:10:13 +0100 Subject: [PATCH 007/103] add visualiser run `elm repl` from ./tests/parser-tests to see live parsing! --- tests/ParserLexerTest.elm | 24 ++ tests/parser-tests/Live.elm | 125 +++++++ tests/parser-tests/Update.elm | 614 ++++++++++++++++++++++++++++++++++ tests/parser-tests/elm.json | 47 +++ tests/parser-tests/index.js | 36 ++ tests/parser-tests/update.js | 88 +++++ 6 files changed, 934 insertions(+) create mode 100644 tests/ParserLexerTest.elm create mode 100644 tests/parser-tests/Live.elm create mode 100644 tests/parser-tests/Update.elm create mode 100644 tests/parser-tests/elm.json create mode 100644 tests/parser-tests/index.js create mode 100644 tests/parser-tests/update.js diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm new file mode 100644 index 00000000..501c5665 --- /dev/null +++ b/tests/ParserLexerTest.elm @@ -0,0 +1,24 @@ +module ParserTest2 exposing (test)) + +import Dict +import Elm.AST.Frontend as Frontend +import Elm.AST.Frontend.Unwrapped exposing (Expr(..), Pattern(..)) +import Elm.Compiler.Error exposing (ParseContext, ParseProblem) +import Elm.Data.Declaration as Declaration exposing (DeclarationBody) +import Elm.Data.Exposing exposing (ExposedItem(..), Exposing(..)) +import Elm.Data.Module exposing (ModuleType(..)) +import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) +import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) +import Elm.Data.TypeAnnotation exposing (TypeAnnotation) +import Expect exposing (Expectation) +import OurExtras.String as String +import Parser.Advanced as P +import Stage.Parse.Parser +import String.Extra as String +import Test exposing (Test, describe, test) + + + +-- DO NOT EDIT BELOW THIS LINE + +inputs : List (String, List (Located LexItem), ) diff --git a/tests/parser-tests/Live.elm b/tests/parser-tests/Live.elm new file mode 100644 index 00000000..6f3fb2b6 --- /dev/null +++ b/tests/parser-tests/Live.elm @@ -0,0 +1,125 @@ +module Live exposing (main) + +import Browser +import Elm.Data.Located as Located +import Html exposing (Html) +import Html.Attributes as Attributes +import Html.Events as Events +import Parser.Advanced as P +import Stage.Parse.Contextualize as Contextualize +import Stage.Parse.Lexer as Lexer + + +{-| We're essentially a Node.JS app (until we get self-hosting :P ). +So, `Platform.worker` is the only option for us. +-} +main : Program () String Msg +main = + Browser.element + { init = init + , update = update + , subscriptions = subscriptions + , view = view + } + + +{-| `Compiling` is the state we'll be most of the time. The other two are +mostly useless; they do effectively stop `subscriptions` and `update` though. +-} +type alias Model = + String + + +type Msg + = NewString String + + +subscriptions : Model -> Sub Msg +subscriptions _ = + Sub.none + + +init : () -> ( Model, Cmd never ) +init () = + ( """type alias Model =""", Cmd.none ) + + +view : Model -> Html Msg +view model = + let + source = + model + + lexed = + P.run Lexer.parser source + in + Html.div + [ Attributes.style "display" "flex" + , Attributes.style "flex-direction" "row" + ] + [ Html.div + [] + [ Html.textarea + [ Events.onInput <| NewString + , Attributes.value source + , Attributes.rows 20 + , Attributes.cols 80 + ] + [] + , Html.div + [ Attributes.style "font-family" "monospace" ] + -- [ Attributes.style "w" ] + (case lexed of + Ok lexItems -> + lexItems + |> List.map + (\item -> + let + { start, end } = + Located.getRegion item + in + Html.div + [ Attributes.style "white-space" "pre-wrap" ] + [ Html.text + ("(" + ++ String.padLeft 3 '0' (String.fromInt start.row) + ++ ", " + ++ String.padLeft 3 '0' (String.fromInt start.col) + ++ ") - (" + ++ String.padLeft 3 '0' (String.fromInt end.row) + ++ ", " + ++ String.padLeft 3 '0' (String.fromInt end.col) + ++ "): \"" + ++ (item |> Located.unwrap |> Lexer.toString |> String.replace " " "·") + ++ "\"" + ) + ] + ) + + Err e -> + [ Html.text (Debug.toString e) ] + ) + ] + , Html.div + [ Attributes.style "font-family" "monospace" ] + -- [ Attributes.style "w" ] + (case lexed of + Ok lexItems -> + [ Html.div + [ Attributes.style "white-space" "pre-wrap" ] + [ Html.text + (Debug.toString (Contextualize.parser (lexItems |> List.map Located.unwrap))) + ] + ] + + Err e -> + [] + ) + ] + + +update : Msg -> Model -> ( Model, Cmd Msg ) +update msg model = + case msg of + NewString string -> + ( string, Cmd.none ) diff --git a/tests/parser-tests/Update.elm b/tests/parser-tests/Update.elm new file mode 100644 index 00000000..a4efb382 --- /dev/null +++ b/tests/parser-tests/Update.elm @@ -0,0 +1,614 @@ +module parser-tests.Update exposing (main) + +import Dict exposing (Dict) +import Dict.Extra +import Elm.AST.Frontend as Frontend +import Elm.Compiler.Error as Error exposing (Error(..), ParseError(..)) +import Elm.Data.Declaration as Declaration +import Elm.Data.FileContents exposing (FileContents) +import Elm.Data.FilePath as FilePath exposing (FilePath) +import Elm.Data.Module exposing (Module) +import Elm.Data.ModuleName as ModuleName exposing (ModuleName) +import Elm.Data.Project exposing (Project) +import Elm.Data.Qualifiedness exposing (PossiblyQualified) +import Elm.Data.TypeAnnotation exposing (TypeAnnotation) +import Elm.Project +import Json.Decode as JD +import OurExtras.Tuple3 as Tuple3 +import Parser.Advanced as P +import Platform +import Ports exposing (println) +import Set exposing (Set) +import Stage.Desugar as Desugar +import Stage.Emit.JavaScript as EmitJS +import Stage.Emit.JsonAST as EmitJson +import Stage.InferTypes as InferTypes +import Stage.Optimize as Optimize +import Stage.Parse as Parse +import Stage.Parse.Parser as SPP +import String.Extra + + +{-| We're essentially a Node.JS app (until we get self-hosting :P ). +So, `Platform.worker` is the only option for us. +-} +main : Program Flags (Model Frontend.ProjectFields) Msg +main = + Platform.worker + { init = init + , update = update + , subscriptions = subscriptions + } + + +type alias Flags = + { mainFilePath : String + , mainFileContents : String + , elmJson : String + , outputFormat : String + } + + +{-| `Compiling` is the state we'll be most of the time. The other two are +mostly useless; they do effectively stop `subscriptions` and `update` though. +-} +type Model projectFields + = Compiling (Model_ projectFields) + | {- We don't need to remember the error, because we report it + at the time of transition to this new model. See `handleFatalError`. + -} + EncounteredError + | Finished + + +{-| Because we're mostly in the `Compiling` state, it is worthwhile +to make functions work with its data instead of the general `Model`. +-} +type alias Model_ projectFields = + { project : Project projectFields + , waitingForFiles : Dict ModuleName (Set FilePath) + , outputFormat : String + } + + +type Msg + = ReadFileSuccess + { filePath : FilePath + , fileContents : FileContents + } + | ReadFileError + { moduleName : ModuleName + , filePath : FilePath + , errorCode : String + } + + +subscriptions : Model expr -> Sub Msg +subscriptions model = + case model of + Compiling _ -> + {- We'll be waiting for the various file contents we've asked for + with `readFile`, but only on the happy path. They are of no use + to us when we've already found an error elsewhere or finished + the compilation. + -} + Ports.waitForReadFile + ReadFileError + ReadFileSuccess + + EncounteredError -> + Sub.none + + Finished -> + Sub.none + + +{-| The JS wrapper gives us the main filepath, its contents, and the contents +of the elm.json file. +We have two tasks here: + + - decode the elm.json file to something meaningful + - find (and check against the filepath) the main module name + +-} +init : Flags -> ( Model Frontend.ProjectFields, Cmd Msg ) +init { mainFilePath, mainFileContents, elmJson, outputFormat } = + let + elmJsonProject : Result Error Elm.Project.Project + elmJsonProject = + JD.decodeString (JD.map normalizeDirs Elm.Project.decoder) elmJson + |> Result.mapError (ParseError << InvalidElmJson) + + mainModuleName : Result CLIError ModuleName + mainModuleName = + findMainModuleName mainFilePath mainFileContents + + modelAndCmd : Result CLIError ( Model Frontend.ProjectFields, Cmd Msg ) + modelAndCmd = + Result.map2 + (\mainModuleName_ elmJsonProject_ -> + let + model = + { project = + { mainFilePath = mainFilePath + , mainModuleName = mainModuleName_ + , elmJson = elmJsonProject_ + , sourceDirectories = getSourceDirectories elmJsonProject_ + , modules = Dict.empty + } + , waitingForFiles = Dict.singleton mainModuleName_ (Set.singleton mainFilePath) + , outputFormat = outputFormat + } + in + model + |> handleReadFileSuccess + MainModule + { filePath = mainFilePath + , fileContents = mainFileContents + } + ) + mainModuleName + (elmJsonProject |> Result.mapError CompilerError) + in + case modelAndCmd of + Ok modelAndCmd_ -> + modelAndCmd_ + + Err error -> + handleFatalError error + + +{-| First, read the declared module name from the file contents. +Then, check it against the file path. + +The funny thing is that the main file doesn't have to be present in the source +directories mentioned in elm.json, so we have to try and match a part of the +filename with the read module name and see if it matches. + +We can be a little clever: count the dots in the supposedly correct module name +in the file contents, then to get the source directory, remove "that amount + 1" +of parts separated by `/` slashes in the filename. + +Either this agrees or nothing will. + + module C.D.E exposing (..) + A/B/C/D/E.elm + -> 2 dots, remove 2+1 rightmost parts separated by `/` from the filepath + -> remove 3 rightmost parts from [A,B,C,D,E.elm] + -> [A,B] + -> join using "/" + -> `A/B` + +-} +findMainModuleName : FilePath -> String -> Result CLIError ModuleName +findMainModuleName filePath contents = + getDeclaredModuleName contents + |> Result.andThen + (\declaredModuleName -> + let + numberOfDotsInModuleName : Int + numberOfDotsInModuleName = + String.Extra.countOccurrences "." declaredModuleName + + sourceDirectory : String + sourceDirectory = + filePath + |> String.split "/" + |> List.reverse + |> List.drop (numberOfDotsInModuleName + 1) + |> List.reverse + |> String.join "/" + in + ModuleName.expectedModuleName + { sourceDirectory = sourceDirectory + , filePath = filePath + } + |> Result.fromMaybe + (ModuleNameDoesntMatchFilePath + { moduleName = declaredModuleName + , filePath = filePath + } + |> ParseError + |> CompilerError + ) + ) + + +getDeclaredModuleName : String -> Result CLIError ModuleName +getDeclaredModuleName fileContents = + P.run SPP.moduleDeclaration fileContents + |> Result.map Tuple3.second + |> Result.mapError + (\err -> + ( err, fileContents ) + |> ParseProblem + |> ParseError + |> CompilerError + ) + + +normalizeDirs : Elm.Project.Project -> Elm.Project.Project +normalizeDirs project = + case project of + Elm.Project.Application data -> + Elm.Project.Application + { data + | dirs = + List.map + FilePath.removeTrailingSlash + data.dirs + } + + Elm.Project.Package data -> + Elm.Project.Package data + + +{-| Applications tell us their source directories; packages have `src/`. +-} +getSourceDirectories : Elm.Project.Project -> List FilePath +getSourceDirectories elmProject = + case elmProject of + Elm.Project.Application { dirs } -> + dirs + + Elm.Project.Package _ -> + [ "src" ] + + +update : Msg -> Model Frontend.ProjectFields -> ( Model Frontend.ProjectFields, Cmd Msg ) +update msg model = + case model of + Compiling model_ -> + update_ msg model_ + + EncounteredError -> + ( model, Cmd.none ) + + Finished -> + ( model, Cmd.none ) + + +update_ : Msg -> Model_ Frontend.ProjectFields -> ( Model Frontend.ProjectFields, Cmd Msg ) +update_ msg model = + case {- log -} msg of + ReadFileSuccess file -> + handleReadFileSuccess OtherModule file model + + ReadFileError r -> + handleReadFileError r model + + +type ModuleType + = MainModule + | OtherModule + + +handleReadFileSuccess : + ModuleType + -> { filePath : FilePath, fileContents : FileContents } + -> Model_ Frontend.ProjectFields + -> ( Model Frontend.ProjectFields, Cmd Msg ) +handleReadFileSuccess moduleType ({ filePath } as file) ({ project } as model) = + if isWaitingFor filePath model then + let + parseResult = + Parse.parse file + |> Result.andThen + (case moduleType of + MainModule -> + {- We've already checked the main module name in a + bit different way during `init`. (Differently + because main modules don't need to live inside + the source directories.) No need to check + it again! + -} + Ok + + OtherModule -> + checkModuleNameAndFilePath + { sourceDirectories = project.sourceDirectories + , filePath = filePath + } + ) + in + case parseResult of + Err error -> + handleFatalError <| CompilerError error + + Ok ({ name, imports } as parsedModule) -> + let + newModules : Dict ModuleName (Module Frontend.LocatedExpr TypeAnnotation PossiblyQualified) + newModules = + Dict.update name + (always (Just parsedModule)) + project.modules + + newProject : Project Frontend.ProjectFields + newProject = + { project | modules = newModules } + + filesToBeRead : Dict ModuleName (Set FilePath) + filesToBeRead = + imports + |> Dict.filter (\moduleName _ -> not <| Dict.member moduleName newModules) + |> Dict.keys + |> List.map + (\moduleName -> + {- We don't know in which source directory the + module will be, so we're trying them all. + + Our Model_.waitingForFiles remembers all the + tries and: + * when one succeeds the others are forgotten + * when all fail we raise an error + -} + ( moduleName + , project.sourceDirectories + |> List.map + (\sourceDirectory -> + FilePath.expectedFilePath + { sourceDirectory = sourceDirectory + , moduleName = moduleName + } + ) + |> Set.fromList + ) + ) + |> Dict.fromList + + newWaitingForFiles : Dict ModuleName (Set FilePath) + newWaitingForFiles = + model.waitingForFiles + |> Dict.remove name + {- There's no need for a more general Dict.merge + here because a module name is always going to + generate the same set of possible file paths over + the run of the compiler. + -} + |> Dict.union filesToBeRead + + newModel : Model_ Frontend.ProjectFields + newModel = + { model + | project = newProject + , waitingForFiles = newWaitingForFiles + } + in + if Dict.isEmpty newWaitingForFiles then + compile model.outputFormat newProject + + else + ( Compiling newModel + , filesToBeRead + |> Dict.toList + |> List.concatMap + (\( moduleName, possibleFiles ) -> + possibleFiles + |> Set.toList + |> List.map + (\filePath_ -> + { moduleName = moduleName + , filePath = filePath_ + } + ) + ) + |> List.map Ports.readFile + |> Cmd.batch + ) + + else + handleFatalError (MultipleFilesForModule filePath) + + +isWaitingFor : FilePath -> Model_ projectFields -> Bool +isWaitingFor filePath { waitingForFiles } = + Dict.Extra.any + (\_ possibleFiles -> Set.member filePath possibleFiles) + waitingForFiles + + +handleReadFileError : + { moduleName : ModuleName + , filePath : FilePath + , errorCode : String + } + -> Model_ Frontend.ProjectFields + -> ( Model Frontend.ProjectFields, Cmd Msg ) +handleReadFileError { moduleName, filePath } model = + case Dict.get moduleName model.waitingForFiles of + Nothing -> + {- We've got a read error after a file was successfully found + elsewhere; we can safely ignore it! + -} + ( Compiling model + , Cmd.none + ) + + Just possibleFiles -> + if Set.isEmpty (Set.remove filePath possibleFiles) then + -- This was our last chance for finding that module! + handleFatalError (ModuleNotInSourceDirectories moduleName) + + else + ( Compiling + { model + | waitingForFiles = + model.waitingForFiles + |> Dict.update moduleName + {- Due to the above `Set.isEmpty` check we know that + removing this possibility leaves some more + possibilities open; we won't end up with an empty + set then. + -} + (Maybe.map (Set.remove filePath)) + } + , Cmd.none + ) + + +{-| We're done reading and parsing files. All the IO is done, now we can do +the rest synchronously! +-} +compile : String -> Project Frontend.ProjectFields -> ( Model Frontend.ProjectFields, Cmd Msg ) +compile format project = + let + _ = + project.modules + |> Dict.values + |> List.map + (\module_ -> + Dict.values module_.declarations + |> List.map + (\decl -> + decl.body + |> Declaration.mapBody + Frontend.unwrap + identity + identity + |> Debug.log (decl.module_ ++ "." ++ decl.name) + ) + ) + + emitter = + case format of + "JSON" -> + EmitJson.emitProject + + _ -> + EmitJS.emitProject + in + Ok project + |> Result.andThen Desugar.desugar + |> Result.andThen InferTypes.inferTypes + |> Result.map Optimize.optimize + |> Result.andThen emitter + |> Result.mapError CompilerError + |> writeToFSAndExit + + +{-| We've got our output ready for writing to the filesystem! +(Well, that or an error somewhere along the process.) + +Let's do that - report the error or write the output to a file. + +-} +writeToFSAndExit : + Result CLIError (Dict FilePath FileContents) + -> ( Model Frontend.ProjectFields, Cmd Msg ) +writeToFSAndExit result = + case result of + Ok outputFiles -> + let + outputCmds = + outputFiles + |> Dict.toList + |> List.map + (\( filePath, fileContents ) -> + Ports.writeToFile + { filePath = filePath + , fileContents = fileContents + } + ) + in + ( Finished + , Cmd.batch + (println "Compilation finished, writing output to `out.js`." + :: outputCmds + ) + ) + + Err error -> + handleFatalError error + + +{-| When an error happens, we bail out as early as possible. +Stop everything, abort mission, jump ship! + +The `EncounteredError` model stops most everything (`update`, `subscriptions`). + +-} +handleFatalError : CLIError -> ( Model dontcare, Cmd Msg ) +handleFatalError error = + ( EncounteredError + , Cmd.batch + [ Ports.printlnStderr (errorToString error) + , Ports.setExitCode 1 + ] + ) + + +log : Msg -> Msg +log msg = + let + string = + case msg of + ReadFileSuccess { filePath } -> + "ReadFileSuccess: " ++ filePath + + ReadFileError error -> + "ReadFileError: " ++ Debug.toString error + + _ = + Debug.log string () + in + msg + + + +-- ERRORS + + +type CLIError + = ModuleNotInSourceDirectories ModuleName + | MultipleFilesForModule FilePath + | CompilerError Error + + +errorToString : CLIError -> String +errorToString error = + case error of + ModuleNotInSourceDirectories moduleName -> + "Module `" + ++ moduleName + ++ "` cannot be found in your `sourceDirectories`." + + MultipleFilesForModule filePath -> + {- TODO better error by tracking both the previously successful file + and this one, and the module name. + -} + "File `" + ++ filePath + ++ "` clashes with some other module in your `sourceDirectories`." + + CompilerError compilerError -> + Error.toString compilerError + + +{-| TODO maybe there should be a "Checks" module for checks across phases? +-} +checkModuleNameAndFilePath : + { sourceDirectories : List FilePath, filePath : FilePath } + -> Module Frontend.LocatedExpr TypeAnnotation PossiblyQualified + -> Result Error (Module Frontend.LocatedExpr TypeAnnotation PossiblyQualified) +checkModuleNameAndFilePath { sourceDirectories, filePath } ({ name } as parsedModule) = + let + makesNameAgree : FilePath -> Bool + makesNameAgree sourceDirectory = + ModuleName.expectedModuleName + { sourceDirectory = sourceDirectory + , filePath = filePath + } + == Just name + in + if List.any makesNameAgree sourceDirectories then + Ok parsedModule + + else + Err + (ParseError + (ModuleNameDoesntMatchFilePath + { moduleName = name + , filePath = filePath + } + ) + ) diff --git a/tests/parser-tests/elm.json b/tests/parser-tests/elm.json new file mode 100644 index 00000000..229e02e9 --- /dev/null +++ b/tests/parser-tests/elm.json @@ -0,0 +1,47 @@ +{ + "type": "application", + "source-directories": [ + ".", + "../../src" + ], + "elm-version": "0.19.1", + "dependencies": { + "direct": { + "Janiczek/transform": "1.1.0", + "dmy/elm-pratt-parser": "2.0.0", + "elm/browser": "1.0.2", + "elm/core": "1.0.5", + "elm/html": "1.0.0", + "elm/json": "1.1.3", + "elm/parser": "1.1.0", + "elm/project-metadata-utils": "1.0.1", + "elm-community/dict-extra": "2.4.0", + "elm-community/graph": "6.0.0", + "elm-community/maybe-extra": "5.2.0", + "elm-community/result-extra": "2.4.0", + "elm-community/string-extra": "4.0.1", + "erlandsona/assoc-set": "1.1.0", + "pzp1997/assoc-list": "1.0.0", + "rtfeldman/elm-hex": "1.0.0", + "turboMaCk/non-empty-list-alias": "1.1.0" + }, + "indirect": { + "avh4/elm-fifo": "1.0.4", + "elm/regex": "1.0.0", + "elm/time": "1.0.0", + "elm/url": "1.0.0", + "elm/virtual-dom": "1.0.2", + "elm-community/intdict": "3.0.0" + } + }, + "test-dependencies": { + "direct": { + "elm-community/random-extra": "3.1.0", + "elm-explorations/test": "1.2.2" + }, + "indirect": { + "elm/random": "1.0.0", + "owanturist/elm-union-find": "1.0.0" + } + } +} diff --git a/tests/parser-tests/index.js b/tests/parser-tests/index.js new file mode 100644 index 00000000..1f8a37df --- /dev/null +++ b/tests/parser-tests/index.js @@ -0,0 +1,36 @@ +const {Elm} = require('./elm.js'); +const readline = require('readline'); + +module.exports = (name, opts) => { + const program = Elm[name].init({ + flags: {argv: process.argv, versionMessage: '0.0.1'}, + }); + + program.ports.print.subscribe((message) => { + console.log(message); + }); + program.ports.printAndExitFailure.subscribe((message) => { + console.log(message); + process.exit(1); + }); + program.ports.printAndExitSuccess.subscribe((message) => { + console.log(message); + process.exit(0); + }); + + if (opts && opts.stdin) { + const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout, + terminal: false, + }); + + rl.on('line', function (line) { + program.ports.onStdinLine.send(line); + }); + + rl.on('close', function (line) { + program.ports.onStdinClosed.send(null); + }); + } +}; diff --git a/tests/parser-tests/update.js b/tests/parser-tests/update.js new file mode 100644 index 00000000..67a23d15 --- /dev/null +++ b/tests/parser-tests/update.js @@ -0,0 +1,88 @@ +#!/usr/bin/env node + +const HELP = ` + +Usage: parser-tests + +Create + +Options: +-h, --help display this help and exit + +`.trim(); + +const warning_comment_lines = ` + +-- ESLINT GLOBAL VARIABLES +-- +-- Do not edit below this line as it is generated by tests/generate-globals.py +-- + +` + .trim() + .split('\n'); + +// import_re = (r"import\s+((?:[.\w]+\.)?(\w+))\s+(?:as (\w+)\s+)?" +// r"exposing\s+\((\w+(?:,\s+\w+)*)\)") + +// def processFile(file): +// globals = [] + +// module_name = Path(file).stem + +// last_line_empty = False + +// with fileinput.input(file, inplace=True) as f: +// for line in f: +// if line.startswith(warning_comment_lines[0]): +// break +// else: +// print(line, end='') +// last_line_empty = line.strip() == '' +// importMatch = re.search(import_re, line) + +// if importMatch is not None: +// # Use alias if it is there, otherwise use last part of +// # import. +// moduleAlias = importMatch[3] +// if moduleAlias is None: +// moduleAlias = importMatch[2] + +// vars = map( +// lambda defName: "__{}_{}".format( +// moduleAlias, defName.strip()), +// importMatch[4].split(","), +// ) + +// globals.append("/* global {} */".format(", ".join(vars))) + +// unused_var_config = '{{ "varsIgnorePattern": "_{}_.*" }}'.format( +// module_name) + +// with open(file, "a") as f: +// if not last_line_empty: +// print(file=f) + +// print("\n".join(warning_comment_lines), file=f) +// print(file=f) +// print('/* eslint no-unused-vars: ["error", {}] */'.format( +// unused_var_config), +// file=f) +// print(file=f) +// print("\n".join(globals), file=f) + +// def main(): +// if len(sys.argv) < 2: +// print("generate-globals.py: error! At least one path or glob required", +// file=sys.stderr) +// exit(1) + +// if "-h" in sys.argv or "--help" in sys.argv: +// print(HELP) +// exit(0) + +// for provided_glob in sys.argv[1:]: +// for path in glob.glob(provided_glob, recursive=True): +// processFile(path) + +// main() From d9c7650c1d667728077b6ce127cd421fa74193c8 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 24 Sep 2020 15:07:49 +0100 Subject: [PATCH 008/103] refactor function layout --- src/Stage/Parse/Contextualize.elm | 182 ++++++++++++++++-------------- 1 file changed, 97 insertions(+), 85 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 981f1134..5af17097 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -158,114 +158,118 @@ type Expecting | Expecting_TypeName -parser : List LexItem -> List (Result ( State, Error ) Block) -parser items = - parserHelp +run : List LexItem -> List (Result ( State, Error ) Block) +run items = + runHelp items { previousBlocks = [] , state = State_BlockStart } -parserHelp : List LexItem -> State_ -> List (Result ( State, Error ) Block) -parserHelp items state = - let - newState = - case state.state of - State_Error_Recovery -> - parseBlockStart - >> Result.withDefault State_Error_Recovery - >> Ok - >> Just - - State_BlockStart -> - parseBlockStart - >> Just +runHelp : List LexItem -> State_ -> List (Result ( State, Error ) Block) +runHelp items state = + case items of + item :: rest -> + runHelp + rest + (case parseAnything state.state item of + Just (Ok newState_) -> + { previousBlocks = state.previousBlocks + , state = newState_ + } - State_BlockFirstItem BlockFirstItem_Type -> - parseTypeBlock + Just (Err error) -> + { previousBlocks = Err ( state.state, error ) :: state.previousBlocks + , state = State_Error_Recovery + } - State_BlockFirstItem BlockFirstItem_Module -> - Debug.todo "" + Nothing -> + state + ) - State_BlockFirstItem (BlockFirstItem_Name name) -> - Debug.todo "" + [] -> + List.reverse + (case blockFromState state.state of + Nothing -> + state.previousBlocks - State_BlockTypeAlias BlockTypeAlias_Keywords -> - parseTypeAliasName + Just newBlock -> + (newBlock |> Result.mapError (\err -> ( state.state, err ))) + :: state.previousBlocks + ) - State_BlockTypeAlias (BlockTypeAlias_Named name) -> - parseAssignment - (State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name)) - State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name) -> - parserTypeExpr - (\res -> - case res of - TypeExpressionResult_Progress expr -> - State_BlockTypeAlias (BlockTypeAlias_Completish name expr) +parseAnything : State -> LexItem -> Maybe (Result Error State) +parseAnything state = + case state of + State_Error_Recovery -> + parseBlockStart + >> Result.withDefault State_Error_Recovery + >> Ok + >> Just - TypeExpressionResult_Done expr -> - State_BlockTypeAlias (BlockTypeAlias_Complete name expr) + State_BlockStart -> + parseBlockStart + >> Just - TypeExpressionResult_Empty -> - Debug.todo "" - ) - { current = ( TypeExpressionContext_Alias, Nothing ) - , stack = empty - } + State_BlockFirstItem BlockFirstItem_Type -> + parseTypeBlock - State_BlockTypeAlias (BlockTypeAlias_Completish name exprSoFar) -> - parserTypeExpr - (\res -> - case res of - TypeExpressionResult_Progress expr -> - State_BlockTypeAlias (BlockTypeAlias_Completish name expr) + State_BlockFirstItem BlockFirstItem_Module -> + Debug.todo "" - TypeExpressionResult_Done expr -> - State_BlockTypeAlias (BlockTypeAlias_Complete name expr) + State_BlockFirstItem (BlockFirstItem_Name name) -> + Debug.todo "" - TypeExpressionResult_Empty -> - Debug.todo "" - ) - exprSoFar + State_BlockTypeAlias BlockTypeAlias_Keywords -> + parseTypeAliasName - State_BlockTypeAlias (BlockTypeAlias_Complete name expr) -> - Debug.todo "" + State_BlockTypeAlias (BlockTypeAlias_Named name) -> + parseAssignment + (State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name)) - State_BlockCustomType (BlockCustomType_Named name) -> - parseAssignment - (State_BlockCustomType (BlockCustomType_NamedAssigns name)) + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name) -> + parserTypeExpr + (\res -> + case res of + TypeExpressionResult_Progress expr -> + State_BlockTypeAlias (BlockTypeAlias_Completish name expr) - State_BlockCustomType (BlockCustomType_NamedAssigns name) -> - Debug.todo "" - in - case items of - item :: rest -> - case newState item of - Just (Ok newState_) -> - parserHelp rest { previousBlocks = state.previousBlocks, state = newState_ } + TypeExpressionResult_Done expr -> + State_BlockTypeAlias (BlockTypeAlias_Complete name expr) - Just (Err error) -> - parserHelp - rest - { previousBlocks = Err ( state.state, error ) :: state.previousBlocks - , state = State_Error_Recovery - } + TypeExpressionResult_Empty -> + Debug.todo "" + ) + { current = ( TypeExpressionContext_Alias, Nothing ) + , stack = empty + } - Nothing -> - parserHelp rest state + State_BlockTypeAlias (BlockTypeAlias_Completish name exprSoFar) -> + parserTypeExpr + (\res -> + case res of + TypeExpressionResult_Progress expr -> + State_BlockTypeAlias (BlockTypeAlias_Completish name expr) - [] -> - List.reverse - (case blockFromState state.state of - Nothing -> - state.previousBlocks + TypeExpressionResult_Done expr -> + State_BlockTypeAlias (BlockTypeAlias_Complete name expr) - Just newBlock -> - (newBlock |> Result.mapError (\err -> ( state.state, err ))) - :: state.previousBlocks + TypeExpressionResult_Empty -> + Debug.todo "" ) + exprSoFar + + State_BlockTypeAlias (BlockTypeAlias_Complete name expr) -> + Debug.todo "" + + State_BlockCustomType (BlockCustomType_Named name) -> + parseAssignment + (State_BlockCustomType (BlockCustomType_NamedAssigns name)) + + State_BlockCustomType (BlockCustomType_NamedAssigns name) -> + Debug.todo "" {-| @@ -273,7 +277,7 @@ parserHelp items state = ### Panics -If the LexItem is `Newlines`. +If the LexItem is a `Newlines` with indentation or is `Whitespace`. -} parseBlockStart : LexItem -> Result Error State @@ -296,9 +300,17 @@ parseBlockStart item = Token.TokenTypeOrConstructor typeOrConstructor -> Err (Error_BlockStartsWithTypeOrConstructor typeOrConstructor) - Lexer.Newlines _ _ -> + Lexer.Newlines _ 0 -> Ok State_BlockStart + Lexer.Newlines _ _ -> + Error_Panic "parseBlockStart expects a block but found some indented content" + |> Err + + Lexer.Whitespace _ -> + Error_Panic "parseBlockStart expects a block but found some indented content" + |> Err + _ -> Err (Error_InvalidToken item Expecting_Block) From cced4b725c9609928f432fb4178fc0c3aac32d51 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 24 Sep 2020 15:23:51 +0100 Subject: [PATCH 009/103] use explicit parse result type --- src/Stage/Parse/Contextualize.elm | 172 +++++++++++++++++------------- 1 file changed, 98 insertions(+), 74 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 5af17097..0584482a 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -1,5 +1,15 @@ module Stage.Parse.Contextualize exposing (..) +{-| Here we define parsers. A parser is function + + type alias Parser = + Lexer.LexItem -> ParseResult + +that takes one lexed item and produces either an error or some state (it can also +choose to skip the lexed item). + +-} + import Elm.AST.Frontend as Frontend exposing (Expr(..), LocatedExpr, LocatedPattern, Pattern(..)) import Elm.Data.Declaration import Elm.Data.Exposing @@ -68,6 +78,13 @@ type State | State_BlockCustomType BlockCustomType +type ParseResult + = ParseResult_Ok State + | ParseResult_Err Error + | ParseResult_Skip + | ParseResult_Panic String + + type alias State_ = { previousBlocks : List (Result ( State, Error ) Block) , state : State @@ -124,6 +141,29 @@ partialTypeExpressionToConcreteType pte = ConcreteType.Unit +recoverErrors : ParseResult -> ParseResult +recoverErrors res = + case res of + ParseResult_Err _ -> + ParseResult_Ok State_Error_Recovery + + _ -> + res + + +parseResultFromMaybeResult : Maybe (Result Error State) -> ParseResult +parseResultFromMaybeResult x = + case x of + Just (Ok s) -> + ParseResult_Ok s + + Just (Err e) -> + ParseResult_Err e + + Nothing -> + ParseResult_Skip + + type TypeExpressionContext = TypeExpressionContext_Bracket Lexer.BracketType | TypeExpressionContext_Alias @@ -174,17 +214,25 @@ runHelp items state = runHelp rest (case parseAnything state.state item of - Just (Ok newState_) -> + ParseResult_Ok newState_ -> { previousBlocks = state.previousBlocks , state = newState_ } - Just (Err error) -> + ParseResult_Err error -> { previousBlocks = Err ( state.state, error ) :: state.previousBlocks , state = State_Error_Recovery } - Nothing -> + ParseResult_Panic error -> + -- TODO(harry): more violent error heres + { previousBlocks = + Err ( state.state, Error_Panic error ) + :: state.previousBlocks + , state = State_Error_Recovery + } + + ParseResult_Skip -> state ) @@ -200,18 +248,15 @@ runHelp items state = ) -parseAnything : State -> LexItem -> Maybe (Result Error State) +parseAnything : State -> LexItem -> ParseResult parseAnything state = case state of State_Error_Recovery -> parseBlockStart - >> Result.withDefault State_Error_Recovery - >> Ok - >> Just + >> recoverErrors State_BlockStart -> parseBlockStart - >> Just State_BlockFirstItem BlockFirstItem_Type -> parseTypeBlock @@ -280,154 +325,137 @@ parseAnything state = If the LexItem is a `Newlines` with indentation or is `Whitespace`. -} -parseBlockStart : LexItem -> Result Error State +parseBlockStart : LexItem -> ParseResult parseBlockStart item = case item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword Token.Type -> - Ok (State_BlockFirstItem BlockFirstItem_Type) + ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Type) Token.TokenKeyword Token.Module -> - Ok (State_BlockFirstItem BlockFirstItem_Module) + ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Module) Token.TokenKeyword other -> - Err (Error_MisplacedKeyword other) + ParseResult_Err (Error_MisplacedKeyword other) Token.TokenValueOrFunction valOrFunc -> - Ok (State_BlockFirstItem (BlockFirstItem_Name valOrFunc)) + ParseResult_Ok (State_BlockFirstItem (BlockFirstItem_Name valOrFunc)) Token.TokenTypeOrConstructor typeOrConstructor -> - Err (Error_BlockStartsWithTypeOrConstructor typeOrConstructor) + ParseResult_Err (Error_BlockStartsWithTypeOrConstructor typeOrConstructor) Lexer.Newlines _ 0 -> - Ok State_BlockStart + ParseResult_Ok State_BlockStart Lexer.Newlines _ _ -> - Error_Panic "parseBlockStart expects a block but found some indented content" - |> Err + ParseResult_Panic "parseBlockStart expects a block but found some indented content" Lexer.Whitespace _ -> - Error_Panic "parseBlockStart expects a block but found some indented content" - |> Err + ParseResult_Panic "parseBlockStart expects a block but found some indented content" _ -> - Err (Error_InvalidToken item Expecting_Block) + ParseResult_Err (Error_InvalidToken item Expecting_Block) -parseTypeBlock : LexItem -> Maybe (Result Error State) +parseTypeBlock : LexItem -> ParseResult parseTypeBlock item = case item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword Token.Alias -> State_BlockTypeAlias BlockTypeAlias_Keywords - |> Ok - |> Just + |> ParseResult_Ok Token.TokenKeyword other -> Error_MisplacedKeyword other - |> Err - |> Just + |> ParseResult_Err Token.TokenTypeOrConstructor typeOrConstructor -> State_BlockCustomType (BlockCustomType_Named typeOrConstructor) - |> Ok - |> Just + |> ParseResult_Ok Token.TokenValueOrFunction valOrFunc -> Error_TypeNameStartsWithLowerCase valOrFunc - |> Err - |> Just + |> ParseResult_Err Lexer.Newlines _ 0 -> State_BlockStart - |> Ok - |> Just + |> ParseResult_Ok Lexer.Newlines _ _ -> State_BlockFirstItem BlockFirstItem_Type - |> Ok - |> Just + |> ParseResult_Ok Whitespace _ -> - Nothing + ParseResult_Skip _ -> -- TODO(harry) indicate that we could also be expecting the `alias` -- keyword. Error_InvalidToken item Expecting_TypeName - |> Err - |> Just + |> ParseResult_Err -parseTypeAliasName : LexItem -> Maybe (Result Error State) +parseTypeAliasName : LexItem -> ParseResult parseTypeAliasName item = case item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword other -> Error_MisplacedKeyword other - |> Err - |> Just + |> ParseResult_Err Token.TokenTypeOrConstructor typeOrConstructor -> State_BlockTypeAlias (BlockTypeAlias_Named typeOrConstructor) - |> Ok - |> Just + |> ParseResult_Ok Token.TokenValueOrFunction valOrFunc -> Error_TypeNameStartsWithLowerCase valOrFunc - |> Err - |> Just + |> ParseResult_Err Lexer.Newlines _ 0 -> State_BlockStart - |> Ok - |> Just + |> ParseResult_Ok Lexer.Newlines _ _ -> - Nothing + ParseResult_Skip Lexer.Whitespace _ -> - Nothing + ParseResult_Skip _ -> Error_InvalidToken item Expecting_TypeName - |> Err - |> Just + |> ParseResult_Err -parseAssignment : State -> LexItem -> Maybe (Result Error State) +parseAssignment : State -> LexItem -> ParseResult parseAssignment newState item = case item of Lexer.Sigil Lexer.Assign -> newState - |> Ok - |> Just + |> ParseResult_Ok Lexer.Newlines _ 0 -> State_BlockStart - |> Ok - |> Just + |> ParseResult_Ok Lexer.Newlines _ _ -> - Nothing + ParseResult_Skip Lexer.Whitespace _ -> - Nothing + ParseResult_Skip _ -> Error_InvalidToken item (Expecting_Sigil Lexer.Assign) - |> Err - |> Just + |> ParseResult_Err parserTypeExpr : (TypeExpressionResult -> State) -> PartialTypeExpression2 -> LexItem - -> Maybe (Result Error State) + -> ParseResult parserTypeExpr newState { stack, current } item = case item of Lexer.Token str -> @@ -447,8 +475,7 @@ parserTypeExpr newState { stack, current } item = } |> TypeExpressionResult_Progress ) - |> Ok - |> Just + |> ParseResult_Ok ( context, Just (TypeExpression_NamedType { name, args }) ) -> -- TODO(harry): think about how this is fundamentally @@ -470,8 +497,7 @@ parserTypeExpr newState { stack, current } item = } |> TypeExpressionResult_Progress ) - |> Ok - |> Just + |> ParseResult_Ok ( context, Just TypeExpression_Unit ) -> Error_UnitTypeDoesTakeArgs @@ -480,8 +506,7 @@ parserTypeExpr newState { stack, current } item = , args = empty } ) - |> Err - |> Just + |> ParseResult_Err Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> case role of @@ -494,11 +519,10 @@ parserTypeExpr newState { stack, current } item = } |> TypeExpressionResult_Progress ) - |> Ok - |> Just + |> ParseResult_Ok Lexer.Close -> - case current of + (case current of ( TypeExpressionContext_Bracket Lexer.Round, mexpr ) -> case mexpr of Nothing -> @@ -563,22 +587,22 @@ parserTypeExpr newState { stack, current } item = Error_UnmatchedBracket Lexer.Round Lexer.Close |> Err |> Just + ) + |> parseResultFromMaybeResult Lexer.Newlines _ 0 -> State_BlockStart - |> Ok - |> Just + |> ParseResult_Ok Lexer.Newlines _ _ -> - Nothing + ParseResult_Skip Lexer.Whitespace _ -> - Nothing + ParseResult_Skip _ -> Error_InvalidToken item (Expecting_Sigil Lexer.Assign) - |> Err - |> Just + |> ParseResult_Err blockFromState : State -> Maybe (Result Error Block) From b4b00ae466cdfa8f85289e095c93ed0a8529e650 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 00:12:27 +0100 Subject: [PATCH 010/103] add automatic parser/test test generation --- parser-tests/.gitignore | 1 + {tests/parser-tests => parser-tests}/Live.elm | 2 +- parser-tests/Update.elm | 101 +++ {tests/parser-tests => parser-tests}/elm.json | 2 +- {tests/parser-tests => parser-tests}/index.js | 0 parser-tests/snippets/type-alias | 1 + .../parser-tests => parser-tests}/update.js | 59 +- src/Elm/Data/Located.elm | 2 +- src/Stage/Parse/Contextualize.elm | 25 +- tests/ParserLexerTest.elm | 53 +- tests/ParserLexerTestCases.elm | 49 ++ tests/parser-tests/Update.elm | 614 ------------------ 12 files changed, 258 insertions(+), 651 deletions(-) create mode 100644 parser-tests/.gitignore rename {tests/parser-tests => parser-tests}/Live.elm (97%) create mode 100644 parser-tests/Update.elm rename {tests/parser-tests => parser-tests}/elm.json (98%) rename {tests/parser-tests => parser-tests}/index.js (100%) create mode 100644 parser-tests/snippets/type-alias rename {tests/parser-tests => parser-tests}/update.js (59%) mode change 100644 => 100755 create mode 100644 tests/ParserLexerTestCases.elm delete mode 100644 tests/parser-tests/Update.elm diff --git a/parser-tests/.gitignore b/parser-tests/.gitignore new file mode 100644 index 00000000..1942e6d3 --- /dev/null +++ b/parser-tests/.gitignore @@ -0,0 +1 @@ +/elm.js diff --git a/tests/parser-tests/Live.elm b/parser-tests/Live.elm similarity index 97% rename from tests/parser-tests/Live.elm rename to parser-tests/Live.elm index 6f3fb2b6..8788d2de 100644 --- a/tests/parser-tests/Live.elm +++ b/parser-tests/Live.elm @@ -108,7 +108,7 @@ view model = [ Html.div [ Attributes.style "white-space" "pre-wrap" ] [ Html.text - (Debug.toString (Contextualize.parser (lexItems |> List.map Located.unwrap))) + (Debug.toString (Contextualize.run (lexItems |> List.map Located.unwrap))) ] ] diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm new file mode 100644 index 00000000..6f18b8ff --- /dev/null +++ b/parser-tests/Update.elm @@ -0,0 +1,101 @@ +port module Update exposing (main) + +import Elm.Data.Located as Located exposing (Located) +import Platform +import Stage.Parse.Contextualize as Contextualize +import Stage.Parse.Lexer as Lexer +import Parser.Advanced as P + + +port output : String -> Cmd never + + +main : Program Flags Model Msg +main = + Platform.worker + { init = init + , update = update + , subscriptions = subscriptions + } + + +type alias Model = + () + + +type alias Msg = + () + + +type alias Flags = + List + { name : String + , source : String + } + + +subscriptions : Model -> Sub Msg +subscriptions _ = + Sub.none + + +init : Flags -> ( Model, Cmd never ) +init snippets = + let + rlexed : List (Result (List (P.DeadEnd Never Lexer.LexProblem)) (List (Located Lexer.LexItem))) + rlexed = + snippets + |> List.map (.source >> P.run Lexer.parser) + + mrcontextualized : List (Maybe (List (Result ( Contextualize.State, Contextualize.Error ) Contextualize.Block))) + mrcontextualized = + rlexed + |> List.map + (Result.toMaybe + >> Maybe.map + (List.map Located.unwrap + >> Contextualize.run + ) + ) + in + ( () + , output + (""" [ """ + ++ (List.map3 + (\{ name, source } lexed contextualized -> + "{ name = \"" + ++ name + ++ """" + , source = \"\"\"""" + ++ source + ++ """\"\"\" + , lexed = """ + ++ (Debug.toString lexed + |> String.replace "Located" """ + Located""" + ) + ++ """ + , contextualized =""" + ++ (Debug.toString contextualized + |> String.replace "}" """ + }""" + ) + ++ """ + }""" + ) + snippets + rlexed + mrcontextualized + |> String.join """ + , """ + ) + ++ """ + ] + """ + ) + ) + + +update : Msg -> Model -> ( Model, Cmd Msg ) +update () model = + ( model, Cmd.none ) diff --git a/tests/parser-tests/elm.json b/parser-tests/elm.json similarity index 98% rename from tests/parser-tests/elm.json rename to parser-tests/elm.json index 229e02e9..0dc746e1 100644 --- a/tests/parser-tests/elm.json +++ b/parser-tests/elm.json @@ -2,7 +2,7 @@ "type": "application", "source-directories": [ ".", - "../../src" + "../src" ], "elm-version": "0.19.1", "dependencies": { diff --git a/tests/parser-tests/index.js b/parser-tests/index.js similarity index 100% rename from tests/parser-tests/index.js rename to parser-tests/index.js diff --git a/parser-tests/snippets/type-alias b/parser-tests/snippets/type-alias new file mode 100644 index 00000000..28e25425 --- /dev/null +++ b/parser-tests/snippets/type-alias @@ -0,0 +1 @@ +type alias Model = List Int diff --git a/tests/parser-tests/update.js b/parser-tests/update.js old mode 100644 new mode 100755 similarity index 59% rename from tests/parser-tests/update.js rename to parser-tests/update.js index 67a23d15..9ec67ad3 --- a/tests/parser-tests/update.js +++ b/parser-tests/update.js @@ -1,10 +1,16 @@ #!/usr/bin/env node +const fs = require('fs').promises; +const path = require('path'); +const assert = require('assert'); +const {Elm} = require('./elm.js'); + const HELP = ` Usage: parser-tests -Create +Convert the elm syntax snippets in ./snippets to source/lexed/contextualized +test cases in ../ParserLexerTest.elm. Options: -h, --help display this help and exit @@ -13,15 +19,60 @@ Options: const warning_comment_lines = ` --- ESLINT GLOBAL VARIABLES --- --- Do not edit below this line as it is generated by tests/generate-globals.py +-- AUTO GENERATED TEST CASES -- +-- Do not edit below this line or your changes will be overwritten by +-- tests/parser-tests/update.js + ` .trim() .split('\n'); +const TEST_FILE_PATH = path.join(__dirname, '..', 'tests', 'ParserLexerTestCases.elm'); +const SNIPPETS_DIR_PATH = path.join(__dirname, 'snippets'); + +async function main() { + const testFile = await fs.readFile(TEST_FILE_PATH, 'utf-8'); + + const epilogueStart = testFile.indexOf(warning_comment_lines[0]); + assert.notStrictEqual(epilogueStart, -1); + + const testFileStart = testFile.slice(0, epilogueStart).trim(); + + const snippets = await Promise.all( + (await fs.readdir(SNIPPETS_DIR_PATH)).map(async (name) => ({ + name, + source: await fs.readFile(path.join(SNIPPETS_DIR_PATH, name), 'utf-8'), + })) + ); + + const tests = await new Promise((resolve, reject) => { + const app = Elm.Update.init({flags: snippets}); + app.ports.output.subscribe(resolve); + }); + + const newTestFile = [ + testFileStart, + '\n\n', + warning_comment_lines.join('\n'), + '\n', + 'testCases :', + ' List', + ' { contextualized : Maybe (List (Result error1 Block))', + ' , lexed : Result error (List (Located LexItem))', + ' , name : String', + ' , source : String', + ' }', + 'testCases =', + tests, + ].join('\n'); + + await fs.writeFile(TEST_FILE_PATH, newTestFile); +} + +main(); + // import_re = (r"import\s+((?:[.\w]+\.)?(\w+))\s+(?:as (\w+)\s+)?" // r"exposing\s+\((\w+(?:,\s+\w+)*)\)") diff --git a/src/Elm/Data/Located.elm b/src/Elm/Data/Located.elm index 491feb83..44ce3aa0 100644 --- a/src/Elm/Data/Located.elm +++ b/src/Elm/Data/Located.elm @@ -1,5 +1,5 @@ module Elm.Data.Located exposing - ( Located, Region, Position + ( Located(..), Region, Position , located, unwrap, getRegion, map, merge, replaceWith , dummyRegion, mergeRegions, regionToComparable , positionToComparable, comparePosition diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 0584482a..853d7cda 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -225,7 +225,7 @@ runHelp items state = } ParseResult_Panic error -> - -- TODO(harry): more violent error heres + -- TODO(harry): more violent error here { previousBlocks = Err ( state.state, Error_Panic error ) :: state.previousBlocks @@ -380,12 +380,13 @@ parseTypeBlock item = |> ParseResult_Err Lexer.Newlines _ 0 -> - State_BlockStart - |> ParseResult_Ok + -- TODO(harry): we might be partway through a custom type here, + -- adjust error accordingly. + Error_PartwayThroughTypeAlias + |> ParseResult_Err Lexer.Newlines _ _ -> - State_BlockFirstItem BlockFirstItem_Type - |> ParseResult_Ok + ParseResult_Skip Whitespace _ -> ParseResult_Skip @@ -415,8 +416,8 @@ parseTypeAliasName item = |> ParseResult_Err Lexer.Newlines _ 0 -> - State_BlockStart - |> ParseResult_Ok + Error_PartwayThroughTypeAlias + |> ParseResult_Err Lexer.Newlines _ _ -> ParseResult_Skip @@ -437,8 +438,10 @@ parseAssignment newState item = |> ParseResult_Ok Lexer.Newlines _ 0 -> - State_BlockStart - |> ParseResult_Ok + -- TODO(harry): we might be partway through almsot anything here, + -- adjust error accordingly. + Error_PartwayThroughTypeAlias + |> ParseResult_Err Lexer.Newlines _ _ -> ParseResult_Skip @@ -456,7 +459,7 @@ parserTypeExpr : -> PartialTypeExpression2 -> LexItem -> ParseResult -parserTypeExpr newState { stack, current } item = +parserTypeExpr newState ({ stack, current } as prevExpr) item = case item of Lexer.Token str -> case current of @@ -591,7 +594,7 @@ parserTypeExpr newState { stack, current } item = |> parseResultFromMaybeResult Lexer.Newlines _ 0 -> - State_BlockStart + newState (TypeExpressionResult_Progress prevExpr) |> ParseResult_Ok Lexer.Newlines _ _ -> diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm index 501c5665..9b5f31ae 100644 --- a/tests/ParserLexerTest.elm +++ b/tests/ParserLexerTest.elm @@ -1,24 +1,39 @@ -module ParserTest2 exposing (test)) +module ParserLexerTest exposing (tests) -import Dict -import Elm.AST.Frontend as Frontend -import Elm.AST.Frontend.Unwrapped exposing (Expr(..), Pattern(..)) -import Elm.Compiler.Error exposing (ParseContext, ParseProblem) -import Elm.Data.Declaration as Declaration exposing (DeclarationBody) -import Elm.Data.Exposing exposing (ExposedItem(..), Exposing(..)) -import Elm.Data.Module exposing (ModuleType(..)) -import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) -import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) -import Elm.Data.TypeAnnotation exposing (TypeAnnotation) -import Expect exposing (Expectation) -import OurExtras.String as String +import Elm.Data.Located as Located exposing (Located) +import Expect import Parser.Advanced as P -import Stage.Parse.Parser -import String.Extra as String +import ParserLexerTestCases +import Stage.Parse.Contextualize as Contextualize +import Stage.Parse.Lexer as Lexer import Test exposing (Test, describe, test) - --- DO NOT EDIT BELOW THIS LINE - -inputs : List (String, List (Located LexItem), ) +tests = + describe "parser lexer test cases" + (ParserLexerTestCases.testCases + |> List.map + (\{ name, source, lexed, contextualized } -> + describe name + ([ Just + (test "lexing" <| + \() -> + source + |> P.run Lexer.parser + |> Expect.equal lexed + ) + , contextualized + |> Maybe.map + (\contextualized_ -> + test "parsing" <| + \() -> + source + |> P.run Lexer.parser + |> Result.map (List.map Located.unwrap >> Contextualize.run) + |> Expect.equal (Ok contextualized_) + ) + ] + |> List.filterMap (\x -> x) + ) + ) + ) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm new file mode 100644 index 00000000..cf08b19f --- /dev/null +++ b/tests/ParserLexerTestCases.elm @@ -0,0 +1,49 @@ +module ParserLexerTestCases exposing (testCases) + +import Elm.Data.Located as Located exposing (Located(..)) +import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) +import Elm.Data.Type.Concrete exposing (ConcreteType(..)) +import Stage.Parse.Contextualize as Contextualize exposing (..) +import Stage.Parse.Lexer as Lexer exposing (..) +import Stage.Parse.Token exposing (TypeOrConstructor(..)) +import Test exposing (Test, describe, test) + + + +-- AUTO GENERATED TEST CASES +-- +-- Do not edit below this line or your changes will be overwritten by +-- tests/parser-tests/update.js + + +testCases : + List + { contextualized : Maybe (List (Result error1 Block)) + , lexed : Result error (List (Located LexItem)) + , name : String + , source : String + } +testCases = + [ { name = "type-alias" + , source = """type alias Model = List Int +""" + , lexed = Ok [ + Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type"), + Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1), + Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias"), + Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1), + Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model"), + Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1), + Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign), + Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1), + Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List"), + Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1), + Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int"), + Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0)] + , contextualized =Just [Ok (TypeAlias { expr = UserDefinedType { args = [UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing + }], name = "List", qualifiedness = PossiblyQualified Nothing + }, ty = TypeOrConstructor "Model" + })] + } + ] + \ No newline at end of file diff --git a/tests/parser-tests/Update.elm b/tests/parser-tests/Update.elm deleted file mode 100644 index a4efb382..00000000 --- a/tests/parser-tests/Update.elm +++ /dev/null @@ -1,614 +0,0 @@ -module parser-tests.Update exposing (main) - -import Dict exposing (Dict) -import Dict.Extra -import Elm.AST.Frontend as Frontend -import Elm.Compiler.Error as Error exposing (Error(..), ParseError(..)) -import Elm.Data.Declaration as Declaration -import Elm.Data.FileContents exposing (FileContents) -import Elm.Data.FilePath as FilePath exposing (FilePath) -import Elm.Data.Module exposing (Module) -import Elm.Data.ModuleName as ModuleName exposing (ModuleName) -import Elm.Data.Project exposing (Project) -import Elm.Data.Qualifiedness exposing (PossiblyQualified) -import Elm.Data.TypeAnnotation exposing (TypeAnnotation) -import Elm.Project -import Json.Decode as JD -import OurExtras.Tuple3 as Tuple3 -import Parser.Advanced as P -import Platform -import Ports exposing (println) -import Set exposing (Set) -import Stage.Desugar as Desugar -import Stage.Emit.JavaScript as EmitJS -import Stage.Emit.JsonAST as EmitJson -import Stage.InferTypes as InferTypes -import Stage.Optimize as Optimize -import Stage.Parse as Parse -import Stage.Parse.Parser as SPP -import String.Extra - - -{-| We're essentially a Node.JS app (until we get self-hosting :P ). -So, `Platform.worker` is the only option for us. --} -main : Program Flags (Model Frontend.ProjectFields) Msg -main = - Platform.worker - { init = init - , update = update - , subscriptions = subscriptions - } - - -type alias Flags = - { mainFilePath : String - , mainFileContents : String - , elmJson : String - , outputFormat : String - } - - -{-| `Compiling` is the state we'll be most of the time. The other two are -mostly useless; they do effectively stop `subscriptions` and `update` though. --} -type Model projectFields - = Compiling (Model_ projectFields) - | {- We don't need to remember the error, because we report it - at the time of transition to this new model. See `handleFatalError`. - -} - EncounteredError - | Finished - - -{-| Because we're mostly in the `Compiling` state, it is worthwhile -to make functions work with its data instead of the general `Model`. --} -type alias Model_ projectFields = - { project : Project projectFields - , waitingForFiles : Dict ModuleName (Set FilePath) - , outputFormat : String - } - - -type Msg - = ReadFileSuccess - { filePath : FilePath - , fileContents : FileContents - } - | ReadFileError - { moduleName : ModuleName - , filePath : FilePath - , errorCode : String - } - - -subscriptions : Model expr -> Sub Msg -subscriptions model = - case model of - Compiling _ -> - {- We'll be waiting for the various file contents we've asked for - with `readFile`, but only on the happy path. They are of no use - to us when we've already found an error elsewhere or finished - the compilation. - -} - Ports.waitForReadFile - ReadFileError - ReadFileSuccess - - EncounteredError -> - Sub.none - - Finished -> - Sub.none - - -{-| The JS wrapper gives us the main filepath, its contents, and the contents -of the elm.json file. -We have two tasks here: - - - decode the elm.json file to something meaningful - - find (and check against the filepath) the main module name - --} -init : Flags -> ( Model Frontend.ProjectFields, Cmd Msg ) -init { mainFilePath, mainFileContents, elmJson, outputFormat } = - let - elmJsonProject : Result Error Elm.Project.Project - elmJsonProject = - JD.decodeString (JD.map normalizeDirs Elm.Project.decoder) elmJson - |> Result.mapError (ParseError << InvalidElmJson) - - mainModuleName : Result CLIError ModuleName - mainModuleName = - findMainModuleName mainFilePath mainFileContents - - modelAndCmd : Result CLIError ( Model Frontend.ProjectFields, Cmd Msg ) - modelAndCmd = - Result.map2 - (\mainModuleName_ elmJsonProject_ -> - let - model = - { project = - { mainFilePath = mainFilePath - , mainModuleName = mainModuleName_ - , elmJson = elmJsonProject_ - , sourceDirectories = getSourceDirectories elmJsonProject_ - , modules = Dict.empty - } - , waitingForFiles = Dict.singleton mainModuleName_ (Set.singleton mainFilePath) - , outputFormat = outputFormat - } - in - model - |> handleReadFileSuccess - MainModule - { filePath = mainFilePath - , fileContents = mainFileContents - } - ) - mainModuleName - (elmJsonProject |> Result.mapError CompilerError) - in - case modelAndCmd of - Ok modelAndCmd_ -> - modelAndCmd_ - - Err error -> - handleFatalError error - - -{-| First, read the declared module name from the file contents. -Then, check it against the file path. - -The funny thing is that the main file doesn't have to be present in the source -directories mentioned in elm.json, so we have to try and match a part of the -filename with the read module name and see if it matches. - -We can be a little clever: count the dots in the supposedly correct module name -in the file contents, then to get the source directory, remove "that amount + 1" -of parts separated by `/` slashes in the filename. - -Either this agrees or nothing will. - - module C.D.E exposing (..) - A/B/C/D/E.elm - -> 2 dots, remove 2+1 rightmost parts separated by `/` from the filepath - -> remove 3 rightmost parts from [A,B,C,D,E.elm] - -> [A,B] - -> join using "/" - -> `A/B` - --} -findMainModuleName : FilePath -> String -> Result CLIError ModuleName -findMainModuleName filePath contents = - getDeclaredModuleName contents - |> Result.andThen - (\declaredModuleName -> - let - numberOfDotsInModuleName : Int - numberOfDotsInModuleName = - String.Extra.countOccurrences "." declaredModuleName - - sourceDirectory : String - sourceDirectory = - filePath - |> String.split "/" - |> List.reverse - |> List.drop (numberOfDotsInModuleName + 1) - |> List.reverse - |> String.join "/" - in - ModuleName.expectedModuleName - { sourceDirectory = sourceDirectory - , filePath = filePath - } - |> Result.fromMaybe - (ModuleNameDoesntMatchFilePath - { moduleName = declaredModuleName - , filePath = filePath - } - |> ParseError - |> CompilerError - ) - ) - - -getDeclaredModuleName : String -> Result CLIError ModuleName -getDeclaredModuleName fileContents = - P.run SPP.moduleDeclaration fileContents - |> Result.map Tuple3.second - |> Result.mapError - (\err -> - ( err, fileContents ) - |> ParseProblem - |> ParseError - |> CompilerError - ) - - -normalizeDirs : Elm.Project.Project -> Elm.Project.Project -normalizeDirs project = - case project of - Elm.Project.Application data -> - Elm.Project.Application - { data - | dirs = - List.map - FilePath.removeTrailingSlash - data.dirs - } - - Elm.Project.Package data -> - Elm.Project.Package data - - -{-| Applications tell us their source directories; packages have `src/`. --} -getSourceDirectories : Elm.Project.Project -> List FilePath -getSourceDirectories elmProject = - case elmProject of - Elm.Project.Application { dirs } -> - dirs - - Elm.Project.Package _ -> - [ "src" ] - - -update : Msg -> Model Frontend.ProjectFields -> ( Model Frontend.ProjectFields, Cmd Msg ) -update msg model = - case model of - Compiling model_ -> - update_ msg model_ - - EncounteredError -> - ( model, Cmd.none ) - - Finished -> - ( model, Cmd.none ) - - -update_ : Msg -> Model_ Frontend.ProjectFields -> ( Model Frontend.ProjectFields, Cmd Msg ) -update_ msg model = - case {- log -} msg of - ReadFileSuccess file -> - handleReadFileSuccess OtherModule file model - - ReadFileError r -> - handleReadFileError r model - - -type ModuleType - = MainModule - | OtherModule - - -handleReadFileSuccess : - ModuleType - -> { filePath : FilePath, fileContents : FileContents } - -> Model_ Frontend.ProjectFields - -> ( Model Frontend.ProjectFields, Cmd Msg ) -handleReadFileSuccess moduleType ({ filePath } as file) ({ project } as model) = - if isWaitingFor filePath model then - let - parseResult = - Parse.parse file - |> Result.andThen - (case moduleType of - MainModule -> - {- We've already checked the main module name in a - bit different way during `init`. (Differently - because main modules don't need to live inside - the source directories.) No need to check - it again! - -} - Ok - - OtherModule -> - checkModuleNameAndFilePath - { sourceDirectories = project.sourceDirectories - , filePath = filePath - } - ) - in - case parseResult of - Err error -> - handleFatalError <| CompilerError error - - Ok ({ name, imports } as parsedModule) -> - let - newModules : Dict ModuleName (Module Frontend.LocatedExpr TypeAnnotation PossiblyQualified) - newModules = - Dict.update name - (always (Just parsedModule)) - project.modules - - newProject : Project Frontend.ProjectFields - newProject = - { project | modules = newModules } - - filesToBeRead : Dict ModuleName (Set FilePath) - filesToBeRead = - imports - |> Dict.filter (\moduleName _ -> not <| Dict.member moduleName newModules) - |> Dict.keys - |> List.map - (\moduleName -> - {- We don't know in which source directory the - module will be, so we're trying them all. - - Our Model_.waitingForFiles remembers all the - tries and: - * when one succeeds the others are forgotten - * when all fail we raise an error - -} - ( moduleName - , project.sourceDirectories - |> List.map - (\sourceDirectory -> - FilePath.expectedFilePath - { sourceDirectory = sourceDirectory - , moduleName = moduleName - } - ) - |> Set.fromList - ) - ) - |> Dict.fromList - - newWaitingForFiles : Dict ModuleName (Set FilePath) - newWaitingForFiles = - model.waitingForFiles - |> Dict.remove name - {- There's no need for a more general Dict.merge - here because a module name is always going to - generate the same set of possible file paths over - the run of the compiler. - -} - |> Dict.union filesToBeRead - - newModel : Model_ Frontend.ProjectFields - newModel = - { model - | project = newProject - , waitingForFiles = newWaitingForFiles - } - in - if Dict.isEmpty newWaitingForFiles then - compile model.outputFormat newProject - - else - ( Compiling newModel - , filesToBeRead - |> Dict.toList - |> List.concatMap - (\( moduleName, possibleFiles ) -> - possibleFiles - |> Set.toList - |> List.map - (\filePath_ -> - { moduleName = moduleName - , filePath = filePath_ - } - ) - ) - |> List.map Ports.readFile - |> Cmd.batch - ) - - else - handleFatalError (MultipleFilesForModule filePath) - - -isWaitingFor : FilePath -> Model_ projectFields -> Bool -isWaitingFor filePath { waitingForFiles } = - Dict.Extra.any - (\_ possibleFiles -> Set.member filePath possibleFiles) - waitingForFiles - - -handleReadFileError : - { moduleName : ModuleName - , filePath : FilePath - , errorCode : String - } - -> Model_ Frontend.ProjectFields - -> ( Model Frontend.ProjectFields, Cmd Msg ) -handleReadFileError { moduleName, filePath } model = - case Dict.get moduleName model.waitingForFiles of - Nothing -> - {- We've got a read error after a file was successfully found - elsewhere; we can safely ignore it! - -} - ( Compiling model - , Cmd.none - ) - - Just possibleFiles -> - if Set.isEmpty (Set.remove filePath possibleFiles) then - -- This was our last chance for finding that module! - handleFatalError (ModuleNotInSourceDirectories moduleName) - - else - ( Compiling - { model - | waitingForFiles = - model.waitingForFiles - |> Dict.update moduleName - {- Due to the above `Set.isEmpty` check we know that - removing this possibility leaves some more - possibilities open; we won't end up with an empty - set then. - -} - (Maybe.map (Set.remove filePath)) - } - , Cmd.none - ) - - -{-| We're done reading and parsing files. All the IO is done, now we can do -the rest synchronously! --} -compile : String -> Project Frontend.ProjectFields -> ( Model Frontend.ProjectFields, Cmd Msg ) -compile format project = - let - _ = - project.modules - |> Dict.values - |> List.map - (\module_ -> - Dict.values module_.declarations - |> List.map - (\decl -> - decl.body - |> Declaration.mapBody - Frontend.unwrap - identity - identity - |> Debug.log (decl.module_ ++ "." ++ decl.name) - ) - ) - - emitter = - case format of - "JSON" -> - EmitJson.emitProject - - _ -> - EmitJS.emitProject - in - Ok project - |> Result.andThen Desugar.desugar - |> Result.andThen InferTypes.inferTypes - |> Result.map Optimize.optimize - |> Result.andThen emitter - |> Result.mapError CompilerError - |> writeToFSAndExit - - -{-| We've got our output ready for writing to the filesystem! -(Well, that or an error somewhere along the process.) - -Let's do that - report the error or write the output to a file. - --} -writeToFSAndExit : - Result CLIError (Dict FilePath FileContents) - -> ( Model Frontend.ProjectFields, Cmd Msg ) -writeToFSAndExit result = - case result of - Ok outputFiles -> - let - outputCmds = - outputFiles - |> Dict.toList - |> List.map - (\( filePath, fileContents ) -> - Ports.writeToFile - { filePath = filePath - , fileContents = fileContents - } - ) - in - ( Finished - , Cmd.batch - (println "Compilation finished, writing output to `out.js`." - :: outputCmds - ) - ) - - Err error -> - handleFatalError error - - -{-| When an error happens, we bail out as early as possible. -Stop everything, abort mission, jump ship! - -The `EncounteredError` model stops most everything (`update`, `subscriptions`). - --} -handleFatalError : CLIError -> ( Model dontcare, Cmd Msg ) -handleFatalError error = - ( EncounteredError - , Cmd.batch - [ Ports.printlnStderr (errorToString error) - , Ports.setExitCode 1 - ] - ) - - -log : Msg -> Msg -log msg = - let - string = - case msg of - ReadFileSuccess { filePath } -> - "ReadFileSuccess: " ++ filePath - - ReadFileError error -> - "ReadFileError: " ++ Debug.toString error - - _ = - Debug.log string () - in - msg - - - --- ERRORS - - -type CLIError - = ModuleNotInSourceDirectories ModuleName - | MultipleFilesForModule FilePath - | CompilerError Error - - -errorToString : CLIError -> String -errorToString error = - case error of - ModuleNotInSourceDirectories moduleName -> - "Module `" - ++ moduleName - ++ "` cannot be found in your `sourceDirectories`." - - MultipleFilesForModule filePath -> - {- TODO better error by tracking both the previously successful file - and this one, and the module name. - -} - "File `" - ++ filePath - ++ "` clashes with some other module in your `sourceDirectories`." - - CompilerError compilerError -> - Error.toString compilerError - - -{-| TODO maybe there should be a "Checks" module for checks across phases? --} -checkModuleNameAndFilePath : - { sourceDirectories : List FilePath, filePath : FilePath } - -> Module Frontend.LocatedExpr TypeAnnotation PossiblyQualified - -> Result Error (Module Frontend.LocatedExpr TypeAnnotation PossiblyQualified) -checkModuleNameAndFilePath { sourceDirectories, filePath } ({ name } as parsedModule) = - let - makesNameAgree : FilePath -> Bool - makesNameAgree sourceDirectory = - ModuleName.expectedModuleName - { sourceDirectory = sourceDirectory - , filePath = filePath - } - == Just name - in - if List.any makesNameAgree sourceDirectories then - Ok parsedModule - - else - Err - (ParseError - (ModuleNameDoesntMatchFilePath - { moduleName = name - , filePath = filePath - } - ) - ) From 00a8ebee47261294b6da643b41ba9b37d31dbfeb Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 10:57:45 +0100 Subject: [PATCH 011/103] add extra parser/lexer test cases and fix contextualisation so that the new cases do not cause crashes --- Makefile | 7 + parser-tests/index.js | 36 --- .../snippets/type-alias-funky-indentation | 2 + .../snippets/type-alias-funky-indentation-2 | 3 + parser-tests/snippets/type-alias-partial | 1 + parser-tests/snippets/type-alias-partial-2 | 1 + parser-tests/snippets/type-alias-partial-3 | 1 + parser-tests/snippets/type-partial | 1 + parser-tests/update.js | 34 +-- src/Stage/Parse/Contextualize.elm | 39 ++-- src/Stage/Parse/Lexer.elm | 2 +- tests/ParserLexerTestCases.elm | 212 ++++++++++++++++-- 12 files changed, 243 insertions(+), 96 deletions(-) delete mode 100644 parser-tests/index.js create mode 100644 parser-tests/snippets/type-alias-funky-indentation create mode 100644 parser-tests/snippets/type-alias-funky-indentation-2 create mode 100644 parser-tests/snippets/type-alias-partial create mode 100644 parser-tests/snippets/type-alias-partial-2 create mode 100644 parser-tests/snippets/type-alias-partial-3 create mode 100644 parser-tests/snippets/type-partial diff --git a/Makefile b/Makefile index cd440061..ed2268ad 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,13 @@ test: build npx elm-test npx ava +.PHONY: regenerate +regenerate: + cd parser-tests \ + && npx elm make Update.elm --output elm.js \ + && node update + elm-format tests/ParserLexerTestCases.elm --yes + .PHONY: format format: npx elm-format $(FORMAT_DIRS) --yes diff --git a/parser-tests/index.js b/parser-tests/index.js deleted file mode 100644 index 1f8a37df..00000000 --- a/parser-tests/index.js +++ /dev/null @@ -1,36 +0,0 @@ -const {Elm} = require('./elm.js'); -const readline = require('readline'); - -module.exports = (name, opts) => { - const program = Elm[name].init({ - flags: {argv: process.argv, versionMessage: '0.0.1'}, - }); - - program.ports.print.subscribe((message) => { - console.log(message); - }); - program.ports.printAndExitFailure.subscribe((message) => { - console.log(message); - process.exit(1); - }); - program.ports.printAndExitSuccess.subscribe((message) => { - console.log(message); - process.exit(0); - }); - - if (opts && opts.stdin) { - const rl = readline.createInterface({ - input: process.stdin, - output: process.stdout, - terminal: false, - }); - - rl.on('line', function (line) { - program.ports.onStdinLine.send(line); - }); - - rl.on('close', function (line) { - program.ports.onStdinClosed.send(null); - }); - } -}; diff --git a/parser-tests/snippets/type-alias-funky-indentation b/parser-tests/snippets/type-alias-funky-indentation new file mode 100644 index 00000000..8550df91 --- /dev/null +++ b/parser-tests/snippets/type-alias-funky-indentation @@ -0,0 +1,2 @@ +type alias + Model = List Int diff --git a/parser-tests/snippets/type-alias-funky-indentation-2 b/parser-tests/snippets/type-alias-funky-indentation-2 new file mode 100644 index 00000000..c2026530 --- /dev/null +++ b/parser-tests/snippets/type-alias-funky-indentation-2 @@ -0,0 +1,3 @@ +type alias + Model = + List Int diff --git a/parser-tests/snippets/type-alias-partial b/parser-tests/snippets/type-alias-partial new file mode 100644 index 00000000..75eda7f0 --- /dev/null +++ b/parser-tests/snippets/type-alias-partial @@ -0,0 +1 @@ +type alias diff --git a/parser-tests/snippets/type-alias-partial-2 b/parser-tests/snippets/type-alias-partial-2 new file mode 100644 index 00000000..2d0f58fe --- /dev/null +++ b/parser-tests/snippets/type-alias-partial-2 @@ -0,0 +1 @@ +type alias Hi diff --git a/parser-tests/snippets/type-alias-partial-3 b/parser-tests/snippets/type-alias-partial-3 new file mode 100644 index 00000000..b9163533 --- /dev/null +++ b/parser-tests/snippets/type-alias-partial-3 @@ -0,0 +1 @@ +type alias Hi = diff --git a/parser-tests/snippets/type-partial b/parser-tests/snippets/type-partial new file mode 100644 index 00000000..aa80e646 --- /dev/null +++ b/parser-tests/snippets/type-partial @@ -0,0 +1 @@ +type diff --git a/parser-tests/update.js b/parser-tests/update.js index 9ec67ad3..baa6d508 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -5,19 +5,7 @@ const path = require('path'); const assert = require('assert'); const {Elm} = require('./elm.js'); -const HELP = ` - -Usage: parser-tests - -Convert the elm syntax snippets in ./snippets to source/lexed/contextualized -test cases in ../ParserLexerTest.elm. - -Options: --h, --help display this help and exit - -`.trim(); - -const warning_comment_lines = ` +const warningCommentLines = ` -- AUTO GENERATED TEST CASES -- @@ -35,19 +23,19 @@ const SNIPPETS_DIR_PATH = path.join(__dirname, 'snippets'); async function main() { const testFile = await fs.readFile(TEST_FILE_PATH, 'utf-8'); - const epilogueStart = testFile.indexOf(warning_comment_lines[0]); + const epilogueStart = testFile.indexOf(warningCommentLines[0]); assert.notStrictEqual(epilogueStart, -1); const testFileStart = testFile.slice(0, epilogueStart).trim(); const snippets = await Promise.all( - (await fs.readdir(SNIPPETS_DIR_PATH)).map(async (name) => ({ + (await fs.readdir(SNIPPETS_DIR_PATH)).sort().map(async (name) => ({ name, source: await fs.readFile(path.join(SNIPPETS_DIR_PATH, name), 'utf-8'), })) ); - const tests = await new Promise((resolve, reject) => { + const tests = await new Promise((resolve) => { const app = Elm.Update.init({flags: snippets}); app.ports.output.subscribe(resolve); }); @@ -55,15 +43,15 @@ async function main() { const newTestFile = [ testFileStart, '\n\n', - warning_comment_lines.join('\n'), + warningCommentLines.join('\n'), '\n', 'testCases :', ' List', - ' { contextualized : Maybe (List (Result error1 Block))', - ' , lexed : Result error (List (Located LexItem))', - ' , name : String', - ' , source : String', - ' }', + ' { contextualized : Maybe (List (Result ( State, Error ) Block))', + ' , lexed : Result error (List (Located LexItem))', + ' , name : String', + ' , source : String', + ' }', 'testCases =', tests, ].join('\n'); @@ -73,7 +61,7 @@ async function main() { main(); -// import_re = (r"import\s+((?:[.\w]+\.)?(\w+))\s+(?:as (\w+)\s+)?" +// Import_re = (r"import\s+((?:[.\w]+\.)?(\w+))\s+(?:as (\w+)\s+)?" // r"exposing\s+\((\w+(?:,\s+\w+)*)\)") // def processFile(file): diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 853d7cda..759a3861 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -188,7 +188,8 @@ type Error | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole | Error_UnitTypeDoesTakeArgs PartialTypeExpression - | Error_PartwayThroughTypeAlias + | Error_PartwayThroughCustomType + | Error_PartwayThroughTypeAlias BlockTypeAlias | Error_Panic String @@ -380,9 +381,9 @@ parseTypeBlock item = |> ParseResult_Err Lexer.Newlines _ 0 -> - -- TODO(harry): we might be partway through a custom type here, + -- TODO(harry): we might be partway through a type alias here, -- adjust error accordingly. - Error_PartwayThroughTypeAlias + Error_PartwayThroughCustomType |> ParseResult_Err Lexer.Newlines _ _ -> @@ -416,7 +417,7 @@ parseTypeAliasName item = |> ParseResult_Err Lexer.Newlines _ 0 -> - Error_PartwayThroughTypeAlias + Error_PartwayThroughTypeAlias BlockTypeAlias_Keywords |> ParseResult_Err Lexer.Newlines _ _ -> @@ -440,7 +441,7 @@ parseAssignment newState item = Lexer.Newlines _ 0 -> -- TODO(harry): we might be partway through almsot anything here, -- adjust error accordingly. - Error_PartwayThroughTypeAlias + Error_PartwayThroughCustomType |> ParseResult_Err Lexer.Newlines _ _ -> @@ -620,22 +621,22 @@ blockFromState state = State_BlockFirstItem firstItem -> Debug.todo "handle incomplete block" - State_BlockTypeAlias BlockTypeAlias_Keywords -> - Error_PartwayThroughTypeAlias + State_BlockTypeAlias (BlockTypeAlias_Keywords as ta) -> + Error_PartwayThroughTypeAlias ta |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Named _) -> - Error_PartwayThroughTypeAlias + State_BlockTypeAlias ((BlockTypeAlias_Named _) as ta) -> + Error_PartwayThroughTypeAlias ta |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_NamedAssigns _) -> - Error_PartwayThroughTypeAlias + State_BlockTypeAlias ((BlockTypeAlias_NamedAssigns _) as ta) -> + Error_PartwayThroughTypeAlias ta |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Completish name { stack, current }) -> + State_BlockTypeAlias ((BlockTypeAlias_Completish name { stack, current }) as ta) -> let -- _ = -- Debug.log "part" partialExpr @@ -652,7 +653,19 @@ blockFromState state = |> Ok |> Just - _ -> + ( Nothing, TypeExpressionContext_Alias, Nothing ) -> + Error_PartwayThroughTypeAlias ta + |> Err + |> Just + + x -> + let + _ = + Debug.log "we have" state + + _ = + Debug.log "we have" x + in Debug.todo "handle maybe incomplete block" State_BlockTypeAlias (BlockTypeAlias_Complete name expr) -> diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 24e493d1..82b29762 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -192,7 +192,7 @@ toString item = String.repeat i " " Newlines empties identationSpaces -> - (Debug.log "empties" empties + (empties |> List.map (\spacesInEmptyLine -> "\n" ++ String.repeat spacesInEmptyLine " ") |> String.join "" ) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index cf08b19f..f789dd38 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -18,32 +18,198 @@ import Test exposing (Test, describe, test) testCases : List - { contextualized : Maybe (List (Result error1 Block)) - , lexed : Result error (List (Located LexItem)) - , name : String - , source : String - } + { contextualized : Maybe (List (Result ( State, Error ) Block)) + , lexed : Result error (List (Located LexItem)) + , name : String + , source : String + } testCases = [ { name = "type-alias" , source = """type alias Model = List Int """ - , lexed = Ok [ - Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type"), - Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1), - Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias"), - Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1), - Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model"), - Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1), - Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign), - Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1), - Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List"), - Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1), - Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int"), - Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0)] - , contextualized =Just [Ok (TypeAlias { expr = UserDefinedType { args = [UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing - }], name = "List", qualifiedness = PossiblyQualified Nothing - }, ty = TypeOrConstructor "Model" - })] + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int") + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , ty = TypeOrConstructor "Model" + } + ) + ] + } + , { name = "type-alias-funky-indentation" + , source = """type alias + Model = List Int +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) + , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token "Model") + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 1) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Sigil Assign) + , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Whitespace 1) + , Located { end = { col = 17, row = 2 }, start = { col = 13, row = 2 } } (Token "List") + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Whitespace 1) + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 2 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , ty = TypeOrConstructor "Model" + } + ) + ] + } + , { name = "type-alias-funky-indentation-2" + , source = """type alias + Model = + List Int +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) + , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token "Model") + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 1) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Sigil Assign) + , Located { end = { col = 2, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 1) + , Located { end = { col = 6, row = 3 }, start = { col = 2, row = 3 } } (Token "List") + , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) + , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Token "Int") + , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , ty = TypeOrConstructor "Model" + } + ) + ] + } + , { name = "type-alias-partial" + , source = """type alias +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) + ] + , contextualized = Just [ Err ( State_BlockTypeAlias BlockTypeAlias_Keywords, Error_PartwayThroughTypeAlias BlockTypeAlias_Keywords ) ] + } + , { name = "type-alias-partial-2" + , source = """type alias Hi +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) + ] + , contextualized = Just [ Err ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")), Error_PartwayThroughCustomType ) ] + } + , { name = "type-alias-partial-3" + , source = """type alias Hi = +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { current = ( TypeExpressionContext_Alias, Nothing ) + , stack = Stack [] + } + ) + , Error_PartwayThroughTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { current = ( TypeExpressionContext_Alias, Nothing ) + , stack = Stack [] + } + ) + ) + ] + } + , { name = "type-partial" + , source = """type +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0) + ] + , contextualized = Just [ Err ( State_BlockFirstItem BlockFirstItem_Type, Error_PartwayThroughCustomType ) ] } ] - \ No newline at end of file From 5b72af1ec325652a78569e0a8878ca9daa08735c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 11:05:36 +0100 Subject: [PATCH 012/103] improve test case formatting --- parser-tests/Update.elm | 16 ++++++--- parser-tests/update.js | 65 ---------------------------------- tests/ParserLexerTestCases.elm | 48 +++++++++---------------- 3 files changed, 28 insertions(+), 101 deletions(-) diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 6f18b8ff..bd214cf4 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -71,14 +71,12 @@ init snippets = ++ """\"\"\" , lexed = """ ++ (Debug.toString lexed - |> String.replace "Located" """ - Located""" + |> preFormatElmCode ) ++ """ , contextualized =""" ++ (Debug.toString contextualized - |> String.replace "}" """ - }""" + |> preFormatElmCode ) ++ """ }""" @@ -99,3 +97,13 @@ init snippets = update : Msg -> Model -> ( Model, Cmd Msg ) update () model = ( model, Cmd.none ) + + +preFormatElmCode : String -> String +preFormatElmCode = + {-String.replace "}" """ + }""" + >>-} String.replace "]" """ + ]""" + >> String.replace """[ + ]""" "[]" diff --git a/parser-tests/update.js b/parser-tests/update.js index baa6d508..218b74f3 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -60,68 +60,3 @@ async function main() { } main(); - -// Import_re = (r"import\s+((?:[.\w]+\.)?(\w+))\s+(?:as (\w+)\s+)?" -// r"exposing\s+\((\w+(?:,\s+\w+)*)\)") - -// def processFile(file): -// globals = [] - -// module_name = Path(file).stem - -// last_line_empty = False - -// with fileinput.input(file, inplace=True) as f: -// for line in f: -// if line.startswith(warning_comment_lines[0]): -// break -// else: -// print(line, end='') -// last_line_empty = line.strip() == '' -// importMatch = re.search(import_re, line) - -// if importMatch is not None: -// # Use alias if it is there, otherwise use last part of -// # import. -// moduleAlias = importMatch[3] -// if moduleAlias is None: -// moduleAlias = importMatch[2] - -// vars = map( -// lambda defName: "__{}_{}".format( -// moduleAlias, defName.strip()), -// importMatch[4].split(","), -// ) - -// globals.append("/* global {} */".format(", ".join(vars))) - -// unused_var_config = '{{ "varsIgnorePattern": "_{}_.*" }}'.format( -// module_name) - -// with open(file, "a") as f: -// if not last_line_empty: -// print(file=f) - -// print("\n".join(warning_comment_lines), file=f) -// print(file=f) -// print('/* eslint no-unused-vars: ["error", {}] */'.format( -// unused_var_config), -// file=f) -// print(file=f) -// print("\n".join(globals), file=f) - -// def main(): -// if len(sys.argv) < 2: -// print("generate-globals.py: error! At least one path or glob required", -// file=sys.stderr) -// exit(1) - -// if "-h" in sys.argv or "--help" in sys.argv: -// print(HELP) -// exit(0) - -// for provided_glob in sys.argv[1:]: -// for path in glob.glob(provided_glob, recursive=True): -// processFile(path) - -// main() diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index f789dd38..010eb522 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -49,11 +49,7 @@ testCases = { expr = UserDefinedType { args = - [ UserDefinedType - { args = [] - , name = "Int" - , qualifiedness = PossiblyQualified Nothing - } + [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -89,11 +85,7 @@ testCases = { expr = UserDefinedType { args = - [ UserDefinedType - { args = [] - , name = "Int" - , qualifiedness = PossiblyQualified Nothing - } + [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -130,11 +122,7 @@ testCases = { expr = UserDefinedType { args = - [ UserDefinedType - { args = [] - , name = "Int" - , qualifiedness = PossiblyQualified Nothing - } + [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -154,7 +142,10 @@ testCases = , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) ] - , contextualized = Just [ Err ( State_BlockTypeAlias BlockTypeAlias_Keywords, Error_PartwayThroughTypeAlias BlockTypeAlias_Keywords ) ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias BlockTypeAlias_Keywords, Error_PartwayThroughTypeAlias BlockTypeAlias_Keywords ) + ] } , { name = "type-alias-partial-2" , source = """type alias Hi @@ -168,7 +159,10 @@ testCases = , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) ] - , contextualized = Just [ Err ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")), Error_PartwayThroughCustomType ) ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")), Error_PartwayThroughCustomType ) + ] } , { name = "type-alias-partial-3" , source = """type alias Hi = @@ -186,20 +180,7 @@ testCases = ] , contextualized = Just - [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = ( TypeExpressionContext_Alias, Nothing ) - , stack = Stack [] - } - ) - , Error_PartwayThroughTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = ( TypeExpressionContext_Alias, Nothing ) - , stack = Stack [] - } - ) - ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { current = ( TypeExpressionContext_Alias, Nothing ), stack = Stack [] }), Error_PartwayThroughTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { current = ( TypeExpressionContext_Alias, Nothing ), stack = Stack [] }) ) ] } , { name = "type-partial" @@ -210,6 +191,9 @@ testCases = [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0) ] - , contextualized = Just [ Err ( State_BlockFirstItem BlockFirstItem_Type, Error_PartwayThroughCustomType ) ] + , contextualized = + Just + [ Err ( State_BlockFirstItem BlockFirstItem_Type, Error_PartwayThroughCustomType ) + ] } ] From abda9e15386634f4a85cf57a2d92c7dac36a4374 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 11:07:00 +0100 Subject: [PATCH 013/103] remove current state from errors we return the current state seperately so this is just duplication --- src/Stage/Parse/Contextualize.elm | 27 +++++++++++++-------------- tests/ParserLexerTestCases.elm | 8 ++++---- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 759a3861..12cddb50 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -188,8 +188,7 @@ type Error | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole | Error_UnitTypeDoesTakeArgs PartialTypeExpression - | Error_PartwayThroughCustomType - | Error_PartwayThroughTypeAlias BlockTypeAlias + | Error_PartwayThroughTypeAlias | Error_Panic String @@ -381,9 +380,9 @@ parseTypeBlock item = |> ParseResult_Err Lexer.Newlines _ 0 -> - -- TODO(harry): we might be partway through a type alias here, + -- TODO(harry): we might be partway through a custom type here, -- adjust error accordingly. - Error_PartwayThroughCustomType + Error_PartwayThroughTypeAlias |> ParseResult_Err Lexer.Newlines _ _ -> @@ -417,7 +416,7 @@ parseTypeAliasName item = |> ParseResult_Err Lexer.Newlines _ 0 -> - Error_PartwayThroughTypeAlias BlockTypeAlias_Keywords + Error_PartwayThroughTypeAlias |> ParseResult_Err Lexer.Newlines _ _ -> @@ -441,7 +440,7 @@ parseAssignment newState item = Lexer.Newlines _ 0 -> -- TODO(harry): we might be partway through almsot anything here, -- adjust error accordingly. - Error_PartwayThroughCustomType + Error_PartwayThroughTypeAlias |> ParseResult_Err Lexer.Newlines _ _ -> @@ -621,22 +620,22 @@ blockFromState state = State_BlockFirstItem firstItem -> Debug.todo "handle incomplete block" - State_BlockTypeAlias (BlockTypeAlias_Keywords as ta) -> - Error_PartwayThroughTypeAlias ta + State_BlockTypeAlias BlockTypeAlias_Keywords -> + Error_PartwayThroughTypeAlias |> Err |> Just - State_BlockTypeAlias ((BlockTypeAlias_Named _) as ta) -> - Error_PartwayThroughTypeAlias ta + State_BlockTypeAlias (BlockTypeAlias_Named _) -> + Error_PartwayThroughTypeAlias |> Err |> Just - State_BlockTypeAlias ((BlockTypeAlias_NamedAssigns _) as ta) -> - Error_PartwayThroughTypeAlias ta + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns _) -> + Error_PartwayThroughTypeAlias |> Err |> Just - State_BlockTypeAlias ((BlockTypeAlias_Completish name { stack, current }) as ta) -> + State_BlockTypeAlias (BlockTypeAlias_Completish name { stack, current }) -> let -- _ = -- Debug.log "part" partialExpr @@ -654,7 +653,7 @@ blockFromState state = |> Just ( Nothing, TypeExpressionContext_Alias, Nothing ) -> - Error_PartwayThroughTypeAlias ta + Error_PartwayThroughTypeAlias |> Err |> Just diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 010eb522..2289b505 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -144,7 +144,7 @@ testCases = ] , contextualized = Just - [ Err ( State_BlockTypeAlias BlockTypeAlias_Keywords, Error_PartwayThroughTypeAlias BlockTypeAlias_Keywords ) + [ Err ( State_BlockTypeAlias BlockTypeAlias_Keywords, Error_PartwayThroughTypeAlias ) ] } , { name = "type-alias-partial-2" @@ -161,7 +161,7 @@ testCases = ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")), Error_PartwayThroughCustomType ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")), Error_PartwayThroughTypeAlias ) ] } , { name = "type-alias-partial-3" @@ -180,7 +180,7 @@ testCases = ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { current = ( TypeExpressionContext_Alias, Nothing ), stack = Stack [] }), Error_PartwayThroughTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { current = ( TypeExpressionContext_Alias, Nothing ), stack = Stack [] }) ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { current = ( TypeExpressionContext_Alias, Nothing ), stack = Stack [] }), Error_PartwayThroughTypeAlias ) ] } , { name = "type-partial" @@ -193,7 +193,7 @@ testCases = ] , contextualized = Just - [ Err ( State_BlockFirstItem BlockFirstItem_Type, Error_PartwayThroughCustomType ) + [ Err ( State_BlockFirstItem BlockFirstItem_Type, Error_PartwayThroughTypeAlias ) ] } ] From 370eeeb68a8e76b321513dd92fc9a944b8cf4e47 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 11:32:06 +0100 Subject: [PATCH 014/103] add type alias test cases with brackets and fix crashes (and buggy parsing of bad syntax into a valid AST). --- .../type-alias-invalid-multiple-brackets | 1 + .../type-alias-invalid-multiple-brackets-2 | 1 + .../type-alias-invalid-multiple-brackets-3 | 1 + .../snippets/type-alias-partial-with-bracket | 1 + .../type-alias-partial-with-bracket-2 | 2 + parser-tests/snippets/type-alias-unit | 1 + parser-tests/snippets/type-alias-with-bracket | 1 + src/Stage/Parse/Contextualize.elm | 116 +++++---- tests/ParserLexerTestCases.elm | 222 ++++++++++++++++++ 9 files changed, 285 insertions(+), 61 deletions(-) create mode 100644 parser-tests/snippets/type-alias-invalid-multiple-brackets create mode 100644 parser-tests/snippets/type-alias-invalid-multiple-brackets-2 create mode 100644 parser-tests/snippets/type-alias-invalid-multiple-brackets-3 create mode 100644 parser-tests/snippets/type-alias-partial-with-bracket create mode 100644 parser-tests/snippets/type-alias-partial-with-bracket-2 create mode 100644 parser-tests/snippets/type-alias-unit create mode 100644 parser-tests/snippets/type-alias-with-bracket diff --git a/parser-tests/snippets/type-alias-invalid-multiple-brackets b/parser-tests/snippets/type-alias-invalid-multiple-brackets new file mode 100644 index 00000000..a296281f --- /dev/null +++ b/parser-tests/snippets/type-alias-invalid-multiple-brackets @@ -0,0 +1 @@ +type alias Hi = (Int) () diff --git a/parser-tests/snippets/type-alias-invalid-multiple-brackets-2 b/parser-tests/snippets/type-alias-invalid-multiple-brackets-2 new file mode 100644 index 00000000..14e48f96 --- /dev/null +++ b/parser-tests/snippets/type-alias-invalid-multiple-brackets-2 @@ -0,0 +1 @@ +type alias Hi = () () diff --git a/parser-tests/snippets/type-alias-invalid-multiple-brackets-3 b/parser-tests/snippets/type-alias-invalid-multiple-brackets-3 new file mode 100644 index 00000000..b6cca46d --- /dev/null +++ b/parser-tests/snippets/type-alias-invalid-multiple-brackets-3 @@ -0,0 +1 @@ +type alias Hi = () (Int) diff --git a/parser-tests/snippets/type-alias-partial-with-bracket b/parser-tests/snippets/type-alias-partial-with-bracket new file mode 100644 index 00000000..e834db67 --- /dev/null +++ b/parser-tests/snippets/type-alias-partial-with-bracket @@ -0,0 +1 @@ +type alias Hi = ( diff --git a/parser-tests/snippets/type-alias-partial-with-bracket-2 b/parser-tests/snippets/type-alias-partial-with-bracket-2 new file mode 100644 index 00000000..338f61f0 --- /dev/null +++ b/parser-tests/snippets/type-alias-partial-with-bracket-2 @@ -0,0 +1,2 @@ +type alias Hi = ( + Int diff --git a/parser-tests/snippets/type-alias-unit b/parser-tests/snippets/type-alias-unit new file mode 100644 index 00000000..70908a19 --- /dev/null +++ b/parser-tests/snippets/type-alias-unit @@ -0,0 +1 @@ +type alias Hi = () diff --git a/parser-tests/snippets/type-alias-with-bracket b/parser-tests/snippets/type-alias-with-bracket new file mode 100644 index 00000000..a11313ad --- /dev/null +++ b/parser-tests/snippets/type-alias-with-bracket @@ -0,0 +1 @@ +type alias Hi = (Int) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 12cddb50..801333ff 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -123,6 +123,7 @@ type PartialTypeExpression , args : Stack PartialTypeExpression } | TypeExpression_Unit + | TypeExpression_Bracketed PartialTypeExpression partialTypeExpressionToConcreteType : PartialTypeExpression -> ConcreteType PossiblyQualified @@ -140,6 +141,9 @@ partialTypeExpressionToConcreteType pte = TypeExpression_Unit -> ConcreteType.Unit + TypeExpression_Bracketed ty -> + partialTypeExpressionToConcreteType ty + recoverErrors : ParseResult -> ParseResult recoverErrors res = @@ -187,7 +191,7 @@ type Error | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole - | Error_UnitTypeDoesTakeArgs PartialTypeExpression + | Error_TypeDoesTakeArgs PartialTypeExpression PartialTypeExpression | Error_PartwayThroughTypeAlias | Error_Panic String @@ -502,8 +506,19 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = ) |> ParseResult_Ok + ( context, Just ((TypeExpression_Bracketed _) as ty) ) -> + Error_TypeDoesTakeArgs + ty + (TypeExpression_NamedType + { name = str + , args = empty + } + ) + |> ParseResult_Err + ( context, Just TypeExpression_Unit ) -> - Error_UnitTypeDoesTakeArgs + Error_TypeDoesTakeArgs + TypeExpression_Unit (TypeExpression_NamedType { name = str , args = empty @@ -527,62 +542,51 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = Lexer.Close -> (case current of ( TypeExpressionContext_Bracket Lexer.Round, mexpr ) -> - case mexpr of - Nothing -> - (case pop stack of - Just ( ( newContext, newExprToAddTo ), newStack ) -> - let - rnewExpr = - case newExprToAddTo of - Nothing -> - Just TypeExpression_Unit - |> Ok - - Just (TypeExpression_NamedType { name, args }) -> - Just - (TypeExpression_NamedType - { name = name - , args = - TypeExpression_Unit - |> pushOnto args - } - ) - |> Ok - - Just TypeExpression_Unit -> - Error_UnitTypeDoesTakeArgs TypeExpression_Unit - |> Err - in - rnewExpr - |> Result.map - (\newExpr -> - { stack = newStack - , current = ( newContext, newExpr ) - } - |> TypeExpressionResult_Progress - ) - + let + expr = + mexpr |> Maybe.withDefault TypeExpression_Unit + in + (case pop stack of + Just ( ( newContext, newExprToAddTo ), newStack ) -> + (case newExprToAddTo of Nothing -> - TypeExpressionResult_Done TypeExpression_Unit + TypeExpression_Bracketed expr + |> Just + |> Ok + + Just (TypeExpression_NamedType { name, args }) -> + Just + (TypeExpression_NamedType + { name = name + , args = + expr + |> pushOnto args + } + ) |> Ok - ) - |> Result.map newState - |> Just - Just expr -> - newState - (case pop stack of - Just ( newCurrent, newStack ) -> + Just TypeExpression_Unit -> + Error_TypeDoesTakeArgs TypeExpression_Unit expr + |> Err + + Just ((TypeExpression_Bracketed _) as ty) -> + Error_TypeDoesTakeArgs ty expr + |> Err + ) + |> Result.map + (\newExpr -> { stack = newStack - , current = Debug.todo "newCurrent" + , current = ( newContext, newExpr ) } |> TypeExpressionResult_Progress + ) - Nothing -> - TypeExpressionResult_Done expr - ) + Nothing -> + TypeExpressionResult_Done expr |> Ok - |> Just + ) + |> Result.map newState + |> Just _ -> -- TODO(harry): can we add information about the @@ -652,21 +656,11 @@ blockFromState state = |> Ok |> Just - ( Nothing, TypeExpressionContext_Alias, Nothing ) -> + _ -> Error_PartwayThroughTypeAlias |> Err |> Just - x -> - let - _ = - Debug.log "we have" state - - _ = - Debug.log "we have" x - in - Debug.todo "handle maybe incomplete block" - State_BlockTypeAlias (BlockTypeAlias_Complete name expr) -> { ty = name , expr = partialTypeExpressionToConcreteType expr diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 2289b505..d9a4e210 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -132,6 +132,116 @@ testCases = ) ] } + , { name = "type-alias-invalid-multiple-brackets" + , source = """type alias Hi = (Int) () +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { current = ( TypeExpressionContext_Bracket Round, Nothing ) + , stack = + Stack + [ ( TypeExpressionContext_Alias, Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) ) + ] + } + ) + , Error_TypeDoesTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) TypeExpression_Unit + ) + ] + } + , { name = "type-alias-invalid-multiple-brackets-2" + , source = """type alias Hi = () () +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { current = ( TypeExpressionContext_Bracket Round, Nothing ) + , stack = + Stack + [ ( TypeExpressionContext_Alias, Just (TypeExpression_Bracketed TypeExpression_Unit) ) + ] + } + ) + , Error_TypeDoesTakeArgs (TypeExpression_Bracketed TypeExpression_Unit) TypeExpression_Unit + ) + ] + } + , { name = "type-alias-invalid-multiple-brackets-3" + , source = """type alias Hi = () (Int) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Token "Int") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { current = ( TypeExpressionContext_Bracket Round, Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) + , stack = + Stack + [ ( TypeExpressionContext_Alias, Just (TypeExpression_Bracketed TypeExpression_Unit) ) + ] + } + ) + , Error_TypeDoesTakeArgs (TypeExpression_Bracketed TypeExpression_Unit) (TypeExpression_NamedType { args = Stack [], name = "Int" }) + ) + ] + } , { name = "type-alias-partial" , source = """type alias """ @@ -183,6 +293,118 @@ testCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { current = ( TypeExpressionContext_Alias, Nothing ), stack = Stack [] }), Error_PartwayThroughTypeAlias ) ] } + , { name = "type-alias-partial-with-bracket" + , source = """type alias Hi = ( +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { current = ( TypeExpressionContext_Bracket Round, Nothing ) + , stack = + Stack + [ ( TypeExpressionContext_Alias, Nothing ) + ] + } + ) + , Error_PartwayThroughTypeAlias + ) + ] + } + , { name = "type-alias-partial-with-bracket-2" + , source = """type alias Hi = ( + Int +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) + , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { current = ( TypeExpressionContext_Bracket Round, Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) + , stack = + Stack + [ ( TypeExpressionContext_Alias, Nothing ) + ] + } + ) + , Error_PartwayThroughTypeAlias + ) + ] + } + , { name = "type-alias-unit" + , source = """type alias Hi = () +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok (TypeAlias { expr = Unit, ty = TypeOrConstructor "Hi" }) + ] + } + , { name = "type-alias-with-bracket" + , source = """type alias Hi = (Int) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi" }) + ] + } , { name = "type-partial" , source = """type """ From 55e6b04e2384d181b72e0398b7b5fad35a55dd7e Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 12:12:49 +0100 Subject: [PATCH 015/103] error in regenerate on panic --- Makefile | 6 ++++-- parser-tests/update.js | 5 +++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index ed2268ad..49cf8b00 100644 --- a/Makefile +++ b/Makefile @@ -39,8 +39,10 @@ test: build regenerate: cd parser-tests \ && npx elm make Update.elm --output elm.js \ - && node update - elm-format tests/ParserLexerTestCases.elm --yes + && node update \ + ; CODE=$$? \ + ; elm-format ../tests/ParserLexerTestCases.elm --yes \ + ; exit $$CODE .PHONY: format format: diff --git a/parser-tests/update.js b/parser-tests/update.js index 218b74f3..13687026 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -40,6 +40,11 @@ async function main() { app.ports.output.subscribe(resolve); }); + if (tests.includes('Panic')) { + console.error('ERROR: One or more test cases panicked!'); + process.exitCode = 1; + } + const newTestFile = [ testFileStart, '\n\n', From cd97b4c397910438b3c191a5c6e5ee8517616f11 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 12:13:12 +0100 Subject: [PATCH 016/103] reject multiline types with no indentation --- .../type-alias-multiline-missing-indentation | 2 + src/Stage/Parse/Contextualize.elm | 65 ++++++++++++++----- tests/ParserLexerTestCases.elm | 27 +++++++- 3 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 parser-tests/snippets/type-alias-multiline-missing-indentation diff --git a/parser-tests/snippets/type-alias-multiline-missing-indentation b/parser-tests/snippets/type-alias-multiline-missing-indentation new file mode 100644 index 00000000..9dd9e669 --- /dev/null +++ b/parser-tests/snippets/type-alias-multiline-missing-indentation @@ -0,0 +1,2 @@ +type alias Model = +List Int diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 801333ff..2a0cbe85 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -215,30 +215,41 @@ runHelp : List LexItem -> State_ -> List (Result ( State, Error ) Block) runHelp items state = case items of item :: rest -> - runHelp - rest - (case parseAnything state.state item of - ParseResult_Ok newState_ -> + case parseAnything state.state item of + ParseResult_Ok newState_ -> + runHelp + rest { previousBlocks = state.previousBlocks , state = newState_ } - ParseResult_Err error -> + ParseResult_Err error -> + runHelp + rest { previousBlocks = Err ( state.state, error ) :: state.previousBlocks - , state = State_Error_Recovery + , state = + case item of + Lexer.Newlines _ 0 -> + State_BlockStart + + _ -> + State_Error_Recovery } - ParseResult_Panic error -> - -- TODO(harry): more violent error here + ParseResult_Panic error -> + -- TODO(harry): more violent error here + runHelp + [{- An empty list to abort parsing. -}] { previousBlocks = Err ( state.state, Error_Panic error ) :: state.previousBlocks , state = State_Error_Recovery } - ParseResult_Skip -> + ParseResult_Skip -> + runHelp + rest state - ) [] -> List.reverse @@ -256,8 +267,15 @@ parseAnything : State -> LexItem -> ParseResult parseAnything state = case state of State_Error_Recovery -> - parseBlockStart - >> recoverErrors + \item -> + case item of + Lexer.Newlines _ 0 -> + State_BlockStart + |> ParseResult_Ok + + _ -> + State_Error_Recovery + |> ParseResult_Ok State_BlockStart -> parseBlockStart @@ -353,10 +371,10 @@ parseBlockStart item = ParseResult_Ok State_BlockStart Lexer.Newlines _ _ -> - ParseResult_Panic "parseBlockStart expects a block but found some indented content" + ParseResult_Panic "parseBlockStart expects a block but found some indented content." Lexer.Whitespace _ -> - ParseResult_Panic "parseBlockStart expects a block but found some indented content" + ParseResult_Panic "parseBlockStart expects a block but found some whitespace" _ -> ParseResult_Err (Error_InvalidToken item Expecting_Block) @@ -598,8 +616,23 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = |> parseResultFromMaybeResult Lexer.Newlines _ 0 -> - newState (TypeExpressionResult_Progress prevExpr) - |> ParseResult_Ok + (case prevExpr.current of + ( _, Nothing ) -> + Error_PartwayThroughTypeAlias + |> Err + + ( TypeExpressionContext_Alias, Just expr ) -> + -- TODO(harry) we need to consider the stack here + TypeExpressionResult_Done expr + |> Ok + + ( TypeExpressionContext_Bracket _, Just expr ) -> + Error_PartwayThroughTypeAlias + |> Err + ) + |> Result.map newState + |> Just + |> parseResultFromMaybeResult Lexer.Newlines _ _ -> ParseResult_Skip diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index d9a4e210..03b5ec8c 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -242,6 +242,31 @@ testCases = ) ] } + , { name = "type-alias-multiline-missing-indentation" + , source = """type alias Model = +List Int +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "List") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")), Error_PartwayThroughTypeAlias ) + , Err ( State_BlockStart, Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") ) + ] + } , { name = "type-alias-partial" , source = """type alias """ @@ -290,7 +315,7 @@ testCases = ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { current = ( TypeExpressionContext_Alias, Nothing ), stack = Stack [] }), Error_PartwayThroughTypeAlias ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")), Error_PartwayThroughTypeAlias ) ] } , { name = "type-alias-partial-with-bracket" From 7322d79f72df4e69d4aa79abe6597615061335c1 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 16:22:18 +0100 Subject: [PATCH 017/103] rework nesting we also add a special case into our test case update script so that we can write test cases and prefix them with an underscore to exclude them from generation --- parser-tests/update.js | 11 ++- src/Stage/Parse/Contextualize.elm | 154 +++++++++++++++++++++--------- tests/ParserLexerTestCases.elm | 20 ++-- 3 files changed, 127 insertions(+), 58 deletions(-) diff --git a/parser-tests/update.js b/parser-tests/update.js index 13687026..7125bf6b 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -29,10 +29,13 @@ async function main() { const testFileStart = testFile.slice(0, epilogueStart).trim(); const snippets = await Promise.all( - (await fs.readdir(SNIPPETS_DIR_PATH)).sort().map(async (name) => ({ - name, - source: await fs.readFile(path.join(SNIPPETS_DIR_PATH, name), 'utf-8'), - })) + (await fs.readdir(SNIPPETS_DIR_PATH)) + .sort() + .filter((name) => !name.startsWith('_')) + .map(async (name) => ({ + name, + source: await fs.readFile(path.join(SNIPPETS_DIR_PATH, name), 'utf-8'), + })) ); const tests = await new Promise((resolve) => { diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 2a0cbe85..990bca6a 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -169,13 +169,21 @@ parseResultFromMaybeResult x = type TypeExpressionContext - = TypeExpressionContext_Bracket Lexer.BracketType - | TypeExpressionContext_Alias + = TypeExpressionContext_Nested NestingType (Maybe PartialTypeExpression) + + + +-- | TypeExpressionContext_Record + + +type NestingType + = NestingType_Bracket + | NestingType_TypeAlias type alias PartialTypeExpression2 = - { stack : Stack ( TypeExpressionContext, Maybe PartialTypeExpression ) - , current : ( TypeExpressionContext, Maybe PartialTypeExpression ) + { stack : Stack TypeExpressionContext + , current : TypeExpressionContext } @@ -309,7 +317,7 @@ parseAnything state = TypeExpressionResult_Empty -> Debug.todo "" ) - { current = ( TypeExpressionContext_Alias, Nothing ) + { current = TypeExpressionContext_Nested NestingType_TypeAlias Nothing , stack = empty } @@ -485,46 +493,45 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = case item of Lexer.Token str -> case current of - ( context, Nothing ) -> + TypeExpressionContext_Nested nestingType Nothing -> newState ({ stack = stack , current = - ( context - , Just - (TypeExpression_NamedType - { name = str - , args = empty - } + TypeExpressionContext_Nested + nestingType + (Just + (TypeExpression_NamedType + { name = str + , args = empty + } + ) ) - ) } |> TypeExpressionResult_Progress ) |> ParseResult_Ok - ( context, Just (TypeExpression_NamedType { name, args }) ) -> - -- TODO(harry): think about how this is fundamentally - -- similar to the definition of custom type constructors. - -- The value of `_context` is key I think. + TypeExpressionContext_Nested nestingType (Just (TypeExpression_NamedType { name, args })) -> newState ({ stack = stack , current = - ( context - , Just - (TypeExpression_NamedType - { name = name - , args = - TypeExpression_NamedType { name = str, args = empty } - |> pushOnto args - } + TypeExpressionContext_Nested + nestingType + (Just + (TypeExpression_NamedType + { name = name + , args = + TypeExpression_NamedType { name = str, args = empty } + |> pushOnto args + } + ) ) - ) } |> TypeExpressionResult_Progress ) |> ParseResult_Ok - ( context, Just ((TypeExpression_Bracketed _) as ty) ) -> + TypeExpressionContext_Nested nestingType (Just ((TypeExpression_Bracketed _) as ty)) -> Error_TypeDoesTakeArgs ty (TypeExpression_NamedType @@ -534,7 +541,7 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = ) |> ParseResult_Err - ( context, Just TypeExpression_Unit ) -> + TypeExpressionContext_Nested nestingType (Just TypeExpression_Unit) -> Error_TypeDoesTakeArgs TypeExpression_Unit (TypeExpression_NamedType @@ -551,7 +558,7 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = ({ stack = current |> pushOnto stack - , current = ( TypeExpressionContext_Bracket Lexer.Round, Nothing ) + , current = TypeExpressionContext_Nested NestingType_Bracket Nothing } |> TypeExpressionResult_Progress ) @@ -559,13 +566,13 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = Lexer.Close -> (case current of - ( TypeExpressionContext_Bracket Lexer.Round, mexpr ) -> + TypeExpressionContext_Nested NestingType_Bracket mexpr -> let expr = mexpr |> Maybe.withDefault TypeExpression_Unit in (case pop stack of - Just ( ( newContext, newExprToAddTo ), newStack ) -> + Just ( TypeExpressionContext_Nested newNestingType newExprToAddTo, newStack ) -> (case newExprToAddTo of Nothing -> TypeExpression_Bracketed expr @@ -594,7 +601,7 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = |> Result.map (\newExpr -> { stack = newStack - , current = ( newContext, newExpr ) + , current = TypeExpressionContext_Nested newNestingType newExpr } |> TypeExpressionResult_Progress ) @@ -615,18 +622,84 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = ) |> parseResultFromMaybeResult + -- Lexer.Sigil (Lexer.Bracket Lexer.Curly role) -> + -- case role of + -- Lexer.Open -> + -- newState + -- ({ stack = + -- current + -- |> pushOnto stack + -- , current = TypeExpressionContext_Record Nothing + -- } + -- |> TypeExpressionResult_Progress + -- ) + -- |> ParseResult_Ok + -- Lexer.Close -> + -- (case current of + -- ( TypeExpressionContext_Bracket, mexpr ) -> + -- let + -- expr = + -- mexpr |> Maybe.withDefault TypeExpression_Unit + -- in + -- (case pop stack of + -- Just ( ( newContext, newExprToAddTo ), newStack ) -> + -- (case newExprToAddTo of + -- Nothing -> + -- TypeExpression_Bracketed expr + -- |> Just + -- |> Ok + -- Just (TypeExpression_NamedType { name, args }) -> + -- Just + -- (TypeExpression_NamedType + -- { name = name + -- , args = + -- expr + -- |> pushOnto args + -- } + -- ) + -- |> Ok + -- Just TypeExpression_Unit -> + -- Error_TypeDoesTakeArgs TypeExpression_Unit expr + -- |> Err + -- Just ((TypeExpression_Bracketed _) as ty) -> + -- Error_TypeDoesTakeArgs ty expr + -- |> Err + -- ) + -- |> Result.map + -- (\newExpr -> + -- { stack = newStack + -- , current = ( newContext, newExpr ) + -- } + -- |> TypeExpressionResult_Progress + -- ) + -- Nothing -> + -- TypeExpressionResult_Done expr + -- |> Ok + -- ) + -- |> Result.map newState + -- |> Just + -- _ -> + -- -- TODO(harry): can we add information about the + -- -- bracket we are expecting here? + -- Error_UnmatchedBracket Lexer.Round Lexer.Close + -- |> Err + -- |> Just + -- ) + -- |> parseResultFromMaybeResult Lexer.Newlines _ 0 -> (case prevExpr.current of - ( _, Nothing ) -> + TypeExpressionContext_Nested _ Nothing -> Error_PartwayThroughTypeAlias |> Err - ( TypeExpressionContext_Alias, Just expr ) -> + TypeExpressionContext_Nested NestingType_TypeAlias (Just expr) -> -- TODO(harry) we need to consider the stack here TypeExpressionResult_Done expr |> Ok - ( TypeExpressionContext_Bracket _, Just expr ) -> + -- ( TypeExpressionContext_Record (Just expr) ) -> + -- Debug.todo "" + TypeExpressionContext_Nested NestingType_Bracket (Just expr) -> Error_PartwayThroughTypeAlias |> Err ) @@ -673,15 +746,8 @@ blockFromState state = |> Just State_BlockTypeAlias (BlockTypeAlias_Completish name { stack, current }) -> - let - -- _ = - -- Debug.log "part" partialExpr - ( context, mexpr ) = - current - in - -- TODO(harry): handle maybe incomplete block - case ( pop stack, context, mexpr ) of - ( Nothing, TypeExpressionContext_Alias, Just expr ) -> + case ( pop stack, current ) of + ( Nothing, TypeExpressionContext_Nested NestingType_TypeAlias (Just expr) ) -> { ty = name , expr = partialTypeExpressionToConcreteType expr } diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 03b5ec8c..1e265c16 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -158,10 +158,10 @@ testCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = ( TypeExpressionContext_Bracket Round, Nothing ) + { current = TypeExpressionContext_Nested NestingType_Bracket Nothing , stack = Stack - [ ( TypeExpressionContext_Alias, Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) ) + [ TypeExpressionContext_Nested NestingType_TypeAlias (Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" }))) ] } ) @@ -194,10 +194,10 @@ testCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = ( TypeExpressionContext_Bracket Round, Nothing ) + { current = TypeExpressionContext_Nested NestingType_Bracket Nothing , stack = Stack - [ ( TypeExpressionContext_Alias, Just (TypeExpression_Bracketed TypeExpression_Unit) ) + [ TypeExpressionContext_Nested NestingType_TypeAlias (Just (TypeExpression_Bracketed TypeExpression_Unit)) ] } ) @@ -231,10 +231,10 @@ testCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = ( TypeExpressionContext_Bracket Round, Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) + { current = TypeExpressionContext_Nested NestingType_Bracket (Just (TypeExpression_NamedType { args = Stack [], name = "Int" })) , stack = Stack - [ ( TypeExpressionContext_Alias, Just (TypeExpression_Bracketed TypeExpression_Unit) ) + [ TypeExpressionContext_Nested NestingType_TypeAlias (Just (TypeExpression_Bracketed TypeExpression_Unit)) ] } ) @@ -339,10 +339,10 @@ List Int [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = ( TypeExpressionContext_Bracket Round, Nothing ) + { current = TypeExpressionContext_Nested NestingType_Bracket Nothing , stack = Stack - [ ( TypeExpressionContext_Alias, Nothing ) + [ TypeExpressionContext_Nested NestingType_TypeAlias Nothing ] } ) @@ -374,10 +374,10 @@ List Int [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = ( TypeExpressionContext_Bracket Round, Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) + { current = TypeExpressionContext_Nested NestingType_Bracket (Just (TypeExpression_NamedType { args = Stack [], name = "Int" })) , stack = Stack - [ ( TypeExpressionContext_Alias, Nothing ) + [ TypeExpressionContext_Nested NestingType_TypeAlias Nothing ] } ) From 2be359cdf0e422f309126c73db167167beb87994 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 16:23:25 +0100 Subject: [PATCH 018/103] fix meaning of type does not take args error --- parser-tests/snippets/_type-alias-empty-record | 1 + src/Stage/Parse/Contextualize.elm | 14 +++++++------- tests/ParserLexerTestCases.elm | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) create mode 100644 parser-tests/snippets/_type-alias-empty-record diff --git a/parser-tests/snippets/_type-alias-empty-record b/parser-tests/snippets/_type-alias-empty-record new file mode 100644 index 00000000..21e03e70 --- /dev/null +++ b/parser-tests/snippets/_type-alias-empty-record @@ -0,0 +1 @@ +type alias Ty = {} diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 990bca6a..d47d5b50 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -199,7 +199,7 @@ type Error | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole - | Error_TypeDoesTakeArgs PartialTypeExpression PartialTypeExpression + | Error_TypeDoesNotTakeArgs PartialTypeExpression PartialTypeExpression | Error_PartwayThroughTypeAlias | Error_Panic String @@ -532,7 +532,7 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = |> ParseResult_Ok TypeExpressionContext_Nested nestingType (Just ((TypeExpression_Bracketed _) as ty)) -> - Error_TypeDoesTakeArgs + Error_TypeDoesNotTakeArgs ty (TypeExpression_NamedType { name = str @@ -542,7 +542,7 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = |> ParseResult_Err TypeExpressionContext_Nested nestingType (Just TypeExpression_Unit) -> - Error_TypeDoesTakeArgs + Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpression_NamedType { name = str @@ -591,11 +591,11 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = |> Ok Just TypeExpression_Unit -> - Error_TypeDoesTakeArgs TypeExpression_Unit expr + Error_TypeDoesNotTakeArgs TypeExpression_Unit expr |> Err Just ((TypeExpression_Bracketed _) as ty) -> - Error_TypeDoesTakeArgs ty expr + Error_TypeDoesNotTakeArgs ty expr |> Err ) |> Result.map @@ -659,10 +659,10 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = -- ) -- |> Ok -- Just TypeExpression_Unit -> - -- Error_TypeDoesTakeArgs TypeExpression_Unit expr + -- Error_TypeDoesNotTakeArgs TypeExpression_Unit expr -- |> Err -- Just ((TypeExpression_Bracketed _) as ty) -> - -- Error_TypeDoesTakeArgs ty expr + -- Error_TypeDoesNotTakeArgs ty expr -- |> Err -- ) -- |> Result.map diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 1e265c16..b5858574 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -165,7 +165,7 @@ testCases = ] } ) - , Error_TypeDoesTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) TypeExpression_Unit + , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) TypeExpression_Unit ) ] } @@ -201,7 +201,7 @@ testCases = ] } ) - , Error_TypeDoesTakeArgs (TypeExpression_Bracketed TypeExpression_Unit) TypeExpression_Unit + , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed TypeExpression_Unit) TypeExpression_Unit ) ] } @@ -238,7 +238,7 @@ testCases = ] } ) - , Error_TypeDoesTakeArgs (TypeExpression_Bracketed TypeExpression_Unit) (TypeExpression_NamedType { args = Stack [], name = "Int" }) + , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed TypeExpression_Unit) (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) ] } From b57721f7307859cf9c2bf0b3be99d5d68f820613 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 22:04:03 +0100 Subject: [PATCH 019/103] rework handling of complete type aliases --- src/Stage/Parse/Contextualize.elm | 363 ++++++++++++++---------------- tests/ParserLexerTestCases.elm | 34 +-- 2 files changed, 188 insertions(+), 209 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index d47d5b50..59089429 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -80,6 +80,7 @@ type State type ParseResult = ParseResult_Ok State + | ParseResult_Complete Block | ParseResult_Err Error | ParseResult_Skip | ParseResult_Panic String @@ -102,7 +103,6 @@ type BlockTypeAlias | BlockTypeAlias_Named Token.TypeOrConstructor | BlockTypeAlias_NamedAssigns Token.TypeOrConstructor | BlockTypeAlias_Completish Token.TypeOrConstructor PartialTypeExpression2 - | BlockTypeAlias_Complete Token.TypeOrConstructor PartialTypeExpression type BlockCustomType @@ -168,22 +168,9 @@ parseResultFromMaybeResult x = ParseResult_Skip -type TypeExpressionContext - = TypeExpressionContext_Nested NestingType (Maybe PartialTypeExpression) - - - --- | TypeExpressionContext_Record - - -type NestingType - = NestingType_Bracket - | NestingType_TypeAlias - - type alias PartialTypeExpression2 = - { stack : Stack TypeExpressionContext - , current : TypeExpressionContext + { root : Maybe PartialTypeExpression + , bracketStack : Stack (Maybe PartialTypeExpression) } @@ -231,6 +218,13 @@ runHelp items state = , state = newState_ } + ParseResult_Complete block -> + runHelp + rest + { previousBlocks = Ok block :: state.previousBlocks + , state = State_BlockStart + } + ParseResult_Err error -> runHelp rest @@ -310,15 +304,20 @@ parseAnything state = case res of TypeExpressionResult_Progress expr -> State_BlockTypeAlias (BlockTypeAlias_Completish name expr) + |> ParseResult_Ok TypeExpressionResult_Done expr -> - State_BlockTypeAlias (BlockTypeAlias_Complete name expr) + { ty = name + , expr = partialTypeExpressionToConcreteType expr + } + |> TypeAlias + |> ParseResult_Complete TypeExpressionResult_Empty -> Debug.todo "" ) - { current = TypeExpressionContext_Nested NestingType_TypeAlias Nothing - , stack = empty + { root = Nothing + , bracketStack = empty } State_BlockTypeAlias (BlockTypeAlias_Completish name exprSoFar) -> @@ -327,18 +326,20 @@ parseAnything state = case res of TypeExpressionResult_Progress expr -> State_BlockTypeAlias (BlockTypeAlias_Completish name expr) + |> ParseResult_Ok TypeExpressionResult_Done expr -> - State_BlockTypeAlias (BlockTypeAlias_Complete name expr) + { ty = name + , expr = partialTypeExpressionToConcreteType expr + } + |> TypeAlias + |> ParseResult_Complete TypeExpressionResult_Empty -> Debug.todo "" ) exprSoFar - State_BlockTypeAlias (BlockTypeAlias_Complete name expr) -> - Debug.todo "" - State_BlockCustomType (BlockCustomType_Named name) -> parseAssignment (State_BlockCustomType (BlockCustomType_NamedAssigns name)) @@ -485,53 +486,79 @@ parseAssignment newState item = parserTypeExpr : - (TypeExpressionResult -> State) + (TypeExpressionResult -> ParseResult) -> PartialTypeExpression2 -> LexItem -> ParseResult -parserTypeExpr newState ({ stack, current } as prevExpr) item = +parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = case item of Lexer.Token str -> - case current of - TypeExpressionContext_Nested nestingType Nothing -> - newState - ({ stack = stack - , current = - TypeExpressionContext_Nested - nestingType - (Just - (TypeExpression_NamedType - { name = str - , args = empty - } - ) - ) - } - |> TypeExpressionResult_Progress - ) - |> ParseResult_Ok + let + newType = + TypeExpression_NamedType + { name = str + , args = empty + } + in + case pop bracketStack of + Nothing -> + case root of + Nothing -> + { bracketStack = empty + , root = Just newType + } + |> TypeExpressionResult_Progress + |> newState - TypeExpressionContext_Nested nestingType (Just (TypeExpression_NamedType { name, args })) -> - newState - ({ stack = stack - , current = - TypeExpressionContext_Nested - nestingType - (Just + Just (TypeExpression_NamedType { name, args }) -> + { bracketStack = empty + , root = + Just (TypeExpression_NamedType { name = name , args = - TypeExpression_NamedType { name = str, args = empty } + newType |> pushOnto args } ) - ) - } - |> TypeExpressionResult_Progress - ) - |> ParseResult_Ok + } + |> TypeExpressionResult_Progress + |> newState + + Just ((TypeExpression_Bracketed _) as ty) -> + Error_TypeDoesNotTakeArgs ty newType + |> ParseResult_Err + + Just TypeExpression_Unit -> + Error_TypeDoesNotTakeArgs TypeExpression_Unit newType + |> ParseResult_Err + + Just ( Nothing, rest ) -> + { bracketStack = + Just newType + |> pushOnto rest + , root = root + } + |> TypeExpressionResult_Progress + |> newState + + Just ( Just (TypeExpression_NamedType { name, args }), rest ) -> + { bracketStack = + Just + (TypeExpression_NamedType + { name = name + , args = + TypeExpression_NamedType { name = str, args = empty } + |> pushOnto args + } + ) + |> pushOnto rest + , root = root + } + |> TypeExpressionResult_Progress + |> newState - TypeExpressionContext_Nested nestingType (Just ((TypeExpression_Bracketed _) as ty)) -> + Just ( Just ((TypeExpression_Bracketed _) as ty), _ ) -> Error_TypeDoesNotTakeArgs ty (TypeExpression_NamedType @@ -541,7 +568,7 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = ) |> ParseResult_Err - TypeExpressionContext_Nested nestingType (Just TypeExpression_Unit) -> + Just ( Just TypeExpression_Unit, _ ) -> Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpression_NamedType @@ -554,158 +581,118 @@ parserTypeExpr newState ({ stack, current } as prevExpr) item = Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> case role of Lexer.Open -> - newState - ({ stack = - current - |> pushOnto stack - , current = TypeExpressionContext_Nested NestingType_Bracket Nothing - } - |> TypeExpressionResult_Progress - ) - |> ParseResult_Ok + { bracketStack = + Nothing + |> pushOnto bracketStack + , root = root + } + |> TypeExpressionResult_Progress + |> newState Lexer.Close -> - (case current of - TypeExpressionContext_Nested NestingType_Bracket mexpr -> + case pop bracketStack of + Just ( mexpr, poppedBracketStack ) -> let expr = - mexpr |> Maybe.withDefault TypeExpression_Unit - in - (case pop stack of - Just ( TypeExpressionContext_Nested newNestingType newExprToAddTo, newStack ) -> - (case newExprToAddTo of - Nothing -> - TypeExpression_Bracketed expr - |> Just - |> Ok + case mexpr of + Just expr_ -> + TypeExpression_Bracketed expr_ - Just (TypeExpression_NamedType { name, args }) -> - Just - (TypeExpression_NamedType + Nothing -> + TypeExpression_Unit + in + case pop poppedBracketStack of + Just ( newExprToAddTo, rest ) -> + let + rnewExpr = + case newExprToAddTo of + Nothing -> + expr + |> Ok + + Just (TypeExpression_NamedType { name, args }) -> { name = name , args = expr |> pushOnto args } - ) - |> Ok + |> TypeExpression_NamedType + |> Ok + + Just TypeExpression_Unit -> + Error_TypeDoesNotTakeArgs TypeExpression_Unit expr + |> Err + + Just ((TypeExpression_Bracketed _) as ty) -> + Error_TypeDoesNotTakeArgs ty expr + |> Err + in + case rnewExpr of + Ok newExpr -> + { bracketStack = + Just newExpr + |> pushOnto rest + , root = root + } + |> TypeExpressionResult_Progress + |> newState + + Err e -> + ParseResult_Err e + + Nothing -> + case root of + Nothing -> + { bracketStack = empty + , root = Just expr + } + |> TypeExpressionResult_Progress + |> newState + + Just (TypeExpression_NamedType { name, args }) -> + { bracketStack = empty + , root = + Just + (TypeExpression_NamedType + { name = name + , args = + expr + |> pushOnto args + } + ) + } + |> TypeExpressionResult_Progress + |> newState Just TypeExpression_Unit -> Error_TypeDoesNotTakeArgs TypeExpression_Unit expr - |> Err + |> ParseResult_Err Just ((TypeExpression_Bracketed _) as ty) -> Error_TypeDoesNotTakeArgs ty expr - |> Err - ) - |> Result.map - (\newExpr -> - { stack = newStack - , current = TypeExpressionContext_Nested newNestingType newExpr - } - |> TypeExpressionResult_Progress - ) - - Nothing -> - TypeExpressionResult_Done expr - |> Ok - ) - |> Result.map newState - |> Just + |> ParseResult_Err _ -> -- TODO(harry): can we add information about the -- bracket we are expecting here? Error_UnmatchedBracket Lexer.Round Lexer.Close - |> Err - |> Just - ) - |> parseResultFromMaybeResult - - -- Lexer.Sigil (Lexer.Bracket Lexer.Curly role) -> - -- case role of - -- Lexer.Open -> - -- newState - -- ({ stack = - -- current - -- |> pushOnto stack - -- , current = TypeExpressionContext_Record Nothing - -- } - -- |> TypeExpressionResult_Progress - -- ) - -- |> ParseResult_Ok - -- Lexer.Close -> - -- (case current of - -- ( TypeExpressionContext_Bracket, mexpr ) -> - -- let - -- expr = - -- mexpr |> Maybe.withDefault TypeExpression_Unit - -- in - -- (case pop stack of - -- Just ( ( newContext, newExprToAddTo ), newStack ) -> - -- (case newExprToAddTo of - -- Nothing -> - -- TypeExpression_Bracketed expr - -- |> Just - -- |> Ok - -- Just (TypeExpression_NamedType { name, args }) -> - -- Just - -- (TypeExpression_NamedType - -- { name = name - -- , args = - -- expr - -- |> pushOnto args - -- } - -- ) - -- |> Ok - -- Just TypeExpression_Unit -> - -- Error_TypeDoesNotTakeArgs TypeExpression_Unit expr - -- |> Err - -- Just ((TypeExpression_Bracketed _) as ty) -> - -- Error_TypeDoesNotTakeArgs ty expr - -- |> Err - -- ) - -- |> Result.map - -- (\newExpr -> - -- { stack = newStack - -- , current = ( newContext, newExpr ) - -- } - -- |> TypeExpressionResult_Progress - -- ) - -- Nothing -> - -- TypeExpressionResult_Done expr - -- |> Ok - -- ) - -- |> Result.map newState - -- |> Just - -- _ -> - -- -- TODO(harry): can we add information about the - -- -- bracket we are expecting here? - -- Error_UnmatchedBracket Lexer.Round Lexer.Close - -- |> Err - -- |> Just - -- ) - -- |> parseResultFromMaybeResult + |> ParseResult_Err + Lexer.Newlines _ 0 -> - (case prevExpr.current of - TypeExpressionContext_Nested _ Nothing -> + case ( pop prevExpr.bracketStack, prevExpr.root ) of + ( Just _, _ ) -> Error_PartwayThroughTypeAlias - |> Err + |> ParseResult_Err - TypeExpressionContext_Nested NestingType_TypeAlias (Just expr) -> - -- TODO(harry) we need to consider the stack here + ( Nothing, Just expr ) -> TypeExpressionResult_Done expr - |> Ok + |> newState -- ( TypeExpressionContext_Record (Just expr) ) -> -- Debug.todo "" - TypeExpressionContext_Nested NestingType_Bracket (Just expr) -> + ( Nothing, Nothing ) -> Error_PartwayThroughTypeAlias - |> Err - ) - |> Result.map newState - |> Just - |> parseResultFromMaybeResult + |> ParseResult_Err Lexer.Newlines _ _ -> ParseResult_Skip @@ -745,9 +732,9 @@ blockFromState state = |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Completish name { stack, current }) -> - case ( pop stack, current ) of - ( Nothing, TypeExpressionContext_Nested NestingType_TypeAlias (Just expr) ) -> + State_BlockTypeAlias (BlockTypeAlias_Completish name { bracketStack, root }) -> + case ( pop bracketStack, root ) of + ( Nothing, Just expr ) -> { ty = name , expr = partialTypeExpressionToConcreteType expr } @@ -760,14 +747,6 @@ blockFromState state = |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Complete name expr) -> - { ty = name - , expr = partialTypeExpressionToConcreteType expr - } - |> TypeAlias - |> Ok - |> Just - State_BlockCustomType firstItem -> Debug.todo "handle incomplete block" diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index b5858574..72c96d32 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -158,11 +158,11 @@ testCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = TypeExpressionContext_Nested NestingType_Bracket Nothing - , stack = + { bracketStack = Stack - [ TypeExpressionContext_Nested NestingType_TypeAlias (Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" }))) + [ Nothing ] + , root = Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) } ) , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) TypeExpression_Unit @@ -194,14 +194,14 @@ testCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = TypeExpressionContext_Nested NestingType_Bracket Nothing - , stack = + { bracketStack = Stack - [ TypeExpressionContext_Nested NestingType_TypeAlias (Just (TypeExpression_Bracketed TypeExpression_Unit)) + [ Nothing ] + , root = Just TypeExpression_Unit } ) - , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed TypeExpression_Unit) TypeExpression_Unit + , Error_TypeDoesNotTakeArgs TypeExpression_Unit TypeExpression_Unit ) ] } @@ -231,14 +231,14 @@ testCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = TypeExpressionContext_Nested NestingType_Bracket (Just (TypeExpression_NamedType { args = Stack [], name = "Int" })) - , stack = + { bracketStack = Stack - [ TypeExpressionContext_Nested NestingType_TypeAlias (Just (TypeExpression_Bracketed TypeExpression_Unit)) + [ Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ] + , root = Just TypeExpression_Unit } ) - , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed TypeExpression_Unit) (TypeExpression_NamedType { args = Stack [], name = "Int" }) + , Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) ) ] } @@ -339,11 +339,11 @@ List Int [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = TypeExpressionContext_Nested NestingType_Bracket Nothing - , stack = + { bracketStack = Stack - [ TypeExpressionContext_Nested NestingType_TypeAlias Nothing + [ Nothing ] + , root = Nothing } ) , Error_PartwayThroughTypeAlias @@ -374,11 +374,11 @@ List Int [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { current = TypeExpressionContext_Nested NestingType_Bracket (Just (TypeExpression_NamedType { args = Stack [], name = "Int" })) - , stack = + { bracketStack = Stack - [ TypeExpressionContext_Nested NestingType_TypeAlias Nothing + [ Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ] + , root = Nothing } ) , Error_PartwayThroughTypeAlias From fbdc05549149063afe62dcefdf848e5a1e0c1d57 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 22:06:30 +0100 Subject: [PATCH 020/103] collect things together better --- src/Stage/Parse/Contextualize.elm | 98 +++++++++++++++++-------------- 1 file changed, 55 insertions(+), 43 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 59089429..1ffcfac8 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -126,48 +126,6 @@ type PartialTypeExpression | TypeExpression_Bracketed PartialTypeExpression -partialTypeExpressionToConcreteType : PartialTypeExpression -> ConcreteType PossiblyQualified -partialTypeExpressionToConcreteType pte = - case pte of - TypeExpression_NamedType { name, args } -> - ConcreteType.UserDefinedType - { qualifiedness = Qualifiedness.PossiblyQualified Nothing - , name = name - , args = - args - |> toList partialTypeExpressionToConcreteType - } - - TypeExpression_Unit -> - ConcreteType.Unit - - TypeExpression_Bracketed ty -> - partialTypeExpressionToConcreteType ty - - -recoverErrors : ParseResult -> ParseResult -recoverErrors res = - case res of - ParseResult_Err _ -> - ParseResult_Ok State_Error_Recovery - - _ -> - res - - -parseResultFromMaybeResult : Maybe (Result Error State) -> ParseResult -parseResultFromMaybeResult x = - case x of - Just (Ok s) -> - ParseResult_Ok s - - Just (Err e) -> - ParseResult_Err e - - Nothing -> - ParseResult_Skip - - type alias PartialTypeExpression2 = { root : Maybe PartialTypeExpression , bracketStack : Stack (Maybe PartialTypeExpression) @@ -197,6 +155,10 @@ type Expecting | Expecting_TypeName + +-- exported functions + + run : List LexItem -> List (Result ( State, Error ) Block) run items = runHelp @@ -265,6 +227,10 @@ runHelp items state = ) + +-- parsers + + parseAnything : State -> LexItem -> ParseResult parseAnything state = case state of @@ -752,7 +718,53 @@ blockFromState state = --- HELPERS +-- helper functions + + +partialTypeExpressionToConcreteType : PartialTypeExpression -> ConcreteType PossiblyQualified +partialTypeExpressionToConcreteType pte = + case pte of + TypeExpression_NamedType { name, args } -> + ConcreteType.UserDefinedType + { qualifiedness = Qualifiedness.PossiblyQualified Nothing + , name = name + , args = + args + |> toList partialTypeExpressionToConcreteType + } + + TypeExpression_Unit -> + ConcreteType.Unit + + TypeExpression_Bracketed ty -> + partialTypeExpressionToConcreteType ty + + +recoverErrors : ParseResult -> ParseResult +recoverErrors res = + case res of + ParseResult_Err _ -> + ParseResult_Ok State_Error_Recovery + + _ -> + res + + +parseResultFromMaybeResult : Maybe (Result Error State) -> ParseResult +parseResultFromMaybeResult x = + case x of + Just (Ok s) -> + ParseResult_Ok s + + Just (Err e) -> + ParseResult_Err e + + Nothing -> + ParseResult_Skip + + + +-- stacks type Stack a From 01ce21a8eaf36174d492d4bb7a331b534ac871ca Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 25 Sep 2020 23:56:09 +0100 Subject: [PATCH 021/103] lay groundwork for record types We currently do not parse the { or } characters so all the code added in this commit is currently useless. Hopefully, it will be straightforward to add the needed code though and unlock all the record parsing potential. --- ...s-empty-record => type-alias-empty-record} | 0 src/Stage/Parse/Contextualize.elm | 332 ++++++++++++++++-- tests/ParserLexerTestCases.elm | 22 ++ 3 files changed, 316 insertions(+), 38 deletions(-) rename parser-tests/snippets/{_type-alias-empty-record => type-alias-empty-record} (100%) diff --git a/parser-tests/snippets/_type-alias-empty-record b/parser-tests/snippets/type-alias-empty-record similarity index 100% rename from parser-tests/snippets/_type-alias-empty-record rename to parser-tests/snippets/type-alias-empty-record diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 1ffcfac8..a9268a24 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -10,6 +10,7 @@ choose to skip the lexed item). -} +import Dict import Elm.AST.Frontend as Frontend exposing (Expr(..), LocatedExpr, LocatedPattern, Pattern(..)) import Elm.Data.Declaration import Elm.Data.Exposing @@ -124,6 +125,18 @@ type PartialTypeExpression } | TypeExpression_Unit | TypeExpression_Bracketed PartialTypeExpression + | TypeExpression_PartialRecord + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } + | TypeExpression_Record (Stack ( String, PartialTypeExpression )) + + +type LastEntryOfRecord + = LastEntryOfRecord_Empty + | LastEntryOfRecord_Key String + | LastEntryOfRecord_KeyColon String + | LastEntryOfRecord_KeyValue String PartialTypeExpression type alias PartialTypeExpression2 = @@ -144,6 +157,8 @@ type Error | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole + | Error_ExpectedColonWhilstParsingRecord + | Error_ExpectedKeyWhilstParsingRecord | Error_TypeDoesNotTakeArgs PartialTypeExpression PartialTypeExpression | Error_PartwayThroughTypeAlias | Error_Panic String @@ -273,11 +288,17 @@ parseAnything state = |> ParseResult_Ok TypeExpressionResult_Done expr -> - { ty = name - , expr = partialTypeExpressionToConcreteType expr - } - |> TypeAlias - |> ParseResult_Complete + case partialTypeExpressionToConcreteType expr of + Ok concreteType -> + { ty = name + , expr = concreteType + } + |> TypeAlias + |> ParseResult_Complete + + Err () -> + Error_PartwayThroughTypeAlias + |> ParseResult_Err TypeExpressionResult_Empty -> Debug.todo "" @@ -295,11 +316,17 @@ parseAnything state = |> ParseResult_Ok TypeExpressionResult_Done expr -> - { ty = name - , expr = partialTypeExpressionToConcreteType expr - } - |> TypeAlias - |> ParseResult_Complete + case partialTypeExpressionToConcreteType expr of + Ok conceteType -> + { ty = name + , expr = conceteType + } + |> TypeAlias + |> ParseResult_Complete + + Err () -> + Error_PartwayThroughTypeAlias + |> ParseResult_Err TypeExpressionResult_Empty -> Debug.todo "" @@ -467,6 +494,9 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = } in case pop bracketStack of + -- We are in the top level of the type expression; we have + -- found a closing bracket to match every opening bracket we + -- have encounted so far whilst parsing the type expression. Nothing -> case root of Nothing -> @@ -491,6 +521,25 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> TypeExpressionResult_Progress |> newState + Just (TypeExpression_PartialRecord existingPartialRecord) -> + case addTokenToPartialRecord existingPartialRecord str of + Ok newPartialRecord -> + { bracketStack = empty + , root = + newPartialRecord + |> TypeExpression_PartialRecord + |> Just + } + |> TypeExpressionResult_Progress + |> newState + + Err e -> + ParseResult_Err e + + Just ((TypeExpression_Record _) as ty) -> + Error_TypeDoesNotTakeArgs ty newType + |> ParseResult_Err + Just ((TypeExpression_Bracketed _) as ty) -> Error_TypeDoesNotTakeArgs ty newType |> ParseResult_Err @@ -499,6 +548,7 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = Error_TypeDoesNotTakeArgs TypeExpression_Unit newType |> ParseResult_Err + -- This is the first item following an opening bracket. Just ( Nothing, rest ) -> { bracketStack = Just newType @@ -514,7 +564,7 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = (TypeExpression_NamedType { name = name , args = - TypeExpression_NamedType { name = str, args = empty } + newType |> pushOnto args } ) @@ -524,24 +574,32 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> TypeExpressionResult_Progress |> newState - Just ( Just ((TypeExpression_Bracketed _) as ty), _ ) -> - Error_TypeDoesNotTakeArgs - ty - (TypeExpression_NamedType - { name = str - , args = empty + Just ( Just (TypeExpression_PartialRecord existingPartialRecord), rest ) -> + case addTokenToPartialRecord existingPartialRecord str of + Ok newPartialRecord -> + { bracketStack = + newPartialRecord + |> TypeExpression_PartialRecord + |> Just + |> pushOnto rest + , root = root } - ) + |> TypeExpressionResult_Progress + |> newState + + Err e -> + ParseResult_Err e + + Just ( Just ((TypeExpression_Bracketed _) as ty), _ ) -> + Error_TypeDoesNotTakeArgs ty newType + |> ParseResult_Err + + Just ( Just ((TypeExpression_Record _) as ty), _ ) -> + Error_TypeDoesNotTakeArgs ty newType |> ParseResult_Err Just ( Just TypeExpression_Unit, _ ) -> - Error_TypeDoesNotTakeArgs - TypeExpression_Unit - (TypeExpression_NamedType - { name = str - , args = empty - } - ) + Error_TypeDoesNotTakeArgs TypeExpression_Unit newType |> ParseResult_Err Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> @@ -585,10 +643,18 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> TypeExpression_NamedType |> Ok + Just (TypeExpression_PartialRecord partialRecord) -> + addTypeToPartialRecord partialRecord expr + |> Result.map TypeExpression_PartialRecord + Just TypeExpression_Unit -> Error_TypeDoesNotTakeArgs TypeExpression_Unit expr |> Err + Just ((TypeExpression_Record _) as ty) -> + Error_TypeDoesNotTakeArgs ty expr + |> Err + Just ((TypeExpression_Bracketed _) as ty) -> Error_TypeDoesNotTakeArgs ty expr |> Err @@ -630,10 +696,26 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> TypeExpressionResult_Progress |> newState + Just (TypeExpression_PartialRecord partialRecord) -> + case addTypeToPartialRecord partialRecord expr of + Ok pr -> + { bracketStack = empty + , root = Just (TypeExpression_PartialRecord pr) + } + |> TypeExpressionResult_Progress + |> newState + + Err e -> + ParseResult_Err e + Just TypeExpression_Unit -> Error_TypeDoesNotTakeArgs TypeExpression_Unit expr |> ParseResult_Err + Just ((TypeExpression_Record _) as ty) -> + Error_TypeDoesNotTakeArgs ty expr + |> ParseResult_Err + Just ((TypeExpression_Bracketed _) as ty) -> Error_TypeDoesNotTakeArgs ty expr |> ParseResult_Err @@ -701,11 +783,15 @@ blockFromState state = State_BlockTypeAlias (BlockTypeAlias_Completish name { bracketStack, root }) -> case ( pop bracketStack, root ) of ( Nothing, Just expr ) -> - { ty = name - , expr = partialTypeExpressionToConcreteType expr - } - |> TypeAlias - |> Ok + partialTypeExpressionToConcreteType expr + |> Result.map + (\conceteType -> + { ty = name + , expr = conceteType + } + |> TypeAlias + ) + |> Result.mapError (\() -> Error_PartwayThroughTypeAlias) |> Just _ -> @@ -721,24 +807,176 @@ blockFromState state = -- helper functions -partialTypeExpressionToConcreteType : PartialTypeExpression -> ConcreteType PossiblyQualified +addTokenToPartialRecord : + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } + -> String + -> + Result Error + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } +addTokenToPartialRecord { firstEntries, lastEntry } str = + let + newType = + TypeExpression_NamedType + { name = str + , args = empty + } + in + case lastEntry of + LastEntryOfRecord_Empty -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_Key str + } + |> Ok + + LastEntryOfRecord_Key key -> + Error_ExpectedColonWhilstParsingRecord + |> Err + + LastEntryOfRecord_KeyColon key -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue key newType + } + |> Ok + + LastEntryOfRecord_KeyValue key (TypeExpression_NamedType { name, args }) -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue + key + (TypeExpression_NamedType + { name = name + , args = + newType + |> pushOnto args + } + ) + } + |> Ok + + LastEntryOfRecord_KeyValue _ TypeExpression_Unit -> + Error_TypeDoesNotTakeArgs TypeExpression_Unit newType + |> Err + + LastEntryOfRecord_KeyValue _ ((TypeExpression_Bracketed _) as ty) -> + Error_TypeDoesNotTakeArgs ty newType + |> Err + + LastEntryOfRecord_KeyValue _ ((TypeExpression_Record _) as ty) -> + Error_TypeDoesNotTakeArgs ty newType + |> Err + + LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord innerPartialRecord) -> + addTokenToPartialRecord innerPartialRecord str + + +addTypeToPartialRecord : + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } + -> PartialTypeExpression + -> + Result Error + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } +addTypeToPartialRecord { firstEntries, lastEntry } expr = + case lastEntry of + LastEntryOfRecord_Empty -> + Error_ExpectedKeyWhilstParsingRecord + |> Err + + LastEntryOfRecord_Key key -> + Error_ExpectedColonWhilstParsingRecord + |> Err + + LastEntryOfRecord_KeyColon key -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue key expr + } + |> Ok + + LastEntryOfRecord_KeyValue key (TypeExpression_NamedType { name, args }) -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue + key + (TypeExpression_NamedType + { name = name + , args = + expr + |> pushOnto args + } + ) + } + |> Ok + + LastEntryOfRecord_KeyValue _ TypeExpression_Unit -> + Error_TypeDoesNotTakeArgs TypeExpression_Unit expr + |> Err + + LastEntryOfRecord_KeyValue _ ((TypeExpression_Bracketed _) as ty) -> + Error_TypeDoesNotTakeArgs ty expr + |> Err + + LastEntryOfRecord_KeyValue _ ((TypeExpression_Record _) as ty) -> + Error_TypeDoesNotTakeArgs ty expr + |> Err + + LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord innerPartialRecord) -> + addTypeToPartialRecord innerPartialRecord expr + + + +-- TODO(harry): custom error message here + + +partialTypeExpressionToConcreteType : PartialTypeExpression -> Result () (ConcreteType PossiblyQualified) partialTypeExpressionToConcreteType pte = case pte of TypeExpression_NamedType { name, args } -> - ConcreteType.UserDefinedType - { qualifiedness = Qualifiedness.PossiblyQualified Nothing - , name = name - , args = - args - |> toList partialTypeExpressionToConcreteType - } + args + |> toList partialTypeExpressionToConcreteType + |> collectList + |> Result.map + (\goodArgs -> + { qualifiedness = Qualifiedness.PossiblyQualified Nothing + , name = name + , args = goodArgs + } + |> ConcreteType.UserDefinedType + ) TypeExpression_Unit -> ConcreteType.Unit + |> Ok TypeExpression_Bracketed ty -> partialTypeExpressionToConcreteType ty + TypeExpression_PartialRecord ty -> + Err () + + TypeExpression_Record keyValues -> + keyValues + |> toList + (\( key, value ) -> + partialTypeExpressionToConcreteType value + |> Result.map (\concreteValue -> ( key, concreteValue )) + ) + |> collectList + |> Result.map + (\goodKeyValues -> + Dict.fromList goodKeyValues + |> ConcreteType.Record + ) + recoverErrors : ParseResult -> ParseResult recoverErrors res = @@ -750,6 +988,24 @@ recoverErrors res = res +collectList : List (Result e o) -> Result e (List o) +collectList = + collectListHelp [] + + +collectListHelp : List o -> List (Result e o) -> Result e (List o) +collectListHelp new old = + case old of + (Ok curr) :: rest -> + collectListHelp (curr :: new) rest + + (Err e) :: rest -> + Err e + + [] -> + Ok new + + parseResultFromMaybeResult : Maybe (Result Error State) -> ParseResult parseResultFromMaybeResult x = case x of diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 72c96d32..1875f6a7 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -59,6 +59,28 @@ testCases = ) ] } + , { name = "type-alias-empty-record" + , source = """type alias Ty = {} +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + ] + } , { name = "type-alias-funky-indentation" , source = """type alias Model = List Int From 2dad11069d903a5bdad6c3352e0aa35f653df351 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 00:25:15 +0100 Subject: [PATCH 022/103] extract argument adding logic to function --- ...s-empty-record => type-alias-record-empty} | 0 .../type-alias-record-empty-multiline | 4 + .../snippets/type-alias-record-half-empty | 1 + .../snippets/type-alias-record-missing-colon | 1 + .../snippets/type-alias-record-simple | 1 + .../snippets/type-alias-record-two-entries | 1 + src/Stage/Parse/Contextualize.elm | 248 ++++++++---------- tests/ParserLexerTestCases.elm | 186 +++++++++++-- 8 files changed, 275 insertions(+), 167 deletions(-) rename parser-tests/snippets/{type-alias-empty-record => type-alias-record-empty} (100%) create mode 100644 parser-tests/snippets/type-alias-record-empty-multiline create mode 100644 parser-tests/snippets/type-alias-record-half-empty create mode 100644 parser-tests/snippets/type-alias-record-missing-colon create mode 100644 parser-tests/snippets/type-alias-record-simple create mode 100644 parser-tests/snippets/type-alias-record-two-entries diff --git a/parser-tests/snippets/type-alias-empty-record b/parser-tests/snippets/type-alias-record-empty similarity index 100% rename from parser-tests/snippets/type-alias-empty-record rename to parser-tests/snippets/type-alias-record-empty diff --git a/parser-tests/snippets/type-alias-record-empty-multiline b/parser-tests/snippets/type-alias-record-empty-multiline new file mode 100644 index 00000000..36c8e64c --- /dev/null +++ b/parser-tests/snippets/type-alias-record-empty-multiline @@ -0,0 +1,4 @@ +type alias Ty = { + + + } diff --git a/parser-tests/snippets/type-alias-record-half-empty b/parser-tests/snippets/type-alias-record-half-empty new file mode 100644 index 00000000..d5931b68 --- /dev/null +++ b/parser-tests/snippets/type-alias-record-half-empty @@ -0,0 +1 @@ +type alias Ty = { diff --git a/parser-tests/snippets/type-alias-record-missing-colon b/parser-tests/snippets/type-alias-record-missing-colon new file mode 100644 index 00000000..9d0955b8 --- /dev/null +++ b/parser-tests/snippets/type-alias-record-missing-colon @@ -0,0 +1 @@ +type alias Ty = { hi j7 } diff --git a/parser-tests/snippets/type-alias-record-simple b/parser-tests/snippets/type-alias-record-simple new file mode 100644 index 00000000..d0ef26fa --- /dev/null +++ b/parser-tests/snippets/type-alias-record-simple @@ -0,0 +1 @@ +type alias Ty = { hi: 6 } diff --git a/parser-tests/snippets/type-alias-record-two-entries b/parser-tests/snippets/type-alias-record-two-entries new file mode 100644 index 00000000..3a3d579d --- /dev/null +++ b/parser-tests/snippets/type-alias-record-two-entries @@ -0,0 +1 @@ +type alias Ty = { hi: 6, buy: 8 } diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index a9268a24..d87970c0 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -497,56 +497,28 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = -- We are in the top level of the type expression; we have -- found a closing bracket to match every opening bracket we -- have encounted so far whilst parsing the type expression. + -- (We may have found no brackets at all so far.) Nothing -> - case root of - Nothing -> - { bracketStack = empty - , root = Just newType - } - |> TypeExpressionResult_Progress - |> newState + let + rnewRoot = + case root of + Nothing -> + newType + |> Ok - Just (TypeExpression_NamedType { name, args }) -> + Just typeExpression -> + addArgumentTokenToType typeExpression str + in + case rnewRoot of + Ok newRoot -> { bracketStack = empty - , root = - Just - (TypeExpression_NamedType - { name = name - , args = - newType - |> pushOnto args - } - ) + , root = Just newRoot } |> TypeExpressionResult_Progress |> newState - Just (TypeExpression_PartialRecord existingPartialRecord) -> - case addTokenToPartialRecord existingPartialRecord str of - Ok newPartialRecord -> - { bracketStack = empty - , root = - newPartialRecord - |> TypeExpression_PartialRecord - |> Just - } - |> TypeExpressionResult_Progress - |> newState - - Err e -> - ParseResult_Err e - - Just ((TypeExpression_Record _) as ty) -> - Error_TypeDoesNotTakeArgs ty newType - |> ParseResult_Err - - Just ((TypeExpression_Bracketed _) as ty) -> - Error_TypeDoesNotTakeArgs ty newType - |> ParseResult_Err - - Just TypeExpression_Unit -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit newType - |> ParseResult_Err + Err e -> + ParseResult_Err e -- This is the first item following an opening bracket. Just ( Nothing, rest ) -> @@ -558,29 +530,12 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> TypeExpressionResult_Progress |> newState - Just ( Just (TypeExpression_NamedType { name, args }), rest ) -> - { bracketStack = - Just - (TypeExpression_NamedType - { name = name - , args = - newType - |> pushOnto args - } - ) - |> pushOnto rest - , root = root - } - |> TypeExpressionResult_Progress - |> newState - - Just ( Just (TypeExpression_PartialRecord existingPartialRecord), rest ) -> - case addTokenToPartialRecord existingPartialRecord str of - Ok newPartialRecord -> + -- This is an argument to some type that follows an opening bracket. + Just ( Just latestTypeExpr, rest ) -> + case addArgumentTokenToType latestTypeExpr str of + Ok newLatestTypeExpr -> { bracketStack = - newPartialRecord - |> TypeExpression_PartialRecord - |> Just + Just newLatestTypeExpr |> pushOnto rest , root = root } @@ -590,18 +545,6 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = Err e -> ParseResult_Err e - Just ( Just ((TypeExpression_Bracketed _) as ty), _ ) -> - Error_TypeDoesNotTakeArgs ty newType - |> ParseResult_Err - - Just ( Just ((TypeExpression_Record _) as ty), _ ) -> - Error_TypeDoesNotTakeArgs ty newType - |> ParseResult_Err - - Just ( Just TypeExpression_Unit, _ ) -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit newType - |> ParseResult_Err - Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> case role of Lexer.Open -> @@ -626,38 +569,16 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = TypeExpression_Unit in case pop poppedBracketStack of - Just ( newExprToAddTo, rest ) -> + Just ( mnewExprToAddTo, rest ) -> let rnewExpr = - case newExprToAddTo of + case mnewExprToAddTo of Nothing -> expr |> Ok - Just (TypeExpression_NamedType { name, args }) -> - { name = name - , args = - expr - |> pushOnto args - } - |> TypeExpression_NamedType - |> Ok - - Just (TypeExpression_PartialRecord partialRecord) -> - addTypeToPartialRecord partialRecord expr - |> Result.map TypeExpression_PartialRecord - - Just TypeExpression_Unit -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit expr - |> Err - - Just ((TypeExpression_Record _) as ty) -> - Error_TypeDoesNotTakeArgs ty expr - |> Err - - Just ((TypeExpression_Bracketed _) as ty) -> - Error_TypeDoesNotTakeArgs ty expr - |> Err + Just newExprToAddTo -> + addArgumentTypeToType newExprToAddTo expr in case rnewExpr of Ok newExpr -> @@ -673,52 +594,26 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = ParseResult_Err e Nothing -> - case root of - Nothing -> - { bracketStack = empty - , root = Just expr - } - |> TypeExpressionResult_Progress - |> newState + let + rnewRoot = + case root of + Nothing -> + expr + |> Ok - Just (TypeExpression_NamedType { name, args }) -> + Just typeExpression -> + addArgumentTypeToType typeExpression expr + in + case rnewRoot of + Ok newRoot -> { bracketStack = empty - , root = - Just - (TypeExpression_NamedType - { name = name - , args = - expr - |> pushOnto args - } - ) + , root = Just newRoot } |> TypeExpressionResult_Progress |> newState - Just (TypeExpression_PartialRecord partialRecord) -> - case addTypeToPartialRecord partialRecord expr of - Ok pr -> - { bracketStack = empty - , root = Just (TypeExpression_PartialRecord pr) - } - |> TypeExpressionResult_Progress - |> newState - - Err e -> - ParseResult_Err e - - Just TypeExpression_Unit -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit expr - |> ParseResult_Err - - Just ((TypeExpression_Record _) as ty) -> - Error_TypeDoesNotTakeArgs ty expr - |> ParseResult_Err - - Just ((TypeExpression_Bracketed _) as ty) -> - Error_TypeDoesNotTakeArgs ty expr - |> ParseResult_Err + Err e -> + ParseResult_Err e _ -> -- TODO(harry): can we add information about the @@ -736,8 +631,6 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = TypeExpressionResult_Done expr |> newState - -- ( TypeExpressionContext_Record (Just expr) ) -> - -- Debug.todo "" ( Nothing, Nothing ) -> Error_PartwayThroughTypeAlias |> ParseResult_Err @@ -933,6 +826,71 @@ addTypeToPartialRecord { firstEntries, lastEntry } expr = addTypeToPartialRecord innerPartialRecord expr +addArgumentTokenToType : PartialTypeExpression -> String -> Result Error PartialTypeExpression +addArgumentTokenToType existingTypeExpr argToAdd = + let + newType = + TypeExpression_NamedType + { name = argToAdd + , args = empty + } + in + case existingTypeExpr of + TypeExpression_NamedType { name, args } -> + TypeExpression_NamedType + { name = name + , args = + newType + |> pushOnto args + } + |> Ok + + TypeExpression_PartialRecord existingPartialRecord -> + addTokenToPartialRecord existingPartialRecord argToAdd + |> Result.map TypeExpression_PartialRecord + + (TypeExpression_Bracketed _) as ty -> + Error_TypeDoesNotTakeArgs ty newType + |> Err + + (TypeExpression_Record _) as ty -> + Error_TypeDoesNotTakeArgs ty newType + |> Err + + TypeExpression_Unit -> + Error_TypeDoesNotTakeArgs TypeExpression_Unit newType + |> Err + + +addArgumentTypeToType : PartialTypeExpression -> PartialTypeExpression -> Result Error PartialTypeExpression +addArgumentTypeToType existingTypeExpr argToAdd = + case existingTypeExpr of + TypeExpression_NamedType { name, args } -> + { name = name + , args = + argToAdd + |> pushOnto args + } + |> TypeExpression_NamedType + |> Ok + + TypeExpression_PartialRecord partialRecord -> + addTypeToPartialRecord partialRecord argToAdd + |> Result.map TypeExpression_PartialRecord + + TypeExpression_Unit -> + Error_TypeDoesNotTakeArgs TypeExpression_Unit argToAdd + |> Err + + (TypeExpression_Record _) as ty -> + Error_TypeDoesNotTakeArgs ty argToAdd + |> Err + + (TypeExpression_Bracketed _) as ty -> + Error_TypeDoesNotTakeArgs ty argToAdd + |> Err + + -- TODO(harry): custom error message here diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 1875f6a7..36fb5cba 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -59,28 +59,6 @@ testCases = ) ] } - , { name = "type-alias-empty-record" - , source = """type alias Ty = {} -""" - , lexed = - Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) - ] - , contextualized = - Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) - ] - } , { name = "type-alias-funky-indentation" , source = """type alias Model = List Int @@ -407,6 +385,170 @@ List Int ) ] } + , { name = "type-alias-record-empty" + , source = """type alias Ty = {} +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + ] + } + , { name = "type-alias-record-empty-multiline" + , source = """type alias Ty = { + + + } +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 5, row = 4 }, start = { col = 18, row = 1 } } + (Newlines + [ 0 + , 0 + ] + 4 + ) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + ] + } + , { name = "type-alias-record-half-empty" + , source = """type alias Ty = { +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + ] + } + , { name = "type-alias-record-missing-colon" + , source = """type alias Ty = { hi j7 } +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token "j7") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + ] + } + , { name = "type-alias-record-simple" + , source = """type alias Ty = { hi: 6 } +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "6") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + ] + } + , { name = "type-alias-record-two-entries" + , source = """type alias Ty = { hi: 6, buy: 8 } +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "6") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 26, row = 1 } } (Token "buy") + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil Colon) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Whitespace 1) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token "8") + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + ] + } , { name = "type-alias-unit" , source = """type alias Hi = () """ From 7bfb0322c9415ef4322fdff74eb87c27c84cc76c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 00:34:37 +0100 Subject: [PATCH 023/103] unify adding functions for tokens and types --- src/Stage/Parse/Contextualize.elm | 162 +++++++++--------------------- 1 file changed, 47 insertions(+), 115 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index d87970c0..404b5f52 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -507,7 +507,7 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> Ok Just typeExpression -> - addArgumentTokenToType typeExpression str + addArgumentToType typeExpression (TokenOrType_Token str) in case rnewRoot of Ok newRoot -> @@ -532,7 +532,7 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = -- This is an argument to some type that follows an opening bracket. Just ( Just latestTypeExpr, rest ) -> - case addArgumentTokenToType latestTypeExpr str of + case addArgumentToType latestTypeExpr (TokenOrType_Token str) of Ok newLatestTypeExpr -> { bracketStack = Just newLatestTypeExpr @@ -578,7 +578,7 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> Ok Just newExprToAddTo -> - addArgumentTypeToType newExprToAddTo expr + addArgumentToType newExprToAddTo (TokenOrType_Type expr) in case rnewExpr of Ok newExpr -> @@ -602,7 +602,7 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> Ok Just typeExpression -> - addArgumentTypeToType typeExpression expr + addArgumentToType typeExpression (TokenOrType_Type expr) in case rnewRoot of Ok newRoot -> @@ -700,31 +700,47 @@ blockFromState state = -- helper functions -addTokenToPartialRecord : +type TokenOrType + = TokenOrType_Token String + | TokenOrType_Type PartialTypeExpression + + +addToPartialRecord : { firstEntries : Stack ( String, PartialTypeExpression ) , lastEntry : LastEntryOfRecord } - -> String + -> TokenOrType -> Result Error { firstEntries : Stack ( String, PartialTypeExpression ) , lastEntry : LastEntryOfRecord } -addTokenToPartialRecord { firstEntries, lastEntry } str = +addToPartialRecord { firstEntries, lastEntry } tot = let newType = - TypeExpression_NamedType - { name = str - , args = empty - } + case tot of + TokenOrType_Token str -> + TypeExpression_NamedType + { name = str + , args = empty + } + + TokenOrType_Type ty -> + ty in case lastEntry of LastEntryOfRecord_Empty -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_Key str - } - |> Ok + case tot of + TokenOrType_Token str -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_Key str + } + |> Ok + + TokenOrType_Type _ -> + Error_ExpectedKeyWhilstParsingRecord + |> Err LastEntryOfRecord_Key key -> Error_ExpectedColonWhilstParsingRecord @@ -765,75 +781,22 @@ addTokenToPartialRecord { firstEntries, lastEntry } str = |> Err LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord innerPartialRecord) -> - addTokenToPartialRecord innerPartialRecord str - - -addTypeToPartialRecord : - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } - -> PartialTypeExpression - -> - Result Error - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } -addTypeToPartialRecord { firstEntries, lastEntry } expr = - case lastEntry of - LastEntryOfRecord_Empty -> - Error_ExpectedKeyWhilstParsingRecord - |> Err - - LastEntryOfRecord_Key key -> - Error_ExpectedColonWhilstParsingRecord - |> Err - - LastEntryOfRecord_KeyColon key -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue key expr - } - |> Ok - - LastEntryOfRecord_KeyValue key (TypeExpression_NamedType { name, args }) -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue - key - (TypeExpression_NamedType - { name = name - , args = - expr - |> pushOnto args - } - ) - } - |> Ok - - LastEntryOfRecord_KeyValue _ TypeExpression_Unit -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit expr - |> Err - - LastEntryOfRecord_KeyValue _ ((TypeExpression_Bracketed _) as ty) -> - Error_TypeDoesNotTakeArgs ty expr - |> Err - - LastEntryOfRecord_KeyValue _ ((TypeExpression_Record _) as ty) -> - Error_TypeDoesNotTakeArgs ty expr - |> Err - - LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord innerPartialRecord) -> - addTypeToPartialRecord innerPartialRecord expr + addToPartialRecord innerPartialRecord tot -addArgumentTokenToType : PartialTypeExpression -> String -> Result Error PartialTypeExpression -addArgumentTokenToType existingTypeExpr argToAdd = +addArgumentToType : PartialTypeExpression -> TokenOrType -> Result Error PartialTypeExpression +addArgumentToType existingTypeExpr argToAdd = let newType = - TypeExpression_NamedType - { name = argToAdd - , args = empty - } + case argToAdd of + TokenOrType_Token str -> + TypeExpression_NamedType + { name = str + , args = empty + } + + TokenOrType_Type ty -> + ty in case existingTypeExpr of TypeExpression_NamedType { name, args } -> @@ -846,7 +809,7 @@ addArgumentTokenToType existingTypeExpr argToAdd = |> Ok TypeExpression_PartialRecord existingPartialRecord -> - addTokenToPartialRecord existingPartialRecord argToAdd + addToPartialRecord existingPartialRecord argToAdd |> Result.map TypeExpression_PartialRecord (TypeExpression_Bracketed _) as ty -> @@ -862,39 +825,8 @@ addArgumentTokenToType existingTypeExpr argToAdd = |> Err -addArgumentTypeToType : PartialTypeExpression -> PartialTypeExpression -> Result Error PartialTypeExpression -addArgumentTypeToType existingTypeExpr argToAdd = - case existingTypeExpr of - TypeExpression_NamedType { name, args } -> - { name = name - , args = - argToAdd - |> pushOnto args - } - |> TypeExpression_NamedType - |> Ok - - TypeExpression_PartialRecord partialRecord -> - addTypeToPartialRecord partialRecord argToAdd - |> Result.map TypeExpression_PartialRecord - - TypeExpression_Unit -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit argToAdd - |> Err - - (TypeExpression_Record _) as ty -> - Error_TypeDoesNotTakeArgs ty argToAdd - |> Err - - (TypeExpression_Bracketed _) as ty -> - Error_TypeDoesNotTakeArgs ty argToAdd - |> Err - - - --- TODO(harry): custom error message here - - +{-| TODO(harry): custom error message here +-} partialTypeExpressionToConcreteType : PartialTypeExpression -> Result () (ConcreteType PossiblyQualified) partialTypeExpressionToConcreteType pte = case pte of From 0b341b4d7e00e7cd33748a55b425f4b091e2dd63 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 10:56:03 +0100 Subject: [PATCH 024/103] further unicode type expr parsing --- src/Stage/Parse/Contextualize.elm | 164 +++++++++++------------------- 1 file changed, 62 insertions(+), 102 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 404b5f52..d445a3d8 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -486,64 +486,33 @@ parserTypeExpr : parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = case item of Lexer.Token str -> - let - newType = - TypeExpression_NamedType - { name = str - , args = empty - } - in case pop bracketStack of -- We are in the top level of the type expression; we have -- found a closing bracket to match every opening bracket we - -- have encounted so far whilst parsing the type expression. + -- have encountered so far whilst parsing the type expression. -- (We may have found no brackets at all so far.) Nothing -> - let - rnewRoot = - case root of - Nothing -> - newType - |> Ok - - Just typeExpression -> - addArgumentToType typeExpression (TokenOrType_Token str) - in - case rnewRoot of - Ok newRoot -> - { bracketStack = empty - , root = Just newRoot - } - |> TypeExpressionResult_Progress - |> newState - - Err e -> - ParseResult_Err e - - -- This is the first item following an opening bracket. - Just ( Nothing, rest ) -> - { bracketStack = - Just newType - |> pushOnto rest - , root = root - } - |> TypeExpressionResult_Progress - |> newState + addArgumentToType root (TokenOrType_Token str) + |> Result.map + (\newRoot -> + { bracketStack = empty + , root = Just newRoot + } + ) + |> partialTypeExpressionToParseResult newState - -- This is an argument to some type that follows an opening bracket. - Just ( Just latestTypeExpr, rest ) -> - case addArgumentToType latestTypeExpr (TokenOrType_Token str) of - Ok newLatestTypeExpr -> - { bracketStack = - Just newLatestTypeExpr - |> pushOnto rest - , root = root - } - |> TypeExpressionResult_Progress - |> newState - - Err e -> - ParseResult_Err e + -- We are within a nested bracket. + Just ( mlatestTypeExpr, rest ) -> + addArgumentToType mlatestTypeExpr (TokenOrType_Token str) + |> Result.map + (\newLatestTypeExpr -> + { bracketStack = + Just newLatestTypeExpr + |> pushOnto rest + , root = root + } + ) + |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> case role of @@ -570,50 +539,26 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = in case pop poppedBracketStack of Just ( mnewExprToAddTo, rest ) -> - let - rnewExpr = - case mnewExprToAddTo of - Nothing -> - expr - |> Ok - - Just newExprToAddTo -> - addArgumentToType newExprToAddTo (TokenOrType_Type expr) - in - case rnewExpr of - Ok newExpr -> - { bracketStack = - Just newExpr - |> pushOnto rest - , root = root - } - |> TypeExpressionResult_Progress - |> newState - - Err e -> - ParseResult_Err e + addArgumentToType mnewExprToAddTo (TokenOrType_Type expr) + |> Result.map + (\newExpr -> + { bracketStack = + Just newExpr + |> pushOnto rest + , root = root + } + ) + |> partialTypeExpressionToParseResult newState Nothing -> - let - rnewRoot = - case root of - Nothing -> - expr - |> Ok - - Just typeExpression -> - addArgumentToType typeExpression (TokenOrType_Type expr) - in - case rnewRoot of - Ok newRoot -> - { bracketStack = empty - , root = Just newRoot - } - |> TypeExpressionResult_Progress - |> newState - - Err e -> - ParseResult_Err e + addArgumentToType root (TokenOrType_Type expr) + |> Result.map + (\newRoot -> + { bracketStack = empty + , root = Just newRoot + } + ) + |> partialTypeExpressionToParseResult newState _ -> -- TODO(harry): can we add information about the @@ -784,8 +729,8 @@ addToPartialRecord { firstEntries, lastEntry } tot = addToPartialRecord innerPartialRecord tot -addArgumentToType : PartialTypeExpression -> TokenOrType -> Result Error PartialTypeExpression -addArgumentToType existingTypeExpr argToAdd = +addArgumentToType : Maybe PartialTypeExpression -> TokenOrType -> Result Error PartialTypeExpression +addArgumentToType mexistingTypeExpr argToAdd = let newType = case argToAdd of @@ -798,8 +743,12 @@ addArgumentToType existingTypeExpr argToAdd = TokenOrType_Type ty -> ty in - case existingTypeExpr of - TypeExpression_NamedType { name, args } -> + case mexistingTypeExpr of + Nothing -> + newType + |> Ok + + Just (TypeExpression_NamedType { name, args }) -> TypeExpression_NamedType { name = name , args = @@ -808,23 +757,34 @@ addArgumentToType existingTypeExpr argToAdd = } |> Ok - TypeExpression_PartialRecord existingPartialRecord -> + Just (TypeExpression_PartialRecord existingPartialRecord) -> addToPartialRecord existingPartialRecord argToAdd |> Result.map TypeExpression_PartialRecord - (TypeExpression_Bracketed _) as ty -> + Just ((TypeExpression_Bracketed _) as ty) -> Error_TypeDoesNotTakeArgs ty newType |> Err - (TypeExpression_Record _) as ty -> + Just ((TypeExpression_Record _) as ty) -> Error_TypeDoesNotTakeArgs ty newType |> Err - TypeExpression_Unit -> + Just TypeExpression_Unit -> Error_TypeDoesNotTakeArgs TypeExpression_Unit newType |> Err +partialTypeExpressionToParseResult : (TypeExpressionResult -> ParseResult) -> Result Error PartialTypeExpression2 -> ParseResult +partialTypeExpressionToParseResult newState rnewPartialType = + case rnewPartialType of + Ok newPartialType -> + TypeExpressionResult_Progress newPartialType + |> newState + + Err e -> + ParseResult_Err e + + {-| TODO(harry): custom error message here -} partialTypeExpressionToConcreteType : PartialTypeExpression -> Result () (ConcreteType PossiblyQualified) From e85149756a2ca0702e357134be18e151048fdeeb Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 11:12:56 +0100 Subject: [PATCH 025/103] correctly parse recording in type aliases! --- .../snippets/type-alias-record-in-bracket | 1 + src/Stage/Parse/Contextualize.elm | 190 +++++++++++++++++- tests/ParserLexerTestCases.elm | 73 ++++++- 3 files changed, 257 insertions(+), 7 deletions(-) create mode 100644 parser-tests/snippets/type-alias-record-in-bracket diff --git a/parser-tests/snippets/type-alias-record-in-bracket b/parser-tests/snippets/type-alias-record-in-bracket new file mode 100644 index 00000000..c5deb03b --- /dev/null +++ b/parser-tests/snippets/type-alias-record-in-bracket @@ -0,0 +1 @@ +type alias Ty = ({ hi: 6 }) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index d445a3d8..fccca9d3 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -168,6 +168,9 @@ type Expecting = Expecting_Sigil Lexer.LexSigil | Expecting_Block | Expecting_TypeName + -- TODO(harry): reduce number of cases where we do not know what sigil we + -- are expecting. + | Expecting_Unknown @@ -566,6 +569,191 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = Error_UnmatchedBracket Lexer.Round Lexer.Close |> ParseResult_Err + Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> + let + newType = + TypeExpression_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty + } + in + case pop bracketStack of + Nothing -> + addArgumentToType root (TokenOrType_Type newType) + |> Result.map + (\newRoot -> + { bracketStack = empty + , root = Just newRoot + } + ) + |> partialTypeExpressionToParseResult newState + + Just ( mlatestTypeExpr, rest ) -> + addArgumentToType mlatestTypeExpr (TokenOrType_Type newType) + |> Result.map + (\newLatestTypeExpr -> + { bracketStack = + Just newLatestTypeExpr + |> pushOnto rest + , root = root + } + ) + |> partialTypeExpressionToParseResult newState + + Lexer.Sigil Lexer.Colon -> + case pop bracketStack of + Nothing -> + case root of + Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> + case lastEntry of + LastEntryOfRecord_Key key -> + { bracketStack = empty + , root = + TypeExpression_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyColon key + } + |> Just + } + |> TypeExpressionResult_Progress + |> newState + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + -- We are within a nested bracket. + Just ( mlatestTypeExpr, rest ) -> + case mlatestTypeExpr of + Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> + case lastEntry of + LastEntryOfRecord_Key key -> + { bracketStack = + TypeExpression_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyColon key + } + |> Just + |> pushOnto rest + , root = root + } + |> TypeExpressionResult_Progress + |> newState + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Lexer.Sigil Lexer.Comma -> + case pop bracketStack of + Nothing -> + case root of + Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + { bracketStack = empty + , root = + TypeExpression_PartialRecord + { firstEntries = ( key, value ) |> pushOnto firstEntries + , lastEntry = LastEntryOfRecord_Empty + } + |> Just + } + |> TypeExpressionResult_Progress + |> newState + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + -- We are within a nested bracket. + Just ( mlatestTypeExpr, rest ) -> + case mlatestTypeExpr of + Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + { bracketStack = + TypeExpression_PartialRecord + { firstEntries = ( key, value ) |> pushOnto firstEntries + , lastEntry = LastEntryOfRecord_Empty + } + |> Just + |> pushOnto rest + , root = root + } + |> TypeExpressionResult_Progress + |> newState + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> + case pop bracketStack of + Nothing -> + case root of + Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + { bracketStack = empty + , root = + ( key, value ) + |> pushOnto firstEntries + |> TypeExpression_Record + |> Just + } + |> TypeExpressionResult_Progress + |> newState + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + -- We are within a nested bracket. + Just ( mlatestTypeExpr, rest ) -> + case mlatestTypeExpr of + Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + { bracketStack = + ( key, value ) + |> pushOnto firstEntries + |> TypeExpression_Record + |> Just + |> pushOnto rest + , root = root + } + |> TypeExpressionResult_Progress + |> newState + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + Lexer.Newlines _ 0 -> case ( pop prevExpr.bracketStack, prevExpr.root ) of ( Just _, _ ) -> @@ -587,7 +775,7 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = ParseResult_Skip _ -> - Error_InvalidToken item (Expecting_Sigil Lexer.Assign) + Error_InvalidToken item Expecting_Unknown |> ParseResult_Err diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 36fb5cba..ced91199 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -404,7 +404,7 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_InvalidToken (Sigil (Bracket Curly Close)) Expecting_Unknown ) ] } , { name = "type-alias-record-empty-multiline" @@ -436,7 +436,7 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_InvalidToken (Sigil (Bracket Curly Close)) Expecting_Unknown ) ] } , { name = "type-alias-record-half-empty" @@ -457,7 +457,47 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_PartwayThroughTypeAlias ) + ] + } + , { name = "type-alias-record-in-bracket" + , source = """type alias Ty = ({ hi: 6 }) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token "hi") + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Sigil Colon) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Whitespace 1) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token "6") + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) ] } , { name = "type-alias-record-missing-colon" @@ -484,7 +524,7 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }) }), Error_ExpectedColonWhilstParsingRecord ) ] } , { name = "type-alias-record-simple" @@ -512,7 +552,17 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) ] } , { name = "type-alias-record-two-entries" @@ -546,7 +596,18 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Ty")), Error_InvalidToken (Sigil (Bracket Curly Open)) (Expecting_Sigil Assign) ) + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "buy", UserDefinedType { args = [], name = "8", qualifiedness = PossiblyQualified Nothing } ) + , ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) ] } , { name = "type-alias-unit" From d02f75d4ebd765d75d4c0b6a8b0cbf296bb51404 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 11:41:19 +0100 Subject: [PATCH 026/103] fix nesting --- .../snippets/type-alias-record-nested | 4 + src/Stage/Parse/Contextualize.elm | 296 +++++++++++------- tests/ParserLexerTestCases.elm | 108 +++++++ 3 files changed, 302 insertions(+), 106 deletions(-) create mode 100644 parser-tests/snippets/type-alias-record-nested diff --git a/parser-tests/snippets/type-alias-record-nested b/parser-tests/snippets/type-alias-record-nested new file mode 100644 index 00000000..2926818e --- /dev/null +++ b/parser-tests/snippets/type-alias-record-nested @@ -0,0 +1,4 @@ +type alias Ty = + { hi: { a: 7, b: List String } + , ih: CustomType A B C (D E) + } diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index fccca9d3..936f9a4c 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -18,9 +18,11 @@ import Elm.Data.Located as Located exposing (Located) import Elm.Data.Module exposing (Module, ModuleType(..)) import Elm.Data.ModuleName exposing (ModuleName) import Elm.Data.Qualifiedness as Qualifiedness exposing (PossiblyQualified(..)) +import Elm.Data.Type exposing (Type) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) import Elm.Data.TypeAnnotation exposing (TypeAnnotation) import Elm.Data.VarName exposing (VarName) +import Parser exposing (oneOf) import Stage.Parse.Lexer as Lexer exposing (LexItem(..)) import Stage.Parse.Token as Token exposing (Keyword) @@ -604,49 +606,40 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = case pop bracketStack of Nothing -> case root of - Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> - case lastEntry of - LastEntryOfRecord_Key key -> - { bracketStack = empty - , root = - TypeExpression_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyColon key - } - |> Just - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + Just (TypeExpression_PartialRecord pr) -> + addColonToPartialTypeExpression pr + |> Result.map + (\newPr -> + { bracketStack = empty + , root = + newPr + |> TypeExpression_PartialRecord + |> Just + } + ) + |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) + |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err - -- We are within a nested bracket. Just ( mlatestTypeExpr, rest ) -> case mlatestTypeExpr of - Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> - case lastEntry of - LastEntryOfRecord_Key key -> - { bracketStack = - TypeExpression_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyColon key - } - |> Just - |> pushOnto rest - , root = root - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + Just (TypeExpression_PartialRecord pr) -> + addColonToPartialTypeExpression pr + |> Result.map + (\newPr -> + { bracketStack = + newPr + |> TypeExpression_PartialRecord + |> Just + |> pushOnto rest + , root = root + } + ) + |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) + |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown @@ -656,49 +649,40 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = case pop bracketStack of Nothing -> case root of - Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - { bracketStack = empty - , root = - TypeExpression_PartialRecord - { firstEntries = ( key, value ) |> pushOnto firstEntries - , lastEntry = LastEntryOfRecord_Empty - } - |> Just - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + Just (TypeExpression_PartialRecord pr) -> + addCommaToPartialTypeExpression pr + |> Result.map + (\newPr -> + { bracketStack = empty + , root = + newPr + |> TypeExpression_PartialRecord + |> Just + } + ) + |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) + |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err - -- We are within a nested bracket. Just ( mlatestTypeExpr, rest ) -> case mlatestTypeExpr of - Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - { bracketStack = - TypeExpression_PartialRecord - { firstEntries = ( key, value ) |> pushOnto firstEntries - , lastEntry = LastEntryOfRecord_Empty - } - |> Just - |> pushOnto rest - , root = root - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + Just (TypeExpression_PartialRecord pr) -> + addCommaToPartialTypeExpression pr + |> Result.map + (\newPr -> + { bracketStack = + newPr + |> TypeExpression_PartialRecord + |> Just + |> pushOnto rest + , root = root + } + ) + |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) + |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown @@ -708,47 +692,38 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = case pop bracketStack of Nothing -> case root of - Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - { bracketStack = empty - , root = - ( key, value ) - |> pushOnto firstEntries - |> TypeExpression_Record - |> Just - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + Just (TypeExpression_PartialRecord pr) -> + addCloseToPartialTypeExpression pr + |> Result.map + (\newPr -> + { bracketStack = empty + , root = + newPr + |> Just + } + ) + |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) + |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err - -- We are within a nested bracket. Just ( mlatestTypeExpr, rest ) -> case mlatestTypeExpr of - Just (TypeExpression_PartialRecord { firstEntries, lastEntry }) -> - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - { bracketStack = - ( key, value ) - |> pushOnto firstEntries - |> TypeExpression_Record - |> Just - |> pushOnto rest - , root = root - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + Just (TypeExpression_PartialRecord pr) -> + addCloseToPartialTypeExpression pr + |> Result.map + (\newPr -> + { bracketStack = + newPr + |> Just + |> pushOnto rest + , root = root + } + ) + |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) + |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown @@ -915,6 +890,15 @@ addToPartialRecord { firstEntries, lastEntry } tot = LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord innerPartialRecord) -> addToPartialRecord innerPartialRecord tot + |> Result.map + (\newInnerPartialRecord -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue + key + (TypeExpression_PartialRecord newInnerPartialRecord) + } + ) addArgumentToType : Maybe PartialTypeExpression -> TokenOrType -> Result Error PartialTypeExpression @@ -962,6 +946,106 @@ addArgumentToType mexistingTypeExpr argToAdd = |> Err +{-| TODO(harry): custom error message here +-} +addColonToPartialTypeExpression : + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } + -> + Result () + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } +addColonToPartialTypeExpression { firstEntries, lastEntry } = + case lastEntry of + LastEntryOfRecord_Key key -> + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyColon key + } + |> Ok + + LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord pr) -> + addColonToPartialTypeExpression pr + |> Result.map + (\newPr -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue + key + (TypeExpression_PartialRecord newPr) + } + ) + + _ -> + Err () + + +{-| TODO(harry): custom error message here +-} +addCommaToPartialTypeExpression : + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } + -> + Result () + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } +addCommaToPartialTypeExpression { firstEntries, lastEntry } = + case lastEntry of + LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord pr) -> + addCommaToPartialTypeExpression pr + |> Result.map + (\newPr -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue + key + (TypeExpression_PartialRecord newPr) + } + ) + + LastEntryOfRecord_KeyValue key value -> + { firstEntries = ( key, value ) |> pushOnto firstEntries + , lastEntry = LastEntryOfRecord_Empty + } + |> Ok + + _ -> + Err () + + +{-| TODO(harry): custom error message here +-} +addCloseToPartialTypeExpression : + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } + -> Result () PartialTypeExpression +addCloseToPartialTypeExpression { firstEntries, lastEntry } = + case lastEntry of + LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord pr) -> + addCloseToPartialTypeExpression pr + |> Result.map + (\newPte -> + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue key newPte + } + |> TypeExpression_PartialRecord + ) + + LastEntryOfRecord_KeyValue key value -> + ( key, value ) + |> pushOnto firstEntries + |> TypeExpression_Record + |> Ok + + _ -> + Err () + + partialTypeExpressionToParseResult : (TypeExpressionResult -> ParseResult) -> Result Error PartialTypeExpression2 -> ParseResult partialTypeExpressionToParseResult newState rnewPartialType = case rnewPartialType of diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index ced91199..31ec4ffc 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -527,6 +527,114 @@ List Int [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }) }), Error_ExpectedColonWhilstParsingRecord ) ] } + , { name = "type-alias-record-nested" + , source = """type alias Ty = + { hi: { a: 7, b: List String } + , ih: CustomType A B C (D E) + } +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) + , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Token "hi") + , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Sigil Colon) + , Located { end = { col = 12, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 2) + , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Whitespace 1) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token "a") + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Colon) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token "7") + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil Comma) + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Token "b") + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Colon) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) + , Located { end = { col = 27, row = 2 }, start = { col = 23, row = 2 } } (Token "List") + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) + , Located { end = { col = 34, row = 2 }, start = { col = 28, row = 2 } } (Token "String") + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) + , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 5, row = 3 }, start = { col = 36, row = 2 } } (Newlines [] 4) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) + , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) + , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token "ih") + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Colon) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Token "CustomType") + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token "A") + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token "B") + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "C") + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Whitespace 1) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token "D") + , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Whitespace 1) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Token "E") + , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Newlines [] 4) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi" + , Record + (Dict.fromList + [ ( "a", UserDefinedType { args = [], name = "7", qualifiedness = PossiblyQualified Nothing } ) + , ( "b" + , UserDefinedType + { args = + [ UserDefinedType { args = [], name = "String", qualifiedness = PossiblyQualified Nothing } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + ) + ] + ) + ) + , ( "ih" + , UserDefinedType + { args = + [ UserDefinedType + { args = + [ UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } + ] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing } + ] + , name = "CustomType" + , qualifiedness = PossiblyQualified Nothing + } + ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) + ] + } , { name = "type-alias-record-simple" , source = """type alias Ty = { hi: 6 } """ From 59c7ecbb742b31833352ea550a64c8239a6ee8ca Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 14:50:41 +0100 Subject: [PATCH 027/103] deduplicate bracketstack handling code I spotted that the two cases (in root, in nested bracket) can be unified! --- src/Stage/Parse/Contextualize.elm | 247 +++++++++--------------------- 1 file changed, 69 insertions(+), 178 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 936f9a4c..0e590a9a 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -488,50 +488,25 @@ parserTypeExpr : -> PartialTypeExpression2 -> LexItem -> ParseResult -parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = +parserTypeExpr newState prevExpr item = case item of Lexer.Token str -> - case pop bracketStack of - -- We are in the top level of the type expression; we have - -- found a closing bracket to match every opening bracket we - -- have encountered so far whilst parsing the type expression. - -- (We may have found no brackets at all so far.) - Nothing -> - addArgumentToType root (TokenOrType_Token str) - |> Result.map - (\newRoot -> - { bracketStack = empty - , root = Just newRoot - } - ) - |> partialTypeExpressionToParseResult newState - - -- We are within a nested bracket. - Just ( mlatestTypeExpr, rest ) -> - addArgumentToType mlatestTypeExpr (TokenOrType_Token str) - |> Result.map - (\newLatestTypeExpr -> - { bracketStack = - Just newLatestTypeExpr - |> pushOnto rest - , root = root - } - ) - |> partialTypeExpressionToParseResult newState + exprAppend prevExpr (\typeExpr -> addArgumentToType typeExpr (TokenOrType_Token str)) + |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> case role of Lexer.Open -> { bracketStack = Nothing - |> pushOnto bracketStack - , root = root + |> pushOnto prevExpr.bracketStack + , root = prevExpr.root } |> TypeExpressionResult_Progress |> newState Lexer.Close -> - case pop bracketStack of + case pop prevExpr.bracketStack of Just ( mexpr, poppedBracketStack ) -> let expr = @@ -542,28 +517,12 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = Nothing -> TypeExpression_Unit in - case pop poppedBracketStack of - Just ( mnewExprToAddTo, rest ) -> - addArgumentToType mnewExprToAddTo (TokenOrType_Type expr) - |> Result.map - (\newExpr -> - { bracketStack = - Just newExpr - |> pushOnto rest - , root = root - } - ) - |> partialTypeExpressionToParseResult newState - - Nothing -> - addArgumentToType root (TokenOrType_Type expr) - |> Result.map - (\newRoot -> - { bracketStack = empty - , root = Just newRoot - } - ) - |> partialTypeExpressionToParseResult newState + exprAppend + { bracketStack = poppedBracketStack + , root = prevExpr.root + } + (\typeExpr -> addArgumentToType typeExpr (TokenOrType_Type expr)) + |> partialTypeExpressionToParseResult newState _ -> -- TODO(harry): can we add information about the @@ -579,155 +538,55 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = , lastEntry = LastEntryOfRecord_Empty } in - case pop bracketStack of - Nothing -> - addArgumentToType root (TokenOrType_Type newType) - |> Result.map - (\newRoot -> - { bracketStack = empty - , root = Just newRoot - } - ) - |> partialTypeExpressionToParseResult newState - - Just ( mlatestTypeExpr, rest ) -> - addArgumentToType mlatestTypeExpr (TokenOrType_Type newType) - |> Result.map - (\newLatestTypeExpr -> - { bracketStack = - Just newLatestTypeExpr - |> pushOnto rest - , root = root - } - ) - |> partialTypeExpressionToParseResult newState + exprAppend prevExpr (\typeExpr -> addArgumentToType typeExpr (TokenOrType_Type newType)) + |> partialTypeExpressionToParseResult newState Lexer.Sigil Lexer.Colon -> - case pop bracketStack of - Nothing -> - case root of + exprAppend + prevExpr + (\typeExpr -> + case typeExpr of Just (TypeExpression_PartialRecord pr) -> addColonToPartialTypeExpression pr - |> Result.map - (\newPr -> - { bracketStack = empty - , root = - newPr - |> TypeExpression_PartialRecord - |> Just - } - ) + |> Result.map TypeExpression_PartialRecord |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err - - Just ( mlatestTypeExpr, rest ) -> - case mlatestTypeExpr of - Just (TypeExpression_PartialRecord pr) -> - addColonToPartialTypeExpression pr - |> Result.map - (\newPr -> - { bracketStack = - newPr - |> TypeExpression_PartialRecord - |> Just - |> pushOnto rest - , root = root - } - ) - |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - |> partialTypeExpressionToParseResult newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + |> Err + ) + |> partialTypeExpressionToParseResult newState Lexer.Sigil Lexer.Comma -> - case pop bracketStack of - Nothing -> - case root of - Just (TypeExpression_PartialRecord pr) -> - addCommaToPartialTypeExpression pr - |> Result.map - (\newPr -> - { bracketStack = empty - , root = - newPr - |> TypeExpression_PartialRecord - |> Just - } - ) - |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - |> partialTypeExpressionToParseResult newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err - - Just ( mlatestTypeExpr, rest ) -> - case mlatestTypeExpr of + exprAppend + prevExpr + (\typeExpr -> + case typeExpr of Just (TypeExpression_PartialRecord pr) -> addCommaToPartialTypeExpression pr - |> Result.map - (\newPr -> - { bracketStack = - newPr - |> TypeExpression_PartialRecord - |> Just - |> pushOnto rest - , root = root - } - ) + |> Result.map TypeExpression_PartialRecord |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + |> Err + ) + |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> - case pop bracketStack of - Nothing -> - case root of + exprAppend + prevExpr + (\typeExpr -> + case typeExpr of Just (TypeExpression_PartialRecord pr) -> addCloseToPartialTypeExpression pr - |> Result.map - (\newPr -> - { bracketStack = empty - , root = - newPr - |> Just - } - ) |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - |> partialTypeExpressionToParseResult newState _ -> Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err - - Just ( mlatestTypeExpr, rest ) -> - case mlatestTypeExpr of - Just (TypeExpression_PartialRecord pr) -> - addCloseToPartialTypeExpression pr - |> Result.map - (\newPr -> - { bracketStack = - newPr - |> Just - |> pushOnto rest - , root = root - } - ) - |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - |> partialTypeExpressionToParseResult newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + |> Err + ) + |> partialTypeExpressionToParseResult newState Lexer.Newlines _ 0 -> case ( pop prevExpr.bracketStack, prevExpr.root ) of @@ -754,6 +613,38 @@ parserTypeExpr newState ({ bracketStack, root } as prevExpr) item = |> ParseResult_Err +exprAppend : + PartialTypeExpression2 + -> (Maybe PartialTypeExpression -> Result Error PartialTypeExpression) + -> Result Error PartialTypeExpression2 +exprAppend { bracketStack, root } append = + case pop bracketStack of + -- We are in the top level of the type expression; we have + -- found a closing bracket to match every opening bracket we + -- have encountered so far whilst parsing the type expression. + -- (We may have found no brackets at all so far.) + Nothing -> + append root + |> Result.map + (\newRoot -> + { bracketStack = empty + , root = Just newRoot + } + ) + + -- We are within a nested bracket. + Just ( mlatestTypeExpr, rest ) -> + append mlatestTypeExpr + |> Result.map + (\newLatestTypeExpr -> + { bracketStack = + Just newLatestTypeExpr + |> pushOnto rest + , root = root + } + ) + + blockFromState : State -> Maybe (Result Error Block) blockFromState state = case state of From cf139f382b91dff1419fad3d22359328ed44ac05 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 14:53:43 +0100 Subject: [PATCH 028/103] change arg order to simply adding to types --- src/Stage/Parse/Contextualize.elm | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 0e590a9a..dc79a1cb 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -491,7 +491,7 @@ parserTypeExpr : parserTypeExpr newState prevExpr item = case item of Lexer.Token str -> - exprAppend prevExpr (\typeExpr -> addArgumentToType typeExpr (TokenOrType_Token str)) + exprAppend prevExpr (addArgumentToType (TokenOrType_Token str)) |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> @@ -521,7 +521,7 @@ parserTypeExpr newState prevExpr item = { bracketStack = poppedBracketStack , root = prevExpr.root } - (\typeExpr -> addArgumentToType typeExpr (TokenOrType_Type expr)) + (addArgumentToType (TokenOrType_Type expr)) |> partialTypeExpressionToParseResult newState _ -> @@ -538,7 +538,7 @@ parserTypeExpr newState prevExpr item = , lastEntry = LastEntryOfRecord_Empty } in - exprAppend prevExpr (\typeExpr -> addArgumentToType typeExpr (TokenOrType_Type newType)) + exprAppend prevExpr (addArgumentToType (TokenOrType_Type newType)) |> partialTypeExpressionToParseResult newState Lexer.Sigil Lexer.Colon -> @@ -705,16 +705,17 @@ type TokenOrType addToPartialRecord : - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } - -> TokenOrType + TokenOrType + -> + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } -> Result Error { firstEntries : Stack ( String, PartialTypeExpression ) , lastEntry : LastEntryOfRecord } -addToPartialRecord { firstEntries, lastEntry } tot = +addToPartialRecord tot { firstEntries, lastEntry } = let newType = case tot of @@ -780,7 +781,7 @@ addToPartialRecord { firstEntries, lastEntry } tot = |> Err LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord innerPartialRecord) -> - addToPartialRecord innerPartialRecord tot + addToPartialRecord tot innerPartialRecord |> Result.map (\newInnerPartialRecord -> { firstEntries = firstEntries @@ -792,8 +793,8 @@ addToPartialRecord { firstEntries, lastEntry } tot = ) -addArgumentToType : Maybe PartialTypeExpression -> TokenOrType -> Result Error PartialTypeExpression -addArgumentToType mexistingTypeExpr argToAdd = +addArgumentToType : TokenOrType -> Maybe PartialTypeExpression -> Result Error PartialTypeExpression +addArgumentToType argToAdd mexistingTypeExpr = let newType = case argToAdd of @@ -821,7 +822,7 @@ addArgumentToType mexistingTypeExpr argToAdd = |> Ok Just (TypeExpression_PartialRecord existingPartialRecord) -> - addToPartialRecord existingPartialRecord argToAdd + addToPartialRecord argToAdd existingPartialRecord |> Result.map TypeExpression_PartialRecord Just ((TypeExpression_Bracketed _) as ty) -> From 340c030cee9841b574d63ceb7ac2fcc15df42d4f Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 15:09:36 +0100 Subject: [PATCH 029/103] deduplicate adding thigns to records nice reduction in error prone code here! --- src/Stage/Parse/Contextualize.elm | 163 +++++++++--------------------- 1 file changed, 49 insertions(+), 114 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index dc79a1cb..b5f7b1cc 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -542,51 +542,13 @@ parserTypeExpr newState prevExpr item = |> partialTypeExpressionToParseResult newState Lexer.Sigil Lexer.Colon -> - exprAppend - prevExpr - (\typeExpr -> - case typeExpr of - Just (TypeExpression_PartialRecord pr) -> - addColonToPartialTypeExpression pr - |> Result.map TypeExpression_PartialRecord - |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - - _ -> - Error_InvalidToken item Expecting_Unknown - |> Err - ) - |> partialTypeExpressionToParseResult newState + addThingToPartialRecord ThingToAddToPartialRecord_Colon prevExpr item newState Lexer.Sigil Lexer.Comma -> - exprAppend - prevExpr - (\typeExpr -> - case typeExpr of - Just (TypeExpression_PartialRecord pr) -> - addCommaToPartialTypeExpression pr - |> Result.map TypeExpression_PartialRecord - |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - - _ -> - Error_InvalidToken item Expecting_Unknown - |> Err - ) - |> partialTypeExpressionToParseResult newState + addThingToPartialRecord ThingToAddToPartialRecord_Comma prevExpr item newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> - exprAppend - prevExpr - (\typeExpr -> - case typeExpr of - Just (TypeExpression_PartialRecord pr) -> - addCloseToPartialTypeExpression pr - |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - - _ -> - Error_InvalidToken item Expecting_Unknown - |> Err - ) - |> partialTypeExpressionToParseResult newState + addThingToPartialRecord ThingToAddToPartialRecord_Close prevExpr item newState Lexer.Newlines _ 0 -> case ( pop prevExpr.bracketStack, prevExpr.root ) of @@ -838,97 +800,70 @@ addArgumentToType argToAdd mexistingTypeExpr = |> Err -{-| TODO(harry): custom error message here --} -addColonToPartialTypeExpression : - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } - -> - Result () - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } -addColonToPartialTypeExpression { firstEntries, lastEntry } = - case lastEntry of - LastEntryOfRecord_Key key -> - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyColon key - } - |> Ok +type ThingToAddToPartialRecord + = ThingToAddToPartialRecord_Colon + | ThingToAddToPartialRecord_Comma + | ThingToAddToPartialRecord_Close - LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord pr) -> - addColonToPartialTypeExpression pr - |> Result.map - (\newPr -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue - key - (TypeExpression_PartialRecord newPr) - } - ) - _ -> - Err () +addThingToPartialRecord : + ThingToAddToPartialRecord + -> PartialTypeExpression2 + -> Lexer.LexItem + -> (TypeExpressionResult -> ParseResult) + -> ParseResult +addThingToPartialRecord thing prevExpr item newState = + exprAppend + prevExpr + (\typeExpr -> + case typeExpr of + Just (TypeExpression_PartialRecord pr) -> + addThingToPartialRecordHelp thing pr + |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) + _ -> + Error_InvalidToken item Expecting_Unknown + |> Err + ) + |> partialTypeExpressionToParseResult newState -{-| TODO(harry): custom error message here --} -addCommaToPartialTypeExpression : - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } + +addThingToPartialRecordHelp : + ThingToAddToPartialRecord -> - Result () - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } + -> Result () PartialTypeExpression +addThingToPartialRecordHelp thing { firstEntries, lastEntry } = + case ( thing, lastEntry ) of + ( ThingToAddToPartialRecord_Colon, LastEntryOfRecord_Key key ) -> + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyColon key } -addCommaToPartialTypeExpression { firstEntries, lastEntry } = - case lastEntry of - LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord pr) -> - addCommaToPartialTypeExpression pr + |> TypeExpression_PartialRecord + |> Ok + + -- Must come before other `LastEntryOfRecord_KeyValue` cases! + ( _, LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord pr) ) -> + addThingToPartialRecordHelp thing pr |> Result.map (\newPr -> { firstEntries = firstEntries , lastEntry = - LastEntryOfRecord_KeyValue - key - (TypeExpression_PartialRecord newPr) + LastEntryOfRecord_KeyValue key newPr } + |> TypeExpression_PartialRecord ) - LastEntryOfRecord_KeyValue key value -> + ( ThingToAddToPartialRecord_Comma, LastEntryOfRecord_KeyValue key value ) -> { firstEntries = ( key, value ) |> pushOnto firstEntries , lastEntry = LastEntryOfRecord_Empty } + |> TypeExpression_PartialRecord |> Ok - _ -> - Err () - - -{-| TODO(harry): custom error message here --} -addCloseToPartialTypeExpression : - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } - -> Result () PartialTypeExpression -addCloseToPartialTypeExpression { firstEntries, lastEntry } = - case lastEntry of - LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord pr) -> - addCloseToPartialTypeExpression pr - |> Result.map - (\newPte -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue key newPte - } - |> TypeExpression_PartialRecord - ) - - LastEntryOfRecord_KeyValue key value -> + ( ThingToAddToPartialRecord_Close, LastEntryOfRecord_KeyValue key value ) -> ( key, value ) |> pushOnto firstEntries |> TypeExpression_Record From 7ff6e4a20e11b095f8b2ae092013731ad5d0b1ba Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 15:59:20 +0100 Subject: [PATCH 030/103] correctly parse empty records --- src/Stage/Parse/Contextualize.elm | 8 ++++++++ tests/ParserLexerTestCases.elm | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index b5f7b1cc..08e8e592 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -863,6 +863,14 @@ addThingToPartialRecordHelp thing { firstEntries, lastEntry } = |> TypeExpression_PartialRecord |> Ok + ( ThingToAddToPartialRecord_Close, LastEntryOfRecord_Empty ) -> + if firstEntries == empty then + TypeExpression_Record empty + |> Ok + + else + Err () + ( ThingToAddToPartialRecord_Close, LastEntryOfRecord_KeyValue key value ) -> ( key, value ) |> pushOnto firstEntries diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 31ec4ffc..9f82fea5 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -1,5 +1,6 @@ module ParserLexerTestCases exposing (testCases) +import Dict import Elm.Data.Located as Located exposing (Located(..)) import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete exposing (ConcreteType(..)) @@ -404,7 +405,7 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_InvalidToken (Sigil (Bracket Curly Close)) Expecting_Unknown ) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), ty = TypeOrConstructor "Ty" }) ] } , { name = "type-alias-record-empty-multiline" @@ -436,7 +437,7 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_InvalidToken (Sigil (Bracket Curly Close)) Expecting_Unknown ) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), ty = TypeOrConstructor "Ty" }) ] } , { name = "type-alias-record-half-empty" From c6a5faea733519baf2e3e331e0bd2b9fe3faea06 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 16:03:57 +0100 Subject: [PATCH 031/103] specify whether test snippets should parse or not --- .../type-alias-invalid-multiple-brackets | 0 .../type-alias-invalid-multiple-brackets-2 | 0 .../type-alias-invalid-multiple-brackets-3 | 0 .../type-alias-multiline-missing-indentation | 0 .../{ => should-not-parse}/type-alias-partial | 0 .../type-alias-partial-2 | 0 .../type-alias-partial-3 | 0 .../type-alias-partial-with-bracket | 0 .../type-alias-partial-with-bracket-2 | 0 .../type-alias-record-half-empty | 0 .../type-alias-record-missing-colon | 0 .../{ => should-not-parse}/type-partial | 0 .../snippets/{ => should-parse}/type-alias | 0 .../type-alias-funky-indentation | 0 .../type-alias-funky-indentation-2 | 0 .../type-alias-record-empty | 0 .../type-alias-record-empty-multiline | 0 .../type-alias-record-in-bracket | 0 .../type-alias-record-nested | 0 .../type-alias-record-simple | 0 .../type-alias-record-two-entries | 0 .../{ => should-parse}/type-alias-unit | 0 .../type-alias-with-bracket | 0 parser-tests/update.js | 84 +- tests/ParserLexerTest.elm | 70 +- tests/ParserLexerTestCases.elm | 727 +++++++++--------- 26 files changed, 476 insertions(+), 405 deletions(-) rename parser-tests/snippets/{ => should-not-parse}/type-alias-invalid-multiple-brackets (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-invalid-multiple-brackets-2 (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-invalid-multiple-brackets-3 (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-multiline-missing-indentation (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-partial (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-partial-2 (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-partial-3 (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-partial-with-bracket (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-partial-with-bracket-2 (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-record-half-empty (100%) rename parser-tests/snippets/{ => should-not-parse}/type-alias-record-missing-colon (100%) rename parser-tests/snippets/{ => should-not-parse}/type-partial (100%) rename parser-tests/snippets/{ => should-parse}/type-alias (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-funky-indentation (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-funky-indentation-2 (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-record-empty (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-record-empty-multiline (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-record-in-bracket (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-record-nested (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-record-simple (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-record-two-entries (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-unit (100%) rename parser-tests/snippets/{ => should-parse}/type-alias-with-bracket (100%) diff --git a/parser-tests/snippets/type-alias-invalid-multiple-brackets b/parser-tests/snippets/should-not-parse/type-alias-invalid-multiple-brackets similarity index 100% rename from parser-tests/snippets/type-alias-invalid-multiple-brackets rename to parser-tests/snippets/should-not-parse/type-alias-invalid-multiple-brackets diff --git a/parser-tests/snippets/type-alias-invalid-multiple-brackets-2 b/parser-tests/snippets/should-not-parse/type-alias-invalid-multiple-brackets-2 similarity index 100% rename from parser-tests/snippets/type-alias-invalid-multiple-brackets-2 rename to parser-tests/snippets/should-not-parse/type-alias-invalid-multiple-brackets-2 diff --git a/parser-tests/snippets/type-alias-invalid-multiple-brackets-3 b/parser-tests/snippets/should-not-parse/type-alias-invalid-multiple-brackets-3 similarity index 100% rename from parser-tests/snippets/type-alias-invalid-multiple-brackets-3 rename to parser-tests/snippets/should-not-parse/type-alias-invalid-multiple-brackets-3 diff --git a/parser-tests/snippets/type-alias-multiline-missing-indentation b/parser-tests/snippets/should-not-parse/type-alias-multiline-missing-indentation similarity index 100% rename from parser-tests/snippets/type-alias-multiline-missing-indentation rename to parser-tests/snippets/should-not-parse/type-alias-multiline-missing-indentation diff --git a/parser-tests/snippets/type-alias-partial b/parser-tests/snippets/should-not-parse/type-alias-partial similarity index 100% rename from parser-tests/snippets/type-alias-partial rename to parser-tests/snippets/should-not-parse/type-alias-partial diff --git a/parser-tests/snippets/type-alias-partial-2 b/parser-tests/snippets/should-not-parse/type-alias-partial-2 similarity index 100% rename from parser-tests/snippets/type-alias-partial-2 rename to parser-tests/snippets/should-not-parse/type-alias-partial-2 diff --git a/parser-tests/snippets/type-alias-partial-3 b/parser-tests/snippets/should-not-parse/type-alias-partial-3 similarity index 100% rename from parser-tests/snippets/type-alias-partial-3 rename to parser-tests/snippets/should-not-parse/type-alias-partial-3 diff --git a/parser-tests/snippets/type-alias-partial-with-bracket b/parser-tests/snippets/should-not-parse/type-alias-partial-with-bracket similarity index 100% rename from parser-tests/snippets/type-alias-partial-with-bracket rename to parser-tests/snippets/should-not-parse/type-alias-partial-with-bracket diff --git a/parser-tests/snippets/type-alias-partial-with-bracket-2 b/parser-tests/snippets/should-not-parse/type-alias-partial-with-bracket-2 similarity index 100% rename from parser-tests/snippets/type-alias-partial-with-bracket-2 rename to parser-tests/snippets/should-not-parse/type-alias-partial-with-bracket-2 diff --git a/parser-tests/snippets/type-alias-record-half-empty b/parser-tests/snippets/should-not-parse/type-alias-record-half-empty similarity index 100% rename from parser-tests/snippets/type-alias-record-half-empty rename to parser-tests/snippets/should-not-parse/type-alias-record-half-empty diff --git a/parser-tests/snippets/type-alias-record-missing-colon b/parser-tests/snippets/should-not-parse/type-alias-record-missing-colon similarity index 100% rename from parser-tests/snippets/type-alias-record-missing-colon rename to parser-tests/snippets/should-not-parse/type-alias-record-missing-colon diff --git a/parser-tests/snippets/type-partial b/parser-tests/snippets/should-not-parse/type-partial similarity index 100% rename from parser-tests/snippets/type-partial rename to parser-tests/snippets/should-not-parse/type-partial diff --git a/parser-tests/snippets/type-alias b/parser-tests/snippets/should-parse/type-alias similarity index 100% rename from parser-tests/snippets/type-alias rename to parser-tests/snippets/should-parse/type-alias diff --git a/parser-tests/snippets/type-alias-funky-indentation b/parser-tests/snippets/should-parse/type-alias-funky-indentation similarity index 100% rename from parser-tests/snippets/type-alias-funky-indentation rename to parser-tests/snippets/should-parse/type-alias-funky-indentation diff --git a/parser-tests/snippets/type-alias-funky-indentation-2 b/parser-tests/snippets/should-parse/type-alias-funky-indentation-2 similarity index 100% rename from parser-tests/snippets/type-alias-funky-indentation-2 rename to parser-tests/snippets/should-parse/type-alias-funky-indentation-2 diff --git a/parser-tests/snippets/type-alias-record-empty b/parser-tests/snippets/should-parse/type-alias-record-empty similarity index 100% rename from parser-tests/snippets/type-alias-record-empty rename to parser-tests/snippets/should-parse/type-alias-record-empty diff --git a/parser-tests/snippets/type-alias-record-empty-multiline b/parser-tests/snippets/should-parse/type-alias-record-empty-multiline similarity index 100% rename from parser-tests/snippets/type-alias-record-empty-multiline rename to parser-tests/snippets/should-parse/type-alias-record-empty-multiline diff --git a/parser-tests/snippets/type-alias-record-in-bracket b/parser-tests/snippets/should-parse/type-alias-record-in-bracket similarity index 100% rename from parser-tests/snippets/type-alias-record-in-bracket rename to parser-tests/snippets/should-parse/type-alias-record-in-bracket diff --git a/parser-tests/snippets/type-alias-record-nested b/parser-tests/snippets/should-parse/type-alias-record-nested similarity index 100% rename from parser-tests/snippets/type-alias-record-nested rename to parser-tests/snippets/should-parse/type-alias-record-nested diff --git a/parser-tests/snippets/type-alias-record-simple b/parser-tests/snippets/should-parse/type-alias-record-simple similarity index 100% rename from parser-tests/snippets/type-alias-record-simple rename to parser-tests/snippets/should-parse/type-alias-record-simple diff --git a/parser-tests/snippets/type-alias-record-two-entries b/parser-tests/snippets/should-parse/type-alias-record-two-entries similarity index 100% rename from parser-tests/snippets/type-alias-record-two-entries rename to parser-tests/snippets/should-parse/type-alias-record-two-entries diff --git a/parser-tests/snippets/type-alias-unit b/parser-tests/snippets/should-parse/type-alias-unit similarity index 100% rename from parser-tests/snippets/type-alias-unit rename to parser-tests/snippets/should-parse/type-alias-unit diff --git a/parser-tests/snippets/type-alias-with-bracket b/parser-tests/snippets/should-parse/type-alias-with-bracket similarity index 100% rename from parser-tests/snippets/type-alias-with-bracket rename to parser-tests/snippets/should-parse/type-alias-with-bracket diff --git a/parser-tests/update.js b/parser-tests/update.js index 7125bf6b..96ed2b7b 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -17,8 +17,31 @@ const warningCommentLines = ` .trim() .split('\n'); +function typeOfResultCases(shouldParse) { + const resultArgs = shouldParse ? 'never Block' : '(State, Error) never'; + return ` + List + { contextualized : Maybe (List (Result ${resultArgs} )) + , lexed : Result Never (List (Located LexItem)) + , name : String + , source : String + } +`; +} + const TEST_FILE_PATH = path.join(__dirname, '..', 'tests', 'ParserLexerTestCases.elm'); -const SNIPPETS_DIR_PATH = path.join(__dirname, 'snippets'); +const BASE_SNIPPETS_DIR_PATH = path.join(__dirname, 'snippets'); +const SNIPPETS_DIR_PATH = Object.freeze({ + shouldParse: path.join(BASE_SNIPPETS_DIR_PATH, 'should-parse'), + shouldNotParse: path.join(BASE_SNIPPETS_DIR_PATH, 'should-not-parse') +}); + +function getTestCase(snippets) { + return new Promise(resolve => { + const app = Elm.Update.init({flags: snippets}); + app.ports.output.subscribe(resolve); + }); +} async function main() { const testFile = await fs.readFile(TEST_FILE_PATH, 'utf-8'); @@ -29,21 +52,38 @@ async function main() { const testFileStart = testFile.slice(0, epilogueStart).trim(); const snippets = await Promise.all( - (await fs.readdir(SNIPPETS_DIR_PATH)) - .sort() - .filter((name) => !name.startsWith('_')) - .map(async (name) => ({ - name, - source: await fs.readFile(path.join(SNIPPETS_DIR_PATH, name), 'utf-8'), - })) + Object.entries(SNIPPETS_DIR_PATH).map(async ([category, dirPath]) => { + let files; + try { + files = await fs.readdir(dirPath); + } catch (error) { + if (error.code === 'ENOENT') { + return [category, []]; + } + + throw error; + } + + return [ + category, + await Promise.all( + files + .sort() + .filter(name => !name.startsWith('_')) + .map(async name => ({ + name, + source: await fs.readFile(path.join(dirPath, name), 'utf-8') + })) + ) + ]; + }) ); - const tests = await new Promise((resolve) => { - const app = Elm.Update.init({flags: snippets}); - app.ports.output.subscribe(resolve); - }); + const testCases = await Promise.all( + snippets.map(async ([category, snippets2]) => [category, await getTestCase(snippets2)]) + ); - if (tests.includes('Panic')) { + if (testCases.some(tests => tests.includes('Panic'))) { console.error('ERROR: One or more test cases panicked!'); process.exitCode = 1; } @@ -53,15 +93,15 @@ async function main() { '\n\n', warningCommentLines.join('\n'), '\n', - 'testCases :', - ' List', - ' { contextualized : Maybe (List (Result ( State, Error ) Block))', - ' , lexed : Result error (List (Located LexItem))', - ' , name : String', - ' , source : String', - ' }', - 'testCases =', - tests, + testCases + .flatMap(([category, testCases]) => [ + `${category}TestCases :`, + typeOfResultCases(category === 'shouldParse'), + `${category}TestCases =`, + testCases, + '\n' + ]) + .join('\n') ].join('\n'); await fs.writeFile(TEST_FILE_PATH, newTestFile); diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm index 9b5f31ae..4d2f09d8 100644 --- a/tests/ParserLexerTest.elm +++ b/tests/ParserLexerTest.elm @@ -11,29 +11,49 @@ import Test exposing (Test, describe, test) tests = describe "parser lexer test cases" - (ParserLexerTestCases.testCases - |> List.map - (\{ name, source, lexed, contextualized } -> - describe name - ([ Just - (test "lexing" <| - \() -> - source - |> P.run Lexer.parser - |> Expect.equal lexed + [ describe "lexing" + ((ParserLexerTestCases.shouldParseTestCases ++ ParserLexerTestCases.shouldNotParseTestCases) + |> List.map + (\{ name, source, lexed } -> + test name <| + \() -> + source + |> P.run Lexer.parser + |> Expect.equal (lexed |> Result.mapError never) + ) + ) + , describe "should parse" + (ParserLexerTestCases.shouldParseTestCases + |> List.filterMap + (\{ name, source, lexed, contextualized } -> + Maybe.map2 + (\contextualized_ lexed_ -> + test name <| + \() -> + lexed_ + |> List.map Located.unwrap + |> Contextualize.run + |> Expect.equal contextualized_ ) - , contextualized - |> Maybe.map - (\contextualized_ -> - test "parsing" <| - \() -> - source - |> P.run Lexer.parser - |> Result.map (List.map Located.unwrap >> Contextualize.run) - |> Expect.equal (Ok contextualized_) - ) - ] - |> List.filterMap (\x -> x) - ) - ) - ) + contextualized + (Result.toMaybe lexed) + ) + ) + , describe "should not parse" + (ParserLexerTestCases.shouldNotParseTestCases + |> List.filterMap + (\{ name, source, lexed, contextualized } -> + Maybe.map2 + (\contextualized_ lexed_ -> + test name <| + \() -> + lexed_ + |> List.map Located.unwrap + |> Contextualize.run + |> Expect.equal contextualized_ + ) + contextualized + (Result.toMaybe lexed) + ) + ) + ] diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 9f82fea5..8606053c 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -1,4 +1,4 @@ -module ParserLexerTestCases exposing (testCases) +module ParserLexerTestCases exposing (shouldNotParseTestCases, shouldParseTestCases) import Dict import Elm.Data.Located as Located exposing (Located(..)) @@ -17,14 +17,14 @@ import Test exposing (Test, describe, test) -- tests/parser-tests/update.js -testCases : +shouldParseTestCases : List - { contextualized : Maybe (List (Result ( State, Error ) Block)) - , lexed : Result error (List (Located LexItem)) + { contextualized : Maybe (List (Result never Block)) + , lexed : Result Never (List (Located LexItem)) , name : String , source : String } -testCases = +shouldParseTestCases = [ { name = "type-alias" , source = """type alias Model = List Int """ @@ -133,8 +133,8 @@ testCases = ) ] } - , { name = "type-alias-invalid-multiple-brackets" - , source = """type alias Hi = (Int) () + , { name = "type-alias-record-empty" + , source = """type alias Ty = {} """ , lexed = Ok @@ -142,36 +142,24 @@ testCases = , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = - Stack - [ Nothing - ] - , root = Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) - } - ) - , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) TypeExpression_Unit - ) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), ty = TypeOrConstructor "Ty" }) ] } - , { name = "type-alias-invalid-multiple-brackets-2" - , source = """type alias Hi = () () + , { name = "type-alias-record-empty-multiline" + , source = """type alias Ty = { + + + } """ , lexed = Ok @@ -179,35 +167,28 @@ testCases = , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 5, row = 4 }, start = { col = 18, row = 1 } } + (Newlines + [ 0 + , 0 + ] + 4 + ) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) ] , contextualized = Just - [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = - Stack - [ Nothing - ] - , root = Just TypeExpression_Unit - } - ) - , Error_TypeDoesNotTakeArgs TypeExpression_Unit TypeExpression_Unit - ) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), ty = TypeOrConstructor "Ty" }) ] } - , { name = "type-alias-invalid-multiple-brackets-3" - , source = """type alias Hi = () (Int) + , { name = "type-alias-record-in-bracket" + , source = """type alias Ty = ({ hi: 6 }) """ , lexed = Ok @@ -215,37 +196,42 @@ testCases = , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Token "Int") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) + , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token "hi") + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Sigil Colon) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Whitespace 1) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token "6") + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = - Stack - [ Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) ] - , root = Just TypeExpression_Unit - } - ) - , Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) + ) + , ty = TypeOrConstructor "Ty" + } ) ] } - , { name = "type-alias-multiline-missing-indentation" - , source = """type alias Model = -List Int + , { name = "type-alias-record-nested" + , source = """type alias Ty = + { hi: { a: 7, b: List String } + , ih: CustomType A B C (D E) + } """ , lexed = Ok @@ -253,38 +239,142 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "List") - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token "Int") - , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) + , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Token "hi") + , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Sigil Colon) + , Located { end = { col = 12, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 2) + , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Whitespace 1) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token "a") + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Colon) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token "7") + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil Comma) + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Token "b") + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Colon) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) + , Located { end = { col = 27, row = 2 }, start = { col = 23, row = 2 } } (Token "List") + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) + , Located { end = { col = 34, row = 2 }, start = { col = 28, row = 2 } } (Token "String") + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) + , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 5, row = 3 }, start = { col = 36, row = 2 } } (Newlines [] 4) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) + , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) + , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token "ih") + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Colon) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Token "CustomType") + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token "A") + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token "B") + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "C") + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Whitespace 1) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token "D") + , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Whitespace 1) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Token "E") + , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Newlines [] 4) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")), Error_PartwayThroughTypeAlias ) - , Err ( State_BlockStart, Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") ) + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi" + , Record + (Dict.fromList + [ ( "a", UserDefinedType { args = [], name = "7", qualifiedness = PossiblyQualified Nothing } ) + , ( "b" + , UserDefinedType + { args = + [ UserDefinedType { args = [], name = "String", qualifiedness = PossiblyQualified Nothing } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + ) + ] + ) + ) + , ( "ih" + , UserDefinedType + { args = + [ UserDefinedType + { args = + [ UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } + ] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing } + ] + , name = "CustomType" + , qualifiedness = PossiblyQualified Nothing + } + ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) ] } - , { name = "type-alias-partial" - , source = """type alias + , { name = "type-alias-record-simple" + , source = """type alias Ty = { hi: 6 } """ , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") - , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "6") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err ( State_BlockTypeAlias BlockTypeAlias_Keywords, Error_PartwayThroughTypeAlias ) + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) ] } - , { name = "type-alias-partial-2" - , source = """type alias Hi + , { name = "type-alias-record-two-entries" + , source = """type alias Ty = { hi: 6, buy: 8 } """ , lexed = Ok @@ -292,16 +382,44 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") - , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "6") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 26, row = 1 } } (Token "buy") + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil Colon) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Whitespace 1) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token "8") + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")), Error_PartwayThroughTypeAlias ) + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "buy", UserDefinedType { args = [], name = "8", qualifiedness = PossiblyQualified Nothing } ) + , ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) ] } - , { name = "type-alias-partial-3" - , source = """type alias Hi = + , { name = "type-alias-unit" + , source = """type alias Hi = () """ , lexed = Ok @@ -312,15 +430,18 @@ List Int , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")), Error_PartwayThroughTypeAlias ) + [ Ok (TypeAlias { expr = Unit, ty = TypeOrConstructor "Hi" }) ] } - , { name = "type-alias-partial-with-bracket" - , source = """type alias Hi = ( + , { name = "type-alias-with-bracket" + , source = """type alias Hi = (Int) """ , lexed = Ok @@ -333,27 +454,28 @@ List Int , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = - Stack - [ Nothing - ] - , root = Nothing - } - ) - , Error_PartwayThroughTypeAlias - ) + [ Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi" }) ] } - , { name = "type-alias-partial-with-bracket-2" - , source = """type alias Hi = ( - Int + ] + + +shouldNotParseTestCases : + List + { contextualized : Maybe (List (Result ( State, Error ) never)) + , lexed : Result Never (List (Located LexItem)) + , name : String + , source : String + } +shouldNotParseTestCases = + [ { name = "type-alias-invalid-multiple-brackets" + , source = """type alias Hi = (Int) () """ , lexed = Ok @@ -366,9 +488,12 @@ List Int , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) - , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token "Int") - , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) ] , contextualized = Just @@ -377,17 +502,17 @@ List Int (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { bracketStack = Stack - [ Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) + [ Nothing ] - , root = Nothing + , root = Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) } ) - , Error_PartwayThroughTypeAlias + , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) TypeExpression_Unit ) ] } - , { name = "type-alias-record-empty" - , source = """type alias Ty = {} + , { name = "type-alias-invalid-multiple-brackets-2" + , source = """type alias Hi = () () """ , lexed = Ok @@ -395,24 +520,35 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), ty = TypeOrConstructor "Ty" }) + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { bracketStack = + Stack + [ Nothing + ] + , root = Just TypeExpression_Unit + } + ) + , Error_TypeDoesNotTakeArgs TypeExpression_Unit TypeExpression_Unit + ) ] } - , { name = "type-alias-record-empty-multiline" - , source = """type alias Ty = { - - - } + , { name = "type-alias-invalid-multiple-brackets-3" + , source = """type alias Hi = () (Int) """ , lexed = Ok @@ -420,28 +556,37 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 5, row = 4 }, start = { col = 18, row = 1 } } - (Newlines - [ 0 - , 0 - ] - 4 - ) - , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Token "Int") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), ty = TypeOrConstructor "Ty" }) + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { bracketStack = + Stack + [ Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) + ] + , root = Just TypeExpression_Unit + } + ) + , Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) + ) ] } - , { name = "type-alias-record-half-empty" - , source = """type alias Ty = { + , { name = "type-alias-multiline-missing-indentation" + , source = """type alias Model = +List Int """ , lexed = Ok @@ -449,60 +594,38 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "List") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_PartwayThroughTypeAlias ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")), Error_PartwayThroughTypeAlias ) + , Err ( State_BlockStart, Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") ) ] - } - , { name = "type-alias-record-in-bracket" - , source = """type alias Ty = ({ hi: 6 }) -""" - , lexed = - Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token "hi") - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Sigil Colon) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Whitespace 1) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token "6") - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) + } + , { name = "type-alias-partial" + , source = """type alias +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) - ] - ) - , ty = TypeOrConstructor "Ty" - } - ) + [ Err ( State_BlockTypeAlias BlockTypeAlias_Keywords, Error_PartwayThroughTypeAlias ) ] } - , { name = "type-alias-record-missing-colon" - , source = """type alias Ty = { hi j7 } + , { name = "type-alias-partial-2" + , source = """type alias Hi """ , lexed = Ok @@ -510,29 +633,16 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token "j7") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }) }), Error_ExpectedColonWhilstParsingRecord ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")), Error_PartwayThroughTypeAlias ) ] } - , { name = "type-alias-record-nested" - , source = """type alias Ty = - { hi: { a: 7, b: List String } - , ih: CustomType A B C (D E) - } + , { name = "type-alias-partial-3" + , source = """type alias Hi = """ , lexed = Ok @@ -540,104 +650,18 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) - , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Token "hi") - , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Sigil Colon) - , Located { end = { col = 12, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 2) - , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Whitespace 1) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token "a") - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Colon) - , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token "7") - , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil Comma) - , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Token "b") - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Colon) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) - , Located { end = { col = 27, row = 2 }, start = { col = 23, row = 2 } } (Token "List") - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) - , Located { end = { col = 34, row = 2 }, start = { col = 28, row = 2 } } (Token "String") - , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) - , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 5, row = 3 }, start = { col = 36, row = 2 } } (Newlines [] 4) - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) - , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) - , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token "ih") - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Colon) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Token "CustomType") - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token "A") - , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token "B") - , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "C") - , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Whitespace 1) - , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token "D") - , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Whitespace 1) - , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Token "E") - , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Newlines [] 4) - , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "hi" - , Record - (Dict.fromList - [ ( "a", UserDefinedType { args = [], name = "7", qualifiedness = PossiblyQualified Nothing } ) - , ( "b" - , UserDefinedType - { args = - [ UserDefinedType { args = [], name = "String", qualifiedness = PossiblyQualified Nothing } - ] - , name = "List" - , qualifiedness = PossiblyQualified Nothing - } - ) - ] - ) - ) - , ( "ih" - , UserDefinedType - { args = - [ UserDefinedType - { args = - [ UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } - ] - , name = "D" - , qualifiedness = PossiblyQualified Nothing - } - , UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing } - ] - , name = "CustomType" - , qualifiedness = PossiblyQualified Nothing - } - ) - ] - ) - , ty = TypeOrConstructor "Ty" - } - ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")), Error_PartwayThroughTypeAlias ) ] } - , { name = "type-alias-record-simple" - , source = """type alias Ty = { hi: 6 } + , { name = "type-alias-partial-with-bracket" + , source = """type alias Hi = ( """ , lexed = Ok @@ -645,37 +669,32 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "6") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { bracketStack = + Stack + [ Nothing ] - ) - , ty = TypeOrConstructor "Ty" - } + , root = Nothing + } + ) + , Error_PartwayThroughTypeAlias ) ] } - , { name = "type-alias-record-two-entries" - , source = """type alias Ty = { hi: 6, buy: 8 } + , { name = "type-alias-partial-with-bracket-2" + , source = """type alias Hi = ( + Int """ , lexed = Ok @@ -683,44 +702,33 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "6") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 26, row = 1 } } (Token "buy") - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil Colon) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Whitespace 1) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token "8") - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) + , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) ] , contextualized = Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "buy", UserDefinedType { args = [], name = "8", qualifiedness = PossiblyQualified Nothing } ) - , ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { bracketStack = + Stack + [ Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ] - ) - , ty = TypeOrConstructor "Ty" - } + , root = Nothing + } + ) + , Error_PartwayThroughTypeAlias ) ] } - , { name = "type-alias-unit" - , source = """type alias Hi = () + , { name = "type-alias-record-half-empty" + , source = """type alias Ty = { """ , lexed = Ok @@ -728,21 +736,20 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok (TypeAlias { expr = Unit, ty = TypeOrConstructor "Hi" }) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_PartwayThroughTypeAlias ) ] } - , { name = "type-alias-with-bracket" - , source = """type alias Hi = (Int) + , { name = "type-alias-record-missing-colon" + , source = """type alias Ty = { hi j7 } """ , lexed = Ok @@ -750,18 +757,22 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token "j7") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi" }) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }) }), Error_ExpectedColonWhilstParsingRecord ) ] } , { name = "type-partial" From 316ec0e5267ff874cef1b2354282864667e24bfe Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 16:49:45 +0100 Subject: [PATCH 032/103] unnest case-of expresions in parser --- src/Stage/Parse/Contextualize.elm | 66 +++++++++++++++---------------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 08e8e592..21486749 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -494,41 +494,39 @@ parserTypeExpr newState prevExpr item = exprAppend prevExpr (addArgumentToType (TokenOrType_Token str)) |> partialTypeExpressionToParseResult newState - Lexer.Sigil (Lexer.Bracket Lexer.Round role) -> - case role of - Lexer.Open -> - { bracketStack = - Nothing - |> pushOnto prevExpr.bracketStack - , root = prevExpr.root - } - |> TypeExpressionResult_Progress - |> newState + Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> + { bracketStack = + Nothing + |> pushOnto prevExpr.bracketStack + , root = prevExpr.root + } + |> TypeExpressionResult_Progress + |> newState - Lexer.Close -> - case pop prevExpr.bracketStack of - Just ( mexpr, poppedBracketStack ) -> - let - expr = - case mexpr of - Just expr_ -> - TypeExpression_Bracketed expr_ - - Nothing -> - TypeExpression_Unit - in - exprAppend - { bracketStack = poppedBracketStack - , root = prevExpr.root - } - (addArgumentToType (TokenOrType_Type expr)) - |> partialTypeExpressionToParseResult newState - - _ -> - -- TODO(harry): can we add information about the - -- bracket we are expecting here? - Error_UnmatchedBracket Lexer.Round Lexer.Close - |> ParseResult_Err + Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> + case pop prevExpr.bracketStack of + Just ( mexpr, poppedBracketStack ) -> + let + expr = + case mexpr of + Just expr_ -> + TypeExpression_Bracketed expr_ + + Nothing -> + TypeExpression_Unit + in + exprAppend + { bracketStack = poppedBracketStack + , root = prevExpr.root + } + (addArgumentToType (TokenOrType_Type expr)) + |> partialTypeExpressionToParseResult newState + + _ -> + -- TODO(harry): can we add information about the + -- bracket we are expecting here? + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> ParseResult_Err Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> let From c528a0e8747d3e61f4eb1b7a9f2b0b27531e95b4 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 16:57:12 +0100 Subject: [PATCH 033/103] prepare to use nestingStack for records --- src/Stage/Parse/Contextualize.elm | 38 +++++++++++++++++-------------- tests/ParserLexerTestCases.elm | 24 +++++++++---------- 2 files changed, 33 insertions(+), 29 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 21486749..5cd30e14 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -141,9 +141,13 @@ type LastEntryOfRecord | LastEntryOfRecord_KeyValue String PartialTypeExpression +type NestingType + = NestingType_Bracket (Maybe PartialTypeExpression) + + type alias PartialTypeExpression2 = { root : Maybe PartialTypeExpression - , bracketStack : Stack (Maybe PartialTypeExpression) + , nestingStack : Stack NestingType } @@ -309,7 +313,7 @@ parseAnything state = Debug.todo "" ) { root = Nothing - , bracketStack = empty + , nestingStack = empty } State_BlockTypeAlias (BlockTypeAlias_Completish name exprSoFar) -> @@ -495,17 +499,17 @@ parserTypeExpr newState prevExpr item = |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> - { bracketStack = - Nothing - |> pushOnto prevExpr.bracketStack + { nestingStack = + NestingType_Bracket Nothing + |> pushOnto prevExpr.nestingStack , root = prevExpr.root } |> TypeExpressionResult_Progress |> newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> - case pop prevExpr.bracketStack of - Just ( mexpr, poppedBracketStack ) -> + case pop prevExpr.nestingStack of + Just ( NestingType_Bracket mexpr, poppedNestingStack ) -> let expr = case mexpr of @@ -516,7 +520,7 @@ parserTypeExpr newState prevExpr item = TypeExpression_Unit in exprAppend - { bracketStack = poppedBracketStack + { nestingStack = poppedNestingStack , root = prevExpr.root } (addArgumentToType (TokenOrType_Type expr)) @@ -549,7 +553,7 @@ parserTypeExpr newState prevExpr item = addThingToPartialRecord ThingToAddToPartialRecord_Close prevExpr item newState Lexer.Newlines _ 0 -> - case ( pop prevExpr.bracketStack, prevExpr.root ) of + case ( pop prevExpr.nestingStack, prevExpr.root ) of ( Just _, _ ) -> Error_PartwayThroughTypeAlias |> ParseResult_Err @@ -577,8 +581,8 @@ exprAppend : PartialTypeExpression2 -> (Maybe PartialTypeExpression -> Result Error PartialTypeExpression) -> Result Error PartialTypeExpression2 -exprAppend { bracketStack, root } append = - case pop bracketStack of +exprAppend { nestingStack, root } append = + case pop nestingStack of -- We are in the top level of the type expression; we have -- found a closing bracket to match every opening bracket we -- have encountered so far whilst parsing the type expression. @@ -587,18 +591,18 @@ exprAppend { bracketStack, root } append = append root |> Result.map (\newRoot -> - { bracketStack = empty + { nestingStack = empty , root = Just newRoot } ) -- We are within a nested bracket. - Just ( mlatestTypeExpr, rest ) -> + Just ( NestingType_Bracket mlatestTypeExpr, rest ) -> append mlatestTypeExpr |> Result.map (\newLatestTypeExpr -> - { bracketStack = - Just newLatestTypeExpr + { nestingStack = + NestingType_Bracket (Just newLatestTypeExpr) |> pushOnto rest , root = root } @@ -632,8 +636,8 @@ blockFromState state = |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Completish name { bracketStack, root }) -> - case ( pop bracketStack, root ) of + State_BlockTypeAlias (BlockTypeAlias_Completish name { nestingStack, root }) -> + case ( pop nestingStack, root ) of ( Nothing, Just expr ) -> partialTypeExpressionToConcreteType expr |> Result.map diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 8606053c..192a9823 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -500,9 +500,9 @@ shouldNotParseTestCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = + { nestingStack = Stack - [ Nothing + [ NestingType_Bracket Nothing ] , root = Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) } @@ -536,9 +536,9 @@ shouldNotParseTestCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = + { nestingStack = Stack - [ Nothing + [ NestingType_Bracket Nothing ] , root = Just TypeExpression_Unit } @@ -573,9 +573,9 @@ shouldNotParseTestCases = [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = + { nestingStack = Stack - [ Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) + [ NestingType_Bracket (Just (TypeExpression_NamedType { args = Stack [], name = "Int" })) ] , root = Just TypeExpression_Unit } @@ -681,9 +681,9 @@ List Int [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = + { nestingStack = Stack - [ Nothing + [ NestingType_Bracket Nothing ] , root = Nothing } @@ -716,9 +716,9 @@ List Int [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { bracketStack = + { nestingStack = Stack - [ Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) + [ NestingType_Bracket (Just (TypeExpression_NamedType { args = Stack [], name = "Int" })) ] , root = Nothing } @@ -745,7 +745,7 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_PartwayThroughTypeAlias ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nestingStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_PartwayThroughTypeAlias ) ] } , { name = "type-alias-record-missing-colon" @@ -772,7 +772,7 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { bracketStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }) }), Error_ExpectedColonWhilstParsingRecord ) + [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nestingStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }) }), Error_ExpectedColonWhilstParsingRecord ) ] } , { name = "type-partial" From 25c923ce11f4a29b11ff5c3bcaf4f23cd4610307 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 18:05:24 +0100 Subject: [PATCH 034/103] use nesting stack for records this is much better! No more recursive decent into type expressions! --- src/Stage/Parse/Contextualize.elm | 223 +++++++++++++++--------------- tests/ParserLexerTestCases.elm | 26 +++- 2 files changed, 135 insertions(+), 114 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 5cd30e14..bb059521 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -127,10 +127,6 @@ type PartialTypeExpression } | TypeExpression_Unit | TypeExpression_Bracketed PartialTypeExpression - | TypeExpression_PartialRecord - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } | TypeExpression_Record (Stack ( String, PartialTypeExpression )) @@ -141,8 +137,15 @@ type LastEntryOfRecord | LastEntryOfRecord_KeyValue String PartialTypeExpression +type alias PartialRecord = + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntry : LastEntryOfRecord + } + + type NestingType = NestingType_Bracket (Maybe PartialTypeExpression) + | NestingType_PartialRecord PartialRecord type alias PartialTypeExpression2 = @@ -495,7 +498,7 @@ parserTypeExpr : parserTypeExpr newState prevExpr item = case item of Lexer.Token str -> - exprAppend prevExpr (addArgumentToType (TokenOrType_Token str)) + exprAppend prevExpr (TokenOrType_Token str) |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> @@ -523,7 +526,7 @@ parserTypeExpr newState prevExpr item = { nestingStack = poppedNestingStack , root = prevExpr.root } - (addArgumentToType (TokenOrType_Type expr)) + (TokenOrType_Type expr) |> partialTypeExpressionToParseResult newState _ -> @@ -533,15 +536,16 @@ parserTypeExpr newState prevExpr item = |> ParseResult_Err Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> - let - newType = - TypeExpression_PartialRecord - { firstEntries = empty - , lastEntry = LastEntryOfRecord_Empty - } - in - exprAppend prevExpr (addArgumentToType (TokenOrType_Type newType)) - |> partialTypeExpressionToParseResult newState + { nestingStack = + NestingType_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty + } + |> pushOnto prevExpr.nestingStack + , root = prevExpr.root + } + |> TypeExpressionResult_Progress + |> newState Lexer.Sigil Lexer.Colon -> addThingToPartialRecord ThingToAddToPartialRecord_Colon prevExpr item newState @@ -550,7 +554,47 @@ parserTypeExpr newState prevExpr item = addThingToPartialRecord ThingToAddToPartialRecord_Comma prevExpr item newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> - addThingToPartialRecord ThingToAddToPartialRecord_Close prevExpr item newState + case pop prevExpr.nestingStack of + Just ( NestingType_PartialRecord { firstEntries, lastEntry }, poppedNestingStack ) -> + let + fromRecord record = + let + tot = + record + |> TypeExpression_Record + |> TokenOrType_Type + in + exprAppend + { nestingStack = poppedNestingStack + , root = prevExpr.root + } + tot + |> partialTypeExpressionToParseResult newState + in + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + ( key, value ) + |> pushOnto firstEntries + |> fromRecord + + LastEntryOfRecord_Empty -> + if firstEntries == empty then + empty + |> fromRecord + + else + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + -- TODO(harry): can we add information about the + -- bracket we are expecting here? + Error_UnmatchedBracket Lexer.Curly Lexer.Close + |> ParseResult_Err Lexer.Newlines _ 0 -> case ( pop prevExpr.nestingStack, prevExpr.root ) of @@ -579,16 +623,16 @@ parserTypeExpr newState prevExpr item = exprAppend : PartialTypeExpression2 - -> (Maybe PartialTypeExpression -> Result Error PartialTypeExpression) + -> TokenOrType -> Result Error PartialTypeExpression2 -exprAppend { nestingStack, root } append = +exprAppend { nestingStack, root } tot = case pop nestingStack of -- We are in the top level of the type expression; we have -- found a closing bracket to match every opening bracket we -- have encountered so far whilst parsing the type expression. -- (We may have found no brackets at all so far.) Nothing -> - append root + addArgumentToType tot root |> Result.map (\newRoot -> { nestingStack = empty @@ -597,8 +641,8 @@ exprAppend { nestingStack, root } append = ) -- We are within a nested bracket. - Just ( NestingType_Bracket mlatestTypeExpr, rest ) -> - append mlatestTypeExpr + Just ( NestingType_Bracket mostNested, rest ) -> + addArgumentToType tot mostNested |> Result.map (\newLatestTypeExpr -> { nestingStack = @@ -608,6 +652,17 @@ exprAppend { nestingStack, root } append = } ) + Just ( NestingType_PartialRecord existingPartialRecord, rest ) -> + addToPartialRecord tot existingPartialRecord + |> Result.map + (\newPartialRecord -> + { nestingStack = + NestingType_PartialRecord newPartialRecord + |> pushOnto rest + , root = root + } + ) + blockFromState : State -> Maybe (Result Error Block) blockFromState state = @@ -670,15 +725,8 @@ type TokenOrType addToPartialRecord : TokenOrType - -> - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } - -> - Result Error - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } + -> PartialRecord + -> Result Error PartialRecord addToPartialRecord tot { firstEntries, lastEntry } = let newType = @@ -744,18 +792,6 @@ addToPartialRecord tot { firstEntries, lastEntry } = Error_TypeDoesNotTakeArgs ty newType |> Err - LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord innerPartialRecord) -> - addToPartialRecord tot innerPartialRecord - |> Result.map - (\newInnerPartialRecord -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue - key - (TypeExpression_PartialRecord newInnerPartialRecord) - } - ) - addArgumentToType : TokenOrType -> Maybe PartialTypeExpression -> Result Error PartialTypeExpression addArgumentToType argToAdd mexistingTypeExpr = @@ -785,10 +821,6 @@ addArgumentToType argToAdd mexistingTypeExpr = } |> Ok - Just (TypeExpression_PartialRecord existingPartialRecord) -> - addToPartialRecord argToAdd existingPartialRecord - |> Result.map TypeExpression_PartialRecord - Just ((TypeExpression_Bracketed _) as ty) -> Error_TypeDoesNotTakeArgs ty newType |> Err @@ -805,7 +837,6 @@ addArgumentToType argToAdd mexistingTypeExpr = type ThingToAddToPartialRecord = ThingToAddToPartialRecord_Colon | ThingToAddToPartialRecord_Comma - | ThingToAddToPartialRecord_Close addThingToPartialRecord : @@ -815,72 +846,43 @@ addThingToPartialRecord : -> (TypeExpressionResult -> ParseResult) -> ParseResult addThingToPartialRecord thing prevExpr item newState = - exprAppend - prevExpr - (\typeExpr -> - case typeExpr of - Just (TypeExpression_PartialRecord pr) -> - addThingToPartialRecordHelp thing pr - |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - - _ -> - Error_InvalidToken item Expecting_Unknown - |> Err - ) - |> partialTypeExpressionToParseResult newState - - -addThingToPartialRecordHelp : - ThingToAddToPartialRecord - -> - { firstEntries : Stack ( String, PartialTypeExpression ) - , lastEntry : LastEntryOfRecord - } - -> Result () PartialTypeExpression -addThingToPartialRecordHelp thing { firstEntries, lastEntry } = - case ( thing, lastEntry ) of - ( ThingToAddToPartialRecord_Colon, LastEntryOfRecord_Key key ) -> - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyColon key - } - |> TypeExpression_PartialRecord - |> Ok - - -- Must come before other `LastEntryOfRecord_KeyValue` cases! - ( _, LastEntryOfRecord_KeyValue key (TypeExpression_PartialRecord pr) ) -> - addThingToPartialRecordHelp thing pr - |> Result.map - (\newPr -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue key newPr - } - |> TypeExpression_PartialRecord - ) - - ( ThingToAddToPartialRecord_Comma, LastEntryOfRecord_KeyValue key value ) -> - { firstEntries = ( key, value ) |> pushOnto firstEntries - , lastEntry = LastEntryOfRecord_Empty - } - |> TypeExpression_PartialRecord - |> Ok + let + getNewPartialRecord { firstEntries, lastEntry } = + case ( thing, lastEntry ) of + ( ThingToAddToPartialRecord_Colon, LastEntryOfRecord_Key key ) -> + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyColon key + } + |> Ok - ( ThingToAddToPartialRecord_Close, LastEntryOfRecord_Empty ) -> - if firstEntries == empty then - TypeExpression_Record empty - |> Ok + ( ThingToAddToPartialRecord_Comma, LastEntryOfRecord_KeyValue key value ) -> + { firstEntries = ( key, value ) |> pushOnto firstEntries + , lastEntry = LastEntryOfRecord_Empty + } + |> Ok - else - Err () + _ -> + Err () - ( ThingToAddToPartialRecord_Close, LastEntryOfRecord_KeyValue key value ) -> - ( key, value ) - |> pushOnto firstEntries - |> TypeExpression_Record - |> Ok + newNestedTypeExpression = + case pop prevExpr.nestingStack of + Just ( NestingType_PartialRecord existingPartialRecord, rest ) -> + getNewPartialRecord existingPartialRecord + |> Result.map + (\newPartialRecord -> + { nestingStack = + NestingType_PartialRecord newPartialRecord + |> pushOnto rest + , root = prevExpr.root + } + ) - _ -> - Err () + _ -> + Err () + in + newNestedTypeExpression + |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) + |> partialTypeExpressionToParseResult newState partialTypeExpressionToParseResult : (TypeExpressionResult -> ParseResult) -> Result Error PartialTypeExpression2 -> ParseResult @@ -919,9 +921,6 @@ partialTypeExpressionToConcreteType pte = TypeExpression_Bracketed ty -> partialTypeExpressionToConcreteType ty - TypeExpression_PartialRecord ty -> - Err () - TypeExpression_Record keyValues -> keyValues |> toList diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 192a9823..277b1f73 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -745,7 +745,18 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nestingStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }) }), Error_PartwayThroughTypeAlias ) + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Ty") + { nestingStack = + Stack + [ NestingType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty } + ] + , root = Nothing + } + ) + , Error_PartwayThroughTypeAlias + ) ] } , { name = "type-alias-record-missing-colon" @@ -772,7 +783,18 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nestingStack = Stack [], root = Just (TypeExpression_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }) }), Error_ExpectedColonWhilstParsingRecord ) + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Ty") + { nestingStack = + Stack + [ NestingType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" } + ] + , root = Nothing + } + ) + , Error_ExpectedColonWhilstParsingRecord + ) ] } , { name = "type-partial" From b205c534a2659a06d70489f0ef495170839e15d9 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 23:49:19 +0100 Subject: [PATCH 035/103] parse tuples --- .../type-alias-with-quadruple | 2 + .../type-alias-with-tuple-double-comma | 1 + .../type-alias-with-tuple-not-closed | 4 + .../should-parse/type-alias-with-pair | 2 + .../should-parse/type-alias-with-tripple | 2 + src/Stage/Parse/Contextualize.elm | 164 +++++-- tests/ParserLexerTestCases.elm | 428 +++++++++++++++++- 7 files changed, 566 insertions(+), 37 deletions(-) create mode 100644 parser-tests/snippets/should-not-parse/type-alias-with-quadruple create mode 100644 parser-tests/snippets/should-not-parse/type-alias-with-tuple-double-comma create mode 100644 parser-tests/snippets/should-not-parse/type-alias-with-tuple-not-closed create mode 100644 parser-tests/snippets/should-parse/type-alias-with-pair create mode 100644 parser-tests/snippets/should-parse/type-alias-with-tripple diff --git a/parser-tests/snippets/should-not-parse/type-alias-with-quadruple b/parser-tests/snippets/should-not-parse/type-alias-with-quadruple new file mode 100644 index 00000000..1d848f3b --- /dev/null +++ b/parser-tests/snippets/should-not-parse/type-alias-with-quadruple @@ -0,0 +1,2 @@ +type alias Hi = (Int, A, B, C, D) +type alias Hi = (A Int, C D E F, H I (J K), L M () O P) diff --git a/parser-tests/snippets/should-not-parse/type-alias-with-tuple-double-comma b/parser-tests/snippets/should-not-parse/type-alias-with-tuple-double-comma new file mode 100644 index 00000000..03cae1e5 --- /dev/null +++ b/parser-tests/snippets/should-not-parse/type-alias-with-tuple-double-comma @@ -0,0 +1 @@ +type alias Hi = (Int, , A) diff --git a/parser-tests/snippets/should-not-parse/type-alias-with-tuple-not-closed b/parser-tests/snippets/should-not-parse/type-alias-with-tuple-not-closed new file mode 100644 index 00000000..053bc457 --- /dev/null +++ b/parser-tests/snippets/should-not-parse/type-alias-with-tuple-not-closed @@ -0,0 +1,4 @@ +type alias Hi = (Int, + + +type alias Hi2 = (Int) diff --git a/parser-tests/snippets/should-parse/type-alias-with-pair b/parser-tests/snippets/should-parse/type-alias-with-pair new file mode 100644 index 00000000..4d9f7b29 --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-with-pair @@ -0,0 +1,2 @@ +type alias Hi = (Int, List String) +type alias Hi = (Int) diff --git a/parser-tests/snippets/should-parse/type-alias-with-tripple b/parser-tests/snippets/should-parse/type-alias-with-tripple new file mode 100644 index 00000000..54357e69 --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-with-tripple @@ -0,0 +1,2 @@ +type alias Hi = (Int, Two, Three) +type alias Hi = ((), (), ()) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index bb059521..8d8033c3 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -127,6 +127,7 @@ type PartialTypeExpression } | TypeExpression_Unit | TypeExpression_Bracketed PartialTypeExpression + | TypeExpression_Tuple PartialTypeExpression PartialTypeExpression (List PartialTypeExpression) | TypeExpression_Record (Stack ( String, PartialTypeExpression )) @@ -144,7 +145,7 @@ type alias PartialRecord = type NestingType - = NestingType_Bracket (Maybe PartialTypeExpression) + = NestingType_Bracket ( Stack PartialTypeExpression, Maybe PartialTypeExpression ) | NestingType_PartialRecord PartialRecord @@ -169,6 +170,13 @@ type Error | Error_ExpectedColonWhilstParsingRecord | Error_ExpectedKeyWhilstParsingRecord | Error_TypeDoesNotTakeArgs PartialTypeExpression PartialTypeExpression + | Error_TooManyTupleArgs + -- + (ConcreteType PossiblyQualified) + (ConcreteType PossiblyQualified) + (ConcreteType PossiblyQualified) + (ConcreteType PossiblyQualified) + (List (ConcreteType PossiblyQualified)) | Error_PartwayThroughTypeAlias | Error_Panic String @@ -308,8 +316,8 @@ parseAnything state = |> TypeAlias |> ParseResult_Complete - Err () -> - Error_PartwayThroughTypeAlias + Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> + Error_TooManyTupleArgs a b c d e |> ParseResult_Err TypeExpressionResult_Empty -> @@ -336,8 +344,8 @@ parseAnything state = |> TypeAlias |> ParseResult_Complete - Err () -> - Error_PartwayThroughTypeAlias + Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> + Error_TooManyTupleArgs a b c d e |> ParseResult_Err TypeExpressionResult_Empty -> @@ -503,7 +511,7 @@ parserTypeExpr newState prevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> { nestingStack = - NestingType_Bracket Nothing + NestingType_Bracket ( empty, Nothing ) |> pushOnto prevExpr.nestingStack , root = prevExpr.root } @@ -512,22 +520,50 @@ parserTypeExpr newState prevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> case pop prevExpr.nestingStack of - Just ( NestingType_Bracket mexpr, poppedNestingStack ) -> + Just ( NestingType_Bracket ( argStack, mexpr ), poppedNestingStack ) -> let - expr = - case mexpr of - Just expr_ -> - TypeExpression_Bracketed expr_ + rexpr = + if argStack /= empty && mexpr == Nothing then + -- We have a trailing comma! + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> Err - Nothing -> - TypeExpression_Unit + else + let + fullArgsList = + (case mexpr of + Just expr -> + expr |> pushOnto argStack + + Nothing -> + argStack + ) + |> toList (\x -> x) + in + case fullArgsList of + [] -> + TypeExpression_Unit + |> Ok + + first :: [] -> + TypeExpression_Bracketed first + |> Ok + + first :: second :: rest -> + TypeExpression_Tuple first second rest + |> Ok in - exprAppend - { nestingStack = poppedNestingStack - , root = prevExpr.root - } - (TokenOrType_Type expr) - |> partialTypeExpressionToParseResult newState + case rexpr of + Ok expr -> + exprAppend + { nestingStack = poppedNestingStack + , root = prevExpr.root + } + (TokenOrType_Type expr) + |> partialTypeExpressionToParseResult newState + + Err e -> + ParseResult_Err e _ -> -- TODO(harry): can we add information about the @@ -641,12 +677,12 @@ exprAppend { nestingStack, root } tot = ) -- We are within a nested bracket. - Just ( NestingType_Bracket mostNested, rest ) -> + Just ( NestingType_Bracket ( argStack, mostNested ), rest ) -> addArgumentToType tot mostNested |> Result.map (\newLatestTypeExpr -> { nestingStack = - NestingType_Bracket (Just newLatestTypeExpr) + NestingType_Bracket ( argStack, Just newLatestTypeExpr ) |> pushOnto rest , root = root } @@ -702,7 +738,7 @@ blockFromState state = } |> TypeAlias ) - |> Result.mapError (\() -> Error_PartwayThroughTypeAlias) + |> Result.mapError (\(ToConcreteTypeError_TooManyTupleArgs a b c d e) -> Error_TooManyTupleArgs a b c d e) |> Just _ -> @@ -788,6 +824,10 @@ addToPartialRecord tot { firstEntries, lastEntry } = Error_TypeDoesNotTakeArgs ty newType |> Err + LastEntryOfRecord_KeyValue _ ((TypeExpression_Tuple _ _ _) as ty) -> + Error_TypeDoesNotTakeArgs ty newType + |> Err + LastEntryOfRecord_KeyValue _ ((TypeExpression_Record _) as ty) -> Error_TypeDoesNotTakeArgs ty newType |> Err @@ -825,6 +865,10 @@ addArgumentToType argToAdd mexistingTypeExpr = Error_TypeDoesNotTakeArgs ty newType |> Err + Just ((TypeExpression_Tuple _ _ _) as ty) -> + Error_TypeDoesNotTakeArgs ty newType + |> Err + Just ((TypeExpression_Record _) as ty) -> Error_TypeDoesNotTakeArgs ty newType |> Err @@ -839,6 +883,12 @@ type ThingToAddToPartialRecord | ThingToAddToPartialRecord_Comma +{-| TODO(harry): We can add things to a tuple too! Rename this function +appropriately. + +TODO(harry): We can inline this function. + +-} addThingToPartialRecord : ThingToAddToPartialRecord -> PartialTypeExpression2 @@ -877,6 +927,19 @@ addThingToPartialRecord thing prevExpr item newState = } ) + Just ( NestingType_Bracket ( argStack, Just expr ), rest ) -> + case thing of + ThingToAddToPartialRecord_Colon -> + Err () + + ThingToAddToPartialRecord_Comma -> + { nestingStack = + NestingType_Bracket ( expr |> pushOnto argStack, Nothing ) + |> pushOnto rest + , root = prevExpr.root + } + |> Ok + _ -> Err () in @@ -896,15 +959,25 @@ partialTypeExpressionToParseResult newState rnewPartialType = ParseResult_Err e +type ToConcreteTypeError + = ToConcreteTypeError_TooManyTupleArgs + -- + (ConcreteType PossiblyQualified) + (ConcreteType PossiblyQualified) + (ConcreteType PossiblyQualified) + (ConcreteType PossiblyQualified) + (List (ConcreteType PossiblyQualified)) + + {-| TODO(harry): custom error message here -} -partialTypeExpressionToConcreteType : PartialTypeExpression -> Result () (ConcreteType PossiblyQualified) +partialTypeExpressionToConcreteType : PartialTypeExpression -> Result ToConcreteTypeError (ConcreteType PossiblyQualified) partialTypeExpressionToConcreteType pte = case pte of TypeExpression_NamedType { name, args } -> args |> toList partialTypeExpressionToConcreteType - |> collectList + |> collectList (\x -> x) |> Result.map (\goodArgs -> { qualifiedness = Qualifiedness.PossiblyQualified Nothing @@ -921,6 +994,31 @@ partialTypeExpressionToConcreteType pte = TypeExpression_Bracketed ty -> partialTypeExpressionToConcreteType ty + TypeExpression_Tuple first second [] -> + Result.map2 + ConcreteType.Tuple + (partialTypeExpressionToConcreteType first) + (partialTypeExpressionToConcreteType second) + + TypeExpression_Tuple first second (third :: []) -> + Result.map3 + ConcreteType.Tuple3 + (partialTypeExpressionToConcreteType first) + (partialTypeExpressionToConcreteType second) + (partialTypeExpressionToConcreteType third) + + TypeExpression_Tuple first second (third :: fouth :: rest) -> + Result.map5 + ToConcreteTypeError_TooManyTupleArgs + (partialTypeExpressionToConcreteType first) + (partialTypeExpressionToConcreteType second) + (partialTypeExpressionToConcreteType third) + (partialTypeExpressionToConcreteType fouth) + (rest + |> collectList partialTypeExpressionToConcreteType + ) + |> Result.andThen Err + TypeExpression_Record keyValues -> keyValues |> toList @@ -928,7 +1026,7 @@ partialTypeExpressionToConcreteType pte = partialTypeExpressionToConcreteType value |> Result.map (\concreteValue -> ( key, concreteValue )) ) - |> collectList + |> collectList (\x -> x) |> Result.map (\goodKeyValues -> Dict.fromList goodKeyValues @@ -946,19 +1044,21 @@ recoverErrors res = res -collectList : List (Result e o) -> Result e (List o) +collectList : (a -> Result e o) -> List a -> Result e (List o) collectList = collectListHelp [] -collectListHelp : List o -> List (Result e o) -> Result e (List o) -collectListHelp new old = +collectListHelp : List o -> (a -> Result e o) -> List a -> Result e (List o) +collectListHelp new func old = case old of - (Ok curr) :: rest -> - collectListHelp (curr :: new) rest + curr :: rest -> + case func curr of + Ok o -> + collectListHelp (o :: new) func rest - (Err e) :: rest -> - Err e + Err e -> + Err e [] -> Ok new diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 277b1f73..44f004be 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -463,6 +463,114 @@ shouldParseTestCases = [ Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi" }) ] } + , { name = "type-alias-with-pair" + , source = """type alias Hi = (Int, List String) +type alias Hi = (Int) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token "List") + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Token "String") + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token "Int") + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Tuple (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) + (UserDefinedType + { args = + [ UserDefinedType { args = [], name = "String", qualifiedness = PossiblyQualified Nothing } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ty = TypeOrConstructor "Hi" + } + ) + , Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi" }) + ] + } + , { name = "type-alias-with-tripple" + , source = """type alias Hi = (Int, Two, Three) +type alias Hi = ((), (), ()) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Two") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Comma) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Token "Three") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Sigil Comma) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Whitespace 1) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil Comma) + , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Whitespace 1) + , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 29, row = 2 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok (TypeAlias { expr = Tuple3 (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "Two", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "Three", qualifiedness = PossiblyQualified Nothing }), ty = TypeOrConstructor "Hi" }) + , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, ty = TypeOrConstructor "Hi" }) + ] + } ] @@ -502,7 +610,7 @@ shouldNotParseTestCases = (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nestingStack = Stack - [ NestingType_Bracket Nothing + [ NestingType_Bracket ( Stack [], Nothing ) ] , root = Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) } @@ -538,7 +646,7 @@ shouldNotParseTestCases = (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nestingStack = Stack - [ NestingType_Bracket Nothing + [ NestingType_Bracket ( Stack [], Nothing ) ] , root = Just TypeExpression_Unit } @@ -575,7 +683,7 @@ shouldNotParseTestCases = (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nestingStack = Stack - [ NestingType_Bracket (Just (TypeExpression_NamedType { args = Stack [], name = "Int" })) + [ NestingType_Bracket ( Stack [], Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) ] , root = Just TypeExpression_Unit } @@ -683,7 +791,7 @@ List Int (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nestingStack = Stack - [ NestingType_Bracket Nothing + [ NestingType_Bracket ( Stack [], Nothing ) ] , root = Nothing } @@ -718,7 +826,7 @@ List Int (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nestingStack = Stack - [ NestingType_Bracket (Just (TypeExpression_NamedType { args = Stack [], name = "Int" })) + [ NestingType_Bracket ( Stack [], Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) ] , root = Nothing } @@ -797,6 +905,316 @@ List Int ) ] } + , { name = "type-alias-with-quadruple" + , source = """type alias Hi = (Int, A, B, C, D) +type alias Hi = (A Int, C D E F, H I (J K), L M () O P) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "A") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token "B") + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil Comma) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token "C") + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil Comma) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token "D") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Token "A") + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) + , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Token "Int") + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil Comma) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) + , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Token "C") + , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Whitespace 1) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token "D") + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Whitespace 1) + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Token "E") + , Located { end = { col = 31, row = 2 }, start = { col = 30, row = 2 } } (Whitespace 1) + , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Token "F") + , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Sigil Comma) + , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Whitespace 1) + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Token "H") + , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Whitespace 1) + , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Token "I") + , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) + , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Token "J") + , Located { end = { col = 41, row = 2 }, start = { col = 40, row = 2 } } (Whitespace 1) + , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Token "K") + , Located { end = { col = 43, row = 2 }, start = { col = 42, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 44, row = 2 }, start = { col = 43, row = 2 } } (Sigil Comma) + , Located { end = { col = 45, row = 2 }, start = { col = 44, row = 2 } } (Whitespace 1) + , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Token "L") + , Located { end = { col = 47, row = 2 }, start = { col = 46, row = 2 } } (Whitespace 1) + , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Token "M") + , Located { end = { col = 49, row = 2 }, start = { col = 48, row = 2 } } (Whitespace 1) + , Located { end = { col = 50, row = 2 }, start = { col = 49, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 51, row = 2 }, start = { col = 50, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 52, row = 2 }, start = { col = 51, row = 2 } } (Whitespace 1) + , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Token "O") + , Located { end = { col = 54, row = 2 }, start = { col = 53, row = 2 } } (Whitespace 1) + , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Token "P") + , Located { end = { col = 56, row = 2 }, start = { col = 55, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nestingStack = Stack [] + , root = + Just + (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) + (TypeExpression_NamedType { args = Stack [], name = "A" }) + [ TypeExpression_NamedType { args = Stack [], name = "B" } + , TypeExpression_NamedType { args = Stack [], name = "C" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + ) + } + ) + , Error_TooManyTupleArgs (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) + (UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing }) + (UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing }) + (UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing }) + [ UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } + ] + ) + , Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nestingStack = Stack [] + , root = + Just + (TypeExpression_Tuple + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , name = "A" + } + ) + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "F" } + , TypeExpression_NamedType { args = Stack [], name = "E" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + , name = "C" + } + ) + [ TypeExpression_NamedType + { args = + Stack + [ TypeExpression_Bracketed + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "K" } + ] + , name = "J" + } + ) + , TypeExpression_NamedType { args = Stack [], name = "I" } + ] + , name = "H" + } + , TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "P" } + , TypeExpression_NamedType { args = Stack [], name = "O" } + , TypeExpression_Unit + , TypeExpression_NamedType { args = Stack [], name = "M" } + ] + , name = "L" + } + ] + ) + } + ) + , Error_TooManyTupleArgs + (UserDefinedType + { args = + [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + ] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = + [ UserDefinedType { args = [], name = "F", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } + ] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = + [ UserDefinedType + { args = + [ UserDefinedType { args = [], name = "K", qualifiedness = PossiblyQualified Nothing } + ] + , name = "J" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType { args = [], name = "I", qualifiedness = PossiblyQualified Nothing } + ] + , name = "H" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = + [ UserDefinedType { args = [], name = "P", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "O", qualifiedness = PossiblyQualified Nothing } + , Unit + , UserDefinedType { args = [], name = "M", qualifiedness = PossiblyQualified Nothing } + ] + , name = "L" + , qualifiedness = PossiblyQualified Nothing + } + ) + [] + ) + ] + } + , { name = "type-alias-with-tuple-double-comma" + , source = """type alias Hi = (Int, , A) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "A") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nestingStack = + Stack + [ NestingType_Bracket + ( Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , Nothing + ) + ] + , root = Nothing + } + ) + , Error_InvalidToken (Sigil Comma) Expecting_Unknown + ) + ] + } + , { name = "type-alias-with-tuple-not-closed" + , source = """type alias Hi = (Int, + + +type alias Hi2 = (Int) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + , Located { end = { col = 1, row = 4 }, start = { col = 22, row = 1 } } + (Newlines + [ 0 + , 0 + ] + 0 + ) + , Located { end = { col = 5, row = 4 }, start = { col = 1, row = 4 } } (Token "type") + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Whitespace 1) + , Located { end = { col = 11, row = 4 }, start = { col = 6, row = 4 } } (Token "alias") + , Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } (Whitespace 1) + , Located { end = { col = 15, row = 4 }, start = { col = 12, row = 4 } } (Token "Hi2") + , Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } (Whitespace 1) + , Located { end = { col = 17, row = 4 }, start = { col = 16, row = 4 } } (Sigil Assign) + , Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Whitespace 1) + , Located { end = { col = 19, row = 4 }, start = { col = 18, row = 4 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 22, row = 4 }, start = { col = 19, row = 4 } } (Token "Int") + , Located { end = { col = 23, row = 4 }, start = { col = 22, row = 4 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 23, row = 4 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nestingStack = + Stack + [ NestingType_Bracket + ( Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , Nothing + ) + ] + , root = Nothing + } + ) + , Error_PartwayThroughTypeAlias + ) + , Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi2" }) + ] + } , { name = "type-partial" , source = """type """ From 725fd1c3d09dd9835202c889d86461c6fa96279a Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 26 Sep 2020 23:56:40 +0100 Subject: [PATCH 036/103] fix test cases --- .../type-alias-with-tuple-not-closed | 2 +- .../type-alias-with-tripple-in-record | 4 + tests/ParserLexerTestCases.elm | 91 ++++++++++++++++--- 3 files changed, 81 insertions(+), 16 deletions(-) create mode 100644 parser-tests/snippets/should-parse/type-alias-with-tripple-in-record diff --git a/parser-tests/snippets/should-not-parse/type-alias-with-tuple-not-closed b/parser-tests/snippets/should-not-parse/type-alias-with-tuple-not-closed index 053bc457..2b6ad7ea 100644 --- a/parser-tests/snippets/should-not-parse/type-alias-with-tuple-not-closed +++ b/parser-tests/snippets/should-not-parse/type-alias-with-tuple-not-closed @@ -1,4 +1,4 @@ type alias Hi = (Int, -type alias Hi2 = (Int) + diff --git a/parser-tests/snippets/should-parse/type-alias-with-tripple-in-record b/parser-tests/snippets/should-parse/type-alias-with-tripple-in-record new file mode 100644 index 00000000..410d38b1 --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-with-tripple-in-record @@ -0,0 +1,4 @@ +type alias Hi = + { a: (Int, Int, Int) + , b: ({ good_bye: () }) + } diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 44f004be..f79fd6f5 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -571,6 +571,79 @@ type alias Hi = ((), (), ()) , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, ty = TypeOrConstructor "Hi" }) ] } + , { name = "type-alias-with-tripple-in-record" + , source = """type alias Hi = + { a: (Int, Int, Int) + , b: ({ good_bye: () }) + } +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) + , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token "a") + , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Sigil Colon) + , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Token "Int") + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Sigil Comma) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Whitespace 1) + , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Token "Int") + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil Comma) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) + , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Token "Int") + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Newlines [] 4) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) + , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Token "b") + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil Colon) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Token "good_bye") + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Sigil Colon) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Whitespace 1) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 5, row = 4 }, start = { col = 28, row = 3 } } (Newlines [] 4) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "a", Tuple3 (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) ) + , ( "b" + , Record + (Dict.fromList + [ ( "good_bye", Unit ) + ] + ) + ) + ] + ) + , ty = TypeOrConstructor "Hi" + } + ) + ] + } ] @@ -1158,7 +1231,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , source = """type alias Hi = (Int, -type alias Hi2 = (Int) + """ , lexed = Ok @@ -1173,25 +1246,14 @@ type alias Hi2 = (Int) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) - , Located { end = { col = 1, row = 4 }, start = { col = 22, row = 1 } } + , Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } (Newlines [ 0 , 0 + , 0 ] 0 ) - , Located { end = { col = 5, row = 4 }, start = { col = 1, row = 4 } } (Token "type") - , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Whitespace 1) - , Located { end = { col = 11, row = 4 }, start = { col = 6, row = 4 } } (Token "alias") - , Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } (Whitespace 1) - , Located { end = { col = 15, row = 4 }, start = { col = 12, row = 4 } } (Token "Hi2") - , Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } (Whitespace 1) - , Located { end = { col = 17, row = 4 }, start = { col = 16, row = 4 } } (Sigil Assign) - , Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Whitespace 1) - , Located { end = { col = 19, row = 4 }, start = { col = 18, row = 4 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 22, row = 4 }, start = { col = 19, row = 4 } } (Token "Int") - , Located { end = { col = 23, row = 4 }, start = { col = 22, row = 4 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 5 }, start = { col = 23, row = 4 } } (Newlines [] 0) ] , contextualized = Just @@ -1212,7 +1274,6 @@ type alias Hi2 = (Int) ) , Error_PartwayThroughTypeAlias ) - , Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi2" }) ] } , { name = "type-partial" From f8ca5d372f964d2048d2206244a385ec85ad488b Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 28 Sep 2020 21:55:52 +0100 Subject: [PATCH 037/103] fix list ordering of collectList --- src/Stage/Parse/Contextualize.elm | 2 +- tests/ParserLexerTest.elm | 104 ++++++++++++++++-------------- 2 files changed, 58 insertions(+), 48 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 8d8033c3..5fd0b52e 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -1061,7 +1061,7 @@ collectListHelp new func old = Err e [] -> - Ok new + Ok (List.reverse new) parseResultFromMaybeResult : Maybe (Result Error State) -> ParseResult diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm index 4d2f09d8..de1a8619 100644 --- a/tests/ParserLexerTest.elm +++ b/tests/ParserLexerTest.elm @@ -2,58 +2,68 @@ module ParserLexerTest exposing (tests) import Elm.Data.Located as Located exposing (Located) import Expect +import Fuzz import Parser.Advanced as P import ParserLexerTestCases import Stage.Parse.Contextualize as Contextualize import Stage.Parse.Lexer as Lexer -import Test exposing (Test, describe, test) +import Test exposing (Test, describe, fuzz, test) tests = - describe "parser lexer test cases" - [ describe "lexing" - ((ParserLexerTestCases.shouldParseTestCases ++ ParserLexerTestCases.shouldNotParseTestCases) - |> List.map - (\{ name, source, lexed } -> - test name <| - \() -> - source - |> P.run Lexer.parser - |> Expect.equal (lexed |> Result.mapError never) - ) - ) - , describe "should parse" - (ParserLexerTestCases.shouldParseTestCases - |> List.filterMap - (\{ name, source, lexed, contextualized } -> - Maybe.map2 - (\contextualized_ lexed_ -> - test name <| - \() -> - lexed_ - |> List.map Located.unwrap - |> Contextualize.run - |> Expect.equal contextualized_ - ) - contextualized - (Result.toMaybe lexed) - ) - ) - , describe "should not parse" - (ParserLexerTestCases.shouldNotParseTestCases - |> List.filterMap - (\{ name, source, lexed, contextualized } -> - Maybe.map2 - (\contextualized_ lexed_ -> - test name <| - \() -> - lexed_ - |> List.map Located.unwrap - |> Contextualize.run - |> Expect.equal contextualized_ - ) - contextualized - (Result.toMaybe lexed) - ) - ) + describe "parser lexer test" + [ describe "helpers" + [ fuzz (Fuzz.list Fuzz.int) "collectList" <| + \ls -> + ls + |> Contextualize.collectList Ok + |> Expect.equal (Ok ls) + ] + , describe "generated test cases" + [ describe "lexing" + ((ParserLexerTestCases.shouldParseTestCases ++ ParserLexerTestCases.shouldNotParseTestCases) + |> List.map + (\{ name, source, lexed } -> + test name <| + \() -> + source + |> P.run Lexer.parser + |> Expect.equal (lexed |> Result.mapError never) + ) + ) + , describe "should parse" + (ParserLexerTestCases.shouldParseTestCases + |> List.filterMap + (\{ name, source, lexed, contextualized } -> + Maybe.map2 + (\contextualized_ lexed_ -> + test name <| + \() -> + lexed_ + |> List.map Located.unwrap + |> Contextualize.run + |> Expect.equal contextualized_ + ) + contextualized + (Result.toMaybe lexed) + ) + ) + , describe "should not parse" + (ParserLexerTestCases.shouldNotParseTestCases + |> List.filterMap + (\{ name, source, lexed, contextualized } -> + Maybe.map2 + (\contextualized_ lexed_ -> + test name <| + \() -> + lexed_ + |> List.map Located.unwrap + |> Contextualize.run + |> Expect.equal contextualized_ + ) + contextualized + (Result.toMaybe lexed) + ) + ) + ] ] From 11109bf6eabb5d654764d5516e9e11f1054df9a2 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 28 Sep 2020 21:56:18 +0100 Subject: [PATCH 038/103] add three key record test snippet --- .../should-parse/type-alias-record-3-entries | 1 + tests/ParserLexerTestCases.elm | 74 ++++++++++++++++--- 2 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 parser-tests/snippets/should-parse/type-alias-record-3-entries diff --git a/parser-tests/snippets/should-parse/type-alias-record-3-entries b/parser-tests/snippets/should-parse/type-alias-record-3-entries new file mode 100644 index 00000000..d7de8e6d --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-record-3-entries @@ -0,0 +1 @@ +type alias Ty = { a: A, b: B, c: C } diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index f79fd6f5..9c13003d 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -133,6 +133,58 @@ shouldParseTestCases = ) ] } + , { name = "type-alias-record-3-entries" + , source = """type alias Ty = { a: A, b: B, c: C } +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Token "a") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil Colon) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Token "A") + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "b") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Colon) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token "B") + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil Comma) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Whitespace 1) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token "c") + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Sigil Colon) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token "C") + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Whitespace 1) + , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 37, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "a", UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing } ) + , ( "b", UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing } ) + , ( "c", UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) + ] + } , { name = "type-alias-record-empty" , source = """type alias Ty = {} """ @@ -313,16 +365,16 @@ shouldParseTestCases = , ( "ih" , UserDefinedType { args = - [ UserDefinedType + [ UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [ UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } ] , name = "D" , qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing } ] , name = "CustomType" , qualifiedness = PossiblyQualified Nothing @@ -1145,9 +1197,9 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) (UserDefinedType { args = - [ UserDefinedType { args = [], name = "F", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } , UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "F", qualifiedness = PossiblyQualified Nothing } ] , name = "C" , qualifiedness = PossiblyQualified Nothing @@ -1155,14 +1207,14 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) (UserDefinedType { args = - [ UserDefinedType + [ UserDefinedType { args = [], name = "I", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [ UserDefinedType { args = [], name = "K", qualifiedness = PossiblyQualified Nothing } ] , name = "J" , qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "I", qualifiedness = PossiblyQualified Nothing } ] , name = "H" , qualifiedness = PossiblyQualified Nothing @@ -1170,10 +1222,10 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) (UserDefinedType { args = - [ UserDefinedType { args = [], name = "P", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "O", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType { args = [], name = "M", qualifiedness = PossiblyQualified Nothing } , Unit - , UserDefinedType { args = [], name = "M", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "O", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "P", qualifiedness = PossiblyQualified Nothing } ] , name = "L" , qualifiedness = PossiblyQualified Nothing From d1d09228c8d54ae74be6cb271b45482395e75845 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 28 Sep 2020 21:58:37 +0100 Subject: [PATCH 039/103] use list for record entries long term goal: not use Stacks in PartialTypeExpressions --- src/Stage/Parse/Contextualize.elm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 5fd0b52e..f57cc948 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -128,7 +128,7 @@ type PartialTypeExpression | TypeExpression_Unit | TypeExpression_Bracketed PartialTypeExpression | TypeExpression_Tuple PartialTypeExpression PartialTypeExpression (List PartialTypeExpression) - | TypeExpression_Record (Stack ( String, PartialTypeExpression )) + | TypeExpression_Record (List ( String, PartialTypeExpression )) type LastEntryOfRecord @@ -611,11 +611,12 @@ parserTypeExpr newState prevExpr item = LastEntryOfRecord_KeyValue key value -> ( key, value ) |> pushOnto firstEntries + |> toList (\x -> x) |> fromRecord LastEntryOfRecord_Empty -> if firstEntries == empty then - empty + [] |> fromRecord else @@ -1021,12 +1022,11 @@ partialTypeExpressionToConcreteType pte = TypeExpression_Record keyValues -> keyValues - |> toList + |> collectList (\( key, value ) -> partialTypeExpressionToConcreteType value |> Result.map (\concreteValue -> ( key, concreteValue )) ) - |> collectList (\x -> x) |> Result.map (\goodKeyValues -> Dict.fromList goodKeyValues From cd69bacc255304f9f8a26a859ddc2b1d47051436 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Wed, 30 Sep 2020 12:36:13 +0100 Subject: [PATCH 040/103] add bracket in record test case --- .../should-parse/type-alias-bracket-in-record | 1 + tests/ParserLexerTestCases.elm | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 parser-tests/snippets/should-parse/type-alias-bracket-in-record diff --git a/parser-tests/snippets/should-parse/type-alias-bracket-in-record b/parser-tests/snippets/should-parse/type-alias-bracket-in-record new file mode 100644 index 00000000..c9a28038 --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-bracket-in-record @@ -0,0 +1 @@ +type alias Ty = { hi: (Int) } diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 9c13003d..d5b6b6cf 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -60,6 +60,46 @@ shouldParseTestCases = ) ] } + , { name = "type-alias-bracket-in-record" + , source = """type alias Ty = { hi: (Int) } +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token "Int") + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi", UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } ) + ] + ) + , ty = TypeOrConstructor "Ty" + } + ) + ] + } , { name = "type-alias-funky-indentation" , source = """type alias Model = List Int From 277570f3a3145af86b9468da71dfc437a6e41644 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 3 Oct 2020 10:13:15 +0100 Subject: [PATCH 041/103] wip: use nesting stack for type with args --- Makefile | 2 +- parser-tests/Update.elm | 2 + .../snippets/should-parse/type-alias-function | 1 + .../should-parse/type-alias-function-generic | 1 + .../should-parse/type-alias-function-record | 1 + .../should-parse/type-alias-function-tuple | 1 + .../should-parse/type-alias-with-bracket-2 | 1 + parser-tests/update.js | 27 +- src/Stage/Parse/Contextualize.elm | 901 +++++++++++------- tests/ParserLexerTest.elm | 93 +- tests/ParserLexerTestCases.elm | 495 +++++++--- 11 files changed, 967 insertions(+), 558 deletions(-) create mode 100644 parser-tests/snippets/should-parse/type-alias-function create mode 100644 parser-tests/snippets/should-parse/type-alias-function-generic create mode 100644 parser-tests/snippets/should-parse/type-alias-function-record create mode 100644 parser-tests/snippets/should-parse/type-alias-function-tuple create mode 100644 parser-tests/snippets/should-parse/type-alias-with-bracket-2 diff --git a/Makefile b/Makefile index 49cf8b00..deb61483 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ test: build regenerate: cd parser-tests \ && npx elm make Update.elm --output elm.js \ - && node update \ + && node --unhandled-rejections=strict update \ ; CODE=$$? \ ; elm-format ../tests/ParserLexerTestCases.elm --yes \ ; exit $$CODE diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index bd214cf4..fa4a0260 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -107,3 +107,5 @@ preFormatElmCode = ]""" >> String.replace """[ ]""" "[]" + >> String.replace """Err (""" """Err ( + """ diff --git a/parser-tests/snippets/should-parse/type-alias-function b/parser-tests/snippets/should-parse/type-alias-function new file mode 100644 index 00000000..f28a436b --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-function @@ -0,0 +1 @@ +type alias Function = List Int -> List (List Int) diff --git a/parser-tests/snippets/should-parse/type-alias-function-generic b/parser-tests/snippets/should-parse/type-alias-function-generic new file mode 100644 index 00000000..b52b9d14 --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-function-generic @@ -0,0 +1 @@ +type alias Function a = List Int -> List (List a) diff --git a/parser-tests/snippets/should-parse/type-alias-function-record b/parser-tests/snippets/should-parse/type-alias-function-record new file mode 100644 index 00000000..7c4aecfe --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-function-record @@ -0,0 +1 @@ +type alias Function = { a: { b: C}, d: E } -> {} diff --git a/parser-tests/snippets/should-parse/type-alias-function-tuple b/parser-tests/snippets/should-parse/type-alias-function-tuple new file mode 100644 index 00000000..846a2516 --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-function-tuple @@ -0,0 +1 @@ +type alias Function = () -> (Int, String) diff --git a/parser-tests/snippets/should-parse/type-alias-with-bracket-2 b/parser-tests/snippets/should-parse/type-alias-with-bracket-2 new file mode 100644 index 00000000..a52b546c --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-with-bracket-2 @@ -0,0 +1 @@ +type alias Hi = (List Int) diff --git a/parser-tests/update.js b/parser-tests/update.js index 96ed2b7b..7d58e2b6 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -17,27 +17,24 @@ const warningCommentLines = ` .trim() .split('\n'); -function typeOfResultCases(shouldParse) { - const resultArgs = shouldParse ? 'never Block' : '(State, Error) never'; - return ` +const TYPE_OF_RESULT_CASES = ` List - { contextualized : Maybe (List (Result ${resultArgs} )) + { contextualized : Maybe (List (Result (State, Error) Block)) , lexed : Result Never (List (Located LexItem)) , name : String , source : String } `; -} const TEST_FILE_PATH = path.join(__dirname, '..', 'tests', 'ParserLexerTestCases.elm'); const BASE_SNIPPETS_DIR_PATH = path.join(__dirname, 'snippets'); const SNIPPETS_DIR_PATH = Object.freeze({ shouldParse: path.join(BASE_SNIPPETS_DIR_PATH, 'should-parse'), - shouldNotParse: path.join(BASE_SNIPPETS_DIR_PATH, 'should-not-parse') + shouldNotParse: path.join(BASE_SNIPPETS_DIR_PATH, 'should-not-parse'), }); function getTestCase(snippets) { - return new Promise(resolve => { + return new Promise((resolve) => { const app = Elm.Update.init({flags: snippets}); app.ports.output.subscribe(resolve); }); @@ -69,12 +66,12 @@ async function main() { await Promise.all( files .sort() - .filter(name => !name.startsWith('_')) - .map(async name => ({ + .filter((name) => !name.startsWith('_')) + .map(async (name) => ({ name, - source: await fs.readFile(path.join(dirPath, name), 'utf-8') + source: await fs.readFile(path.join(dirPath, name), 'utf-8'), })) - ) + ), ]; }) ); @@ -83,7 +80,7 @@ async function main() { snippets.map(async ([category, snippets2]) => [category, await getTestCase(snippets2)]) ); - if (testCases.some(tests => tests.includes('Panic'))) { + if (testCases.some((tests) => tests.includes('Panic'))) { console.error('ERROR: One or more test cases panicked!'); process.exitCode = 1; } @@ -96,12 +93,12 @@ async function main() { testCases .flatMap(([category, testCases]) => [ `${category}TestCases :`, - typeOfResultCases(category === 'shouldParse'), + TYPE_OF_RESULT_CASES, `${category}TestCases =`, testCases, - '\n' + '\n', ]) - .join('\n') + .join('\n'), ].join('\n'); await fs.writeFile(TEST_FILE_PATH, newTestFile); diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index f57cc948..e65f5720 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -22,8 +22,9 @@ import Elm.Data.Type exposing (Type) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) import Elm.Data.TypeAnnotation exposing (TypeAnnotation) import Elm.Data.VarName exposing (VarName) +import List.NonEmpty.Zipper exposing (prev) import Parser exposing (oneOf) -import Stage.Parse.Lexer as Lexer exposing (LexItem(..)) +import Stage.Parse.Lexer as Lexer exposing (LexItem(..), LexSigil(..), newlinesParser) import Stage.Parse.Token as Token exposing (Keyword) @@ -105,7 +106,8 @@ type BlockTypeAlias = BlockTypeAlias_Keywords | BlockTypeAlias_Named Token.TypeOrConstructor | BlockTypeAlias_NamedAssigns Token.TypeOrConstructor - | BlockTypeAlias_Completish Token.TypeOrConstructor PartialTypeExpression2 + | BlockTypeAlias_Completish Token.TypeOrConstructor PartialTypeExpressionLeaf + | BlockTypeAlias_Complete Token.TypeOrConstructor PartialTypeExpression type BlockCustomType @@ -144,21 +146,36 @@ type alias PartialRecord = } -type NestingType - = NestingType_Bracket ( Stack PartialTypeExpression, Maybe PartialTypeExpression ) - | NestingType_PartialRecord PartialRecord +type NestingParentType + = NestingParentType_Bracket (Stack PartialTypeExpression) + | NestingParentType_PartialRecord + { firstEntries : Stack ( String, PartialTypeExpression ) + , lastEntryName : String + } + | NestingParentType_TypeWithArgs + { name : String + , args : Stack PartialTypeExpression + } + + +type NestingLeafType + = NestingLeafType_Bracket (Stack PartialTypeExpression) (Maybe PartialTypeExpression) + | NestingLeafType_PartialRecord PartialRecord + | NestingLeafType_TypeWithArgs + { name : String + , args : Stack PartialTypeExpression + } -type alias PartialTypeExpression2 = - { root : Maybe PartialTypeExpression - , nestingStack : Stack NestingType +type alias PartialTypeExpressionLeaf = + { parents : List NestingParentType + , nesting : NestingLeafType } type TypeExpressionResult - = TypeExpressionResult_Progress PartialTypeExpression2 + = TypeExpressionResult_Progress PartialTypeExpressionLeaf | TypeExpressionResult_Done PartialTypeExpression - | TypeExpressionResult_Empty type Error @@ -170,6 +187,7 @@ type Error | Error_ExpectedColonWhilstParsingRecord | Error_ExpectedKeyWhilstParsingRecord | Error_TypeDoesNotTakeArgs PartialTypeExpression PartialTypeExpression + | Error_ExtraItemAfterBlock PartialTypeExpression Lexer.LexItem | Error_TooManyTupleArgs -- (ConcreteType PossiblyQualified) @@ -268,6 +286,19 @@ runHelp items state = parseAnything : State -> LexItem -> ParseResult parseAnything state = + let + newTypeAliasState name res = + case res of + TypeExpressionResult_Progress expr -> + State_BlockTypeAlias (BlockTypeAlias_Completish name expr) + |> ParseResult_Ok + + TypeExpressionResult_Done expr -> + expr + |> BlockTypeAlias_Complete name + |> State_BlockTypeAlias + |> ParseResult_Ok + in case state of State_Error_Recovery -> \item -> @@ -287,10 +318,10 @@ parseAnything state = parseTypeBlock State_BlockFirstItem BlockFirstItem_Module -> - Debug.todo "" + Debug.todo "BlockFirstItem_Module" State_BlockFirstItem (BlockFirstItem_Name name) -> - Debug.todo "" + Debug.todo "BlockFirstItem_Name" State_BlockTypeAlias BlockTypeAlias_Keywords -> parseTypeAliasName @@ -301,64 +332,56 @@ parseAnything state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name) -> parserTypeExpr - (\res -> - case res of - TypeExpressionResult_Progress expr -> - State_BlockTypeAlias (BlockTypeAlias_Completish name expr) - |> ParseResult_Ok - - TypeExpressionResult_Done expr -> - case partialTypeExpressionToConcreteType expr of - Ok concreteType -> - { ty = name - , expr = concreteType - } - |> TypeAlias - |> ParseResult_Complete - - Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> - Error_TooManyTupleArgs a b c d e - |> ParseResult_Err - - TypeExpressionResult_Empty -> - Debug.todo "" - ) - { root = Nothing - , nestingStack = empty - } + (newTypeAliasState name) + Nothing State_BlockTypeAlias (BlockTypeAlias_Completish name exprSoFar) -> parserTypeExpr - (\res -> - case res of - TypeExpressionResult_Progress expr -> - State_BlockTypeAlias (BlockTypeAlias_Completish name expr) - |> ParseResult_Ok + (newTypeAliasState name) + (Just exprSoFar) + + State_BlockTypeAlias (BlockTypeAlias_Complete aliasName expr) -> + let + rBlock = + case partialTypeExpressionToConcreteType expr of + Ok concreteType -> + { ty = aliasName + , expr = concreteType + } + |> TypeAlias + |> Ok - TypeExpressionResult_Done expr -> - case partialTypeExpressionToConcreteType expr of - Ok conceteType -> - { ty = name - , expr = conceteType - } - |> TypeAlias - |> ParseResult_Complete + Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> + Error_TooManyTupleArgs a b c d e + |> Err + in + \item -> + case item of + Lexer.Newlines _ 0 -> + case rBlock of + Ok block -> + block + |> ParseResult_Complete - Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> - Error_TooManyTupleArgs a b c d e - |> ParseResult_Err + Err e -> + ParseResult_Err e - TypeExpressionResult_Empty -> - Debug.todo "" - ) - exprSoFar + Lexer.Newlines _ _ -> + ParseResult_Skip + + Whitespace _ -> + ParseResult_Skip + + _ -> + Error_ExtraItemAfterBlock expr item + |> ParseResult_Err State_BlockCustomType (BlockCustomType_Named name) -> parseAssignment (State_BlockCustomType (BlockCustomType_NamedAssigns name)) State_BlockCustomType (BlockCustomType_NamedAssigns name) -> - Debug.todo "" + Debug.todo "BlockCustomType_NamedAssigns" {-| @@ -500,152 +523,323 @@ parseAssignment newState item = parserTypeExpr : (TypeExpressionResult -> ParseResult) - -> PartialTypeExpression2 + -> Maybe PartialTypeExpressionLeaf -> LexItem -> ParseResult -parserTypeExpr newState prevExpr item = +parserTypeExpr newState mPrevExpr item = case item of Lexer.Token str -> - exprAppend prevExpr (TokenOrType_Token str) - |> partialTypeExpressionToParseResult newState + case mPrevExpr of + Just prevExpr -> + exprAppend prevExpr str + |> partialTypeExpressionToParseResult newState + + Nothing -> + { parents = [] + , nesting = + NestingLeafType_TypeWithArgs + { name = str + , args = empty + } + } + |> TypeExpressionResult_Progress + |> newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> - { nestingStack = - NestingType_Bracket ( empty, Nothing ) - |> pushOnto prevExpr.nestingStack - , root = prevExpr.root - } - |> TypeExpressionResult_Progress - |> newState + leafToParents mPrevExpr + |> Result.map + (\parents -> + { parents = parents + , nesting = NestingLeafType_Bracket empty Nothing + } + ) + |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> - case pop prevExpr.nestingStack of - Just ( NestingType_Bracket ( argStack, mexpr ), poppedNestingStack ) -> - let - rexpr = - if argStack /= empty && mexpr == Nothing then - -- We have a trailing comma! - Error_UnmatchedBracket Lexer.Round Lexer.Close - |> Err - - else - let - fullArgsList = - (case mexpr of - Just expr -> - expr |> pushOnto argStack - - Nothing -> - argStack - ) - |> toList (\x -> x) - in - case fullArgsList of - [] -> - TypeExpression_Unit - |> Ok - - first :: [] -> - TypeExpression_Bracketed first - |> Ok - - first :: second :: rest -> - TypeExpression_Tuple first second rest - |> Ok - in - case rexpr of - Ok expr -> - exprAppend - { nestingStack = poppedNestingStack - , root = prevExpr.root - } - (TokenOrType_Type expr) - |> partialTypeExpressionToParseResult newState + case mPrevExpr of + Just prevExpr -> + case autoCollapseNesting prevExpr of + TypeExpressionResult_Done expr -> + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> ParseResult_Err - Err e -> - ParseResult_Err e + TypeExpressionResult_Progress collapsedLeaf -> + case collapsedLeaf.nesting of + NestingLeafType_TypeWithArgs { name, args } -> + Debug.todo "Make this state impossible" + + NestingLeafType_Bracket argStack mLastExpression -> + let + rexpr = + if argStack /= empty && mLastExpression == Nothing then + -- We have a trailing comma! + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> Err + + else + let + fullArgsList = + (case mLastExpression of + Just expr -> + expr |> pushOnto argStack + + Nothing -> + argStack + ) + |> toList (\x -> x) + in + case fullArgsList of + [] -> + TypeExpression_Unit + |> Ok + + first :: [] -> + TypeExpression_Bracketed first + |> Ok + + first :: second :: rest -> + TypeExpression_Tuple first second rest + |> Ok + in + case rexpr of + Ok expr -> + case collapsedLeaf.parents of + nesting :: grandparents -> + { nesting = + case nesting of + NestingParentType_PartialRecord { firstEntries, lastEntryName } -> + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr + } + + NestingParentType_Bracket els -> + NestingLeafType_Bracket els (Just expr) + + NestingParentType_TypeWithArgs { name, args } -> + NestingLeafType_TypeWithArgs + { name = name + , args = expr |> pushOnto args + } + , parents = grandparents + } + |> TypeExpressionResult_Progress + |> newState + + [] -> + expr + |> TypeExpressionResult_Done + |> newState + + Err e -> + ParseResult_Err e + + NestingLeafType_PartialRecord _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err - _ -> - -- TODO(harry): can we add information about the - -- bracket we are expecting here? + Nothing -> Error_UnmatchedBracket Lexer.Round Lexer.Close |> ParseResult_Err Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> - { nestingStack = - NestingType_PartialRecord - { firstEntries = empty - , lastEntry = LastEntryOfRecord_Empty + case leafToParents mPrevExpr of + Ok newParents -> + { nesting = + NestingLeafType_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty + } + , parents = newParents } - |> pushOnto prevExpr.nestingStack - , root = prevExpr.root - } - |> TypeExpressionResult_Progress - |> newState + |> TypeExpressionResult_Progress + |> newState + + Err e -> + e + |> ParseResult_Err Lexer.Sigil Lexer.Colon -> - addThingToPartialRecord ThingToAddToPartialRecord_Colon prevExpr item newState + let + getNewPartialRecord parents { firstEntries, lastEntry } = + case lastEntry of + LastEntryOfRecord_Key key -> + { parents = parents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyColon key + } + } + |> TypeExpressionResult_Progress + |> newState - Lexer.Sigil Lexer.Comma -> - addThingToPartialRecord ThingToAddToPartialRecord_Comma prevExpr item newState + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + in + case mPrevExpr of + Just prevExpr -> + case prevExpr.nesting of + NestingLeafType_PartialRecord existingPartialRecord -> + getNewPartialRecord prevExpr.parents existingPartialRecord - Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> - case pop prevExpr.nestingStack of - Just ( NestingType_PartialRecord { firstEntries, lastEntry }, poppedNestingStack ) -> - let - fromRecord record = - let - tot = - record - |> TypeExpression_Record - |> TokenOrType_Type - in - exprAppend - { nestingStack = poppedNestingStack - , root = prevExpr.root - } - tot - |> partialTypeExpressionToParseResult newState - in + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Nothing -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Lexer.Sigil Lexer.Comma -> + let + getNewPartialRecord parents { firstEntries, lastEntry } = case lastEntry of LastEntryOfRecord_KeyValue key value -> - ( key, value ) - |> pushOnto firstEntries - |> toList (\x -> x) - |> fromRecord + { parents = parents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = ( key, value ) |> pushOnto firstEntries + , lastEntry = LastEntryOfRecord_Empty + } + } + |> TypeExpressionResult_Progress + |> newState - LastEntryOfRecord_Empty -> - if firstEntries == empty then - [] - |> fromRecord + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + in + case mPrevExpr |> Maybe.map autoCollapseNesting of + Just (TypeExpressionResult_Done expr) -> + Error_UnmatchedBracket Lexer.Curly Lexer.Close + |> ParseResult_Err + + Just (TypeExpressionResult_Progress collapsedLeaf) -> + case collapsedLeaf.nesting of + NestingLeafType_PartialRecord existingPartialRecord -> + getNewPartialRecord collapsedLeaf.parents existingPartialRecord - else - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + NestingLeafType_Bracket argStack (Just expr) -> + { nesting = + NestingLeafType_Bracket (expr |> pushOnto argStack) Nothing + , parents = collapsedLeaf.parents + } + |> TypeExpressionResult_Progress + |> newState _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err - _ -> - -- TODO(harry): can we add information about the - -- bracket we are expecting here? + Nothing -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> + case mPrevExpr of + Just prevExpr -> + case autoCollapseNesting prevExpr of + TypeExpressionResult_Done expr -> + Error_UnmatchedBracket Lexer.Curly Lexer.Close + |> ParseResult_Err + + TypeExpressionResult_Progress collapsedLeaf -> + case collapsedLeaf.nesting of + NestingLeafType_TypeWithArgs { name, args } -> + Debug.todo "Make this state impossible" + + NestingLeafType_Bracket argStack mLastExpression -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + let + fromRecord recordEntries = + let + record = + TypeExpression_Record recordEntries + in + case collapsedLeaf.parents of + [] -> + record + |> TypeExpressionResult_Done + |> newState + + nesting :: grandparents -> + (case nesting of + -- We are within a nested bracket. + NestingParentType_Bracket argStack -> + { parents = grandparents + , nesting = NestingLeafType_Bracket argStack (Just record) + } + + NestingParentType_PartialRecord existingPartialRecord -> + { parents = grandparents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = existingPartialRecord.firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue + existingPartialRecord.lastEntryName + record + } + } + + NestingParentType_TypeWithArgs { name, args } -> + { nesting = + NestingLeafType_TypeWithArgs + { name = name + , args = + record + |> pushOnto args + } + , parents = grandparents + } + ) + |> TypeExpressionResult_Progress + |> newState + in + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + ( key, value ) + |> pushOnto firstEntries + |> toList (\x -> x) + |> fromRecord + + LastEntryOfRecord_Empty -> + if firstEntries == empty then + [] + |> fromRecord + + else + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Nothing -> Error_UnmatchedBracket Lexer.Curly Lexer.Close |> ParseResult_Err Lexer.Newlines _ 0 -> - case ( pop prevExpr.nestingStack, prevExpr.root ) of - ( Just _, _ ) -> + case mPrevExpr of + Nothing -> Error_PartwayThroughTypeAlias |> ParseResult_Err - ( Nothing, Just expr ) -> - TypeExpressionResult_Done expr - |> newState + Just prevExpr -> + case autoCollapseNesting prevExpr of + TypeExpressionResult_Done expr -> + TypeExpressionResult_Done expr + |> newState - ( Nothing, Nothing ) -> - Error_PartwayThroughTypeAlias - |> ParseResult_Err + TypeExpressionResult_Progress collapsedLeaf -> + Error_PartwayThroughTypeAlias + |> ParseResult_Err Lexer.Newlines _ _ -> ParseResult_Skip @@ -658,47 +852,118 @@ parserTypeExpr newState prevExpr item = |> ParseResult_Err -exprAppend : - PartialTypeExpression2 - -> TokenOrType - -> Result Error PartialTypeExpression2 -exprAppend { nestingStack, root } tot = - case pop nestingStack of - -- We are in the top level of the type expression; we have - -- found a closing bracket to match every opening bracket we - -- have encountered so far whilst parsing the type expression. - -- (We may have found no brackets at all so far.) +leafToParents : Maybe PartialTypeExpressionLeaf -> Result Error (List NestingParentType) +leafToParents leaf = + case leaf of Nothing -> - addArgumentToType tot root + Ok [] + + Just { parents, nesting } -> + (case nesting of + NestingLeafType_Bracket _ (Just lastType) -> + -- Cannot nest unless there is a trailing comma! + Error_TypeDoesNotTakeArgs lastType (Debug.todo "") + |> Err + + NestingLeafType_Bracket els Nothing -> + NestingParentType_Bracket els + |> Ok + + NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + case lastEntry of + LastEntryOfRecord_Empty -> + Error_ExpectedKeyWhilstParsingRecord + |> Err + + LastEntryOfRecord_Key _ -> + Error_ExpectedColonWhilstParsingRecord + |> Err + + LastEntryOfRecord_KeyColon key -> + NestingParentType_PartialRecord { firstEntries = firstEntries, lastEntryName = key } + |> Ok + + LastEntryOfRecord_KeyValue _ lastValueType -> + Error_TypeDoesNotTakeArgs lastValueType (Debug.todo "") + |> Err + + NestingLeafType_TypeWithArgs details -> + NestingParentType_TypeWithArgs details + |> Ok + ) |> Result.map - (\newRoot -> - { nestingStack = empty - , root = Just newRoot - } - ) + (\n -> n :: parents) + +exprAppend : + PartialTypeExpressionLeaf + -> String + -> Result Error PartialTypeExpressionLeaf +exprAppend ({ parents, nesting } as currentLeaf) token = + let + newType = + TypeExpression_NamedType + { name = token + , args = empty + } + in + case nesting of -- We are within a nested bracket. - Just ( NestingType_Bracket ( argStack, mostNested ), rest ) -> - addArgumentToType tot mostNested - |> Result.map - (\newLatestTypeExpr -> - { nestingStack = - NestingType_Bracket ( argStack, Just newLatestTypeExpr ) - |> pushOnto rest - , root = root - } - ) + NestingLeafType_Bracket argStack mostNested -> + case mostNested of + Nothing -> + leafToParents (Just currentLeaf) + |> Result.map + (\newParents -> + { parents = newParents + , nesting = + NestingLeafType_TypeWithArgs + { name = token + , args = empty + } + } + ) - Just ( NestingType_PartialRecord existingPartialRecord, rest ) -> - addToPartialRecord tot existingPartialRecord - |> Result.map - (\newPartialRecord -> - { nestingStack = - NestingType_PartialRecord newPartialRecord - |> pushOnto rest - , root = root - } - ) + Just existingRoot -> + Error_TypeDoesNotTakeArgs TypeExpression_Unit newType + |> Err + + NestingLeafType_PartialRecord pr -> + case pr.lastEntry of + LastEntryOfRecord_Empty -> + { parents = parents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = pr.firstEntries + , lastEntry = LastEntryOfRecord_Key token + } + } + |> Ok + + _ -> + leafToParents (Just currentLeaf) + |> Result.map + (\newParents -> + { parents = newParents + , nesting = + NestingLeafType_TypeWithArgs + { name = token + , args = empty + } + } + ) + + NestingLeafType_TypeWithArgs { name, args } -> + { nesting = + NestingLeafType_TypeWithArgs + { name = name + , args = + newType + |> pushOnto args + } + , parents = parents + } + |> Ok blockFromState : State -> Maybe (Result Error Block) @@ -728,13 +993,13 @@ blockFromState state = |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Completish name { nestingStack, root }) -> - case ( pop nestingStack, root ) of - ( Nothing, Just expr ) -> + State_BlockTypeAlias (BlockTypeAlias_Completish aliasName partialExpr) -> + case autoCollapseNesting partialExpr of + TypeExpressionResult_Done expr -> partialTypeExpressionToConcreteType expr |> Result.map (\conceteType -> - { ty = name + { ty = aliasName , expr = conceteType } |> TypeAlias @@ -742,11 +1007,26 @@ blockFromState state = |> Result.mapError (\(ToConcreteTypeError_TooManyTupleArgs a b c d e) -> Error_TooManyTupleArgs a b c d e) |> Just - _ -> + TypeExpressionResult_Progress collapsedLeaf -> Error_PartwayThroughTypeAlias |> Err |> Just + State_BlockTypeAlias (BlockTypeAlias_Complete aliasName expr) -> + case partialTypeExpressionToConcreteType expr of + Ok concreteType -> + { ty = aliasName + , expr = concreteType + } + |> TypeAlias + |> Ok + |> Just + + Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> + Error_TooManyTupleArgs a b c d e + |> Err + |> Just + State_BlockCustomType firstItem -> Debug.todo "handle incomplete block" @@ -757,39 +1037,27 @@ blockFromState state = type TokenOrType = TokenOrType_Token String - | TokenOrType_Type PartialTypeExpression addToPartialRecord : - TokenOrType + String -> PartialRecord -> Result Error PartialRecord -addToPartialRecord tot { firstEntries, lastEntry } = +addToPartialRecord token { firstEntries, lastEntry } = let newType = - case tot of - TokenOrType_Token str -> - TypeExpression_NamedType - { name = str - , args = empty - } - - TokenOrType_Type ty -> - ty + TypeExpression_NamedType + { name = token + , args = empty + } in case lastEntry of LastEntryOfRecord_Empty -> - case tot of - TokenOrType_Token str -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_Key str - } - |> Ok - - TokenOrType_Type _ -> - Error_ExpectedKeyWhilstParsingRecord - |> Err + { firstEntries = firstEntries + , lastEntry = + LastEntryOfRecord_Key token + } + |> Ok LastEntryOfRecord_Key key -> Error_ExpectedColonWhilstParsingRecord @@ -802,86 +1070,46 @@ addToPartialRecord tot { firstEntries, lastEntry } = } |> Ok - LastEntryOfRecord_KeyValue key (TypeExpression_NamedType { name, args }) -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue - key - (TypeExpression_NamedType - { name = name - , args = - newType - |> pushOnto args - } - ) - } - |> Ok - - LastEntryOfRecord_KeyValue _ TypeExpression_Unit -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit newType - |> Err - - LastEntryOfRecord_KeyValue _ ((TypeExpression_Bracketed _) as ty) -> - Error_TypeDoesNotTakeArgs ty newType - |> Err - - LastEntryOfRecord_KeyValue _ ((TypeExpression_Tuple _ _ _) as ty) -> - Error_TypeDoesNotTakeArgs ty newType - |> Err - - LastEntryOfRecord_KeyValue _ ((TypeExpression_Record _) as ty) -> - Error_TypeDoesNotTakeArgs ty newType - |> Err - - -addArgumentToType : TokenOrType -> Maybe PartialTypeExpression -> Result Error PartialTypeExpression -addArgumentToType argToAdd mexistingTypeExpr = - let - newType = - case argToAdd of - TokenOrType_Token str -> - TypeExpression_NamedType - { name = str - , args = empty - } - - TokenOrType_Type ty -> - ty - in - case mexistingTypeExpr of - Nothing -> - newType - |> Ok - - Just (TypeExpression_NamedType { name, args }) -> - TypeExpression_NamedType - { name = name - , args = - newType - |> pushOnto args - } - |> Ok - - Just ((TypeExpression_Bracketed _) as ty) -> - Error_TypeDoesNotTakeArgs ty newType + LastEntryOfRecord_KeyValue key value -> + Error_TypeDoesNotTakeArgs value newType |> Err - Just ((TypeExpression_Tuple _ _ _) as ty) -> - Error_TypeDoesNotTakeArgs ty newType - |> Err - Just ((TypeExpression_Record _) as ty) -> - Error_TypeDoesNotTakeArgs ty newType - |> Err +autoCollapseNesting : PartialTypeExpressionLeaf -> TypeExpressionResult +autoCollapseNesting pte = + case pte.nesting of + NestingLeafType_TypeWithArgs { name, args } -> + let + newTypeExpr = + TypeExpression_NamedType { name = name, args = args } + in + case pte.parents of + nesting :: grandparents -> + { parents = grandparents + , nesting = + case nesting of + NestingParentType_TypeWithArgs _ -> + Debug.todo "Make this state impossible" + + NestingParentType_Bracket els -> + NestingLeafType_Bracket els (Just newTypeExpr) + + NestingParentType_PartialRecord { firstEntries, lastEntryName } -> + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyValue lastEntryName newTypeExpr + } + } + |> autoCollapseNesting - Just TypeExpression_Unit -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit newType - |> Err + [] -> + TypeExpressionResult_Done newTypeExpr + NestingLeafType_Bracket _ _ -> + TypeExpressionResult_Progress pte -type ThingToAddToPartialRecord - = ThingToAddToPartialRecord_Colon - | ThingToAddToPartialRecord_Comma + NestingLeafType_PartialRecord _ -> + TypeExpressionResult_Progress pte {-| TODO(harry): We can add things to a tuple too! Rename this function @@ -890,66 +1118,7 @@ appropriately. TODO(harry): We can inline this function. -} -addThingToPartialRecord : - ThingToAddToPartialRecord - -> PartialTypeExpression2 - -> Lexer.LexItem - -> (TypeExpressionResult -> ParseResult) - -> ParseResult -addThingToPartialRecord thing prevExpr item newState = - let - getNewPartialRecord { firstEntries, lastEntry } = - case ( thing, lastEntry ) of - ( ThingToAddToPartialRecord_Colon, LastEntryOfRecord_Key key ) -> - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyColon key - } - |> Ok - - ( ThingToAddToPartialRecord_Comma, LastEntryOfRecord_KeyValue key value ) -> - { firstEntries = ( key, value ) |> pushOnto firstEntries - , lastEntry = LastEntryOfRecord_Empty - } - |> Ok - - _ -> - Err () - - newNestedTypeExpression = - case pop prevExpr.nestingStack of - Just ( NestingType_PartialRecord existingPartialRecord, rest ) -> - getNewPartialRecord existingPartialRecord - |> Result.map - (\newPartialRecord -> - { nestingStack = - NestingType_PartialRecord newPartialRecord - |> pushOnto rest - , root = prevExpr.root - } - ) - - Just ( NestingType_Bracket ( argStack, Just expr ), rest ) -> - case thing of - ThingToAddToPartialRecord_Colon -> - Err () - - ThingToAddToPartialRecord_Comma -> - { nestingStack = - NestingType_Bracket ( expr |> pushOnto argStack, Nothing ) - |> pushOnto rest - , root = prevExpr.root - } - |> Ok - - _ -> - Err () - in - newNestedTypeExpression - |> Result.mapError (\() -> Error_InvalidToken item Expecting_Unknown) - |> partialTypeExpressionToParseResult newState - - -partialTypeExpressionToParseResult : (TypeExpressionResult -> ParseResult) -> Result Error PartialTypeExpression2 -> ParseResult +partialTypeExpressionToParseResult : (TypeExpressionResult -> ParseResult) -> Result Error PartialTypeExpressionLeaf -> ParseResult partialTypeExpressionToParseResult newState rnewPartialType = case rnewPartialType of Ok newPartialType -> diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm index de1a8619..af5de7d7 100644 --- a/tests/ParserLexerTest.elm +++ b/tests/ParserLexerTest.elm @@ -31,38 +31,87 @@ tests = |> Expect.equal (lexed |> Result.mapError never) ) ) - , describe "should parse" - (ParserLexerTestCases.shouldParseTestCases - |> List.filterMap + , describe "test cases are up to date" + (ParserLexerTestCases.shouldNotParseTestCases + ++ ParserLexerTestCases.shouldParseTestCases + |> List.map (\{ name, source, lexed, contextualized } -> - Maybe.map2 - (\contextualized_ lexed_ -> - test name <| - \() -> + test name <| + \() -> + case ( lexed, contextualized ) of + ( Ok lexed_, Just contextualized_ ) -> lexed_ |> List.map Located.unwrap |> Contextualize.run |> Expect.equal contextualized_ - ) - contextualized - (Result.toMaybe lexed) + + ( Err _, _ ) -> + Expect.fail "bug: cannot lex" + + ( Ok _, Nothing ) -> + Expect.fail "bug: cannot lex" + ) + ) + , describe "should parse" + (ParserLexerTestCases.shouldNotParseTestCases + |> List.map + (\{ name, source, lexed, contextualized } -> + test name <| + \() -> + case ( lexed, contextualized ) of + ( Ok lexed_, Just contextualized_ ) -> + () + |> Expect.all + (lexed_ + |> List.map Located.unwrap + |> Contextualize.run + |> List.map + (\rBlock () -> + case rBlock of + Ok _ -> + Expect.pass + + Err _ -> + Expect.fail "it does not parse" + ) + ) + + ( Err _, _ ) -> + Expect.fail "bug: cannot lex" + + ( Ok _, Nothing ) -> + Expect.fail "bug: cannot lex" ) ) , describe "should not parse" (ParserLexerTestCases.shouldNotParseTestCases - |> List.filterMap + |> List.map (\{ name, source, lexed, contextualized } -> - Maybe.map2 - (\contextualized_ lexed_ -> - test name <| - \() -> - lexed_ - |> List.map Located.unwrap - |> Contextualize.run - |> Expect.equal contextualized_ - ) - contextualized - (Result.toMaybe lexed) + test name <| + \() -> + case ( lexed, contextualized ) of + ( Ok lexed_, Just contextualized_ ) -> + () + |> Expect.all + (lexed_ + |> List.map Located.unwrap + |> Contextualize.run + |> List.map + (\rBlock () -> + case rBlock of + Ok _ -> + Expect.fail "it did parse" + + Err _ -> + Expect.pass + ) + ) + + ( Err _, _ ) -> + Expect.fail "bug: cannot lex" + + ( Ok _, Nothing ) -> + Expect.fail "bug: cannot lex" ) ) ] diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index d5b6b6cf..f0f75ba5 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -19,7 +19,7 @@ import Test exposing (Test, describe, test) shouldParseTestCases : List - { contextualized : Maybe (List (Result never Block)) + { contextualized : Maybe (List (Result ( State, Error ) Block)) , lexed : Result Never (List (Located LexItem)) , name : String , source : String @@ -100,6 +100,199 @@ shouldParseTestCases = ) ] } + , { name = "type-alias-function" + , source = """type alias Function = List Int -> List (List Int) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token "List") + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Token "Int") + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Sigil (Operator Subtract)) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Operator GreaterThan)) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) + , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Token "List") + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Token "List") + , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Whitespace 1) + , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Token "Int") + , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function") + { nesting = + NestingLeafType_TypeWithArgs + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , name = "List" + } + , parents = [] + } + ) + , Error_InvalidToken (Sigil (Operator Subtract)) Expecting_Unknown + ) + ] + } + , { name = "type-alias-function-generic" + , source = """type alias Function a = List Int -> List (List a) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token "a") + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Assign) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Token "List") + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Operator Subtract)) + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Sigil (Operator GreaterThan)) + , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) + , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Token "List") + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Token "List") + , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Whitespace 1) + , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token "a") + , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function")) + , Error_InvalidToken (Token "a") (Expecting_Sigil Assign) + ) + ] + } + , { name = "type-alias-function-record" + , source = """type alias Function = { a: { b: C}, d: E } -> {} +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "a") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Colon) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token "b") + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Sigil Colon) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token "C") + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Sigil Comma) + , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) + , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Token "d") + , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Sigil Colon) + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token "E") + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Whitespace 1) + , Located { end = { col = 45, row = 1 }, start = { col = 44, row = 1 } } (Sigil (Operator Subtract)) + , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Sigil (Operator GreaterThan)) + , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Whitespace 1) + , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 49, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias + (BlockTypeAlias_Complete (TypeOrConstructor "Function") + (TypeExpression_Record + [ ( "a" + , TypeExpression_Record + [ ( "b", TypeExpression_NamedType { args = Stack [], name = "C" } ) + ] + ) + , ( "d", TypeExpression_NamedType { args = Stack [], name = "E" } ) + ] + ) + ) + , Error_ExtraItemAfterBlock + (TypeExpression_Record + [ ( "a" + , TypeExpression_Record + [ ( "b", TypeExpression_NamedType { args = Stack [], name = "C" } ) + ] + ) + , ( "d", TypeExpression_NamedType { args = Stack [], name = "E" } ) + ] + ) + (Sigil (Operator Subtract)) + ) + ] + } + , { name = "type-alias-function-tuple" + , source = """type alias Function = () -> (Int, String) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Operator Subtract)) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Operator GreaterThan)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil Comma) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) + , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Token "String") + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Function") TypeExpression_Unit) + , Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Operator Subtract)) + ) + ] + } , { name = "type-alias-funky-indentation" , source = """type alias Model = List Int @@ -555,6 +748,43 @@ shouldParseTestCases = [ Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi" }) ] } + , { name = "type-alias-with-bracket-2" + , source = """type alias Hi = (List Int) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Token "List") + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Int") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + UserDefinedType + { args = + [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , ty = TypeOrConstructor "Hi" + } + ) + ] + } , { name = "type-alias-with-pair" , source = """type alias Hi = (Int, List String) type alias Hi = (Int) @@ -741,7 +971,7 @@ type alias Hi = ((), (), ()) shouldNotParseTestCases : List - { contextualized : Maybe (List (Result ( State, Error ) never)) + { contextualized : Maybe (List (Result ( State, Error ) Block)) , lexed : Result Never (List (Located LexItem)) , name : String , source : String @@ -771,16 +1001,8 @@ shouldNotParseTestCases = , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = - Stack - [ NestingType_Bracket ( Stack [], Nothing ) - ] - , root = Just (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) - } - ) - , Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) TypeExpression_Unit + ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" }))) + , Error_ExtraItemAfterBlock (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) (Sigil (Bracket Round Open)) ) ] } @@ -807,16 +1029,8 @@ shouldNotParseTestCases = , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = - Stack - [ NestingType_Bracket ( Stack [], Nothing ) - ] - , root = Just TypeExpression_Unit - } - ) - , Error_TypeDoesNotTakeArgs TypeExpression_Unit TypeExpression_Unit + ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") TypeExpression_Unit) + , Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Bracket Round Open)) ) ] } @@ -844,16 +1058,8 @@ shouldNotParseTestCases = , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = - Stack - [ NestingType_Bracket ( Stack [], Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) - ] - , root = Just TypeExpression_Unit - } - ) - , Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) + ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") TypeExpression_Unit) + , Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Bracket Round Open)) ) ] } @@ -878,8 +1084,14 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")), Error_PartwayThroughTypeAlias ) - , Err ( State_BlockStart, Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") ) + [ Err + ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")) + , Error_PartwayThroughTypeAlias + ) + , Err + ( State_BlockStart + , Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") + ) ] } , { name = "type-alias-partial" @@ -894,7 +1106,10 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias BlockTypeAlias_Keywords, Error_PartwayThroughTypeAlias ) + [ Err + ( State_BlockTypeAlias BlockTypeAlias_Keywords + , Error_PartwayThroughTypeAlias + ) ] } , { name = "type-alias-partial-2" @@ -911,7 +1126,10 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")), Error_PartwayThroughTypeAlias ) + [ Err + ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")) + , Error_PartwayThroughTypeAlias + ) ] } , { name = "type-alias-partial-3" @@ -930,7 +1148,10 @@ List Int ] , contextualized = Just - [ Err ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")), Error_PartwayThroughTypeAlias ) + [ Err + ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")) + , Error_PartwayThroughTypeAlias + ) ] } , { name = "type-alias-partial-with-bracket" @@ -952,15 +1173,7 @@ List Int , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = - Stack - [ NestingType_Bracket ( Stack [], Nothing ) - ] - , root = Nothing - } - ) + ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) , Error_PartwayThroughTypeAlias ) ] @@ -989,11 +1202,10 @@ List Int [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = - Stack - [ NestingType_Bracket ( Stack [], Just (TypeExpression_NamedType { args = Stack [], name = "Int" }) ) - ] - , root = Nothing + { nesting = NestingLeafType_TypeWithArgs { args = Stack [], name = "Int" } + , parents = + [ NestingParentType_Bracket (Stack []) + ] } ) , Error_PartwayThroughTypeAlias @@ -1019,15 +1231,7 @@ List Int , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Ty") - { nestingStack = - Stack - [ NestingType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty } - ] - , root = Nothing - } - ) + ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) , Error_PartwayThroughTypeAlias ) ] @@ -1057,15 +1261,7 @@ List Int , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Ty") - { nestingStack = - Stack - [ NestingType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" } - ] - , root = Nothing - } - ) + ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) , Error_ExpectedColonWhilstParsingRecord ) ] @@ -1151,18 +1347,14 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) Just [ Err ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = Stack [] - , root = - Just - (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) - (TypeExpression_NamedType { args = Stack [], name = "A" }) - [ TypeExpression_NamedType { args = Stack [], name = "B" } - , TypeExpression_NamedType { args = Stack [], name = "C" } - , TypeExpression_NamedType { args = Stack [], name = "D" } - ] - ) - } + (BlockTypeAlias_Complete (TypeOrConstructor "Hi") + (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) + (TypeExpression_NamedType { args = Stack [], name = "A" }) + [ TypeExpression_NamedType { args = Stack [], name = "B" } + , TypeExpression_NamedType { args = Stack [], name = "C" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + ) ) , Error_TooManyTupleArgs (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing }) @@ -1173,58 +1365,54 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) , Err ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = Stack [] - , root = - Just - (TypeExpression_Tuple - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - , name = "A" - } - ) - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "F" } - , TypeExpression_NamedType { args = Stack [], name = "E" } - , TypeExpression_NamedType { args = Stack [], name = "D" } - ] - , name = "C" - } - ) - [ TypeExpression_NamedType - { args = - Stack - [ TypeExpression_Bracketed - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "K" } - ] - , name = "J" - } - ) - , TypeExpression_NamedType { args = Stack [], name = "I" } - ] - , name = "H" - } - , TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "P" } - , TypeExpression_NamedType { args = Stack [], name = "O" } - , TypeExpression_Unit - , TypeExpression_NamedType { args = Stack [], name = "M" } - ] - , name = "L" - } - ] - ) - } + (BlockTypeAlias_Complete (TypeOrConstructor "Hi") + (TypeExpression_Tuple + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , name = "A" + } + ) + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "F" } + , TypeExpression_NamedType { args = Stack [], name = "E" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + , name = "C" + } + ) + [ TypeExpression_NamedType + { args = + Stack + [ TypeExpression_Bracketed + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "K" } + ] + , name = "J" + } + ) + , TypeExpression_NamedType { args = Stack [], name = "I" } + ] + , name = "H" + } + , TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "P" } + , TypeExpression_NamedType { args = Stack [], name = "O" } + , TypeExpression_Unit + , TypeExpression_NamedType { args = Stack [], name = "M" } + ] + , name = "L" + } + ] + ) ) , Error_TooManyTupleArgs (UserDefinedType @@ -1303,16 +1491,14 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = - Stack - [ NestingType_Bracket - ( Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - , Nothing - ) - ] - , root = Nothing + { nesting = + NestingLeafType_Bracket + (Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + ) + Nothing + , parents = [] } ) , Error_InvalidToken (Sigil Comma) Expecting_Unknown @@ -1352,16 +1538,14 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) [ Err ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nestingStack = - Stack - [ NestingType_Bracket - ( Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - , Nothing - ) - ] - , root = Nothing + { nesting = + NestingLeafType_Bracket + (Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + ) + Nothing + , parents = [] } ) , Error_PartwayThroughTypeAlias @@ -1378,7 +1562,10 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , contextualized = Just - [ Err ( State_BlockFirstItem BlockFirstItem_Type, Error_PartwayThroughTypeAlias ) + [ Err + ( State_BlockFirstItem BlockFirstItem_Type + , Error_PartwayThroughTypeAlias + ) ] } ] From e83034f914e95e1f08e1e5a251e85372ad676a84 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 3 Oct 2020 22:15:49 +0100 Subject: [PATCH 042/103] test the correct cases --- tests/ParserLexerTest.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm index af5de7d7..e83fea21 100644 --- a/tests/ParserLexerTest.elm +++ b/tests/ParserLexerTest.elm @@ -53,7 +53,7 @@ tests = ) ) , describe "should parse" - (ParserLexerTestCases.shouldNotParseTestCases + (ParserLexerTestCases.shouldParseTestCases |> List.map (\{ name, source, lexed, contextualized } -> test name <| From 5c554b1252e7a3bb798226ce4ed5590477186d23 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sat, 3 Oct 2020 22:20:13 +0100 Subject: [PATCH 043/103] correctly lex -> items --- src/Stage/Parse/Lexer.elm | 10 ++++++---- tests/ParserLexerTestCases.elm | 18 +++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 82b29762..b4215be9 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -417,6 +417,12 @@ sigilParser = |> P.map (\() -> Operator Or) , P.symbol (P.Token ".." ExpectingSigil) |> P.map (\() -> DoubleDot) + , P.symbol (P.Token "->" ExpectingSigil) + |> P.map (\() -> ThinArrow) + , P.symbol (P.Token ">=" ExpectingSigil) + |> P.map (\() -> Operator GreaterThanEquals) + , P.symbol (P.Token "<=" ExpectingSigil) + |> P.map (\() -> Operator LessThanEquals) -- Single character sigils , P.symbol (P.Token "^" ExpectingSigil) @@ -433,10 +439,6 @@ sigilParser = |> P.map (\() -> Operator GreaterThan) , P.symbol (P.Token "<" ExpectingSigil) |> P.map (\() -> Operator LessThan) - , P.symbol (P.Token ">=" ExpectingSigil) - |> P.map (\() -> Operator GreaterThanEquals) - , P.symbol (P.Token "<=" ExpectingSigil) - |> P.map (\() -> Operator LessThanEquals) , P.symbol (P.Token "-" ExpectingSigil) |> P.map (\() -> Operator Subtract) , P.symbol (P.Token "+" ExpectingSigil) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index f0f75ba5..7e1beb62 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -117,8 +117,7 @@ shouldParseTestCases = , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Token "Int") , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Sigil (Operator Subtract)) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Operator GreaterThan)) + , Located { end = { col = 34, row = 1 }, start = { col = 32, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Token "List") , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) @@ -145,7 +144,7 @@ shouldParseTestCases = , parents = [] } ) - , Error_InvalidToken (Sigil (Operator Subtract)) Expecting_Unknown + , Error_InvalidToken (Sigil ThinArrow) Expecting_Unknown ) ] } @@ -168,8 +167,7 @@ shouldParseTestCases = , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Operator Subtract)) - , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Sigil (Operator GreaterThan)) + , Located { end = { col = 36, row = 1 }, start = { col = 34, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Token "List") , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) @@ -222,8 +220,7 @@ shouldParseTestCases = , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Whitespace 1) - , Located { end = { col = 45, row = 1 }, start = { col = 44, row = 1 } } (Sigil (Operator Subtract)) - , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Sigil (Operator GreaterThan)) + , Located { end = { col = 46, row = 1 }, start = { col = 44, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Whitespace 1) , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Sigil (Bracket Curly Close)) @@ -254,7 +251,7 @@ shouldParseTestCases = , ( "d", TypeExpression_NamedType { args = Stack [], name = "E" } ) ] ) - (Sigil (Operator Subtract)) + (Sigil ThinArrow) ) ] } @@ -274,8 +271,7 @@ shouldParseTestCases = , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Operator Subtract)) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Operator GreaterThan)) + , Located { end = { col = 28, row = 1 }, start = { col = 26, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Open)) , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") @@ -289,7 +285,7 @@ shouldParseTestCases = Just [ Err ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Function") TypeExpression_Unit) - , Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Operator Subtract)) + , Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil ThinArrow) ) ] } From da880250805dea87b40cd84472f1acef9e3bf2cd Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sun, 4 Oct 2020 16:57:40 +0100 Subject: [PATCH 044/103] include failing item in error --- parser-tests/Update.elm | 2 +- parser-tests/update.js | 2 +- src/Stage/Parse/Contextualize.elm | 39 ++- tests/ParserLexerTestCases.elm | 453 ++++++++++++++---------------- 4 files changed, 253 insertions(+), 243 deletions(-) diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index fa4a0260..7868e360 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -47,7 +47,7 @@ init snippets = snippets |> List.map (.source >> P.run Lexer.parser) - mrcontextualized : List (Maybe (List (Result ( Contextualize.State, Contextualize.Error ) Contextualize.Block))) + mrcontextualized : List (Maybe (List Contextualize.RunResult)) mrcontextualized = rlexed |> List.map diff --git a/parser-tests/update.js b/parser-tests/update.js index 7d58e2b6..2fe91a10 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -19,7 +19,7 @@ const warningCommentLines = ` const TYPE_OF_RESULT_CASES = ` List - { contextualized : Maybe (List (Result (State, Error) Block)) + { contextualized : Maybe (List Contextualize.RunResult) , lexed : Result Never (List (Located LexItem)) , name : String , source : String diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index e65f5720..2508c539 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -91,7 +91,7 @@ type ParseResult type alias State_ = - { previousBlocks : List (Result ( State, Error ) Block) + { previousBlocks : List RunResult , state : State } @@ -212,7 +212,16 @@ type Expecting -- exported functions -run : List LexItem -> List (Result ( State, Error ) Block) +type alias RunResult = + Result + { state : State + , item : Maybe =LexItem + , error : Error + } + Block + + +run : List LexItem -> List RunResult run items = runHelp items @@ -221,7 +230,7 @@ run items = } -runHelp : List LexItem -> State_ -> List (Result ( State, Error ) Block) +runHelp : List LexItem -> State_ -> List RunResult runHelp items state = case items of item :: rest -> @@ -243,7 +252,13 @@ runHelp items state = ParseResult_Err error -> runHelp rest - { previousBlocks = Err ( state.state, error ) :: state.previousBlocks + { previousBlocks = + Err + { state = state.state + , item = Just item + , error = error + } + :: state.previousBlocks , state = case item of Lexer.Newlines _ 0 -> @@ -258,7 +273,11 @@ runHelp items state = runHelp [{- An empty list to abort parsing. -}] { previousBlocks = - Err ( state.state, Error_Panic error ) + Err + { state = state.state + , item = Just item + , error = Error_Panic error + } :: state.previousBlocks , state = State_Error_Recovery } @@ -275,7 +294,15 @@ runHelp items state = state.previousBlocks Just newBlock -> - (newBlock |> Result.mapError (\err -> ( state.state, err ))) + (newBlock + |> Result.mapError + (\err -> + { state = state.state + , item = Nothing + , error = err + } + ) + ) :: state.previousBlocks ) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 7e1beb62..3d00222c 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -19,7 +19,7 @@ import Test exposing (Test, describe, test) shouldParseTestCases : List - { contextualized : Maybe (List (Result ( State, Error ) Block)) + { contextualized : Maybe (List Contextualize.RunResult) , lexed : Result Never (List (Located LexItem)) , name : String , source : String @@ -131,21 +131,23 @@ shouldParseTestCases = , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function") - { nesting = - NestingLeafType_TypeWithArgs - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - , name = "List" - } - , parents = [] - } - ) - , Error_InvalidToken (Sigil ThinArrow) Expecting_Unknown - ) + { error = Error_InvalidToken (Sigil ThinArrow) Expecting_Unknown + , item = Just (Sigil ThinArrow) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function") + { nesting = + NestingLeafType_TypeWithArgs + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , name = "List" + } + , parents = [] + } + ) + } ] } , { name = "type-alias-function-generic" @@ -180,10 +182,7 @@ shouldParseTestCases = ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function")) - , Error_InvalidToken (Token "a") (Expecting_Sigil Assign) - ) + [ Err { error = Error_InvalidToken (Token "a") (Expecting_Sigil Assign), item = Just (Token "a"), state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function")) } ] } , { name = "type-alias-function-record" @@ -229,8 +228,8 @@ shouldParseTestCases = , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Complete (TypeOrConstructor "Function") + { error = + Error_ExtraItemAfterBlock (TypeExpression_Record [ ( "a" , TypeExpression_Record @@ -240,19 +239,22 @@ shouldParseTestCases = , ( "d", TypeExpression_NamedType { args = Stack [], name = "E" } ) ] ) - ) - , Error_ExtraItemAfterBlock - (TypeExpression_Record - [ ( "a" - , TypeExpression_Record - [ ( "b", TypeExpression_NamedType { args = Stack [], name = "C" } ) + (Sigil ThinArrow) + , item = Just (Sigil ThinArrow) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Complete (TypeOrConstructor "Function") + (TypeExpression_Record + [ ( "a" + , TypeExpression_Record + [ ( "b", TypeExpression_NamedType { args = Stack [], name = "C" } ) + ] + ) + , ( "d", TypeExpression_NamedType { args = Stack [], name = "E" } ) ] - ) - , ( "d", TypeExpression_NamedType { args = Stack [], name = "E" } ) - ] - ) - (Sigil ThinArrow) - ) + ) + ) + } ] } , { name = "type-alias-function-tuple" @@ -283,10 +285,7 @@ shouldParseTestCases = ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Function") TypeExpression_Unit) - , Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil ThinArrow) - ) + [ Err { error = Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil ThinArrow), item = Just (Sigil ThinArrow), state = State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Function") TypeExpression_Unit) } ] } , { name = "type-alias-funky-indentation" @@ -967,7 +966,7 @@ type alias Hi = ((), (), ()) shouldNotParseTestCases : List - { contextualized : Maybe (List (Result ( State, Error ) Block)) + { contextualized : Maybe (List Contextualize.RunResult) , lexed : Result Never (List (Located LexItem)) , name : String , source : String @@ -996,10 +995,7 @@ shouldNotParseTestCases = ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" }))) - , Error_ExtraItemAfterBlock (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) (Sigil (Bracket Round Open)) - ) + [ Err { error = Error_ExtraItemAfterBlock (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) (Sigil (Bracket Round Open)), item = Just (Sigil (Bracket Round Open)), state = State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" }))) } ] } , { name = "type-alias-invalid-multiple-brackets-2" @@ -1024,10 +1020,7 @@ shouldNotParseTestCases = ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") TypeExpression_Unit) - , Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Bracket Round Open)) - ) + [ Err { error = Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Bracket Round Open)), item = Just (Sigil (Bracket Round Open)), state = State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") TypeExpression_Unit) } ] } , { name = "type-alias-invalid-multiple-brackets-3" @@ -1053,10 +1046,7 @@ shouldNotParseTestCases = ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") TypeExpression_Unit) - , Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Bracket Round Open)) - ) + [ Err { error = Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Bracket Round Open)), item = Just (Sigil (Bracket Round Open)), state = State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") TypeExpression_Unit) } ] } , { name = "type-alias-multiline-missing-indentation" @@ -1080,14 +1070,8 @@ List Int ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")) - , Error_PartwayThroughTypeAlias - ) - , Err - ( State_BlockStart - , Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") - ) + [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")) } + , Err { error = Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List"), item = Just (Token "List"), state = State_BlockStart } ] } , { name = "type-alias-partial" @@ -1102,10 +1086,7 @@ List Int ] , contextualized = Just - [ Err - ( State_BlockTypeAlias BlockTypeAlias_Keywords - , Error_PartwayThroughTypeAlias - ) + [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias BlockTypeAlias_Keywords } ] } , { name = "type-alias-partial-2" @@ -1122,10 +1103,7 @@ List Int ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")) - , Error_PartwayThroughTypeAlias - ) + [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")) } ] } , { name = "type-alias-partial-3" @@ -1144,10 +1122,7 @@ List Int ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")) - , Error_PartwayThroughTypeAlias - ) + [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")) } ] } , { name = "type-alias-partial-with-bracket" @@ -1168,10 +1143,7 @@ List Int ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) - , Error_PartwayThroughTypeAlias - ) + [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) } ] } , { name = "type-alias-partial-with-bracket-2" @@ -1196,16 +1168,18 @@ List Int , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nesting = NestingLeafType_TypeWithArgs { args = Stack [], name = "Int" } - , parents = - [ NestingParentType_Bracket (Stack []) - ] - } - ) - , Error_PartwayThroughTypeAlias - ) + { error = Error_PartwayThroughTypeAlias + , item = Just (Newlines [] 0) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nesting = NestingLeafType_TypeWithArgs { args = Stack [], name = "Int" } + , parents = + [ NestingParentType_Bracket (Stack []) + ] + } + ) + } ] } , { name = "type-alias-record-half-empty" @@ -1226,10 +1200,7 @@ List Int ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) - , Error_PartwayThroughTypeAlias - ) + [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) } ] } , { name = "type-alias-record-missing-colon" @@ -1256,10 +1227,7 @@ List Int ] , contextualized = Just - [ Err - ( State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) - , Error_ExpectedColonWhilstParsingRecord - ) + [ Err { error = Error_ExpectedColonWhilstParsingRecord, item = Just (Token "j7"), state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) } ] } , { name = "type-alias-with-quadruple" @@ -1342,121 +1310,127 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Complete (TypeOrConstructor "Hi") - (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) - (TypeExpression_NamedType { args = Stack [], name = "A" }) - [ TypeExpression_NamedType { args = Stack [], name = "B" } - , TypeExpression_NamedType { args = Stack [], name = "C" } - , TypeExpression_NamedType { args = Stack [], name = "D" } - ] + { error = + Error_TooManyTupleArgs (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) + (UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing }) + (UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing }) + (UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing }) + [ UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } + ] + , item = Just (Newlines [] 0) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Complete (TypeOrConstructor "Hi") + (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) + (TypeExpression_NamedType { args = Stack [], name = "A" }) + [ TypeExpression_NamedType { args = Stack [], name = "B" } + , TypeExpression_NamedType { args = Stack [], name = "C" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + ) ) - ) - , Error_TooManyTupleArgs (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) - (UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing }) - (UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing }) - (UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing }) - [ UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } - ] - ) + } , Err - ( State_BlockTypeAlias - (BlockTypeAlias_Complete (TypeOrConstructor "Hi") - (TypeExpression_Tuple - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - , name = "A" - } - ) - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "F" } - , TypeExpression_NamedType { args = Stack [], name = "E" } - , TypeExpression_NamedType { args = Stack [], name = "D" } + { error = + Error_TooManyTupleArgs + (UserDefinedType + { args = + [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + ] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = + [ UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "F", qualifiedness = PossiblyQualified Nothing } + ] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = + [ UserDefinedType { args = [], name = "I", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType + { args = + [ UserDefinedType { args = [], name = "K", qualifiedness = PossiblyQualified Nothing } ] - , name = "C" - } + , name = "J" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "H" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = + [ UserDefinedType { args = [], name = "M", qualifiedness = PossiblyQualified Nothing } + , Unit + , UserDefinedType { args = [], name = "O", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType { args = [], name = "P", qualifiedness = PossiblyQualified Nothing } + ] + , name = "L" + , qualifiedness = PossiblyQualified Nothing + } + ) + [] + , item = Just (Newlines [] 0) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Complete (TypeOrConstructor "Hi") + (TypeExpression_Tuple + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , name = "A" + } + ) + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "F" } + , TypeExpression_NamedType { args = Stack [], name = "E" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + , name = "C" + } + ) + [ TypeExpression_NamedType + { args = + Stack + [ TypeExpression_Bracketed + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "K" } + ] + , name = "J" + } + ) + , TypeExpression_NamedType { args = Stack [], name = "I" } + ] + , name = "H" + } + , TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "P" } + , TypeExpression_NamedType { args = Stack [], name = "O" } + , TypeExpression_Unit + , TypeExpression_NamedType { args = Stack [], name = "M" } + ] + , name = "L" + } + ] ) - [ TypeExpression_NamedType - { args = - Stack - [ TypeExpression_Bracketed - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "K" } - ] - , name = "J" - } - ) - , TypeExpression_NamedType { args = Stack [], name = "I" } - ] - , name = "H" - } - , TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "P" } - , TypeExpression_NamedType { args = Stack [], name = "O" } - , TypeExpression_Unit - , TypeExpression_NamedType { args = Stack [], name = "M" } - ] - , name = "L" - } - ] ) - ) - , Error_TooManyTupleArgs - (UserDefinedType - { args = - [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } - ] - , name = "A" - , qualifiedness = PossiblyQualified Nothing - } - ) - (UserDefinedType - { args = - [ UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "F", qualifiedness = PossiblyQualified Nothing } - ] - , name = "C" - , qualifiedness = PossiblyQualified Nothing - } - ) - (UserDefinedType - { args = - [ UserDefinedType { args = [], name = "I", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType - { args = - [ UserDefinedType { args = [], name = "K", qualifiedness = PossiblyQualified Nothing } - ] - , name = "J" - , qualifiedness = PossiblyQualified Nothing - } - ] - , name = "H" - , qualifiedness = PossiblyQualified Nothing - } - ) - (UserDefinedType - { args = - [ UserDefinedType { args = [], name = "M", qualifiedness = PossiblyQualified Nothing } - , Unit - , UserDefinedType { args = [], name = "O", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "P", qualifiedness = PossiblyQualified Nothing } - ] - , name = "L" - , qualifiedness = PossiblyQualified Nothing - } - ) - [] - ) + } ] } , { name = "type-alias-with-tuple-double-comma" @@ -1485,20 +1459,22 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nesting = - NestingLeafType_Bracket - (Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - ) - Nothing - , parents = [] - } - ) - , Error_InvalidToken (Sigil Comma) Expecting_Unknown - ) + { error = Error_InvalidToken (Sigil Comma) Expecting_Unknown + , item = Just (Sigil Comma) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nesting = + NestingLeafType_Bracket + (Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + ) + Nothing + , parents = [] + } + ) + } ] } , { name = "type-alias-with-tuple-not-closed" @@ -1532,20 +1508,30 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , contextualized = Just [ Err - ( State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") - { nesting = - NestingLeafType_Bracket - (Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - ) - Nothing - , parents = [] - } - ) - , Error_PartwayThroughTypeAlias - ) + { error = Error_PartwayThroughTypeAlias + , item = + Just + (Newlines + [ 0 + , 0 + , 0 + ] + 0 + ) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nesting = + NestingLeafType_Bracket + (Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + ) + Nothing + , parents = [] + } + ) + } ] } , { name = "type-partial" @@ -1558,10 +1544,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , contextualized = Just - [ Err - ( State_BlockFirstItem BlockFirstItem_Type - , Error_PartwayThroughTypeAlias - ) + [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockFirstItem BlockFirstItem_Type } ] } ] From d98c20d890f756349050f1e20ab65c0bc7d0a725 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 11:20:03 +0100 Subject: [PATCH 045/103] first attempt at parsing function types --- parser-tests/Update.elm | 2 + parser-tests/update.js | 2 +- src/Stage/Parse/Contextualize.elm | 539 +++++++++++++++++++++--------- tests/ParserLexerTestCases.elm | 288 ++++++++++------ 4 files changed, 556 insertions(+), 275 deletions(-) diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 7868e360..d936dd2f 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -109,3 +109,5 @@ preFormatElmCode = ]""" "[]" >> String.replace """Err (""" """Err ( """ + >> String.replace """Err {""" """Err { + """ diff --git a/parser-tests/update.js b/parser-tests/update.js index 2fe91a10..662113e1 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -80,7 +80,7 @@ async function main() { snippets.map(async ([category, snippets2]) => [category, await getTestCase(snippets2)]) ); - if (testCases.some((tests) => tests.includes('Panic'))) { + if (testCases.some(([_, tests]) => tests.includes('Panic'))) { console.error('ERROR: One or more test cases panicked!'); process.exitCode = 1; } diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 2508c539..843873da 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -131,6 +131,10 @@ type PartialTypeExpression | TypeExpression_Bracketed PartialTypeExpression | TypeExpression_Tuple PartialTypeExpression PartialTypeExpression (List PartialTypeExpression) | TypeExpression_Record (List ( String, PartialTypeExpression )) + | TypeExpression_Function + { firstInput : PartialTypeExpression + , output : PartialTypeExpression + } type LastEntryOfRecord @@ -156,6 +160,7 @@ type NestingParentType { name : String , args : Stack PartialTypeExpression } + | NestingParentType_Function { firstInput : PartialTypeExpression } type NestingLeafType @@ -165,6 +170,11 @@ type NestingLeafType { name : String , args : Stack PartialTypeExpression } + | NestingLeafType_Function + { firstInput : PartialTypeExpression + , output : Maybe PartialTypeExpression + } + | NestingLeafType_Expr PartialTypeExpression type alias PartialTypeExpressionLeaf = @@ -187,6 +197,7 @@ type Error | Error_ExpectedColonWhilstParsingRecord | Error_ExpectedKeyWhilstParsingRecord | Error_TypeDoesNotTakeArgs PartialTypeExpression PartialTypeExpression + | Error_TypeDoesNotTakeArgs2 PartialTypeExpression | Error_ExtraItemAfterBlock PartialTypeExpression Lexer.LexItem | Error_TooManyTupleArgs -- @@ -215,7 +226,7 @@ type Expecting type alias RunResult = Result { state : State - , item : Maybe =LexItem + , item : Maybe LexItem , error : Error } Block @@ -314,17 +325,24 @@ runHelp items state = parseAnything : State -> LexItem -> ParseResult parseAnything state = let - newTypeAliasState name res = + newTypeAliasState aliasName res = case res of TypeExpressionResult_Progress expr -> - State_BlockTypeAlias (BlockTypeAlias_Completish name expr) + State_BlockTypeAlias (BlockTypeAlias_Completish aliasName expr) |> ParseResult_Ok TypeExpressionResult_Done expr -> - expr - |> BlockTypeAlias_Complete name - |> State_BlockTypeAlias - |> ParseResult_Ok + case partialTypeExpressionToConcreteType expr of + Ok concreteType -> + { ty = aliasName + , expr = concreteType + } + |> TypeAlias + |> ParseResult_Complete + + Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> + Error_TooManyTupleArgs a b c d e + |> ParseResult_Err in case state of State_Error_Recovery -> @@ -585,86 +603,105 @@ parserTypeExpr newState mPrevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> case mPrevExpr of Just prevExpr -> - case autoCollapseNesting prevExpr of - TypeExpressionResult_Done expr -> + let + collapsedLeaf = + autoCollapseNesting prevExpr + in + case collapsedLeaf.nesting of + NestingLeafType_Expr expr -> Error_UnmatchedBracket Lexer.Round Lexer.Close |> ParseResult_Err - TypeExpressionResult_Progress collapsedLeaf -> - case collapsedLeaf.nesting of - NestingLeafType_TypeWithArgs { name, args } -> - Debug.todo "Make this state impossible" + NestingLeafType_TypeWithArgs { name, args } -> + Debug.todo "Make this state impossible" + + NestingLeafType_Bracket argStack mLastExpression -> + let + rexpr = + if argStack /= empty && mLastExpression == Nothing then + -- We have a trailing comma! + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> Err + + else + let + fullArgsList = + (case mLastExpression of + Just expr -> + expr |> pushOnto argStack + + Nothing -> + argStack + ) + |> toList (\x -> x) + in + case fullArgsList of + [] -> + TypeExpression_Unit + |> Ok + + first :: [] -> + TypeExpression_Bracketed first + |> Ok + + first :: second :: rest -> + TypeExpression_Tuple first second rest + |> Ok + in + case rexpr of + Ok expr -> + case collapsedLeaf.parents of + nesting :: grandparents -> + { nesting = + case nesting of + NestingParentType_PartialRecord { firstEntries, lastEntryName } -> + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr + } - NestingLeafType_Bracket argStack mLastExpression -> - let - rexpr = - if argStack /= empty && mLastExpression == Nothing then - -- We have a trailing comma! - Error_UnmatchedBracket Lexer.Round Lexer.Close - |> Err - - else - let - fullArgsList = - (case mLastExpression of - Just expr -> - expr |> pushOnto argStack - - Nothing -> - argStack - ) - |> toList (\x -> x) - in - case fullArgsList of - [] -> - TypeExpression_Unit - |> Ok - - first :: [] -> - TypeExpression_Bracketed first - |> Ok - - first :: second :: rest -> - TypeExpression_Tuple first second rest - |> Ok - in - case rexpr of - Ok expr -> - case collapsedLeaf.parents of - nesting :: grandparents -> - { nesting = - case nesting of - NestingParentType_PartialRecord { firstEntries, lastEntryName } -> - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr - } - - NestingParentType_Bracket els -> - NestingLeafType_Bracket els (Just expr) - - NestingParentType_TypeWithArgs { name, args } -> - NestingLeafType_TypeWithArgs - { name = name - , args = expr |> pushOnto args - } - , parents = grandparents - } - |> TypeExpressionResult_Progress - |> newState + NestingParentType_Bracket els -> + NestingLeafType_Bracket els (Just expr) - [] -> - expr - |> TypeExpressionResult_Done - |> newState + NestingParentType_TypeWithArgs { name, args } -> + NestingLeafType_TypeWithArgs + { name = name + , args = expr |> pushOnto args + } - Err e -> - ParseResult_Err e + NestingParentType_Function { firstInput } -> + NestingLeafType_Function + { firstInput = firstInput + , output = Just expr + } + , parents = grandparents + } + |> TypeExpressionResult_Progress + |> newState + + [] -> + { nesting = NestingLeafType_Expr expr + , parents = [] + } + |> TypeExpressionResult_Progress + |> newState + + Err e -> + ParseResult_Err e + + NestingLeafType_PartialRecord _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err - NestingLeafType_PartialRecord _ -> + NestingLeafType_Function { output } -> + case output of + Nothing -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err + Just _ -> + Debug.todo "Make this state impossible" + Nothing -> Error_UnmatchedBracket Lexer.Round Lexer.Close |> ParseResult_Err @@ -739,11 +776,7 @@ parserTypeExpr newState mPrevExpr item = |> ParseResult_Err in case mPrevExpr |> Maybe.map autoCollapseNesting of - Just (TypeExpressionResult_Done expr) -> - Error_UnmatchedBracket Lexer.Curly Lexer.Close - |> ParseResult_Err - - Just (TypeExpressionResult_Progress collapsedLeaf) -> + Just collapsedLeaf -> case collapsedLeaf.nesting of NestingLeafType_PartialRecord existingPartialRecord -> getNewPartialRecord collapsedLeaf.parents existingPartialRecord @@ -767,91 +800,152 @@ parserTypeExpr newState mPrevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> case mPrevExpr of Just prevExpr -> - case autoCollapseNesting prevExpr of - TypeExpressionResult_Done expr -> + let + collapsedLeaf = + autoCollapseNesting prevExpr + in + case collapsedLeaf.nesting of + NestingLeafType_Expr expr -> Error_UnmatchedBracket Lexer.Curly Lexer.Close |> ParseResult_Err - TypeExpressionResult_Progress collapsedLeaf -> - case collapsedLeaf.nesting of - NestingLeafType_TypeWithArgs { name, args } -> - Debug.todo "Make this state impossible" + NestingLeafType_TypeWithArgs { name, args } -> + Debug.todo "Make this state impossible" - NestingLeafType_Bracket argStack mLastExpression -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + NestingLeafType_Bracket argStack mLastExpression -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err - NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + let + fromRecord recordEntries = let - fromRecord recordEntries = - let - record = - TypeExpression_Record recordEntries - in - case collapsedLeaf.parents of - [] -> - record - |> TypeExpressionResult_Done - |> newState - - nesting :: grandparents -> - (case nesting of - -- We are within a nested bracket. - NestingParentType_Bracket argStack -> - { parents = grandparents - , nesting = NestingLeafType_Bracket argStack (Just record) + record = + TypeExpression_Record recordEntries + in + case collapsedLeaf.parents of + [] -> + { nesting = NestingLeafType_Expr record + , parents = [] + } + |> TypeExpressionResult_Progress + |> newState + + nesting :: grandparents -> + (case nesting of + -- We are within a nested bracket. + NestingParentType_Bracket argStack -> + { parents = grandparents + , nesting = NestingLeafType_Bracket argStack (Just record) + } + + NestingParentType_PartialRecord existingPartialRecord -> + { parents = grandparents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = existingPartialRecord.firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue + existingPartialRecord.lastEntryName + record } + } - NestingParentType_PartialRecord existingPartialRecord -> - { parents = grandparents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = existingPartialRecord.firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue - existingPartialRecord.lastEntryName - record - } + NestingParentType_TypeWithArgs { name, args } -> + { nesting = + NestingLeafType_TypeWithArgs + { name = name + , args = + record + |> pushOnto args } + , parents = grandparents + } - NestingParentType_TypeWithArgs { name, args } -> - { nesting = - NestingLeafType_TypeWithArgs - { name = name - , args = - record - |> pushOnto args - } - , parents = grandparents + NestingParentType_Function { firstInput } -> + { nesting = + NestingLeafType_Function + { firstInput = firstInput + , output = Just record } - ) - |> TypeExpressionResult_Progress - |> newState - in - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - ( key, value ) - |> pushOnto firstEntries - |> toList (\x -> x) - |> fromRecord - - LastEntryOfRecord_Empty -> - if firstEntries == empty then - [] - |> fromRecord - - else - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + , parents = grandparents + } + ) + |> TypeExpressionResult_Progress + |> newState + in + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + ( key, value ) + |> pushOnto firstEntries + |> toList (\x -> x) + |> fromRecord + + LastEntryOfRecord_Empty -> + if firstEntries == empty then + [] + |> fromRecord + + else + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + NestingLeafType_Function { output } -> + case output of + Nothing -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Just _ -> + Debug.todo "Make this state impossible" Nothing -> Error_UnmatchedBracket Lexer.Curly Lexer.Close |> ParseResult_Err + Lexer.Sigil Lexer.ThinArrow -> + let + getNewPartialRecord parents { firstEntries, lastEntry } = + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + { parents = parents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = ( key, value ) |> pushOnto firstEntries + , lastEntry = LastEntryOfRecord_Empty + } + } + |> TypeExpressionResult_Progress + |> newState + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + in + case mPrevExpr |> Maybe.map (autoCollapseNesting >> .nesting) of + Just (NestingLeafType_Expr expr) -> + { nesting = + NestingLeafType_Function + { firstInput = expr + , output = Nothing + } + , parents = [] + } + |> TypeExpressionResult_Progress + |> newState + + Just _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Nothing -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + Lexer.Newlines _ 0 -> case mPrevExpr of Nothing -> @@ -859,12 +953,12 @@ parserTypeExpr newState mPrevExpr item = |> ParseResult_Err Just prevExpr -> - case autoCollapseNesting prevExpr of - TypeExpressionResult_Done expr -> + case (autoCollapseNesting prevExpr).nesting of + NestingLeafType_Expr expr -> TypeExpressionResult_Done expr |> newState - TypeExpressionResult_Progress collapsedLeaf -> + _ -> Error_PartwayThroughTypeAlias |> ParseResult_Err @@ -887,9 +981,14 @@ leafToParents leaf = Just { parents, nesting } -> (case nesting of + NestingLeafType_Expr expr -> + -- Cannot nest unless there is a trailing comma! + Error_TypeDoesNotTakeArgs2 expr + |> Err + NestingLeafType_Bracket _ (Just lastType) -> -- Cannot nest unless there is a trailing comma! - Error_TypeDoesNotTakeArgs lastType (Debug.todo "") + Error_TypeDoesNotTakeArgs2 lastType |> Err NestingLeafType_Bracket els Nothing -> @@ -911,12 +1010,22 @@ leafToParents leaf = |> Ok LastEntryOfRecord_KeyValue _ lastValueType -> - Error_TypeDoesNotTakeArgs lastValueType (Debug.todo "") + Error_TypeDoesNotTakeArgs2 lastValueType |> Err NestingLeafType_TypeWithArgs details -> NestingParentType_TypeWithArgs details |> Ok + + NestingLeafType_Function { firstInput, output } -> + case output of + Nothing -> + NestingParentType_Function { firstInput = firstInput } + |> Ok + + Just te -> + Error_TypeDoesNotTakeArgs2 te + |> Err ) |> Result.map (\n -> n :: parents) @@ -955,6 +1064,10 @@ exprAppend ({ parents, nesting } as currentLeaf) token = Error_TypeDoesNotTakeArgs TypeExpression_Unit newType |> Err + NestingLeafType_Expr expr -> + Error_TypeDoesNotTakeArgs expr newType + |> Err + NestingLeafType_PartialRecord pr -> case pr.lastEntry of LastEntryOfRecord_Empty -> @@ -992,6 +1105,31 @@ exprAppend ({ parents, nesting } as currentLeaf) token = } |> Ok + (NestingLeafType_Function { firstInput, output }) as lt -> + Result.map2 + (\newOutput newParents -> + { parents = newParents + , nesting = + NestingLeafType_TypeWithArgs + { name = token + , args = empty + } + } + ) + (case output of + Just outputExpr -> + Error_TypeDoesNotTakeArgs outputExpr newType + |> Err + + Nothing -> + NestingLeafType_TypeWithArgs + { name = token + , args = empty + } + |> Ok + ) + (leafToParents (Just currentLeaf)) + blockFromState : State -> Maybe (Result Error Block) blockFromState state = @@ -1021,8 +1159,8 @@ blockFromState state = |> Just State_BlockTypeAlias (BlockTypeAlias_Completish aliasName partialExpr) -> - case autoCollapseNesting partialExpr of - TypeExpressionResult_Done expr -> + case (autoCollapseNesting partialExpr).nesting of + NestingLeafType_Expr expr -> partialTypeExpressionToConcreteType expr |> Result.map (\conceteType -> @@ -1034,7 +1172,7 @@ blockFromState state = |> Result.mapError (\(ToConcreteTypeError_TooManyTupleArgs a b c d e) -> Error_TooManyTupleArgs a b c d e) |> Just - TypeExpressionResult_Progress collapsedLeaf -> + _ -> Error_PartwayThroughTypeAlias |> Err |> Just @@ -1102,7 +1240,7 @@ addToPartialRecord token { firstEntries, lastEntry } = |> Err -autoCollapseNesting : PartialTypeExpressionLeaf -> TypeExpressionResult +autoCollapseNesting : PartialTypeExpressionLeaf -> PartialTypeExpressionLeaf autoCollapseNesting pte = case pte.nesting of NestingLeafType_TypeWithArgs { name, args } -> @@ -1118,6 +1256,12 @@ autoCollapseNesting pte = NestingParentType_TypeWithArgs _ -> Debug.todo "Make this state impossible" + NestingParentType_Function { firstInput } -> + NestingLeafType_Function + { firstInput = firstInput + , output = Just newTypeExpr + } + NestingParentType_Bracket els -> NestingLeafType_Bracket els (Just newTypeExpr) @@ -1130,13 +1274,58 @@ autoCollapseNesting pte = |> autoCollapseNesting [] -> - TypeExpressionResult_Done newTypeExpr + { nesting = NestingLeafType_Expr newTypeExpr + , parents = [] + } + + NestingLeafType_Expr _ -> + pte NestingLeafType_Bracket _ _ -> - TypeExpressionResult_Progress pte + pte NestingLeafType_PartialRecord _ -> - TypeExpressionResult_Progress pte + pte + + NestingLeafType_Function { firstInput, output } -> + case output of + Nothing -> + pte + + Just outputExpr -> + let + newTypeExpr = + TypeExpression_Function + { firstInput = firstInput + , output = outputExpr + } + in + case pte.parents of + nesting :: grandparents -> + { parents = grandparents + , nesting = + case nesting of + NestingParentType_TypeWithArgs _ -> + Debug.todo "Make this state impossible" + + NestingParentType_Function _ -> + Debug.todo "Make this state impossible" + + NestingParentType_Bracket els -> + NestingLeafType_Bracket els (Just newTypeExpr) + + NestingParentType_PartialRecord { firstEntries, lastEntryName } -> + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyValue lastEntryName newTypeExpr + } + } + |> autoCollapseNesting + + [] -> + { nesting = NestingLeafType_Expr newTypeExpr + , parents = [] + } {-| TODO(harry): We can add things to a tuple too! Rename this function @@ -1229,6 +1418,30 @@ partialTypeExpressionToConcreteType pte = |> ConcreteType.Record ) + TypeExpression_Function functionTypeExpr -> + let + folder : + ConcreteType a + -> (ConcreteType a -> ConcreteType a) + -> (ConcreteType a -> ConcreteType a) + folder nextArg createConcreteFunction someOutput = + createConcreteFunction + (ConcreteType.Function + { from = nextArg + , to = someOutput + } + ) + in + Result.map2 + (\concreteFirstInput concreteOutput -> + ConcreteType.Function + { from = concreteFirstInput + , to = concreteOutput + } + ) + (partialTypeExpressionToConcreteType functionTypeExpr.firstInput) + (partialTypeExpressionToConcreteType functionTypeExpr.output) + recoverErrors : ParseResult -> ParseResult recoverErrors res = diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 3d00222c..17a96e5d 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -130,24 +130,36 @@ shouldParseTestCases = ] , contextualized = Just - [ Err - { error = Error_InvalidToken (Sigil ThinArrow) Expecting_Unknown - , item = Just (Sigil ThinArrow) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function") - { nesting = - NestingLeafType_TypeWithArgs + [ Ok + (TypeAlias + { expr = + Function + { from = + UserDefinedType { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] + [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + ] , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , to = + UserDefinedType + { args = + [ UserDefinedType + { args = + [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing } - , parents = [] } - ) - } + , ty = TypeOrConstructor "Function" + } + ) ] } , { name = "type-alias-function-generic" @@ -182,7 +194,11 @@ shouldParseTestCases = ] , contextualized = Just - [ Err { error = Error_InvalidToken (Token "a") (Expecting_Sigil Assign), item = Just (Token "a"), state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function")) } + [ Err + { error = Error_InvalidToken (Token "a") (Expecting_Sigil Assign) + , item = Just (Token "a") + , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function")) + } ] } , { name = "type-alias-function-record" @@ -227,34 +243,28 @@ shouldParseTestCases = ] , contextualized = Just - [ Err - { error = - Error_ExtraItemAfterBlock - (TypeExpression_Record - [ ( "a" - , TypeExpression_Record - [ ( "b", TypeExpression_NamedType { args = Stack [], name = "C" } ) - ] - ) - , ( "d", TypeExpression_NamedType { args = Stack [], name = "E" } ) - ] - ) - (Sigil ThinArrow) - , item = Just (Sigil ThinArrow) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Complete (TypeOrConstructor "Function") - (TypeExpression_Record - [ ( "a" - , TypeExpression_Record - [ ( "b", TypeExpression_NamedType { args = Stack [], name = "C" } ) + [ Ok + (TypeAlias + { expr = + Function + { from = + Record + (Dict.fromList + [ ( "a" + , Record + (Dict.fromList + [ ( "b", UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } ) + ] + ) + ) + , ( "d", UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } ) ] - ) - , ( "d", TypeExpression_NamedType { args = Stack [], name = "E" } ) - ] - ) - ) - } + ) + , to = Record (Dict.fromList []) + } + , ty = TypeOrConstructor "Function" + } + ) ] } , { name = "type-alias-function-tuple" @@ -285,7 +295,7 @@ shouldParseTestCases = ] , contextualized = Just - [ Err { error = Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil ThinArrow), item = Just (Sigil ThinArrow), state = State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Function") TypeExpression_Unit) } + [ Ok (TypeAlias { expr = Function { from = Unit, to = Tuple (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "String", qualifiedness = PossiblyQualified Nothing }) }, ty = TypeOrConstructor "Function" }) ] } , { name = "type-alias-funky-indentation" @@ -995,7 +1005,11 @@ shouldNotParseTestCases = ] , contextualized = Just - [ Err { error = Error_ExtraItemAfterBlock (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) (Sigil (Bracket Round Open)), item = Just (Sigil (Bracket Round Open)), state = State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" }))) } + [ Err + { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) + , item = Just (Sigil (Bracket Round Open)) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) + } ] } , { name = "type-alias-invalid-multiple-brackets-2" @@ -1020,7 +1034,11 @@ shouldNotParseTestCases = ] , contextualized = Just - [ Err { error = Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Bracket Round Open)), item = Just (Sigil (Bracket Round Open)), state = State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") TypeExpression_Unit) } + [ Err + { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit + , item = Just (Sigil (Bracket Round Open)) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) + } ] } , { name = "type-alias-invalid-multiple-brackets-3" @@ -1046,7 +1064,11 @@ shouldNotParseTestCases = ] , contextualized = Just - [ Err { error = Error_ExtraItemAfterBlock TypeExpression_Unit (Sigil (Bracket Round Open)), item = Just (Sigil (Bracket Round Open)), state = State_BlockTypeAlias (BlockTypeAlias_Complete (TypeOrConstructor "Hi") TypeExpression_Unit) } + [ Err + { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit + , item = Just (Sigil (Bracket Round Open)) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) + } ] } , { name = "type-alias-multiline-missing-indentation" @@ -1070,8 +1092,16 @@ List Int ] , contextualized = Just - [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")) } - , Err { error = Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List"), item = Just (Token "List"), state = State_BlockStart } + [ Err + { error = Error_PartwayThroughTypeAlias + , item = Just (Newlines [] 0) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")) + } + , Err + { error = Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") + , item = Just (Token "List") + , state = State_BlockStart + } ] } , { name = "type-alias-partial" @@ -1086,7 +1116,11 @@ List Int ] , contextualized = Just - [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias BlockTypeAlias_Keywords } + [ Err + { error = Error_PartwayThroughTypeAlias + , item = Just (Newlines [] 0) + , state = State_BlockTypeAlias BlockTypeAlias_Keywords + } ] } , { name = "type-alias-partial-2" @@ -1103,7 +1137,11 @@ List Int ] , contextualized = Just - [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")) } + [ Err + { error = Error_PartwayThroughTypeAlias + , item = Just (Newlines [] 0) + , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")) + } ] } , { name = "type-alias-partial-3" @@ -1122,7 +1160,11 @@ List Int ] , contextualized = Just - [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")) } + [ Err + { error = Error_PartwayThroughTypeAlias + , item = Just (Newlines [] 0) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")) + } ] } , { name = "type-alias-partial-with-bracket" @@ -1143,7 +1185,11 @@ List Int ] , contextualized = Just - [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) } + [ Err + { error = Error_PartwayThroughTypeAlias + , item = Just (Newlines [] 0) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) + } ] } , { name = "type-alias-partial-with-bracket-2" @@ -1200,7 +1246,11 @@ List Int ] , contextualized = Just - [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) } + [ Err + { error = Error_PartwayThroughTypeAlias + , item = Just (Newlines [] 0) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) + } ] } , { name = "type-alias-record-missing-colon" @@ -1227,7 +1277,11 @@ List Int ] , contextualized = Just - [ Err { error = Error_ExpectedColonWhilstParsingRecord, item = Just (Token "j7"), state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) } + [ Err + { error = Error_ExpectedColonWhilstParsingRecord + , item = Just (Token "j7") + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) + } ] } , { name = "type-alias-with-quadruple" @@ -1320,14 +1374,18 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Newlines [] 0) , state = State_BlockTypeAlias - (BlockTypeAlias_Complete (TypeOrConstructor "Hi") - (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) - (TypeExpression_NamedType { args = Stack [], name = "A" }) - [ TypeExpression_NamedType { args = Stack [], name = "B" } - , TypeExpression_NamedType { args = Stack [], name = "C" } - , TypeExpression_NamedType { args = Stack [], name = "D" } - ] - ) + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nesting = + NestingLeafType_Expr + (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) + (TypeExpression_NamedType { args = Stack [], name = "A" }) + [ TypeExpression_NamedType { args = Stack [], name = "B" } + , TypeExpression_NamedType { args = Stack [], name = "C" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + ) + , parents = [] + } ) } , Err @@ -1381,54 +1439,58 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Newlines [] 0) , state = State_BlockTypeAlias - (BlockTypeAlias_Complete (TypeOrConstructor "Hi") - (TypeExpression_Tuple - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - , name = "A" - } - ) - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "F" } - , TypeExpression_NamedType { args = Stack [], name = "E" } - , TypeExpression_NamedType { args = Stack [], name = "D" } - ] - , name = "C" - } - ) - [ TypeExpression_NamedType - { args = - Stack - [ TypeExpression_Bracketed - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "K" } - ] - , name = "J" - } - ) - , TypeExpression_NamedType { args = Stack [], name = "I" } - ] - , name = "H" - } - , TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "P" } - , TypeExpression_NamedType { args = Stack [], name = "O" } - , TypeExpression_Unit - , TypeExpression_NamedType { args = Stack [], name = "M" } - ] - , name = "L" - } - ] - ) + (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + { nesting = + NestingLeafType_Expr + (TypeExpression_Tuple + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , name = "A" + } + ) + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "F" } + , TypeExpression_NamedType { args = Stack [], name = "E" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + , name = "C" + } + ) + [ TypeExpression_NamedType + { args = + Stack + [ TypeExpression_Bracketed + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "K" } + ] + , name = "J" + } + ) + , TypeExpression_NamedType { args = Stack [], name = "I" } + ] + , name = "H" + } + , TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "P" } + , TypeExpression_NamedType { args = Stack [], name = "O" } + , TypeExpression_Unit + , TypeExpression_NamedType { args = Stack [], name = "M" } + ] + , name = "L" + } + ] + ) + , parents = [] + } ) } ] @@ -1544,7 +1606,11 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , contextualized = Just - [ Err { error = Error_PartwayThroughTypeAlias, item = Just (Newlines [] 0), state = State_BlockFirstItem BlockFirstItem_Type } + [ Err + { error = Error_PartwayThroughTypeAlias + , item = Just (Newlines [] 0) + , state = State_BlockFirstItem BlockFirstItem_Type + } ] } ] From a5a86a83138cae70c0d9b122c3464b776be12c87 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 11:40:51 +0100 Subject: [PATCH 046/103] split parseTypeExpr in two for first lex item --- src/Stage/Parse/Contextualize.elm | 620 +++++++++++++++--------------- 1 file changed, 318 insertions(+), 302 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 843873da..7a182ac6 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -376,14 +376,13 @@ parseAnything state = (State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name)) State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name) -> - parserTypeExpr + parserTypeExprFromEmpty (newTypeAliasState name) - Nothing State_BlockTypeAlias (BlockTypeAlias_Completish name exprSoFar) -> parserTypeExpr (newTypeAliasState name) - (Just exprSoFar) + exprSoFar State_BlockTypeAlias (BlockTypeAlias_Complete aliasName expr) -> let @@ -566,32 +565,85 @@ parseAssignment newState item = |> ParseResult_Err -parserTypeExpr : +parserTypeExprFromEmpty : (TypeExpressionResult -> ParseResult) - -> Maybe PartialTypeExpressionLeaf -> LexItem -> ParseResult -parserTypeExpr newState mPrevExpr item = +parserTypeExprFromEmpty newState item = case item of Lexer.Token str -> - case mPrevExpr of - Just prevExpr -> - exprAppend prevExpr str - |> partialTypeExpressionToParseResult newState + { parents = [] + , nesting = + NestingLeafType_TypeWithArgs + { name = str + , args = empty + } + } + |> TypeExpressionResult_Progress + |> newState - Nothing -> - { parents = [] - , nesting = - NestingLeafType_TypeWithArgs - { name = str - , args = empty - } + Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> + { parents = [] + , nesting = NestingLeafType_Bracket empty Nothing + } + |> TypeExpressionResult_Progress + |> newState + + Lexer.Sigil (Lexer.Bracket role Lexer.Close) -> + Error_UnmatchedBracket role Lexer.Close + |> ParseResult_Err + + Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> + { nesting = + NestingLeafType_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty } - |> TypeExpressionResult_Progress - |> newState + , parents = [] + } + |> TypeExpressionResult_Progress + |> newState + + Lexer.Sigil Lexer.Colon -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Lexer.Sigil Lexer.Comma -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Lexer.Sigil Lexer.ThinArrow -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Lexer.Newlines _ 0 -> + Error_PartwayThroughTypeAlias + |> ParseResult_Err + + Lexer.Newlines _ _ -> + ParseResult_Skip + + Lexer.Whitespace _ -> + ParseResult_Skip + + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + +parserTypeExpr : + (TypeExpressionResult -> ParseResult) + -> PartialTypeExpressionLeaf + -> LexItem + -> ParseResult +parserTypeExpr newState prevExpr item = + case item of + Lexer.Token str -> + exprAppend prevExpr str + |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> - leafToParents mPrevExpr + leafToParents prevExpr |> Result.map (\parents -> { parents = parents @@ -601,113 +653,107 @@ parserTypeExpr newState mPrevExpr item = |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> - case mPrevExpr of - Just prevExpr -> + let + collapsedLeaf = + autoCollapseNesting prevExpr + in + case collapsedLeaf.nesting of + NestingLeafType_Expr expr -> + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> ParseResult_Err + + NestingLeafType_TypeWithArgs { name, args } -> + Debug.todo "Make this state impossible" + + NestingLeafType_Bracket argStack mLastExpression -> let - collapsedLeaf = - autoCollapseNesting prevExpr + rexpr = + if argStack /= empty && mLastExpression == Nothing then + -- We have a trailing comma! + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> Err + + else + let + fullArgsList = + (case mLastExpression of + Just expr -> + expr |> pushOnto argStack + + Nothing -> + argStack + ) + |> toList (\x -> x) + in + case fullArgsList of + [] -> + TypeExpression_Unit + |> Ok + + first :: [] -> + TypeExpression_Bracketed first + |> Ok + + first :: second :: rest -> + TypeExpression_Tuple first second rest + |> Ok in - case collapsedLeaf.nesting of - NestingLeafType_Expr expr -> - Error_UnmatchedBracket Lexer.Round Lexer.Close - |> ParseResult_Err + case rexpr of + Ok expr -> + case collapsedLeaf.parents of + nesting :: grandparents -> + { nesting = + case nesting of + NestingParentType_PartialRecord { firstEntries, lastEntryName } -> + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr + } - NestingLeafType_TypeWithArgs { name, args } -> - Debug.todo "Make this state impossible" + NestingParentType_Bracket els -> + NestingLeafType_Bracket els (Just expr) - NestingLeafType_Bracket argStack mLastExpression -> - let - rexpr = - if argStack /= empty && mLastExpression == Nothing then - -- We have a trailing comma! - Error_UnmatchedBracket Lexer.Round Lexer.Close - |> Err - - else - let - fullArgsList = - (case mLastExpression of - Just expr -> - expr |> pushOnto argStack - - Nothing -> - argStack - ) - |> toList (\x -> x) - in - case fullArgsList of - [] -> - TypeExpression_Unit - |> Ok - - first :: [] -> - TypeExpression_Bracketed first - |> Ok - - first :: second :: rest -> - TypeExpression_Tuple first second rest - |> Ok - in - case rexpr of - Ok expr -> - case collapsedLeaf.parents of - nesting :: grandparents -> - { nesting = - case nesting of - NestingParentType_PartialRecord { firstEntries, lastEntryName } -> - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr - } - - NestingParentType_Bracket els -> - NestingLeafType_Bracket els (Just expr) - - NestingParentType_TypeWithArgs { name, args } -> - NestingLeafType_TypeWithArgs - { name = name - , args = expr |> pushOnto args - } - - NestingParentType_Function { firstInput } -> - NestingLeafType_Function - { firstInput = firstInput - , output = Just expr - } - , parents = grandparents - } - |> TypeExpressionResult_Progress - |> newState + NestingParentType_TypeWithArgs { name, args } -> + NestingLeafType_TypeWithArgs + { name = name + , args = expr |> pushOnto args + } - [] -> - { nesting = NestingLeafType_Expr expr - , parents = [] - } - |> TypeExpressionResult_Progress - |> newState + NestingParentType_Function { firstInput } -> + NestingLeafType_Function + { firstInput = firstInput + , output = Just expr + } + , parents = grandparents + } + |> TypeExpressionResult_Progress + |> newState - Err e -> - ParseResult_Err e + [] -> + { nesting = NestingLeafType_Expr expr + , parents = [] + } + |> TypeExpressionResult_Progress + |> newState - NestingLeafType_PartialRecord _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + Err e -> + ParseResult_Err e - NestingLeafType_Function { output } -> - case output of - Nothing -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + NestingLeafType_PartialRecord _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err - Just _ -> - Debug.todo "Make this state impossible" + NestingLeafType_Function { output } -> + case output of + Nothing -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err - Nothing -> - Error_UnmatchedBracket Lexer.Round Lexer.Close - |> ParseResult_Err + Just _ -> + Debug.todo "Make this state impossible" Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> - case leafToParents mPrevExpr of + case leafToParents prevExpr of Ok newParents -> { nesting = NestingLeafType_PartialRecord @@ -742,17 +788,11 @@ parserTypeExpr newState mPrevExpr item = Error_InvalidToken item Expecting_Unknown |> ParseResult_Err in - case mPrevExpr of - Just prevExpr -> - case prevExpr.nesting of - NestingLeafType_PartialRecord existingPartialRecord -> - getNewPartialRecord prevExpr.parents existingPartialRecord - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + case prevExpr.nesting of + NestingLeafType_PartialRecord existingPartialRecord -> + getNewPartialRecord prevExpr.parents existingPartialRecord - Nothing -> + _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err @@ -774,138 +814,129 @@ parserTypeExpr newState mPrevExpr item = _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err + + collapsedLeaf = + autoCollapseNesting prevExpr in - case mPrevExpr |> Maybe.map autoCollapseNesting of - Just collapsedLeaf -> - case collapsedLeaf.nesting of - NestingLeafType_PartialRecord existingPartialRecord -> - getNewPartialRecord collapsedLeaf.parents existingPartialRecord - - NestingLeafType_Bracket argStack (Just expr) -> - { nesting = - NestingLeafType_Bracket (expr |> pushOnto argStack) Nothing - , parents = collapsedLeaf.parents - } - |> TypeExpressionResult_Progress - |> newState + case collapsedLeaf.nesting of + NestingLeafType_PartialRecord existingPartialRecord -> + getNewPartialRecord collapsedLeaf.parents existingPartialRecord - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + NestingLeafType_Bracket argStack (Just expr) -> + { nesting = + NestingLeafType_Bracket (expr |> pushOnto argStack) Nothing + , parents = collapsedLeaf.parents + } + |> TypeExpressionResult_Progress + |> newState - Nothing -> + _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> - case mPrevExpr of - Just prevExpr -> - let - collapsedLeaf = - autoCollapseNesting prevExpr - in - case collapsedLeaf.nesting of - NestingLeafType_Expr expr -> - Error_UnmatchedBracket Lexer.Curly Lexer.Close - |> ParseResult_Err + let + collapsedLeaf = + autoCollapseNesting prevExpr + in + case collapsedLeaf.nesting of + NestingLeafType_Expr expr -> + Error_UnmatchedBracket Lexer.Curly Lexer.Close + |> ParseResult_Err - NestingLeafType_TypeWithArgs { name, args } -> - Debug.todo "Make this state impossible" + NestingLeafType_TypeWithArgs { name, args } -> + Debug.todo "Make this state impossible" - NestingLeafType_Bracket argStack mLastExpression -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + NestingLeafType_Bracket argStack mLastExpression -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err - NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + let + fromRecord recordEntries = let - fromRecord recordEntries = - let - record = - TypeExpression_Record recordEntries - in - case collapsedLeaf.parents of - [] -> - { nesting = NestingLeafType_Expr record - , parents = [] + record = + TypeExpression_Record recordEntries + in + case collapsedLeaf.parents of + [] -> + { nesting = NestingLeafType_Expr record + , parents = [] + } + |> TypeExpressionResult_Progress + |> newState + + nesting :: grandparents -> + (case nesting of + -- We are within a nested bracket. + NestingParentType_Bracket argStack -> + { parents = grandparents + , nesting = NestingLeafType_Bracket argStack (Just record) } - |> TypeExpressionResult_Progress - |> newState - - nesting :: grandparents -> - (case nesting of - -- We are within a nested bracket. - NestingParentType_Bracket argStack -> - { parents = grandparents - , nesting = NestingLeafType_Bracket argStack (Just record) - } - NestingParentType_PartialRecord existingPartialRecord -> - { parents = grandparents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = existingPartialRecord.firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue - existingPartialRecord.lastEntryName - record - } + NestingParentType_PartialRecord existingPartialRecord -> + { parents = grandparents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = existingPartialRecord.firstEntries + , lastEntry = + LastEntryOfRecord_KeyValue + existingPartialRecord.lastEntryName + record } + } - NestingParentType_TypeWithArgs { name, args } -> - { nesting = - NestingLeafType_TypeWithArgs - { name = name - , args = - record - |> pushOnto args - } - , parents = grandparents + NestingParentType_TypeWithArgs { name, args } -> + { nesting = + NestingLeafType_TypeWithArgs + { name = name + , args = + record + |> pushOnto args } + , parents = grandparents + } - NestingParentType_Function { firstInput } -> - { nesting = - NestingLeafType_Function - { firstInput = firstInput - , output = Just record - } - , parents = grandparents + NestingParentType_Function { firstInput } -> + { nesting = + NestingLeafType_Function + { firstInput = firstInput + , output = Just record } - ) - |> TypeExpressionResult_Progress - |> newState - in - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - ( key, value ) - |> pushOnto firstEntries - |> toList (\x -> x) - |> fromRecord - - LastEntryOfRecord_Empty -> - if firstEntries == empty then - [] - |> fromRecord - - else - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + , parents = grandparents + } + ) + |> TypeExpressionResult_Progress + |> newState + in + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + ( key, value ) + |> pushOnto firstEntries + |> toList (\x -> x) + |> fromRecord - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + LastEntryOfRecord_Empty -> + if firstEntries == empty then + [] + |> fromRecord - NestingLeafType_Function { output } -> - case output of - Nothing -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + else + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err - Just _ -> - Debug.todo "Make this state impossible" + _ -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err - Nothing -> - Error_UnmatchedBracket Lexer.Curly Lexer.Close - |> ParseResult_Err + NestingLeafType_Function { output } -> + case output of + Nothing -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Just _ -> + Debug.todo "Make this state impossible" Lexer.Sigil Lexer.ThinArrow -> let @@ -926,8 +957,8 @@ parserTypeExpr newState mPrevExpr item = Error_InvalidToken item Expecting_Unknown |> ParseResult_Err in - case mPrevExpr |> Maybe.map (autoCollapseNesting >> .nesting) of - Just (NestingLeafType_Expr expr) -> + case (autoCollapseNesting prevExpr).nesting of + NestingLeafType_Expr expr -> { nesting = NestingLeafType_Function { firstInput = expr @@ -938,30 +969,20 @@ parserTypeExpr newState mPrevExpr item = |> TypeExpressionResult_Progress |> newState - Just _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err - - Nothing -> + _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err Lexer.Newlines _ 0 -> - case mPrevExpr of - Nothing -> + case (autoCollapseNesting prevExpr).nesting of + NestingLeafType_Expr expr -> + TypeExpressionResult_Done expr + |> newState + + _ -> Error_PartwayThroughTypeAlias |> ParseResult_Err - Just prevExpr -> - case (autoCollapseNesting prevExpr).nesting of - NestingLeafType_Expr expr -> - TypeExpressionResult_Done expr - |> newState - - _ -> - Error_PartwayThroughTypeAlias - |> ParseResult_Err - Lexer.Newlines _ _ -> ParseResult_Skip @@ -973,62 +994,57 @@ parserTypeExpr newState mPrevExpr item = |> ParseResult_Err -leafToParents : Maybe PartialTypeExpressionLeaf -> Result Error (List NestingParentType) -leafToParents leaf = - case leaf of - Nothing -> - Ok [] +leafToParents : PartialTypeExpressionLeaf -> Result Error (List NestingParentType) +leafToParents { parents, nesting } = + (case nesting of + NestingLeafType_Expr expr -> + -- Cannot nest unless there is a trailing comma! + Error_TypeDoesNotTakeArgs2 expr + |> Err - Just { parents, nesting } -> - (case nesting of - NestingLeafType_Expr expr -> - -- Cannot nest unless there is a trailing comma! - Error_TypeDoesNotTakeArgs2 expr + NestingLeafType_Bracket _ (Just lastType) -> + -- Cannot nest unless there is a trailing comma! + Error_TypeDoesNotTakeArgs2 lastType + |> Err + + NestingLeafType_Bracket els Nothing -> + NestingParentType_Bracket els + |> Ok + + NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + case lastEntry of + LastEntryOfRecord_Empty -> + Error_ExpectedKeyWhilstParsingRecord |> Err - NestingLeafType_Bracket _ (Just lastType) -> - -- Cannot nest unless there is a trailing comma! - Error_TypeDoesNotTakeArgs2 lastType + LastEntryOfRecord_Key _ -> + Error_ExpectedColonWhilstParsingRecord |> Err - NestingLeafType_Bracket els Nothing -> - NestingParentType_Bracket els + LastEntryOfRecord_KeyColon key -> + NestingParentType_PartialRecord { firstEntries = firstEntries, lastEntryName = key } |> Ok - NestingLeafType_PartialRecord { firstEntries, lastEntry } -> - case lastEntry of - LastEntryOfRecord_Empty -> - Error_ExpectedKeyWhilstParsingRecord - |> Err - - LastEntryOfRecord_Key _ -> - Error_ExpectedColonWhilstParsingRecord - |> Err - - LastEntryOfRecord_KeyColon key -> - NestingParentType_PartialRecord { firstEntries = firstEntries, lastEntryName = key } - |> Ok + LastEntryOfRecord_KeyValue _ lastValueType -> + Error_TypeDoesNotTakeArgs2 lastValueType + |> Err - LastEntryOfRecord_KeyValue _ lastValueType -> - Error_TypeDoesNotTakeArgs2 lastValueType - |> Err + NestingLeafType_TypeWithArgs details -> + NestingParentType_TypeWithArgs details + |> Ok - NestingLeafType_TypeWithArgs details -> - NestingParentType_TypeWithArgs details + NestingLeafType_Function { firstInput, output } -> + case output of + Nothing -> + NestingParentType_Function { firstInput = firstInput } |> Ok - NestingLeafType_Function { firstInput, output } -> - case output of - Nothing -> - NestingParentType_Function { firstInput = firstInput } - |> Ok - - Just te -> - Error_TypeDoesNotTakeArgs2 te - |> Err - ) - |> Result.map - (\n -> n :: parents) + Just te -> + Error_TypeDoesNotTakeArgs2 te + |> Err + ) + |> Result.map + (\n -> n :: parents) exprAppend : @@ -1048,7 +1064,7 @@ exprAppend ({ parents, nesting } as currentLeaf) token = NestingLeafType_Bracket argStack mostNested -> case mostNested of Nothing -> - leafToParents (Just currentLeaf) + leafToParents currentLeaf |> Result.map (\newParents -> { parents = newParents @@ -1081,7 +1097,7 @@ exprAppend ({ parents, nesting } as currentLeaf) token = |> Ok _ -> - leafToParents (Just currentLeaf) + leafToParents currentLeaf |> Result.map (\newParents -> { parents = newParents @@ -1128,7 +1144,7 @@ exprAppend ({ parents, nesting } as currentLeaf) token = } |> Ok ) - (leafToParents (Just currentLeaf)) + (leafToParents currentLeaf) blockFromState : State -> Maybe (Result Error Block) From 8b996be65621c8cff5193783614caea5d07416b7 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 12:17:29 +0100 Subject: [PATCH 047/103] add curried function type expression Note: it binds the wrong way! A bug. --- parser-tests/Update.elm | 2 + .../type-alias-function-binding-order | 2 + tests/ParserLexerTestCases.elm | 471 ++++++++++++++++-- 3 files changed, 432 insertions(+), 43 deletions(-) create mode 100644 parser-tests/snippets/should-parse/type-alias-function-binding-order diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index d936dd2f..2c5f1dfd 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -111,3 +111,5 @@ preFormatElmCode = """ >> String.replace """Err {""" """Err { """ + >> String.replace """UserDefinedType {""" """UserDefinedType { + """ diff --git a/parser-tests/snippets/should-parse/type-alias-function-binding-order b/parser-tests/snippets/should-parse/type-alias-function-binding-order new file mode 100644 index 00000000..be3bef4d --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-function-binding-order @@ -0,0 +1,2 @@ +type alias Function = A -> B -> C +type alias Function = A -> B -> C -> D diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 17a96e5d..1eade61c 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -50,7 +50,11 @@ shouldParseTestCases = { expr = UserDefinedType { args = - [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -92,7 +96,13 @@ shouldParseTestCases = { expr = Record (Dict.fromList - [ ( "hi", UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } ) + [ ( "hi" + , UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) ] ) , ty = TypeOrConstructor "Ty" @@ -137,7 +147,11 @@ shouldParseTestCases = { from = UserDefinedType { args = - [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -147,7 +161,11 @@ shouldParseTestCases = { args = [ UserDefinedType { args = - [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -162,6 +180,124 @@ shouldParseTestCases = ) ] } + , { name = "type-alias-function-binding-order" + , source = """type alias Function = A -> B -> C +type alias Function = A -> B -> C -> D +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "A") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 27, row = 1 }, start = { col = 25, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token "B") + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) + , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token "C") + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) + , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Token "Function") + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Assign) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token "A") + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) + , Located { end = { col = 27, row = 2 }, start = { col = 25, row = 2 } } (Sigil ThinArrow) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token "B") + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Whitespace 1) + , Located { end = { col = 32, row = 2 }, start = { col = 30, row = 2 } } (Sigil ThinArrow) + , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Whitespace 1) + , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Token "C") + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) + , Located { end = { col = 37, row = 2 }, start = { col = 35, row = 2 } } (Sigil ThinArrow) + , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) + , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token "D") + , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Function + { from = + Function + { from = + UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + , to = + UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + } + , to = + UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + } + , ty = TypeOrConstructor "Function" + } + ) + , Ok + (TypeAlias + { expr = + Function + { from = + Function + { from = + Function + { from = + UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + , to = + UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + } + , to = + UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + } + , to = + UserDefinedType + { args = [] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } + } + , ty = TypeOrConstructor "Function" + } + ) + ] + } , { name = "type-alias-function-generic" , source = """type alias Function a = List Int -> List (List a) """ @@ -253,11 +389,23 @@ shouldParseTestCases = [ ( "a" , Record (Dict.fromList - [ ( "b", UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } ) + [ ( "b" + , UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + ) ] ) ) - , ( "d", UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } ) + , ( "d" + , UserDefinedType + { args = [] + , name = "E" + , qualifiedness = PossiblyQualified Nothing + } + ) ] ) , to = Record (Dict.fromList []) @@ -295,7 +443,29 @@ shouldParseTestCases = ] , contextualized = Just - [ Ok (TypeAlias { expr = Function { from = Unit, to = Tuple (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "String", qualifiedness = PossiblyQualified Nothing }) }, ty = TypeOrConstructor "Function" }) + [ Ok + (TypeAlias + { expr = + Function + { from = Unit + , to = + Tuple + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } + ) + } + , ty = TypeOrConstructor "Function" + } + ) ] } , { name = "type-alias-funky-indentation" @@ -324,7 +494,11 @@ shouldParseTestCases = { expr = UserDefinedType { args = - [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -361,7 +535,11 @@ shouldParseTestCases = { expr = UserDefinedType { args = - [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -413,9 +591,27 @@ shouldParseTestCases = { expr = Record (Dict.fromList - [ ( "a", UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing } ) - , ( "b", UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing } ) - , ( "c", UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } ) + [ ( "a" + , UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ( "b" + , UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ( "c" + , UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + ) ] ) , ty = TypeOrConstructor "Ty" @@ -509,7 +705,13 @@ shouldParseTestCases = { expr = Record (Dict.fromList - [ ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + [ ( "hi" + , UserDefinedType + { args = [] + , name = "6" + , qualifiedness = PossiblyQualified Nothing + } + ) ] ) , ty = TypeOrConstructor "Ty" @@ -587,11 +789,21 @@ shouldParseTestCases = [ ( "hi" , Record (Dict.fromList - [ ( "a", UserDefinedType { args = [], name = "7", qualifiedness = PossiblyQualified Nothing } ) + [ ( "a" + , UserDefinedType + { args = [] + , name = "7" + , qualifiedness = PossiblyQualified Nothing + } + ) , ( "b" , UserDefinedType { args = - [ UserDefinedType { args = [], name = "String", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -603,12 +815,28 @@ shouldParseTestCases = , ( "ih" , UserDefinedType { args = - [ UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } , UserDefinedType { args = - [ UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "E" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "D" , qualifiedness = PossiblyQualified Nothing @@ -655,7 +883,13 @@ shouldParseTestCases = { expr = Record (Dict.fromList - [ ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + [ ( "hi" + , UserDefinedType + { args = [] + , name = "6" + , qualifiedness = PossiblyQualified Nothing + } + ) ] ) , ty = TypeOrConstructor "Ty" @@ -699,8 +933,20 @@ shouldParseTestCases = { expr = Record (Dict.fromList - [ ( "buy", UserDefinedType { args = [], name = "8", qualifiedness = PossiblyQualified Nothing } ) - , ( "hi", UserDefinedType { args = [], name = "6", qualifiedness = PossiblyQualified Nothing } ) + [ ( "buy" + , UserDefinedType + { args = [] + , name = "8" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ( "hi" + , UserDefinedType + { args = [] + , name = "6" + , qualifiedness = PossiblyQualified Nothing + } + ) ] ) , ty = TypeOrConstructor "Ty" @@ -750,7 +996,17 @@ shouldParseTestCases = ] , contextualized = Just - [ Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi" }) + [ Ok + (TypeAlias + { expr = + UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + , ty = TypeOrConstructor "Hi" + } + ) ] } , { name = "type-alias-with-bracket-2" @@ -780,7 +1036,11 @@ shouldParseTestCases = { expr = UserDefinedType { args = - [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -831,10 +1091,20 @@ type alias Hi = (Int) [ Ok (TypeAlias { expr = - Tuple (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) + Tuple + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) (UserDefinedType { args = - [ UserDefinedType { args = [], name = "String", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "List" , qualifiedness = PossiblyQualified Nothing @@ -843,7 +1113,17 @@ type alias Hi = (Int) , ty = TypeOrConstructor "Hi" } ) - , Ok (TypeAlias { expr = UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }, ty = TypeOrConstructor "Hi" }) + , Ok + (TypeAlias + { expr = + UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + , ty = TypeOrConstructor "Hi" + } + ) ] } , { name = "type-alias-with-tripple" @@ -894,7 +1174,31 @@ type alias Hi = ((), (), ()) ] , contextualized = Just - [ Ok (TypeAlias { expr = Tuple3 (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "Two", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "Three", qualifiedness = PossiblyQualified Nothing }), ty = TypeOrConstructor "Hi" }) + [ Ok + (TypeAlias + { expr = + Tuple3 + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "Two" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "Three" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ty = TypeOrConstructor "Hi" + } + ) , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, ty = TypeOrConstructor "Hi" }) ] } @@ -956,7 +1260,27 @@ type alias Hi = ((), (), ()) { expr = Record (Dict.fromList - [ ( "a", Tuple3 (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) ) + [ ( "a" + , Tuple3 + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + ) , ( "b" , Record (Dict.fromList @@ -1365,11 +1689,36 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) Just [ Err { error = - Error_TooManyTupleArgs (UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing }) - (UserDefinedType { args = [], name = "A", qualifiedness = PossiblyQualified Nothing }) - (UserDefinedType { args = [], name = "B", qualifiedness = PossiblyQualified Nothing }) - (UserDefinedType { args = [], name = "C", qualifiedness = PossiblyQualified Nothing }) - [ UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } + Error_TooManyTupleArgs + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + ) + [ UserDefinedType + { args = [] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } ] , item = Just (Newlines [] 0) , state = @@ -1393,7 +1742,11 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) Error_TooManyTupleArgs (UserDefinedType { args = - [ UserDefinedType { args = [], name = "Int", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "A" , qualifiedness = PossiblyQualified Nothing @@ -1401,9 +1754,21 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) (UserDefinedType { args = - [ UserDefinedType { args = [], name = "D", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "E", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "F", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "E" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "F" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "C" , qualifiedness = PossiblyQualified Nothing @@ -1411,10 +1776,18 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) (UserDefinedType { args = - [ UserDefinedType { args = [], name = "I", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "I" + , qualifiedness = PossiblyQualified Nothing + } , UserDefinedType { args = - [ UserDefinedType { args = [], name = "K", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "K" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "J" , qualifiedness = PossiblyQualified Nothing @@ -1426,10 +1799,22 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) (UserDefinedType { args = - [ UserDefinedType { args = [], name = "M", qualifiedness = PossiblyQualified Nothing } + [ UserDefinedType + { args = [] + , name = "M" + , qualifiedness = PossiblyQualified Nothing + } , Unit - , UserDefinedType { args = [], name = "O", qualifiedness = PossiblyQualified Nothing } - , UserDefinedType { args = [], name = "P", qualifiedness = PossiblyQualified Nothing } + , UserDefinedType + { args = [] + , name = "O" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "P" + , qualifiedness = PossiblyQualified Nothing + } ] , name = "L" , qualifiedness = PossiblyQualified Nothing From 8a2b9112979fc3ba998023b26db0d670e336ff5c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 12:18:19 +0100 Subject: [PATCH 048/103] fix: binding of curried function types --- src/Stage/Parse/Contextualize.elm | 101 +++++++++++++++++++++++------- tests/ParserLexerTestCases.elm | 44 ++++++------- 2 files changed, 101 insertions(+), 44 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 7a182ac6..7ca80a0d 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -133,6 +133,7 @@ type PartialTypeExpression | TypeExpression_Record (List ( String, PartialTypeExpression )) | TypeExpression_Function { firstInput : PartialTypeExpression + , otherInputs : List PartialTypeExpression , output : PartialTypeExpression } @@ -160,7 +161,10 @@ type NestingParentType { name : String , args : Stack PartialTypeExpression } - | NestingParentType_Function { firstInput : PartialTypeExpression } + | NestingParentType_Function + { firstInput : PartialTypeExpression + , otherInputs : Stack PartialTypeExpression + } type NestingLeafType @@ -172,6 +176,7 @@ type NestingLeafType } | NestingLeafType_Function { firstInput : PartialTypeExpression + , otherInputs : Stack PartialTypeExpression , output : Maybe PartialTypeExpression } | NestingLeafType_Expr PartialTypeExpression @@ -655,7 +660,7 @@ parserTypeExpr newState prevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> let collapsedLeaf = - autoCollapseNesting prevExpr + autoCollapseNesting CollapseLevel_Function prevExpr in case collapsedLeaf.nesting of NestingLeafType_Expr expr -> @@ -722,6 +727,7 @@ parserTypeExpr newState prevExpr item = NestingParentType_Function { firstInput } -> NestingLeafType_Function { firstInput = firstInput + , otherInputs = empty , output = Just expr } , parents = grandparents @@ -816,7 +822,7 @@ parserTypeExpr newState prevExpr item = |> ParseResult_Err collapsedLeaf = - autoCollapseNesting prevExpr + autoCollapseNesting CollapseLevel_Function prevExpr in case collapsedLeaf.nesting of NestingLeafType_PartialRecord existingPartialRecord -> @@ -837,7 +843,7 @@ parserTypeExpr newState prevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> let collapsedLeaf = - autoCollapseNesting prevExpr + autoCollapseNesting CollapseLevel_Function prevExpr in case collapsedLeaf.nesting of NestingLeafType_Expr expr -> @@ -897,10 +903,11 @@ parserTypeExpr newState prevExpr item = , parents = grandparents } - NestingParentType_Function { firstInput } -> + NestingParentType_Function { firstInput, otherInputs } -> { nesting = NestingLeafType_Function { firstInput = firstInput + , otherInputs = otherInputs , output = Just record } , parents = grandparents @@ -957,11 +964,12 @@ parserTypeExpr newState prevExpr item = Error_InvalidToken item Expecting_Unknown |> ParseResult_Err in - case (autoCollapseNesting prevExpr).nesting of + case (autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr).nesting of NestingLeafType_Expr expr -> { nesting = NestingLeafType_Function { firstInput = expr + , otherInputs = empty , output = Nothing } , parents = [] @@ -969,12 +977,30 @@ parserTypeExpr newState prevExpr item = |> TypeExpressionResult_Progress |> newState + NestingLeafType_Function { firstInput, otherInputs, output } -> + case output of + Nothing -> + Error_InvalidToken item Expecting_Unknown + |> ParseResult_Err + + Just output_ -> + { nesting = + NestingLeafType_Function + { firstInput = firstInput + , otherInputs = output_ |> pushOnto otherInputs + , output = Nothing + } + , parents = [] + } + |> TypeExpressionResult_Progress + |> newState + _ -> Error_InvalidToken item Expecting_Unknown |> ParseResult_Err Lexer.Newlines _ 0 -> - case (autoCollapseNesting prevExpr).nesting of + case (autoCollapseNesting CollapseLevel_Function prevExpr).nesting of NestingLeafType_Expr expr -> TypeExpressionResult_Done expr |> newState @@ -1033,10 +1059,13 @@ leafToParents { parents, nesting } = NestingParentType_TypeWithArgs details |> Ok - NestingLeafType_Function { firstInput, output } -> + NestingLeafType_Function { firstInput, otherInputs, output } -> case output of Nothing -> - NestingParentType_Function { firstInput = firstInput } + NestingParentType_Function + { firstInput = firstInput + , otherInputs = otherInputs + } |> Ok Just te -> @@ -1175,7 +1204,7 @@ blockFromState state = |> Just State_BlockTypeAlias (BlockTypeAlias_Completish aliasName partialExpr) -> - case (autoCollapseNesting partialExpr).nesting of + case (autoCollapseNesting CollapseLevel_Function partialExpr).nesting of NestingLeafType_Expr expr -> partialTypeExpressionToConcreteType expr |> Result.map @@ -1256,8 +1285,13 @@ addToPartialRecord token { firstEntries, lastEntry } = |> Err -autoCollapseNesting : PartialTypeExpressionLeaf -> PartialTypeExpressionLeaf -autoCollapseNesting pte = +type CollapseLevel + = CollapseLevel_TypeWithArgs + | CollapseLevel_Function + + +autoCollapseNesting : CollapseLevel -> PartialTypeExpressionLeaf -> PartialTypeExpressionLeaf +autoCollapseNesting collapseLevel pte = case pte.nesting of NestingLeafType_TypeWithArgs { name, args } -> let @@ -1272,9 +1306,10 @@ autoCollapseNesting pte = NestingParentType_TypeWithArgs _ -> Debug.todo "Make this state impossible" - NestingParentType_Function { firstInput } -> + NestingParentType_Function { firstInput, otherInputs } -> NestingLeafType_Function { firstInput = firstInput + , otherInputs = otherInputs , output = Just newTypeExpr } @@ -1287,7 +1322,7 @@ autoCollapseNesting pte = , lastEntry = LastEntryOfRecord_KeyValue lastEntryName newTypeExpr } } - |> autoCollapseNesting + |> autoCollapseNesting collapseLevel [] -> { nesting = NestingLeafType_Expr newTypeExpr @@ -1303,16 +1338,20 @@ autoCollapseNesting pte = NestingLeafType_PartialRecord _ -> pte - NestingLeafType_Function { firstInput, output } -> - case output of - Nothing -> + NestingLeafType_Function { firstInput, otherInputs, output } -> + case ( collapseLevel, output ) of + ( CollapseLevel_TypeWithArgs, _ ) -> + pte + + ( CollapseLevel_Function, Nothing ) -> pte - Just outputExpr -> + ( CollapseLevel_Function, Just outputExpr ) -> let newTypeExpr = TypeExpression_Function { firstInput = firstInput + , otherInputs = otherInputs |> toList (\x -> x) , output = outputExpr } in @@ -1336,7 +1375,7 @@ autoCollapseNesting pte = , lastEntry = LastEntryOfRecord_KeyValue lastEntryName newTypeExpr } } - |> autoCollapseNesting + |> autoCollapseNesting collapseLevel [] -> { nesting = NestingLeafType_Expr newTypeExpr @@ -1448,14 +1487,27 @@ partialTypeExpressionToConcreteType pte = } ) in - Result.map2 - (\concreteFirstInput concreteOutput -> + Result.map3 + (\concreteFirstInput concreteOtherInputs concreteOutput -> ConcreteType.Function { from = concreteFirstInput - , to = concreteOutput + , to = + List.foldl + (\arg te -> + ConcreteType.Function + { from = arg + , to = te + } + ) + concreteOutput + concreteOtherInputs } ) (partialTypeExpressionToConcreteType functionTypeExpr.firstInput) + (functionTypeExpr.otherInputs + |> List.reverse + |> collectList partialTypeExpressionToConcreteType + ) (partialTypeExpressionToConcreteType functionTypeExpr.output) @@ -1541,3 +1593,8 @@ toList mapper (Stack ls) = (\curr prev -> mapper curr :: prev) [] ls + + +reverseToList : Stack a -> List a +reverseToList (Stack ls) = + ls diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 1eade61c..721d2712 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -234,26 +234,26 @@ type alias Function = A -> B -> C -> D { expr = Function { from = + UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + , to = Function { from = UserDefinedType { args = [] - , name = "A" + , name = "B" , qualifiedness = PossiblyQualified Nothing } , to = UserDefinedType { args = [] - , name = "B" + , name = "C" , qualifiedness = PossiblyQualified Nothing } } - , to = - UserDefinedType - { args = [] - , name = "C" - , qualifiedness = PossiblyQualified Nothing - } } , ty = TypeOrConstructor "Function" } @@ -263,34 +263,34 @@ type alias Function = A -> B -> C -> D { expr = Function { from = + UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + , to = Function { from = + UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + , to = Function { from = UserDefinedType { args = [] - , name = "A" + , name = "C" , qualifiedness = PossiblyQualified Nothing } , to = UserDefinedType { args = [] - , name = "B" + , name = "D" , qualifiedness = PossiblyQualified Nothing } } - , to = - UserDefinedType - { args = [] - , name = "C" - , qualifiedness = PossiblyQualified Nothing - } - } - , to = - UserDefinedType - { args = [] - , name = "D" - , qualifiedness = PossiblyQualified Nothing } } , ty = TypeOrConstructor "Function" From a0c7d37a2a681016757eab6bd9725956f58f29bd Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 13:20:57 +0100 Subject: [PATCH 049/103] move some logic out of main type parser --- src/Stage/Parse/Contextualize.elm | 162 +++++++++++++++--------------- tests/ParserLexerTestCases.elm | 4 +- 2 files changed, 84 insertions(+), 82 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 7ca80a0d..e304e64a 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -194,7 +194,7 @@ type TypeExpressionResult type Error - = Error_InvalidToken LexItem Expecting + = Error_InvalidToken Expecting | Error_MisplacedKeyword Keyword | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction @@ -471,7 +471,7 @@ parseBlockStart item = ParseResult_Panic "parseBlockStart expects a block but found some whitespace" _ -> - ParseResult_Err (Error_InvalidToken item Expecting_Block) + ParseResult_Err (Error_InvalidToken Expecting_Block) parseTypeBlock : LexItem -> ParseResult @@ -510,7 +510,7 @@ parseTypeBlock item = _ -> -- TODO(harry) indicate that we could also be expecting the `alias` -- keyword. - Error_InvalidToken item Expecting_TypeName + Error_InvalidToken Expecting_TypeName |> ParseResult_Err @@ -542,7 +542,7 @@ parseTypeAliasName item = ParseResult_Skip _ -> - Error_InvalidToken item Expecting_TypeName + Error_InvalidToken Expecting_TypeName |> ParseResult_Err @@ -566,7 +566,7 @@ parseAssignment newState item = ParseResult_Skip _ -> - Error_InvalidToken item (Expecting_Sigil Lexer.Assign) + Error_InvalidToken (Expecting_Sigil Lexer.Assign) |> ParseResult_Err @@ -610,15 +610,15 @@ parserTypeExprFromEmpty newState item = |> newState Lexer.Sigil Lexer.Colon -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err Lexer.Sigil Lexer.Comma -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err Lexer.Sigil Lexer.ThinArrow -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err Lexer.Newlines _ 0 -> @@ -632,7 +632,7 @@ parserTypeExprFromEmpty newState item = ParseResult_Skip _ -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -746,13 +746,13 @@ parserTypeExpr newState prevExpr item = ParseResult_Err e NestingLeafType_PartialRecord _ -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err NestingLeafType_Function { output } -> case output of Nothing -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err Just _ -> @@ -776,69 +776,12 @@ parserTypeExpr newState prevExpr item = |> ParseResult_Err Lexer.Sigil Lexer.Colon -> - let - getNewPartialRecord parents { firstEntries, lastEntry } = - case lastEntry of - LastEntryOfRecord_Key key -> - { parents = parents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyColon key - } - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err - in - case prevExpr.nesting of - NestingLeafType_PartialRecord existingPartialRecord -> - getNewPartialRecord prevExpr.parents existingPartialRecord - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + appendColonTo prevExpr + |> partialTypeExpressionToParseResult newState Lexer.Sigil Lexer.Comma -> - let - getNewPartialRecord parents { firstEntries, lastEntry } = - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - { parents = parents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = ( key, value ) |> pushOnto firstEntries - , lastEntry = LastEntryOfRecord_Empty - } - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err - - collapsedLeaf = - autoCollapseNesting CollapseLevel_Function prevExpr - in - case collapsedLeaf.nesting of - NestingLeafType_PartialRecord existingPartialRecord -> - getNewPartialRecord collapsedLeaf.parents existingPartialRecord - - NestingLeafType_Bracket argStack (Just expr) -> - { nesting = - NestingLeafType_Bracket (expr |> pushOnto argStack) Nothing - , parents = collapsedLeaf.parents - } - |> TypeExpressionResult_Progress - |> newState - - _ -> - Error_InvalidToken item Expecting_Unknown - |> ParseResult_Err + appendCommaTo prevExpr + |> partialTypeExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> let @@ -854,7 +797,7 @@ parserTypeExpr newState prevExpr item = Debug.todo "Make this state impossible" NestingLeafType_Bracket argStack mLastExpression -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err NestingLeafType_PartialRecord { firstEntries, lastEntry } -> @@ -929,17 +872,17 @@ parserTypeExpr newState prevExpr item = |> fromRecord else - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err _ -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err NestingLeafType_Function { output } -> case output of Nothing -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err Just _ -> @@ -961,7 +904,7 @@ parserTypeExpr newState prevExpr item = |> newState _ -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err in case (autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr).nesting of @@ -980,7 +923,7 @@ parserTypeExpr newState prevExpr item = NestingLeafType_Function { firstInput, otherInputs, output } -> case output of Nothing -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err Just output_ -> @@ -996,7 +939,7 @@ parserTypeExpr newState prevExpr item = |> newState _ -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err Lexer.Newlines _ 0 -> @@ -1016,7 +959,7 @@ parserTypeExpr newState prevExpr item = ParseResult_Skip _ -> - Error_InvalidToken item Expecting_Unknown + Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -1176,6 +1119,65 @@ exprAppend ({ parents, nesting } as currentLeaf) token = (leafToParents currentLeaf) +appendCommaTo : PartialTypeExpressionLeaf -> Result Error PartialTypeExpressionLeaf +appendCommaTo prevExpr = + let + collapsedLeaf = + autoCollapseNesting CollapseLevel_Function prevExpr + in + case collapsedLeaf.nesting of + NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + { parents = collapsedLeaf.parents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = ( key, value ) |> pushOnto firstEntries + , lastEntry = LastEntryOfRecord_Empty + } + } + |> Ok + + _ -> + Error_InvalidToken Expecting_Unknown + |> Err + + NestingLeafType_Bracket argStack (Just expr) -> + { nesting = + NestingLeafType_Bracket (expr |> pushOnto argStack) Nothing + , parents = collapsedLeaf.parents + } + |> Ok + + _ -> + Error_InvalidToken Expecting_Unknown + |> Err + + +appendColonTo : PartialTypeExpressionLeaf -> Result Error PartialTypeExpressionLeaf +appendColonTo prevExpr = + case prevExpr.nesting of + NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + case lastEntry of + LastEntryOfRecord_Key key -> + { parents = prevExpr.parents + , nesting = + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyColon key + } + } + |> Ok + + _ -> + Error_InvalidToken Expecting_Unknown + |> Err + + _ -> + Error_InvalidToken Expecting_Unknown + |> Err + + blockFromState : State -> Maybe (Result Error Block) blockFromState state = case state of diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 721d2712..b955943c 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -331,7 +331,7 @@ type alias Function = A -> B -> C -> D , contextualized = Just [ Err - { error = Error_InvalidToken (Token "a") (Expecting_Sigil Assign) + { error = Error_InvalidToken (Expecting_Sigil Assign) , item = Just (Token "a") , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function")) } @@ -1906,7 +1906,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , contextualized = Just [ Err - { error = Error_InvalidToken (Sigil Comma) Expecting_Unknown + { error = Error_InvalidToken Expecting_Unknown , item = Just (Sigil Comma) , state = State_BlockTypeAlias From f05c2e4c420bc2494a4ec615d9cef48f3edf0d02 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 13:26:10 +0100 Subject: [PATCH 050/103] move some more logic out of main type parser --- src/Stage/Parse/Contextualize.elm | 181 +++++++++++++++--------------- 1 file changed, 93 insertions(+), 88 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index e304e64a..d19dfe26 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -671,79 +671,8 @@ parserTypeExpr newState prevExpr item = Debug.todo "Make this state impossible" NestingLeafType_Bracket argStack mLastExpression -> - let - rexpr = - if argStack /= empty && mLastExpression == Nothing then - -- We have a trailing comma! - Error_UnmatchedBracket Lexer.Round Lexer.Close - |> Err - - else - let - fullArgsList = - (case mLastExpression of - Just expr -> - expr |> pushOnto argStack - - Nothing -> - argStack - ) - |> toList (\x -> x) - in - case fullArgsList of - [] -> - TypeExpression_Unit - |> Ok - - first :: [] -> - TypeExpression_Bracketed first - |> Ok - - first :: second :: rest -> - TypeExpression_Tuple first second rest - |> Ok - in - case rexpr of - Ok expr -> - case collapsedLeaf.parents of - nesting :: grandparents -> - { nesting = - case nesting of - NestingParentType_PartialRecord { firstEntries, lastEntryName } -> - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr - } - - NestingParentType_Bracket els -> - NestingLeafType_Bracket els (Just expr) - - NestingParentType_TypeWithArgs { name, args } -> - NestingLeafType_TypeWithArgs - { name = name - , args = expr |> pushOnto args - } - - NestingParentType_Function { firstInput } -> - NestingLeafType_Function - { firstInput = firstInput - , otherInputs = empty - , output = Just expr - } - , parents = grandparents - } - |> TypeExpressionResult_Progress - |> newState - - [] -> - { nesting = NestingLeafType_Expr expr - , parents = [] - } - |> TypeExpressionResult_Progress - |> newState - - Err e -> - ParseResult_Err e + closeBracket argStack mLastExpression collapsedLeaf.parents + |> partialTypeExpressionToParseResult newState NestingLeafType_PartialRecord _ -> Error_InvalidToken Expecting_Unknown @@ -759,21 +688,18 @@ parserTypeExpr newState prevExpr item = Debug.todo "Make this state impossible" Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> - case leafToParents prevExpr of - Ok newParents -> - { nesting = - NestingLeafType_PartialRecord - { firstEntries = empty - , lastEntry = LastEntryOfRecord_Empty - } - , parents = newParents - } - |> TypeExpressionResult_Progress - |> newState - - Err e -> - e - |> ParseResult_Err + leafToParents prevExpr + |> Result.map + (\newParents -> + { nesting = + NestingLeafType_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty + } + , parents = newParents + } + ) + |> partialTypeExpressionToParseResult newState Lexer.Sigil Lexer.Colon -> appendColonTo prevExpr @@ -1178,6 +1104,85 @@ appendColonTo prevExpr = |> Err +closeBracket : + Stack PartialTypeExpression + -> Maybe PartialTypeExpression + -> List NestingParentType + -> Result Error PartialTypeExpressionLeaf +closeBracket argStack mLastExpression parents = + let + rexpr = + if argStack /= empty && mLastExpression == Nothing then + -- We have a trailing comma! + Error_UnmatchedBracket Lexer.Round Lexer.Close + |> Err + + else + let + fullArgsList = + (case mLastExpression of + Just expr -> + expr |> pushOnto argStack + + Nothing -> + argStack + ) + |> toList (\x -> x) + in + case fullArgsList of + [] -> + TypeExpression_Unit + |> Ok + + first :: [] -> + TypeExpression_Bracketed first + |> Ok + + first :: second :: rest -> + TypeExpression_Tuple first second rest + |> Ok + in + case rexpr of + Ok expr -> + case parents of + nesting :: grandparents -> + { nesting = + case nesting of + NestingParentType_PartialRecord { firstEntries, lastEntryName } -> + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr + } + + NestingParentType_Bracket els -> + NestingLeafType_Bracket els (Just expr) + + NestingParentType_TypeWithArgs { name, args } -> + NestingLeafType_TypeWithArgs + { name = name + , args = expr |> pushOnto args + } + + NestingParentType_Function { firstInput } -> + NestingLeafType_Function + { firstInput = firstInput + , otherInputs = empty + , output = Just expr + } + , parents = grandparents + } + |> Ok + + [] -> + { nesting = NestingLeafType_Expr expr + , parents = [] + } + |> Ok + + Err e -> + Err e + + blockFromState : State -> Maybe (Result Error Block) blockFromState state = case state of From 95139d6efb0229b827e67b9eed937f33eff73eb8 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 13:35:06 +0100 Subject: [PATCH 051/103] start deduplicating code --- src/Stage/Parse/Contextualize.elm | 132 ++++++++++-------------------- 1 file changed, 42 insertions(+), 90 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index d19dfe26..870dbf18 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -945,6 +945,42 @@ leafToParents { parents, nesting } = (\n -> n :: parents) +parentsToLeafWith : PartialTypeExpression -> List NestingParentType -> PartialTypeExpressionLeaf +parentsToLeafWith expr parents = + case parents of + nesting :: grandparents -> + { nesting = + case nesting of + NestingParentType_PartialRecord { firstEntries, lastEntryName } -> + NestingLeafType_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr + } + + NestingParentType_Bracket els -> + NestingLeafType_Bracket els (Just expr) + + NestingParentType_TypeWithArgs { name, args } -> + NestingLeafType_TypeWithArgs + { name = name + , args = expr |> pushOnto args + } + + NestingParentType_Function { firstInput, otherInputs } -> + NestingLeafType_Function + { firstInput = firstInput + , otherInputs = otherInputs + , output = Just expr + } + , parents = grandparents + } + + [] -> + { nesting = NestingLeafType_Expr expr + , parents = [] + } + + exprAppend : PartialTypeExpressionLeaf -> String @@ -1144,40 +1180,8 @@ closeBracket argStack mLastExpression parents = in case rexpr of Ok expr -> - case parents of - nesting :: grandparents -> - { nesting = - case nesting of - NestingParentType_PartialRecord { firstEntries, lastEntryName } -> - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr - } - - NestingParentType_Bracket els -> - NestingLeafType_Bracket els (Just expr) - - NestingParentType_TypeWithArgs { name, args } -> - NestingLeafType_TypeWithArgs - { name = name - , args = expr |> pushOnto args - } - - NestingParentType_Function { firstInput } -> - NestingLeafType_Function - { firstInput = firstInput - , otherInputs = empty - , output = Just expr - } - , parents = grandparents - } - |> Ok - - [] -> - { nesting = NestingLeafType_Expr expr - , parents = [] - } - |> Ok + parentsToLeafWith expr parents + |> Ok Err e -> Err e @@ -1305,36 +1309,8 @@ autoCollapseNesting collapseLevel pte = newTypeExpr = TypeExpression_NamedType { name = name, args = args } in - case pte.parents of - nesting :: grandparents -> - { parents = grandparents - , nesting = - case nesting of - NestingParentType_TypeWithArgs _ -> - Debug.todo "Make this state impossible" - - NestingParentType_Function { firstInput, otherInputs } -> - NestingLeafType_Function - { firstInput = firstInput - , otherInputs = otherInputs - , output = Just newTypeExpr - } - - NestingParentType_Bracket els -> - NestingLeafType_Bracket els (Just newTypeExpr) - - NestingParentType_PartialRecord { firstEntries, lastEntryName } -> - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyValue lastEntryName newTypeExpr - } - } - |> autoCollapseNesting collapseLevel - - [] -> - { nesting = NestingLeafType_Expr newTypeExpr - , parents = [] - } + parentsToLeafWith newTypeExpr pte.parents + |> autoCollapseNesting collapseLevel NestingLeafType_Expr _ -> pte @@ -1362,32 +1338,8 @@ autoCollapseNesting collapseLevel pte = , output = outputExpr } in - case pte.parents of - nesting :: grandparents -> - { parents = grandparents - , nesting = - case nesting of - NestingParentType_TypeWithArgs _ -> - Debug.todo "Make this state impossible" - - NestingParentType_Function _ -> - Debug.todo "Make this state impossible" - - NestingParentType_Bracket els -> - NestingLeafType_Bracket els (Just newTypeExpr) - - NestingParentType_PartialRecord { firstEntries, lastEntryName } -> - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyValue lastEntryName newTypeExpr - } - } - |> autoCollapseNesting collapseLevel - - [] -> - { nesting = NestingLeafType_Expr newTypeExpr - , parents = [] - } + parentsToLeafWith newTypeExpr pte.parents + |> autoCollapseNesting collapseLevel {-| TODO(harry): We can add things to a tuple too! Rename this function From 5c504a04077f386db5870d7cf72e05ed786e5d4b Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 13:46:04 +0100 Subject: [PATCH 052/103] move record closing into new function --- src/Stage/Parse/Contextualize.elm | 117 ++++++++++-------------------- 1 file changed, 39 insertions(+), 78 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 870dbf18..6c0368ae 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -726,84 +726,9 @@ parserTypeExpr newState prevExpr item = Error_InvalidToken Expecting_Unknown |> ParseResult_Err - NestingLeafType_PartialRecord { firstEntries, lastEntry } -> - let - fromRecord recordEntries = - let - record = - TypeExpression_Record recordEntries - in - case collapsedLeaf.parents of - [] -> - { nesting = NestingLeafType_Expr record - , parents = [] - } - |> TypeExpressionResult_Progress - |> newState - - nesting :: grandparents -> - (case nesting of - -- We are within a nested bracket. - NestingParentType_Bracket argStack -> - { parents = grandparents - , nesting = NestingLeafType_Bracket argStack (Just record) - } - - NestingParentType_PartialRecord existingPartialRecord -> - { parents = grandparents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = existingPartialRecord.firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue - existingPartialRecord.lastEntryName - record - } - } - - NestingParentType_TypeWithArgs { name, args } -> - { nesting = - NestingLeafType_TypeWithArgs - { name = name - , args = - record - |> pushOnto args - } - , parents = grandparents - } - - NestingParentType_Function { firstInput, otherInputs } -> - { nesting = - NestingLeafType_Function - { firstInput = firstInput - , otherInputs = otherInputs - , output = Just record - } - , parents = grandparents - } - ) - |> TypeExpressionResult_Progress - |> newState - in - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - ( key, value ) - |> pushOnto firstEntries - |> toList (\x -> x) - |> fromRecord - - LastEntryOfRecord_Empty -> - if firstEntries == empty then - [] - |> fromRecord - - else - Error_InvalidToken Expecting_Unknown - |> ParseResult_Err - - _ -> - Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + NestingLeafType_PartialRecord pr -> + closeRecord pr collapsedLeaf.parents + |> partialTypeExpressionToParseResult newState NestingLeafType_Function { output } -> case output of @@ -1187,6 +1112,42 @@ closeBracket argStack mLastExpression parents = Err e +closeRecord : + PartialRecord + -> List NestingParentType + -> Result Error PartialTypeExpressionLeaf +closeRecord { firstEntries, lastEntry } parents = + let + fromRecord recordEntries = + let + record = + TypeExpression_Record recordEntries + in + parentsToLeafWith record parents + in + case lastEntry of + LastEntryOfRecord_KeyValue key value -> + ( key, value ) + |> pushOnto firstEntries + |> toList (\x -> x) + |> fromRecord + |> Ok + + LastEntryOfRecord_Empty -> + if firstEntries == empty then + [] + |> fromRecord + |> Ok + + else + Error_InvalidToken Expecting_Unknown + |> Err + + _ -> + Error_InvalidToken Expecting_Unknown + |> Err + + blockFromState : State -> Maybe (Result Error Block) blockFromState state = case state of From 0b05330de2bdf3209094b8d04edf97d4a0cadf08 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 13:52:34 +0100 Subject: [PATCH 053/103] improve bad bracket errors --- src/Stage/Parse/Contextualize.elm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 6c0368ae..b4ea2663 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -199,6 +199,11 @@ type Error | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole + | Error_WrongClosingBracket + { expecting : Lexer.BracketType + , found : Lexer.BracketType + } + | Error_MissingFunctionReturnType | Error_ExpectedColonWhilstParsingRecord | Error_ExpectedKeyWhilstParsingRecord | Error_TypeDoesNotTakeArgs PartialTypeExpression PartialTypeExpression @@ -675,13 +680,16 @@ parserTypeExpr newState prevExpr item = |> partialTypeExpressionToParseResult newState NestingLeafType_PartialRecord _ -> - Error_InvalidToken Expecting_Unknown + Error_WrongClosingBracket + { expecting = Lexer.Curly + , found = Lexer.Round + } |> ParseResult_Err NestingLeafType_Function { output } -> case output of Nothing -> - Error_InvalidToken Expecting_Unknown + Error_MissingFunctionReturnType |> ParseResult_Err Just _ -> @@ -723,7 +731,10 @@ parserTypeExpr newState prevExpr item = Debug.todo "Make this state impossible" NestingLeafType_Bracket argStack mLastExpression -> - Error_InvalidToken Expecting_Unknown + Error_WrongClosingBracket + { expecting = Lexer.Round + , found = Lexer.Curly + } |> ParseResult_Err NestingLeafType_PartialRecord pr -> @@ -733,7 +744,7 @@ parserTypeExpr newState prevExpr item = NestingLeafType_Function { output } -> case output of Nothing -> - Error_InvalidToken Expecting_Unknown + Error_MissingFunctionReturnType |> ParseResult_Err Just _ -> From 52da3ced0caefb855989e74c3b30e92b2e12a95f Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 14:04:32 +0100 Subject: [PATCH 054/103] handle nested function types correctly --- .../type-alias-function-nested-missing-return | 7 + .../should-parse/type-alias-function-nested | 7 + src/Stage/Parse/Contextualize.elm | 56 ++- tests/ParserLexerTestCases.elm | 412 +++++++++++++++++- 4 files changed, 478 insertions(+), 4 deletions(-) create mode 100644 parser-tests/snippets/should-not-parse/type-alias-function-nested-missing-return create mode 100644 parser-tests/snippets/should-parse/type-alias-function-nested diff --git a/parser-tests/snippets/should-not-parse/type-alias-function-nested-missing-return b/parser-tests/snippets/should-not-parse/type-alias-function-nested-missing-return new file mode 100644 index 00000000..33c0ccb0 --- /dev/null +++ b/parser-tests/snippets/should-not-parse/type-alias-function-nested-missing-return @@ -0,0 +1,7 @@ +type alias Function = (() -> ) + +type alias Function2 = { a: () -> } + +type alias Function3 = (() -> , ()) + +type alias Function3 = (Int, () ->, ()) diff --git a/parser-tests/snippets/should-parse/type-alias-function-nested b/parser-tests/snippets/should-parse/type-alias-function-nested new file mode 100644 index 00000000..0960177f --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-function-nested @@ -0,0 +1,7 @@ +type alias Function = (() -> (Int, String)) + +type alias Function2 = { a: () -> (Int, String) } + +type alias Function3 = (() -> (Int, String), ()) + +type alias Function3 = (Int, () -> (Int, String), ()) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index b4ea2663..d678d6cc 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -224,6 +224,7 @@ type Expecting = Expecting_Sigil Lexer.LexSigil | Expecting_Block | Expecting_TypeName + | Expecting_Identifier -- TODO(harry): reduce number of cases where we do not know what sigil we -- are expecting. | Expecting_Unknown @@ -768,8 +769,11 @@ parserTypeExpr newState prevExpr item = _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err + + collapsedLeaf = + autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr in - case (autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr).nesting of + case collapsedLeaf.nesting of NestingLeafType_Expr expr -> { nesting = NestingLeafType_Function @@ -782,6 +786,9 @@ parserTypeExpr newState prevExpr item = |> TypeExpressionResult_Progress |> newState + NestingLeafType_TypeWithArgs {} -> + Debug.todo "make state impossible" + NestingLeafType_Function { firstInput, otherInputs, output } -> case output of Nothing -> @@ -795,15 +802,58 @@ parserTypeExpr newState prevExpr item = , otherInputs = output_ |> pushOnto otherInputs , output = Nothing } - , parents = [] + , parents = collapsedLeaf.parents } |> TypeExpressionResult_Progress |> newState - _ -> + NestingLeafType_Bracket argStack (Just expr) -> + { nesting = + NestingLeafType_Function + { firstInput = expr + , otherInputs = empty + , output = Nothing + } + , parents = NestingParentType_Bracket argStack :: collapsedLeaf.parents + } + |> TypeExpressionResult_Progress + |> newState + + NestingLeafType_Bracket argStack Nothing -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err + NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + case lastEntry of + LastEntryOfRecord_Empty -> + Error_InvalidToken Expecting_Identifier + |> ParseResult_Err + + LastEntryOfRecord_Key _ -> + Error_InvalidToken (Expecting_Sigil Lexer.Colon) + |> ParseResult_Err + + LastEntryOfRecord_KeyColon _ -> + Error_InvalidToken Expecting_Unknown + |> ParseResult_Err + + LastEntryOfRecord_KeyValue key value -> + { nesting = + NestingLeafType_Function + { firstInput = value + , otherInputs = empty + , output = Nothing + } + , parents = + NestingParentType_PartialRecord + { firstEntries = firstEntries + , lastEntryName = key + } + :: collapsedLeaf.parents + } + |> TypeExpressionResult_Progress + |> newState + Lexer.Newlines _ 0 -> case (autoCollapseNesting CollapseLevel_Function prevExpr).nesting of NestingLeafType_Expr expr -> diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index b955943c..3717427f 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -337,6 +337,251 @@ type alias Function = A -> B -> C -> D } ] } + , { name = "type-alias-function-nested" + , source = """type alias Function = (() -> (Int, String)) + +type alias Function2 = { a: () -> (Int, String) } + +type alias Function3 = (() -> (Int, String), ()) + +type alias Function3 = (Int, () -> (Int, String), ()) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Token "Int") + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil Comma) + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Whitespace 1) + , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Token "String") + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 44, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "type") + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token "alias") + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token "Function2") + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Sigil Assign) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "a") + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil Colon) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Whitespace 1) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Whitespace 1) + , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Sigil ThinArrow) + , Located { end = { col = 35, row = 3 }, start = { col = 34, row = 3 } } (Whitespace 1) + , Located { end = { col = 36, row = 3 }, start = { col = 35, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Token "Int") + , Located { end = { col = 40, row = 3 }, start = { col = 39, row = 3 } } (Sigil Comma) + , Located { end = { col = 41, row = 3 }, start = { col = 40, row = 3 } } (Whitespace 1) + , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Token "String") + , Located { end = { col = 48, row = 3 }, start = { col = 47, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 49, row = 3 }, start = { col = 48, row = 3 } } (Whitespace 1) + , Located { end = { col = 50, row = 3 }, start = { col = 49, row = 3 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 50, row = 3 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token "type") + , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) + , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token "alias") + , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token "Function3") + , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Whitespace 1) + , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Sigil Assign) + , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) + , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 27, row = 5 }, start = { col = 26, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 28, row = 5 }, start = { col = 27, row = 5 } } (Whitespace 1) + , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Sigil ThinArrow) + , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Whitespace 1) + , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Token "Int") + , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Sigil Comma) + , Located { end = { col = 37, row = 5 }, start = { col = 36, row = 5 } } (Whitespace 1) + , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Token "String") + , Located { end = { col = 44, row = 5 }, start = { col = 43, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 45, row = 5 }, start = { col = 44, row = 5 } } (Sigil Comma) + , Located { end = { col = 46, row = 5 }, start = { col = 45, row = 5 } } (Whitespace 1) + , Located { end = { col = 47, row = 5 }, start = { col = 46, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 48, row = 5 }, start = { col = 47, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 49, row = 5 }, start = { col = 48, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 7 }, start = { col = 49, row = 5 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token "type") + , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Whitespace 1) + , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token "alias") + , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Whitespace 1) + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token "Function3") + , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Whitespace 1) + , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Sigil Assign) + , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Whitespace 1) + , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token "Int") + , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Sigil Comma) + , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Whitespace 1) + , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 32, row = 7 }, start = { col = 31, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 33, row = 7 }, start = { col = 32, row = 7 } } (Whitespace 1) + , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Sigil ThinArrow) + , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Whitespace 1) + , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Token "Int") + , Located { end = { col = 41, row = 7 }, start = { col = 40, row = 7 } } (Sigil Comma) + , Located { end = { col = 42, row = 7 }, start = { col = 41, row = 7 } } (Whitespace 1) + , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Token "String") + , Located { end = { col = 49, row = 7 }, start = { col = 48, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 50, row = 7 }, start = { col = 49, row = 7 } } (Sigil Comma) + , Located { end = { col = 51, row = 7 }, start = { col = 50, row = 7 } } (Whitespace 1) + , Located { end = { col = 52, row = 7 }, start = { col = 51, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 53, row = 7 }, start = { col = 52, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 54, row = 7 }, start = { col = 53, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 8 }, start = { col = 54, row = 7 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Function + { from = Unit + , to = + Tuple + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } + ) + } + , ty = TypeOrConstructor "Function" + } + ) + , Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "a" + , Function + { from = Unit + , to = + Tuple + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } + ) + } + ) + ] + ) + , ty = TypeOrConstructor "Function2" + } + ) + , Ok + (TypeAlias + { expr = + Tuple + (Function + { from = Unit + , to = + Tuple + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } + ) + } + ) + Unit + , ty = TypeOrConstructor "Function3" + } + ) + , Ok + (TypeAlias + { expr = + Tuple3 + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (Function + { from = Unit + , to = + Tuple + (UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + (UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } + ) + } + ) + Unit + , ty = TypeOrConstructor "Function3" + } + ) + ] + } , { name = "type-alias-function-record" , source = """type alias Function = { a: { b: C}, d: E } -> {} """ @@ -1306,7 +1551,172 @@ shouldNotParseTestCases : , source : String } shouldNotParseTestCases = - [ { name = "type-alias-invalid-multiple-brackets" + [ { name = "type-alias-function-nested-missing-return" + , source = """type alias Function = (() -> ) + +type alias Function2 = { a: () -> } + +type alias Function3 = (() -> , ()) + +type alias Function3 = (Int, () ->, ()) +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 31, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "type") + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token "alias") + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token "Function2") + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Sigil Assign) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "a") + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil Colon) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Whitespace 1) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Whitespace 1) + , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Sigil ThinArrow) + , Located { end = { col = 36, row = 3 }, start = { col = 34, row = 3 } } (Whitespace 2) + , Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 37, row = 3 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token "type") + , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) + , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token "alias") + , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token "Function3") + , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Whitespace 1) + , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Sigil Assign) + , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) + , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 27, row = 5 }, start = { col = 26, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 28, row = 5 }, start = { col = 27, row = 5 } } (Whitespace 1) + , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Sigil ThinArrow) + , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Whitespace 1) + , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil Comma) + , Located { end = { col = 33, row = 5 }, start = { col = 32, row = 5 } } (Whitespace 1) + , Located { end = { col = 34, row = 5 }, start = { col = 33, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 35, row = 5 }, start = { col = 34, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 7 }, start = { col = 36, row = 5 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token "type") + , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Whitespace 1) + , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token "alias") + , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Whitespace 1) + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token "Function3") + , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Whitespace 1) + , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Sigil Assign) + , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Whitespace 1) + , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token "Int") + , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Sigil Comma) + , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Whitespace 1) + , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 32, row = 7 }, start = { col = 31, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 33, row = 7 }, start = { col = 32, row = 7 } } (Whitespace 1) + , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Sigil ThinArrow) + , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Sigil Comma) + , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Whitespace 1) + , Located { end = { col = 38, row = 7 }, start = { col = 37, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 39, row = 7 }, start = { col = 38, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 40, row = 7 }, start = { col = 39, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 8 }, start = { col = 40, row = 7 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Err + { error = Error_MissingFunctionReturnType + , item = Just (Sigil (Bracket Round Close)) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function") + { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } + , parents = + [ NestingParentType_Bracket (Stack []) + ] + } + ) + } + , Err + { error = Error_MissingFunctionReturnType + , item = Just (Sigil (Bracket Curly Close)) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function2") + { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } + , parents = + [ NestingParentType_PartialRecord { firstEntries = Stack [], lastEntryName = "a" } + ] + } + ) + } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Sigil Comma) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function3") + { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } + , parents = + [ NestingParentType_Bracket (Stack []) + ] + } + ) + } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Sigil Comma) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function3") + { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } + , parents = + [ NestingParentType_Bracket + (Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + ) + ] + } + ) + } + ] + } + , { name = "type-alias-invalid-multiple-brackets" , source = """type alias Hi = (Int) () """ , lexed = From cd5edb0469ddb5cd22f66371131a04386f85c3a1 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 14:37:58 +0100 Subject: [PATCH 055/103] add generic args to trype alias AST --- src/Stage/Parse/Contextualize.elm | 45 +++++++++++++---------- src/Stage/Parse/Token.elm | 10 ++--- tests/ParserLexerTestCases.elm | 61 ++++++++++++++++++++++++------- 3 files changed, 77 insertions(+), 39 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index d678d6cc..61c6334f 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -66,6 +66,7 @@ type Block } | TypeAlias { ty : Token.TypeOrConstructor + , genericArgs : List Token.ValueOrFunctionOrGenericType , expr : ConcreteType PossiblyQualified } | CustomType @@ -99,15 +100,15 @@ type alias State_ = type BlockFirstItem = BlockFirstItem_Type | BlockFirstItem_Module - | BlockFirstItem_Name Token.ValueOrFunction + | BlockFirstItem_Name Token.ValueOrFunctionOrGenericType type BlockTypeAlias = BlockTypeAlias_Keywords - | BlockTypeAlias_Named Token.TypeOrConstructor - | BlockTypeAlias_NamedAssigns Token.TypeOrConstructor - | BlockTypeAlias_Completish Token.TypeOrConstructor PartialTypeExpressionLeaf - | BlockTypeAlias_Complete Token.TypeOrConstructor PartialTypeExpression + | BlockTypeAlias_Named Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) + | BlockTypeAlias_NamedAssigns Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) + | BlockTypeAlias_Completish Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) PartialTypeExpressionLeaf + | BlockTypeAlias_Complete Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) PartialTypeExpression type BlockCustomType @@ -197,7 +198,7 @@ type Error = Error_InvalidToken Expecting | Error_MisplacedKeyword Keyword | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor - | Error_TypeNameStartsWithLowerCase Token.ValueOrFunction + | Error_TypeNameStartsWithLowerCase Token.ValueOrFunctionOrGenericType | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole | Error_WrongClosingBracket { expecting : Lexer.BracketType @@ -336,16 +337,17 @@ runHelp items state = parseAnything : State -> LexItem -> ParseResult parseAnything state = let - newTypeAliasState aliasName res = + newTypeAliasState aliasName typeArgs res = case res of TypeExpressionResult_Progress expr -> - State_BlockTypeAlias (BlockTypeAlias_Completish aliasName expr) + State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs expr) |> ParseResult_Ok TypeExpressionResult_Done expr -> case partialTypeExpressionToConcreteType expr of Ok concreteType -> { ty = aliasName + , genericArgs = typeArgs , expr = concreteType } |> TypeAlias @@ -382,25 +384,26 @@ parseAnything state = State_BlockTypeAlias BlockTypeAlias_Keywords -> parseTypeAliasName - State_BlockTypeAlias (BlockTypeAlias_Named name) -> + State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> parseAssignment - (State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name)) + (State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs)) - State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name) -> + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> parserTypeExprFromEmpty - (newTypeAliasState name) + (newTypeAliasState name typeArgs) - State_BlockTypeAlias (BlockTypeAlias_Completish name exprSoFar) -> + State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> parserTypeExpr - (newTypeAliasState name) + (newTypeAliasState name typeArgs) exprSoFar - State_BlockTypeAlias (BlockTypeAlias_Complete aliasName expr) -> + State_BlockTypeAlias (BlockTypeAlias_Complete aliasName typeArgs expr) -> let rBlock = case partialTypeExpressionToConcreteType expr of Ok concreteType -> { ty = aliasName + , genericArgs = typeArgs , expr = concreteType } |> TypeAlias @@ -530,7 +533,7 @@ parseTypeAliasName item = |> ParseResult_Err Token.TokenTypeOrConstructor typeOrConstructor -> - State_BlockTypeAlias (BlockTypeAlias_Named typeOrConstructor) + State_BlockTypeAlias (BlockTypeAlias_Named typeOrConstructor []) |> ParseResult_Ok Token.TokenValueOrFunction valOrFunc -> @@ -1226,23 +1229,24 @@ blockFromState state = |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Named _) -> + State_BlockTypeAlias (BlockTypeAlias_Named _ _) -> Error_PartwayThroughTypeAlias |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_NamedAssigns _) -> + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns _ _) -> Error_PartwayThroughTypeAlias |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Completish aliasName partialExpr) -> + State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs partialExpr) -> case (autoCollapseNesting CollapseLevel_Function partialExpr).nesting of NestingLeafType_Expr expr -> partialTypeExpressionToConcreteType expr |> Result.map (\conceteType -> { ty = aliasName + , genericArgs = typeArgs , expr = conceteType } |> TypeAlias @@ -1255,10 +1259,11 @@ blockFromState state = |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Complete aliasName expr) -> + State_BlockTypeAlias (BlockTypeAlias_Complete aliasName typeArgs expr) -> case partialTypeExpressionToConcreteType expr of Ok concreteType -> { ty = aliasName + , genericArgs = typeArgs , expr = concreteType } |> TypeAlias diff --git a/src/Stage/Parse/Token.elm b/src/Stage/Parse/Token.elm index b3c5fa33..51d55e17 100644 --- a/src/Stage/Parse/Token.elm +++ b/src/Stage/Parse/Token.elm @@ -17,13 +17,13 @@ type TypeOrConstructor = TypeOrConstructor String -type ValueOrFunction - = ValueOrFunction String +type ValueOrFunctionOrGenericType + = ValueOrFunctionOrGenericType String type Token = TokenTypeOrConstructor TypeOrConstructor - | TokenValueOrFunction ValueOrFunction + | TokenValueOrFunction ValueOrFunctionOrGenericType | TokenKeyword Keyword @@ -97,7 +97,7 @@ classifyToken token = TokenTypeOrConstructor (TypeOrConstructor token) else - TokenValueOrFunction (ValueOrFunction token) + TokenValueOrFunction (ValueOrFunctionOrGenericType token) Nothing -> - TokenValueOrFunction (ValueOrFunction token) + TokenValueOrFunction (ValueOrFunctionOrGenericType token) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 3717427f..fb28c22d 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -59,6 +59,7 @@ shouldParseTestCases = , name = "List" , qualifiedness = PossiblyQualified Nothing } + , genericArgs = [] , ty = TypeOrConstructor "Model" } ) @@ -105,6 +106,7 @@ shouldParseTestCases = ) ] ) + , genericArgs = [] , ty = TypeOrConstructor "Ty" } ) @@ -175,6 +177,7 @@ shouldParseTestCases = , qualifiedness = PossiblyQualified Nothing } } + , genericArgs = [] , ty = TypeOrConstructor "Function" } ) @@ -255,6 +258,7 @@ type alias Function = A -> B -> C -> D } } } + , genericArgs = [] , ty = TypeOrConstructor "Function" } ) @@ -293,6 +297,7 @@ type alias Function = A -> B -> C -> D } } } + , genericArgs = [] , ty = TypeOrConstructor "Function" } ) @@ -333,7 +338,7 @@ type alias Function = A -> B -> C -> D [ Err { error = Error_InvalidToken (Expecting_Sigil Assign) , item = Just (Token "a") - , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function")) + , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function") []) } ] } @@ -490,6 +495,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) } + , genericArgs = [] , ty = TypeOrConstructor "Function" } ) @@ -519,6 +525,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ] ) + , genericArgs = [] , ty = TypeOrConstructor "Function2" } ) @@ -545,6 +552,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) Unit + , genericArgs = [] , ty = TypeOrConstructor "Function3" } ) @@ -577,6 +585,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) Unit + , genericArgs = [] , ty = TypeOrConstructor "Function3" } ) @@ -655,6 +664,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) , to = Record (Dict.fromList []) } + , genericArgs = [] , ty = TypeOrConstructor "Function" } ) @@ -708,6 +718,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) } + , genericArgs = [] , ty = TypeOrConstructor "Function" } ) @@ -748,6 +759,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , name = "List" , qualifiedness = PossiblyQualified Nothing } + , genericArgs = [] , ty = TypeOrConstructor "Model" } ) @@ -789,6 +801,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , name = "List" , qualifiedness = PossiblyQualified Nothing } + , genericArgs = [] , ty = TypeOrConstructor "Model" } ) @@ -859,6 +872,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ] ) + , genericArgs = [] , ty = TypeOrConstructor "Ty" } ) @@ -883,7 +897,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , contextualized = Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), ty = TypeOrConstructor "Ty" }) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = TypeOrConstructor "Ty" }) ] } , { name = "type-alias-record-empty-multiline" @@ -915,7 +929,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , contextualized = Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), ty = TypeOrConstructor "Ty" }) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = TypeOrConstructor "Ty" }) ] } , { name = "type-alias-record-in-bracket" @@ -959,6 +973,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ] ) + , genericArgs = [] , ty = TypeOrConstructor "Ty" } ) @@ -1093,6 +1108,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ] ) + , genericArgs = [] , ty = TypeOrConstructor "Ty" } ) @@ -1137,6 +1153,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ] ) + , genericArgs = [] , ty = TypeOrConstructor "Ty" } ) @@ -1194,6 +1211,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ] ) + , genericArgs = [] , ty = TypeOrConstructor "Ty" } ) @@ -1218,7 +1236,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , contextualized = Just - [ Ok (TypeAlias { expr = Unit, ty = TypeOrConstructor "Hi" }) + [ Ok (TypeAlias { expr = Unit, genericArgs = [], ty = TypeOrConstructor "Hi" }) ] } , { name = "type-alias-with-bracket" @@ -1249,6 +1267,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , name = "Int" , qualifiedness = PossiblyQualified Nothing } + , genericArgs = [] , ty = TypeOrConstructor "Hi" } ) @@ -1290,6 +1309,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , name = "List" , qualifiedness = PossiblyQualified Nothing } + , genericArgs = [] , ty = TypeOrConstructor "Hi" } ) @@ -1355,6 +1375,7 @@ type alias Hi = (Int) , qualifiedness = PossiblyQualified Nothing } ) + , genericArgs = [] , ty = TypeOrConstructor "Hi" } ) @@ -1366,6 +1387,7 @@ type alias Hi = (Int) , name = "Int" , qualifiedness = PossiblyQualified Nothing } + , genericArgs = [] , ty = TypeOrConstructor "Hi" } ) @@ -1441,10 +1463,11 @@ type alias Hi = ((), (), ()) , qualifiedness = PossiblyQualified Nothing } ) + , genericArgs = [] , ty = TypeOrConstructor "Hi" } ) - , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, ty = TypeOrConstructor "Hi" }) + , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, genericArgs = [], ty = TypeOrConstructor "Hi" }) ] } , { name = "type-alias-with-tripple-in-record" @@ -1535,6 +1558,7 @@ type alias Hi = ((), (), ()) ) ] ) + , genericArgs = [] , ty = TypeOrConstructor "Hi" } ) @@ -1664,6 +1688,7 @@ type alias Function3 = (Int, () ->, ()) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Function") + [] { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } , parents = [ NestingParentType_Bracket (Stack []) @@ -1677,6 +1702,7 @@ type alias Function3 = (Int, () ->, ()) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Function2") + [] { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } , parents = [ NestingParentType_PartialRecord { firstEntries = Stack [], lastEntryName = "a" } @@ -1690,6 +1716,7 @@ type alias Function3 = (Int, () ->, ()) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Function3") + [] { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } , parents = [ NestingParentType_Bracket (Stack []) @@ -1703,6 +1730,7 @@ type alias Function3 = (Int, () ->, ()) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Function3") + [] { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } , parents = [ NestingParentType_Bracket @@ -1742,7 +1770,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) , item = Just (Sigil (Bracket Round Open)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) } ] } @@ -1771,7 +1799,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit , item = Just (Sigil (Bracket Round Open)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] } @@ -1801,7 +1829,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit , item = Just (Sigil (Bracket Round Open)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] } @@ -1829,7 +1857,7 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Newlines [] 0) - , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model")) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model") []) } , Err { error = Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") @@ -1874,7 +1902,7 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Newlines [] 0) - , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi")) + , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi") []) } ] } @@ -1897,7 +1925,7 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Newlines [] 0) - , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi")) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi") []) } ] } @@ -1922,7 +1950,7 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Newlines [] 0) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) } ] } @@ -1953,6 +1981,7 @@ List Int , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + [] { nesting = NestingLeafType_TypeWithArgs { args = Stack [], name = "Int" } , parents = [ NestingParentType_Bracket (Stack []) @@ -1983,7 +2012,7 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Newlines [] 0) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) } ] } @@ -2014,7 +2043,7 @@ List Int [ Err { error = Error_ExpectedColonWhilstParsingRecord , item = Just (Token "j7") - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) } ] } @@ -2134,6 +2163,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + [] { nesting = NestingLeafType_Expr (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) @@ -2235,6 +2265,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + [] { nesting = NestingLeafType_Expr (TypeExpression_Tuple @@ -2321,6 +2352,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + [] { nesting = NestingLeafType_Bracket (Stack @@ -2378,6 +2410,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + [] { nesting = NestingLeafType_Bracket (Stack From 3779ea548ad9acb896c9aae6bfc3a1cebebbe1e2 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 14:47:10 +0100 Subject: [PATCH 056/103] parse generic type args in type alias --- src/Stage/Parse/Contextualize.elm | 66 ++++++++++++++++++++++++------- tests/ParserLexerTestCases.elm | 50 +++++++++++++++++++---- 2 files changed, 95 insertions(+), 21 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 61c6334f..406853d1 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -105,15 +105,15 @@ type BlockFirstItem type BlockTypeAlias = BlockTypeAlias_Keywords - | BlockTypeAlias_Named Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) + | BlockTypeAlias_Named Token.TypeOrConstructor (Stack Token.ValueOrFunctionOrGenericType) | BlockTypeAlias_NamedAssigns Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) | BlockTypeAlias_Completish Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) PartialTypeExpressionLeaf | BlockTypeAlias_Complete Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) PartialTypeExpression type BlockCustomType - = BlockCustomType_Named Token.TypeOrConstructor - | BlockCustomType_NamedAssigns Token.TypeOrConstructor + = BlockCustomType_Named Token.TypeOrConstructor (Stack Token.ValueOrFunctionOrGenericType) + | BlockCustomType_NamedAssigns Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) {-| Notes: @@ -385,8 +385,20 @@ parseAnything state = parseTypeAliasName State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> - parseAssignment - (State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs)) + parseTypeArgsOrAssignment + (\newTypeArg -> + State_BlockTypeAlias + (BlockTypeAlias_Named + name + (newTypeArg |> pushOnto typeArgs) + ) + ) + (State_BlockTypeAlias + (BlockTypeAlias_NamedAssigns + name + (typeArgs |> toList (\x -> x)) + ) + ) State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> parserTypeExprFromEmpty @@ -434,11 +446,23 @@ parseAnything state = Error_ExtraItemAfterBlock expr item |> ParseResult_Err - State_BlockCustomType (BlockCustomType_Named name) -> - parseAssignment - (State_BlockCustomType (BlockCustomType_NamedAssigns name)) + State_BlockCustomType (BlockCustomType_Named name typeArgs) -> + parseTypeArgsOrAssignment + (\newTypeArg -> + State_BlockCustomType + (BlockCustomType_Named + name + (newTypeArg |> pushOnto typeArgs) + ) + ) + (State_BlockCustomType + (BlockCustomType_NamedAssigns + name + (typeArgs |> toList (\x -> x)) + ) + ) - State_BlockCustomType (BlockCustomType_NamedAssigns name) -> + State_BlockCustomType (BlockCustomType_NamedAssigns name typeArgs) -> Debug.todo "BlockCustomType_NamedAssigns" @@ -497,7 +521,7 @@ parseTypeBlock item = |> ParseResult_Err Token.TokenTypeOrConstructor typeOrConstructor -> - State_BlockCustomType (BlockCustomType_Named typeOrConstructor) + State_BlockCustomType (BlockCustomType_Named typeOrConstructor empty) |> ParseResult_Ok Token.TokenValueOrFunction valOrFunc -> @@ -533,7 +557,7 @@ parseTypeAliasName item = |> ParseResult_Err Token.TokenTypeOrConstructor typeOrConstructor -> - State_BlockTypeAlias (BlockTypeAlias_Named typeOrConstructor []) + State_BlockTypeAlias (BlockTypeAlias_Named typeOrConstructor empty) |> ParseResult_Ok Token.TokenValueOrFunction valOrFunc -> @@ -555,11 +579,25 @@ parseTypeAliasName item = |> ParseResult_Err -parseAssignment : State -> LexItem -> ParseResult -parseAssignment newState item = +parseTypeArgsOrAssignment : (Token.ValueOrFunctionOrGenericType -> State) -> State -> LexItem -> ParseResult +parseTypeArgsOrAssignment onTypeArg onAssignment item = case item of + Lexer.Token str -> + case Token.classifyToken str of + Token.TokenKeyword kw -> + Error_MisplacedKeyword kw + |> ParseResult_Err + + Token.TokenTypeOrConstructor _ -> + Error_InvalidToken (Expecting_Sigil Lexer.Assign) + |> ParseResult_Err + + Token.TokenValueOrFunction argName -> + onTypeArg argName + |> ParseResult_Ok + Lexer.Sigil Lexer.Assign -> - newState + onAssignment |> ParseResult_Ok Lexer.Newlines _ 0 -> diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index fb28c22d..93d2383e 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -6,7 +6,7 @@ import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete exposing (ConcreteType(..)) import Stage.Parse.Contextualize as Contextualize exposing (..) import Stage.Parse.Lexer as Lexer exposing (..) -import Stage.Parse.Token exposing (TypeOrConstructor(..)) +import Stage.Parse.Token exposing (TypeOrConstructor(..), ValueOrFunctionOrGenericType(..)) import Test exposing (Test, describe, test) @@ -335,11 +335,47 @@ type alias Function = A -> B -> C -> D ] , contextualized = Just - [ Err - { error = Error_InvalidToken (Expecting_Sigil Assign) - , item = Just (Token "a") - , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Function") []) - } + [ Ok + (TypeAlias + { expr = + Function + { from = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , to = + UserDefinedType + { args = + [ UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "a" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + } + , genericArgs = + [ ValueOrFunctionOrGenericType "a" + ] + , ty = TypeOrConstructor "Function" + } + ) ] } , { name = "type-alias-function-nested" @@ -1902,7 +1938,7 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Newlines [] 0) - , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi") []) + , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi") (Stack [])) } ] } From 29cc96aab708f754defcf521ab982afac9e74727 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 18:23:21 +0100 Subject: [PATCH 057/103] drop unused custom type variant --- src/Stage/Parse/Contextualize.elm | 54 ------------------------------- 1 file changed, 54 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 406853d1..c9107546 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -108,7 +108,6 @@ type BlockTypeAlias | BlockTypeAlias_Named Token.TypeOrConstructor (Stack Token.ValueOrFunctionOrGenericType) | BlockTypeAlias_NamedAssigns Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) | BlockTypeAlias_Completish Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) PartialTypeExpressionLeaf - | BlockTypeAlias_Complete Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) PartialTypeExpression type BlockCustomType @@ -409,43 +408,6 @@ parseAnything state = (newTypeAliasState name typeArgs) exprSoFar - State_BlockTypeAlias (BlockTypeAlias_Complete aliasName typeArgs expr) -> - let - rBlock = - case partialTypeExpressionToConcreteType expr of - Ok concreteType -> - { ty = aliasName - , genericArgs = typeArgs - , expr = concreteType - } - |> TypeAlias - |> Ok - - Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> - Error_TooManyTupleArgs a b c d e - |> Err - in - \item -> - case item of - Lexer.Newlines _ 0 -> - case rBlock of - Ok block -> - block - |> ParseResult_Complete - - Err e -> - ParseResult_Err e - - Lexer.Newlines _ _ -> - ParseResult_Skip - - Whitespace _ -> - ParseResult_Skip - - _ -> - Error_ExtraItemAfterBlock expr item - |> ParseResult_Err - State_BlockCustomType (BlockCustomType_Named name typeArgs) -> parseTypeArgsOrAssignment (\newTypeArg -> @@ -1297,22 +1259,6 @@ blockFromState state = |> Err |> Just - State_BlockTypeAlias (BlockTypeAlias_Complete aliasName typeArgs expr) -> - case partialTypeExpressionToConcreteType expr of - Ok concreteType -> - { ty = aliasName - , genericArgs = typeArgs - , expr = concreteType - } - |> TypeAlias - |> Ok - |> Just - - Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> - Error_TooManyTupleArgs a b c d e - |> Err - |> Just - State_BlockCustomType firstItem -> Debug.todo "handle incomplete block" From 96fb3989107dea1f1608bf461fe8ca5123b36e2a Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 22:44:49 +0100 Subject: [PATCH 058/103] propagate lex locations further --- Makefile | 3 +- parser-tests/Update.elm | 29 ++++++++--------- parser-tests/update.js | 16 ++++----- src/Stage/Parse/Contextualize.elm | 36 ++++++++++----------- tests/ParserLexerTest.elm | 3 -- tests/ParserLexerTestCases.elm | 54 ++++++++++++++++--------------- 6 files changed, 69 insertions(+), 72 deletions(-) diff --git a/Makefile b/Makefile index deb61483..f63f6aec 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,8 @@ FORMAT_DIRS = \ cli \ example-library-usages \ src \ - tests + tests \ + parser-tests \ .PHONY: run run: build diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 2c5f1dfd..17add7bc 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -1,10 +1,10 @@ port module Update exposing (main) import Elm.Data.Located as Located exposing (Located) +import Parser.Advanced as P import Platform import Stage.Parse.Contextualize as Contextualize import Stage.Parse.Lexer as Lexer -import Parser.Advanced as P port output : String -> Cmd never @@ -51,12 +51,7 @@ init snippets = mrcontextualized = rlexed |> List.map - (Result.toMaybe - >> Maybe.map - (List.map Located.unwrap - >> Contextualize.run - ) - ) + (Result.toMaybe >> Maybe.map Contextualize.run) in ( () , output @@ -71,12 +66,12 @@ init snippets = ++ """\"\"\" , lexed = """ ++ (Debug.toString lexed - |> preFormatElmCode + |> preFormatElmCode ) ++ """ , contextualized =""" ++ (Debug.toString contextualized - |> preFormatElmCode + |> preFormatElmCode ) ++ """ }""" @@ -101,15 +96,17 @@ update () model = preFormatElmCode : String -> String preFormatElmCode = - {-String.replace "}" """ - }""" - >>-} String.replace "]" """ + {- String.replace "}" """ + }""" + >> + -} + String.replace "]" """ ]""" - >> String.replace """[ + >> String.replace """[ ]""" "[]" - >> String.replace """Err (""" """Err ( + >> String.replace """Err (""" """Err ( """ - >> String.replace """Err {""" """Err { + >> String.replace """Err {""" """Err { """ - >> String.replace """UserDefinedType {""" """UserDefinedType { + >> String.replace """UserDefinedType {""" """UserDefinedType { """ diff --git a/parser-tests/update.js b/parser-tests/update.js index 662113e1..ce8a2c72 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -30,11 +30,11 @@ const TEST_FILE_PATH = path.join(__dirname, '..', 'tests', 'ParserLexerTestCases const BASE_SNIPPETS_DIR_PATH = path.join(__dirname, 'snippets'); const SNIPPETS_DIR_PATH = Object.freeze({ shouldParse: path.join(BASE_SNIPPETS_DIR_PATH, 'should-parse'), - shouldNotParse: path.join(BASE_SNIPPETS_DIR_PATH, 'should-not-parse'), + shouldNotParse: path.join(BASE_SNIPPETS_DIR_PATH, 'should-not-parse') }); function getTestCase(snippets) { - return new Promise((resolve) => { + return new Promise(resolve => { const app = Elm.Update.init({flags: snippets}); app.ports.output.subscribe(resolve); }); @@ -66,12 +66,12 @@ async function main() { await Promise.all( files .sort() - .filter((name) => !name.startsWith('_')) - .map(async (name) => ({ + .filter(name => !name.startsWith('_')) + .map(async name => ({ name, - source: await fs.readFile(path.join(dirPath, name), 'utf-8'), + source: await fs.readFile(path.join(dirPath, name), 'utf-8') })) - ), + ) ]; }) ); @@ -96,9 +96,9 @@ async function main() { TYPE_OF_RESULT_CASES, `${category}TestCases =`, testCases, - '\n', + '\n' ]) - .join('\n'), + .join('\n') ].join('\n'); await fs.writeFile(TEST_FILE_PATH, newTestFile); diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index c9107546..30b5a360 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -237,13 +237,13 @@ type Expecting type alias RunResult = Result { state : State - , item : Maybe LexItem + , item : Maybe (Located LexItem) , error : Error } Block -run : List LexItem -> List RunResult +run : List (Located LexItem) -> List RunResult run items = runHelp items @@ -252,7 +252,7 @@ run items = } -runHelp : List LexItem -> State_ -> List RunResult +runHelp : List (Located LexItem) -> State_ -> List RunResult runHelp items state = case items of item :: rest -> @@ -282,7 +282,7 @@ runHelp items state = } :: state.previousBlocks , state = - case item of + case Located.unwrap item of Lexer.Newlines _ 0 -> State_BlockStart @@ -333,7 +333,7 @@ runHelp items state = -- parsers -parseAnything : State -> LexItem -> ParseResult +parseAnything : State -> Located LexItem -> ParseResult parseAnything state = let newTypeAliasState aliasName typeArgs res = @@ -359,7 +359,7 @@ parseAnything state = case state of State_Error_Recovery -> \item -> - case item of + case Located.unwrap item of Lexer.Newlines _ 0 -> State_BlockStart |> ParseResult_Ok @@ -436,9 +436,9 @@ parseAnything state = If the LexItem is a `Newlines` with indentation or is `Whitespace`. -} -parseBlockStart : LexItem -> ParseResult +parseBlockStart : Located LexItem -> ParseResult parseBlockStart item = - case item of + case Located.unwrap item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword Token.Type -> @@ -469,9 +469,9 @@ parseBlockStart item = ParseResult_Err (Error_InvalidToken Expecting_Block) -parseTypeBlock : LexItem -> ParseResult +parseTypeBlock : Located LexItem -> ParseResult parseTypeBlock item = - case item of + case Located.unwrap item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword Token.Alias -> @@ -509,9 +509,9 @@ parseTypeBlock item = |> ParseResult_Err -parseTypeAliasName : LexItem -> ParseResult +parseTypeAliasName : Located LexItem -> ParseResult parseTypeAliasName item = - case item of + case Located.unwrap item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword other -> @@ -541,9 +541,9 @@ parseTypeAliasName item = |> ParseResult_Err -parseTypeArgsOrAssignment : (Token.ValueOrFunctionOrGenericType -> State) -> State -> LexItem -> ParseResult +parseTypeArgsOrAssignment : (Token.ValueOrFunctionOrGenericType -> State) -> State -> Located LexItem -> ParseResult parseTypeArgsOrAssignment onTypeArg onAssignment item = - case item of + case Located.unwrap item of Lexer.Token str -> case Token.classifyToken str of Token.TokenKeyword kw -> @@ -581,10 +581,10 @@ parseTypeArgsOrAssignment onTypeArg onAssignment item = parserTypeExprFromEmpty : (TypeExpressionResult -> ParseResult) - -> LexItem + -> Located LexItem -> ParseResult parserTypeExprFromEmpty newState item = - case item of + case Located.unwrap item of Lexer.Token str -> { parents = [] , nesting = @@ -648,10 +648,10 @@ parserTypeExprFromEmpty newState item = parserTypeExpr : (TypeExpressionResult -> ParseResult) -> PartialTypeExpressionLeaf - -> LexItem + -> Located LexItem -> ParseResult parserTypeExpr newState prevExpr item = - case item of + case Located.unwrap item of Lexer.Token str -> exprAppend prevExpr str |> partialTypeExpressionToParseResult newState diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm index e83fea21..f420c453 100644 --- a/tests/ParserLexerTest.elm +++ b/tests/ParserLexerTest.elm @@ -41,7 +41,6 @@ tests = case ( lexed, contextualized ) of ( Ok lexed_, Just contextualized_ ) -> lexed_ - |> List.map Located.unwrap |> Contextualize.run |> Expect.equal contextualized_ @@ -63,7 +62,6 @@ tests = () |> Expect.all (lexed_ - |> List.map Located.unwrap |> Contextualize.run |> List.map (\rBlock () -> @@ -94,7 +92,6 @@ tests = () |> Expect.all (lexed_ - |> List.map Located.unwrap |> Contextualize.run |> List.map (\rBlock () -> diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 93d2383e..04af97d5 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -1720,7 +1720,7 @@ type alias Function3 = (Int, () ->, ()) Just [ Err { error = Error_MissingFunctionReturnType - , item = Just (Sigil (Bracket Round Close)) + , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Close))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Function") @@ -1734,7 +1734,7 @@ type alias Function3 = (Int, () ->, ()) } , Err { error = Error_MissingFunctionReturnType - , item = Just (Sigil (Bracket Curly Close)) + , item = Just (Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Sigil (Bracket Curly Close))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Function2") @@ -1748,7 +1748,7 @@ type alias Function3 = (Int, () ->, ()) } , Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Sigil Comma) + , item = Just (Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil Comma)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Function3") @@ -1762,7 +1762,7 @@ type alias Function3 = (Int, () ->, ()) } , Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Sigil Comma) + , item = Just (Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Sigil Comma)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Function3") @@ -1805,7 +1805,7 @@ type alias Function3 = (Int, () ->, ()) Just [ Err { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) - , item = Just (Sigil (Bracket Round Open)) + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) } ] @@ -1834,7 +1834,7 @@ type alias Function3 = (Int, () ->, ()) Just [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit - , item = Just (Sigil (Bracket Round Open)) + , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] @@ -1864,7 +1864,7 @@ type alias Function3 = (Int, () ->, ()) Just [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit - , item = Just (Sigil (Bracket Round Open)) + , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] @@ -1892,12 +1892,12 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model") []) } , Err { error = Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") - , item = Just (Token "List") + , item = Just (Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "List")) , state = State_BlockStart } ] @@ -1916,7 +1916,7 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias BlockTypeAlias_Keywords } ] @@ -1937,7 +1937,7 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi") (Stack [])) } ] @@ -1960,7 +1960,7 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi") []) } ] @@ -1985,7 +1985,7 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) } ] @@ -2013,7 +2013,7 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") @@ -2047,7 +2047,7 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) } ] @@ -2078,7 +2078,7 @@ List Int Just [ Err { error = Error_ExpectedColonWhilstParsingRecord - , item = Just (Token "j7") + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token "j7")) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) } ] @@ -2195,7 +2195,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , qualifiedness = PossiblyQualified Nothing } ] - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") @@ -2297,7 +2297,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) } ) [] - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") @@ -2384,7 +2384,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) Just [ Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Sigil Comma) + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") @@ -2436,12 +2436,14 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) { error = Error_PartwayThroughTypeAlias , item = Just - (Newlines - [ 0 - , 0 - , 0 - ] - 0 + (Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } + (Newlines + [ 0 + , 0 + , 0 + ] + 0 + ) ) , state = State_BlockTypeAlias @@ -2472,7 +2474,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Newlines [] 0) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0)) , state = State_BlockFirstItem BlockFirstItem_Type } ] From 7438f2db51bedbdb272190acf3f452b703f3052b Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 5 Oct 2020 23:25:00 +0100 Subject: [PATCH 059/103] parse expressions (wip) --- .../snippets/should-parse/expression-int | 3 + src/Stage/Parse/Contextualize.elm | 237 +++++++++++++++++- src/Stage/Parse/Lexer.elm | 2 +- tests/ParserLexerTestCases.elm | 210 ++++++---------- 4 files changed, 304 insertions(+), 148 deletions(-) create mode 100644 parser-tests/snippets/should-parse/expression-int diff --git a/parser-tests/snippets/should-parse/expression-int b/parser-tests/snippets/should-parse/expression-int new file mode 100644 index 00000000..3d3ed933 --- /dev/null +++ b/parser-tests/snippets/should-parse/expression-int @@ -0,0 +1,3 @@ +a = 5 + +b = 78 diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 30b5a360..96a58e12 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -64,6 +64,13 @@ type Block , name : Elm.Data.ModuleName.ModuleName , exposingList : Elm.Data.Exposing.Exposing } + | ValueDeclaration + { name : Located Token.ValueOrFunctionOrGenericType + + -- TODO(harry): these could be patterns! + , args : List (Located Token.ValueOrFunctionOrGenericType) + , expr : Frontend.LocatedExpr + } | TypeAlias { ty : Token.TypeOrConstructor , genericArgs : List Token.ValueOrFunctionOrGenericType @@ -81,6 +88,7 @@ type State | State_BlockFirstItem BlockFirstItem | State_BlockTypeAlias BlockTypeAlias | State_BlockCustomType BlockCustomType + | State_BlockValueDeclaration BlockValueDeclaration type ParseResult @@ -100,7 +108,6 @@ type alias State_ = type BlockFirstItem = BlockFirstItem_Type | BlockFirstItem_Module - | BlockFirstItem_Name Token.ValueOrFunctionOrGenericType type BlockTypeAlias @@ -115,6 +122,26 @@ type BlockCustomType | BlockCustomType_NamedAssigns Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) +type BlockValueDeclaration + = BlockValueDeclaration_Named + { name : Located Token.ValueOrFunctionOrGenericType + , args : Stack (Located Token.ValueOrFunctionOrGenericType) + } + | BlockValueDeclaration_NamedAssigns + { name : Located Token.ValueOrFunctionOrGenericType + , args : List (Located Token.ValueOrFunctionOrGenericType) + } + | BlockValueDeclaration_Completish + { name : Located Token.ValueOrFunctionOrGenericType + , args : List (Located Token.ValueOrFunctionOrGenericType) + , partialExpr : ExpressionNestingLeaf + } + + + +-- TYPE EXPRESSIONS -- + + {-| Notes: - Type names can start with a lower case character as it may be generic. If @@ -193,10 +220,37 @@ type TypeExpressionResult | TypeExpressionResult_Done PartialTypeExpression + +-- EXPRESSIONS -- + + +type ExpressionNestingParent + = ExpressionNestingParent_Operator + { op : Lexer.LexOperator + , lhs : Frontend.LocatedExpr + , parent : Maybe ExpressionNestingParent + } + + +type ExpressionNestingLeaf + = ExpressionNestingLeaf_Operator + { op : Lexer.LexOperator + , lhs : Frontend.LocatedExpr + , parent : Maybe ExpressionNestingParent + } + | ExpressionNestingLeafType_Expr Frontend.LocatedExpr + + +type ExpressionResult + = ExpressionResult_Progress ExpressionNestingLeaf + | ExpressionResult_Done Frontend.LocatedExpr + + type Error = Error_InvalidToken Expecting | Error_MisplacedKeyword Keyword | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor + -- Type Expressions -- | Error_TypeNameStartsWithLowerCase Token.ValueOrFunctionOrGenericType | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole | Error_WrongClosingBracket @@ -216,7 +270,12 @@ type Error (ConcreteType PossiblyQualified) (ConcreteType PossiblyQualified) (List (ConcreteType PossiblyQualified)) + -- Expressions -- + | Error_InvalidNumericLiteral String + -- Incomplete parsing -- | Error_PartwayThroughTypeAlias + | Error_PartwayThroughValueDeclaration + -- Bugs in the parser -- | Error_Panic String @@ -355,6 +414,26 @@ parseAnything state = Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> Error_TooManyTupleArgs a b c d e |> ParseResult_Err + + newExpressionState name args res = + case res of + ExpressionResult_Progress expr -> + State_BlockValueDeclaration + (BlockValueDeclaration_Completish + { name = name + , args = args + , partialExpr = expr + } + ) + |> ParseResult_Ok + + ExpressionResult_Done expr -> + { name = name + , args = args + , expr = expr + } + |> ValueDeclaration + |> ParseResult_Complete in case state of State_Error_Recovery -> @@ -377,19 +456,43 @@ parseAnything state = State_BlockFirstItem BlockFirstItem_Module -> Debug.todo "BlockFirstItem_Module" - State_BlockFirstItem (BlockFirstItem_Name name) -> - Debug.todo "BlockFirstItem_Name" + State_BlockValueDeclaration (BlockValueDeclaration_Named { name, args }) -> + parseLowercaseArgsOrAssignment + (\newArg -> + State_BlockValueDeclaration + (BlockValueDeclaration_Named + { name = name + , args = newArg |> pushOnto args + } + ) + ) + (State_BlockValueDeclaration + (BlockValueDeclaration_NamedAssigns + { name = name + , args = args |> toList (\x -> x) + } + ) + ) + + State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> + parserExpressionFromEmpty + (newExpressionState name args) + + State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> + parserExpression + (newExpressionState name args) + partialExpr State_BlockTypeAlias BlockTypeAlias_Keywords -> parseTypeAliasName State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> - parseTypeArgsOrAssignment + parseLowercaseArgsOrAssignment (\newTypeArg -> State_BlockTypeAlias (BlockTypeAlias_Named name - (newTypeArg |> pushOnto typeArgs) + (Located.unwrap newTypeArg |> pushOnto typeArgs) ) ) (State_BlockTypeAlias @@ -409,12 +512,12 @@ parseAnything state = exprSoFar State_BlockCustomType (BlockCustomType_Named name typeArgs) -> - parseTypeArgsOrAssignment + parseLowercaseArgsOrAssignment (\newTypeArg -> State_BlockCustomType (BlockCustomType_Named name - (newTypeArg |> pushOnto typeArgs) + (Located.unwrap newTypeArg |> pushOnto typeArgs) ) ) (State_BlockCustomType @@ -438,6 +541,10 @@ If the LexItem is a `Newlines` with indentation or is `Whitespace`. -} parseBlockStart : Located LexItem -> ParseResult parseBlockStart item = + let + withCorrectLocation x = + Located.map (\_ -> x) item + in case Located.unwrap item of Lexer.Token str -> case Token.classifyToken str of @@ -451,7 +558,14 @@ parseBlockStart item = ParseResult_Err (Error_MisplacedKeyword other) Token.TokenValueOrFunction valOrFunc -> - ParseResult_Ok (State_BlockFirstItem (BlockFirstItem_Name valOrFunc)) + ParseResult_Ok + (State_BlockValueDeclaration + (BlockValueDeclaration_Named + { name = withCorrectLocation valOrFunc + , args = empty + } + ) + ) Token.TokenTypeOrConstructor typeOrConstructor -> ParseResult_Err (Error_BlockStartsWithTypeOrConstructor typeOrConstructor) @@ -541,8 +655,12 @@ parseTypeAliasName item = |> ParseResult_Err -parseTypeArgsOrAssignment : (Token.ValueOrFunctionOrGenericType -> State) -> State -> Located LexItem -> ParseResult -parseTypeArgsOrAssignment onTypeArg onAssignment item = +parseLowercaseArgsOrAssignment : (Located Token.ValueOrFunctionOrGenericType -> State) -> State -> Located LexItem -> ParseResult +parseLowercaseArgsOrAssignment onTypeArg onAssignment item = + let + withCorrectLocation x = + Located.map (\_ -> x) item + in case Located.unwrap item of Lexer.Token str -> case Token.classifyToken str of @@ -555,7 +673,7 @@ parseTypeArgsOrAssignment onTypeArg onAssignment item = |> ParseResult_Err Token.TokenValueOrFunction argName -> - onTypeArg argName + onTypeArg (withCorrectLocation argName) |> ParseResult_Ok Lexer.Sigil Lexer.Assign -> @@ -878,6 +996,77 @@ parserTypeExpr newState prevExpr item = |> ParseResult_Err +parserExpressionFromEmpty : + (ExpressionResult -> ParseResult) + -> Located LexItem + -> ParseResult +parserExpressionFromEmpty newState item = + let + withCorrectLocation x = + Located.map (\_ -> x) item + in + case Located.unwrap item of + Lexer.NumericLiteral str -> + case String.toInt str of + Just i -> + Frontend.Int i + |> withCorrectLocation + |> ExpressionNestingLeafType_Expr + |> ExpressionResult_Progress + |> newState + + Nothing -> + Error_InvalidNumericLiteral str + |> ParseResult_Err + + Lexer.Newlines _ 0 -> + Error_PartwayThroughTypeAlias + |> ParseResult_Err + + Lexer.Newlines _ _ -> + ParseResult_Skip + + Lexer.Whitespace _ -> + ParseResult_Skip + + _ -> + Error_InvalidToken Expecting_Unknown + |> ParseResult_Err + + +parserExpression : + (ExpressionResult -> ParseResult) + -> ExpressionNestingLeaf + -> Located LexItem + -> ParseResult +parserExpression newState prevExpr item = + case Located.unwrap item of + Lexer.Newlines _ 0 -> + case prevExpr of + ExpressionNestingLeaf_Operator {} -> + Error_PartwayThroughValueDeclaration + |> ParseResult_Err + + ExpressionNestingLeafType_Expr expr -> + expr + |> ExpressionResult_Done + |> newState + + Lexer.Newlines _ _ -> + ParseResult_Skip + + Lexer.Whitespace _ -> + ParseResult_Skip + + _ -> + Error_InvalidToken Expecting_Unknown + |> ParseResult_Err + + + +-- HELPERS + + leafToParents : PartialTypeExpressionLeaf -> Result Error (List NestingParentType) leafToParents { parents, nesting } = (case nesting of @@ -1262,6 +1451,32 @@ blockFromState state = State_BlockCustomType firstItem -> Debug.todo "handle incomplete block" + State_BlockValueDeclaration (BlockValueDeclaration_Named {}) -> + Error_PartwayThroughValueDeclaration + |> Err + |> Just + + State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns {}) -> + Error_PartwayThroughValueDeclaration + |> Err + |> Just + + State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> + case partialExpr of + ExpressionNestingLeaf_Operator {} -> + Error_PartwayThroughValueDeclaration + |> Err + |> Just + + ExpressionNestingLeafType_Expr expr -> + { name = name + , args = args + , expr = expr + } + |> ValueDeclaration + |> Ok + |> Just + -- helper functions diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index b4215be9..d340342e 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -237,7 +237,7 @@ parser = ([ -- commentParser must come before sigil parser as the sigil -- parser will try to interpret "--" as a sigil P.variable - { start = Char.isAlphaNum + { start = Char.isAlpha , inner = \c -> Char.isAlphaNum c || c == '_' , reserved = Set.empty , expecting = ExpectingToken diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 04af97d5..87765da5 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -1,6 +1,7 @@ module ParserLexerTestCases exposing (shouldNotParseTestCases, shouldParseTestCases) import Dict +import Elm.AST.Frontend exposing (Expr(..)) import Elm.Data.Located as Located exposing (Located(..)) import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete exposing (ConcreteType(..)) @@ -25,7 +26,38 @@ shouldParseTestCases : , source : String } shouldParseTestCases = - [ { name = "type-alias" + [ { name = "expression-int" + , source = """a = 5 + +b = 78 +""" + , lexed = + Ok + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 3 }, start = { col = 6, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token "b") + , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) + , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) + , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") + , Located { end = { col = 1, row = 4 }, start = { col = 7, row = 3 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok (ValueDeclaration { args = [], expr = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Int 5), name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a") }) + , Ok (ValueDeclaration { args = [], expr = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Int 78), name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b") }) + ] + } + , { name = "type-alias" , source = """type alias Model = List Int """ , lexed = @@ -987,7 +1019,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token "hi") , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Sigil Colon) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Whitespace 1) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token "6") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (NumericLiteral "6") , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) @@ -995,24 +1027,20 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , contextualized = Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "hi" - , UserDefinedType - { args = [] - , name = "6" - , qualifiedness = PossiblyQualified Nothing - } - ) + [ Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (NumericLiteral "6")) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Ty") + [] + { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_KeyColon "hi" } + , parents = + [ NestingParentType_Bracket (Stack []) ] - ) - , genericArgs = [] - , ty = TypeOrConstructor "Ty" - } - ) + } + ) + } ] } , { name = "type-alias-record-nested" @@ -1041,7 +1069,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token "a") , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Colon) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token "7") + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (NumericLiteral "7") , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil Comma) , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Token "b") @@ -1077,77 +1105,20 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , contextualized = Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "hi" - , Record - (Dict.fromList - [ ( "a" - , UserDefinedType - { args = [] - , name = "7" - , qualifiedness = PossiblyQualified Nothing - } - ) - , ( "b" - , UserDefinedType - { args = - [ UserDefinedType - { args = [] - , name = "String" - , qualifiedness = PossiblyQualified Nothing - } - ] - , name = "List" - , qualifiedness = PossiblyQualified Nothing - } - ) - ] - ) - ) - , ( "ih" - , UserDefinedType - { args = - [ UserDefinedType - { args = [] - , name = "A" - , qualifiedness = PossiblyQualified Nothing - } - , UserDefinedType - { args = [] - , name = "B" - , qualifiedness = PossiblyQualified Nothing - } - , UserDefinedType - { args = [] - , name = "C" - , qualifiedness = PossiblyQualified Nothing - } - , UserDefinedType - { args = - [ UserDefinedType - { args = [] - , name = "E" - , qualifiedness = PossiblyQualified Nothing - } - ] - , name = "D" - , qualifiedness = PossiblyQualified Nothing - } - ] - , name = "CustomType" - , qualifiedness = PossiblyQualified Nothing - } - ) + [ Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (NumericLiteral "7")) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Ty") + [] + { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_KeyColon "a" } + , parents = + [ NestingParentType_PartialRecord { firstEntries = Stack [], lastEntryName = "hi" } ] - ) - , genericArgs = [] - , ty = TypeOrConstructor "Ty" - } - ) + } + ) + } ] } , { name = "type-alias-record-simple" @@ -1168,31 +1139,18 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "6") + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (NumericLiteral "6") , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "hi" - , UserDefinedType - { args = [] - , name = "6" - , qualifiedness = PossiblyQualified Nothing - } - ) - ] - ) - , genericArgs = [] - , ty = TypeOrConstructor "Ty" - } - ) + [ Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (NumericLiteral "6")) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_KeyColon "hi" }, parents = [] }) + } ] } , { name = "type-alias-record-two-entries" @@ -1213,44 +1171,24 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "6") + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (NumericLiteral "6") , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) , Located { end = { col = 29, row = 1 }, start = { col = 26, row = 1 } } (Token "buy") , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil Colon) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Whitespace 1) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token "8") + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (NumericLiteral "8") , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "buy" - , UserDefinedType - { args = [] - , name = "8" - , qualifiedness = PossiblyQualified Nothing - } - ) - , ( "hi" - , UserDefinedType - { args = [] - , name = "6" - , qualifiedness = PossiblyQualified Nothing - } - ) - ] - ) - , genericArgs = [] - , ty = TypeOrConstructor "Ty" - } - ) + [ Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (NumericLiteral "6")) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_KeyColon "hi" }, parents = [] }) + } ] } , { name = "type-alias-unit" From a881c56af4927e82d968db71883fd45bc45d1260 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 11:00:29 +0100 Subject: [PATCH 060/103] hack test case generation to avoid name clashes --- parser-tests/Update.elm | 19 +++++ .../should-parse/type-alias-and-expression | 3 + src/Stage/Parse/Contextualize.elm | 8 ++- tests/ParserLexerTestCases.elm | 70 ++++++++++++++++++- 4 files changed, 94 insertions(+), 6 deletions(-) create mode 100644 parser-tests/snippets/should-parse/type-alias-and-expression diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 17add7bc..96e432fd 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -72,6 +72,7 @@ init snippets = , contextualized =""" ++ (Debug.toString contextualized |> preFormatElmCode + |> resolveCustomTypeConstructors ) ++ """ }""" @@ -94,6 +95,7 @@ update () model = ( model, Cmd.none ) + preFormatElmCode : String -> String preFormatElmCode = {- String.replace "}" """ @@ -110,3 +112,20 @@ preFormatElmCode = """ >> String.replace """UserDefinedType {""" """UserDefinedType { """ +{-| Always run after preformatting. +-} +resolveCustomTypeConstructors : String -> String +resolveCustomTypeConstructors = + String.split "\n" + >> List.map ( + \line -> + if String.contains "valueExpr__" line then + line + |> String.replace "Int" "Frontend.Int" + |> String.replace "Float" "Frontend.Float" + |> String.replace "Unit" "Frontend.Unit" + else + line + + ) + >> String.join "\n" diff --git a/parser-tests/snippets/should-parse/type-alias-and-expression b/parser-tests/snippets/should-parse/type-alias-and-expression new file mode 100644 index 00000000..841b72b2 --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-and-expression @@ -0,0 +1,3 @@ +type alias Model = List Int + +expr hi = 77 diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 96a58e12..5fdb3199 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -69,7 +69,9 @@ type Block -- TODO(harry): these could be patterns! , args : List (Located Token.ValueOrFunctionOrGenericType) - , expr : Frontend.LocatedExpr + + -- This key's name is hard coded into parser-tests/Update.elm + , valueExpr__ : Frontend.LocatedExpr } | TypeAlias { ty : Token.TypeOrConstructor @@ -430,7 +432,7 @@ parseAnything state = ExpressionResult_Done expr -> { name = name , args = args - , expr = expr + , valueExpr__ = expr } |> ValueDeclaration |> ParseResult_Complete @@ -1471,7 +1473,7 @@ blockFromState state = ExpressionNestingLeafType_Expr expr -> { name = name , args = args - , expr = expr + , valueExpr__ = expr } |> ValueDeclaration |> Ok diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 87765da5..e884fd7e 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -1,7 +1,7 @@ module ParserLexerTestCases exposing (shouldNotParseTestCases, shouldParseTestCases) import Dict -import Elm.AST.Frontend exposing (Expr(..)) +import Elm.AST.Frontend as Frontend import Elm.Data.Located as Located exposing (Located(..)) import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete exposing (ConcreteType(..)) @@ -53,8 +53,8 @@ b = 78 ] , contextualized = Just - [ Ok (ValueDeclaration { args = [], expr = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Int 5), name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a") }) - , Ok (ValueDeclaration { args = [], expr = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Int 78), name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b") }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78) }) ] } , { name = "type-alias" @@ -97,6 +97,70 @@ b = 78 ) ] } + , { name = "type-alias-and-expression" + , source = """type alias Model = List Int + +expr hi = 77 +""" + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 28, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "expr") + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) + , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Token "hi") + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Whitespace 1) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Assign) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) + , Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (NumericLiteral "77") + , Located { end = { col = 1, row = 4 }, start = { col = 13, row = 3 } } (Newlines [] 0) + ] + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , genericArgs = [] + , ty = TypeOrConstructor "Model" + } + ) + , Ok + (ValueDeclaration + { args = + [ Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (ValueOrFunctionOrGenericType "hi") + ] + , name = Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "expr") + , valueExpr__ = Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (Frontend.Int 77) + } + ) + ] + } , { name = "type-alias-bracket-in-record" , source = """type alias Ty = { hi: (Int) } """ From 161a849a1c13cbb85e9cf775797e543ba2888bbb Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 11:02:50 +0100 Subject: [PATCH 061/103] fix test cases that use a number instead of a type --- .../should-parse/type-alias-record-in-bracket | 2 +- .../should-parse/type-alias-record-nested | 2 +- .../should-parse/type-alias-record-simple | 2 +- .../type-alias-record-two-entries | 2 +- tests/ParserLexerTestCases.elm | 231 ++++++++++++------ 5 files changed, 164 insertions(+), 75 deletions(-) diff --git a/parser-tests/snippets/should-parse/type-alias-record-in-bracket b/parser-tests/snippets/should-parse/type-alias-record-in-bracket index c5deb03b..b508363d 100644 --- a/parser-tests/snippets/should-parse/type-alias-record-in-bracket +++ b/parser-tests/snippets/should-parse/type-alias-record-in-bracket @@ -1 +1 @@ -type alias Ty = ({ hi: 6 }) +type alias Ty = ({ hi: Int }) diff --git a/parser-tests/snippets/should-parse/type-alias-record-nested b/parser-tests/snippets/should-parse/type-alias-record-nested index 2926818e..740b4600 100644 --- a/parser-tests/snippets/should-parse/type-alias-record-nested +++ b/parser-tests/snippets/should-parse/type-alias-record-nested @@ -1,4 +1,4 @@ type alias Ty = - { hi: { a: 7, b: List String } + { hi: { a: Int, b: List String } , ih: CustomType A B C (D E) } diff --git a/parser-tests/snippets/should-parse/type-alias-record-simple b/parser-tests/snippets/should-parse/type-alias-record-simple index d0ef26fa..2841ea53 100644 --- a/parser-tests/snippets/should-parse/type-alias-record-simple +++ b/parser-tests/snippets/should-parse/type-alias-record-simple @@ -1 +1 @@ -type alias Ty = { hi: 6 } +type alias Ty = { hi: Int } diff --git a/parser-tests/snippets/should-parse/type-alias-record-two-entries b/parser-tests/snippets/should-parse/type-alias-record-two-entries index 3a3d579d..a4663cf2 100644 --- a/parser-tests/snippets/should-parse/type-alias-record-two-entries +++ b/parser-tests/snippets/should-parse/type-alias-record-two-entries @@ -1 +1 @@ -type alias Ty = { hi: 6, buy: 8 } +type alias Ty = { hi: (), buy: String } diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index e884fd7e..be800f6e 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -1065,7 +1065,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] } , { name = "type-alias-record-in-bracket" - , source = """type alias Ty = ({ hi: 6 }) + , source = """type alias Ty = ({ hi: Int }) """ , lexed = Ok @@ -1083,33 +1083,37 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token "hi") , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Sigil Colon) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Whitespace 1) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (NumericLiteral "6") - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token "Int") + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (NumericLiteral "6")) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Ty") - [] - { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_KeyColon "hi" } - , parents = - [ NestingParentType_Bracket (Stack []) + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi" + , UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) ] - } - ) - } + ) + , genericArgs = [] + , ty = TypeOrConstructor "Ty" + } + ) ] } , { name = "type-alias-record-nested" , source = """type alias Ty = - { hi: { a: 7, b: List String } + { hi: { a: Int, b: List String } , ih: CustomType A B C (D E) } """ @@ -1133,18 +1137,18 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token "a") , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Colon) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (NumericLiteral "7") - , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil Comma) - , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Token "b") - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Colon) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) - , Located { end = { col = 27, row = 2 }, start = { col = 23, row = 2 } } (Token "List") - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) - , Located { end = { col = 34, row = 2 }, start = { col = 28, row = 2 } } (Token "String") - , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) - , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 5, row = 3 }, start = { col = 36, row = 2 } } (Newlines [] 4) + , Located { end = { col = 20, row = 2 }, start = { col = 17, row = 2 } } (Token "Int") + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Sigil Comma) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Whitespace 1) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Token "b") + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil Colon) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) + , Located { end = { col = 29, row = 2 }, start = { col = 25, row = 2 } } (Token "List") + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Whitespace 1) + , Located { end = { col = 36, row = 2 }, start = { col = 30, row = 2 } } (Token "String") + , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Whitespace 1) + , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 5, row = 3 }, start = { col = 38, row = 2 } } (Newlines [] 4) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token "ih") @@ -1169,24 +1173,81 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , contextualized = Just - [ Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (NumericLiteral "7")) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Ty") - [] - { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_KeyColon "a" } - , parents = - [ NestingParentType_PartialRecord { firstEntries = Stack [], lastEntryName = "hi" } + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi" + , Record + (Dict.fromList + [ ( "a" + , UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ( "b" + , UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + ) + ] + ) + ) + , ( "ih" + , UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "E" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "CustomType" + , qualifiedness = PossiblyQualified Nothing + } + ) ] - } - ) - } + ) + , genericArgs = [] + , ty = TypeOrConstructor "Ty" + } + ) ] } , { name = "type-alias-record-simple" - , source = """type alias Ty = { hi: 6 } + , source = """type alias Ty = { hi: Int } """ , lexed = Ok @@ -1203,22 +1264,35 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (NumericLiteral "6") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Int") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (NumericLiteral "6")) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_KeyColon "hi" }, parents = [] }) - } + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi" + , UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + ] + ) + , genericArgs = [] + , ty = TypeOrConstructor "Ty" + } + ) ] } , { name = "type-alias-record-two-entries" - , source = """type alias Ty = { hi: 6, buy: 8 } + , source = """type alias Ty = { hi: (), buy: String } """ , lexed = Ok @@ -1235,24 +1309,39 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (NumericLiteral "6") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 26, row = 1 } } (Token "buy") - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil Colon) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Whitespace 1) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (NumericLiteral "8") - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil Comma) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) + , Located { end = { col = 30, row = 1 }, start = { col = 27, row = 1 } } (Token "buy") + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil Colon) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) + , Located { end = { col = 38, row = 1 }, start = { col = 32, row = 1 } } (Token "String") + , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Whitespace 1) + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 40, row = 1 } } (Newlines [] 0) ] , contextualized = Just - [ Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (NumericLiteral "6")) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_KeyColon "hi" }, parents = [] }) - } + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "buy" + , UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ( "hi", Unit ) + ] + ) + , genericArgs = [] + , ty = TypeOrConstructor "Ty" + } + ) ] } , { name = "type-alias-unit" From 41c88ef7fc30a985526655850997b21f23b314e0 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 11:07:24 +0100 Subject: [PATCH 062/103] change field order in test cases easier to compare the ast to the source now --- parser-tests/Update.elm | 10 +- tests/ParserLexerTestCases.elm | 1650 ++++++++++++++++---------------- 2 files changed, 830 insertions(+), 830 deletions(-) diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 96e432fd..4068585c 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -64,17 +64,17 @@ init snippets = , source = \"\"\"""" ++ source ++ """\"\"\" - , lexed = """ - ++ (Debug.toString lexed - |> preFormatElmCode - ) - ++ """ , contextualized =""" ++ (Debug.toString contextualized |> preFormatElmCode |> resolveCustomTypeConstructors ) ++ """ + , lexed = """ + ++ (Debug.toString lexed + |> preFormatElmCode + ) + ++ """ }""" ) snippets diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index be800f6e..1742d853 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -31,6 +31,11 @@ shouldParseTestCases = b = 78 """ + , contextualized = + Just + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78) }) + ] , lexed = Ok [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") @@ -51,30 +56,10 @@ b = 78 , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") , Located { end = { col = 1, row = 4 }, start = { col = 7, row = 3 } } (Newlines [] 0) ] - , contextualized = - Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78) }) - ] } , { name = "type-alias" , source = """type alias Model = List Int """ - , lexed = - Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int") - , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) - ] , contextualized = Just [ Ok @@ -96,12 +81,6 @@ b = 78 } ) ] - } - , { name = "type-alias-and-expression" - , source = """type alias Model = List Int - -expr hi = 77 -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -115,21 +94,14 @@ expr hi = 77 , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List") , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int") - , Located { end = { col = 1, row = 3 }, start = { col = 28, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "expr") - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) - , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Token "hi") - , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Whitespace 1) - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Assign) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) - , Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (NumericLiteral "77") - , Located { end = { col = 1, row = 4 }, start = { col = 13, row = 3 } } (Newlines [] 0) + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-and-expression" + , source = """type alias Model = List Int + +expr hi = 77 +""" , contextualized = Just [ Ok @@ -160,32 +132,38 @@ expr hi = 77 } ) ] - } - , { name = "type-alias-bracket-in-record" - , source = """type alias Ty = { hi: (Int) } -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token "Int") - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 28, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "expr") + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) + , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Token "hi") + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Whitespace 1) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Assign) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) + , Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (NumericLiteral "77") + , Located { end = { col = 1, row = 4 }, start = { col = 13, row = 3 } } (Newlines [] 0) ] + } + , { name = "type-alias-bracket-in-record" + , source = """type alias Ty = { hi: (Int) } +""" , contextualized = Just [ Ok @@ -207,35 +185,32 @@ expr hi = 77 } ) ] - } - , { name = "type-alias-function" - , source = """type alias Function = List Int -> List (List Int) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token "List") - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Token "Int") - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 32, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) - , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Token "List") - , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Token "List") - , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Whitespace 1) - , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Token "Int") - , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token "Int") + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-function" + , source = """type alias Function = List Int -> List (List Int) +""" , contextualized = Just [ Ok @@ -278,11 +253,6 @@ expr hi = 77 } ) ] - } - , { name = "type-alias-function-binding-order" - , source = """type alias Function = A -> B -> C -type alias Function = A -> B -> C -> D -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -293,39 +263,26 @@ type alias Function = A -> B -> C -> D , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "A") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 25, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token "List") , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token "B") - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token "C") - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Token "Function") - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Assign) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token "A") - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) - , Located { end = { col = 27, row = 2 }, start = { col = 25, row = 2 } } (Sigil ThinArrow) - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) - , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token "B") - , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Whitespace 1) - , Located { end = { col = 32, row = 2 }, start = { col = 30, row = 2 } } (Sigil ThinArrow) - , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Whitespace 1) - , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Token "C") - , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) - , Located { end = { col = 37, row = 2 }, start = { col = 35, row = 2 } } (Sigil ThinArrow) - , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) - , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token "D") - , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Newlines [] 0) + , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Token "Int") + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) + , Located { end = { col = 34, row = 1 }, start = { col = 32, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) + , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Token "List") + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Token "List") + , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Whitespace 1) + , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Token "Int") + , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-function-binding-order" + , source = """type alias Function = A -> B -> C +type alias Function = A -> B -> C -> D +""" , contextualized = Just [ Ok @@ -398,10 +355,6 @@ type alias Function = A -> B -> C -> D } ) ] - } - , { name = "type-alias-function-generic" - , source = """type alias Function a = List Int -> List (List a) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -410,25 +363,45 @@ type alias Function = A -> B -> C -> D , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token "a") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Assign) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "A") , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Token "List") + , Located { end = { col = 27, row = 1 }, start = { col = 25, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token "B") , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) - , Located { end = { col = 36, row = 1 }, start = { col = 34, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Token "List") - , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) - , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Token "List") - , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Whitespace 1) - , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token "a") - , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) + , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token "C") + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) + , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Token "Function") + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Assign) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token "A") + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) + , Located { end = { col = 27, row = 2 }, start = { col = 25, row = 2 } } (Sigil ThinArrow) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token "B") + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Whitespace 1) + , Located { end = { col = 32, row = 2 }, start = { col = 30, row = 2 } } (Sigil ThinArrow) + , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Whitespace 1) + , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Token "C") + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) + , Located { end = { col = 37, row = 2 }, start = { col = 35, row = 2 } } (Sigil ThinArrow) + , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) + , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token "D") + , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Newlines [] 0) ] + } + , { name = "type-alias-function-generic" + , source = """type alias Function a = List Int -> List (List a) +""" , contextualized = Just [ Ok @@ -473,16 +446,6 @@ type alias Function = A -> B -> C -> D } ) ] - } - , { name = "type-alias-function-nested" - , source = """type alias Function = (() -> (Int, String)) - -type alias Function2 = { a: () -> (Int, String) } - -type alias Function3 = (() -> (Int, String), ()) - -type alias Function3 = (Int, () -> (Int, String), ()) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -491,120 +454,35 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token "a") , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Assign) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Token "List") , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Token "Int") - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil Comma) - , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Whitespace 1) - , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Token "String") - , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 3 }, start = { col = 44, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "type") - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token "alias") - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token "Function2") - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Sigil Assign) - , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "a") - , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil Colon) - , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Whitespace 1) - , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Whitespace 1) - , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Sigil ThinArrow) - , Located { end = { col = 35, row = 3 }, start = { col = 34, row = 3 } } (Whitespace 1) - , Located { end = { col = 36, row = 3 }, start = { col = 35, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Token "Int") - , Located { end = { col = 40, row = 3 }, start = { col = 39, row = 3 } } (Sigil Comma) - , Located { end = { col = 41, row = 3 }, start = { col = 40, row = 3 } } (Whitespace 1) - , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Token "String") - , Located { end = { col = 48, row = 3 }, start = { col = 47, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 49, row = 3 }, start = { col = 48, row = 3 } } (Whitespace 1) - , Located { end = { col = 50, row = 3 }, start = { col = 49, row = 3 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 5 }, start = { col = 50, row = 3 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token "type") - , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) - , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token "alias") - , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) - , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token "Function3") - , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Whitespace 1) - , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Sigil Assign) - , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) - , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 27, row = 5 }, start = { col = 26, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 28, row = 5 }, start = { col = 27, row = 5 } } (Whitespace 1) - , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Sigil ThinArrow) - , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Whitespace 1) - , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Token "Int") - , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Sigil Comma) - , Located { end = { col = 37, row = 5 }, start = { col = 36, row = 5 } } (Whitespace 1) - , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Token "String") - , Located { end = { col = 44, row = 5 }, start = { col = 43, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 45, row = 5 }, start = { col = 44, row = 5 } } (Sigil Comma) - , Located { end = { col = 46, row = 5 }, start = { col = 45, row = 5 } } (Whitespace 1) - , Located { end = { col = 47, row = 5 }, start = { col = 46, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 48, row = 5 }, start = { col = 47, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 49, row = 5 }, start = { col = 48, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 7 }, start = { col = 49, row = 5 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token "type") - , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Whitespace 1) - , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token "alias") - , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Whitespace 1) - , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token "Function3") - , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Whitespace 1) - , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Sigil Assign) - , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Whitespace 1) - , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token "Int") - , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Sigil Comma) - , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Whitespace 1) - , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 32, row = 7 }, start = { col = 31, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 33, row = 7 }, start = { col = 32, row = 7 } } (Whitespace 1) - , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Sigil ThinArrow) - , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Whitespace 1) - , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Token "Int") - , Located { end = { col = 41, row = 7 }, start = { col = 40, row = 7 } } (Sigil Comma) - , Located { end = { col = 42, row = 7 }, start = { col = 41, row = 7 } } (Whitespace 1) - , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Token "String") - , Located { end = { col = 49, row = 7 }, start = { col = 48, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 50, row = 7 }, start = { col = 49, row = 7 } } (Sigil Comma) - , Located { end = { col = 51, row = 7 }, start = { col = 50, row = 7 } } (Whitespace 1) - , Located { end = { col = 52, row = 7 }, start = { col = 51, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 53, row = 7 }, start = { col = 52, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 54, row = 7 }, start = { col = 53, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 8 }, start = { col = 54, row = 7 } } (Newlines [] 0) + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) + , Located { end = { col = 36, row = 1 }, start = { col = 34, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) + , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Token "List") + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Token "List") + , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Whitespace 1) + , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token "a") + , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-function-nested" + , source = """type alias Function = (() -> (Int, String)) + +type alias Function2 = { a: () -> (Int, String) } + +type alias Function3 = (() -> (Int, String), ()) + +type alias Function3 = (Int, () -> (Int, String), ()) +""" , contextualized = Just [ Ok @@ -722,10 +600,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] - } - , { name = "type-alias-function-record" - , source = """type alias Function = { a: { b: C}, d: E } -> {} -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -736,33 +610,122 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "a") - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Colon) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token "b") - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Sigil Colon) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token "C") - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Sigil Comma) - , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) - , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Token "d") - , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Sigil Colon) - , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token "E") - , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) - , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Whitespace 1) - , Located { end = { col = 46, row = 1 }, start = { col = 44, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Whitespace 1) - , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 49, row = 1 } } (Newlines [] 0) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Token "Int") + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil Comma) + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Whitespace 1) + , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Token "String") + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 44, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "type") + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token "alias") + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token "Function2") + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Sigil Assign) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "a") + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil Colon) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Whitespace 1) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Whitespace 1) + , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Sigil ThinArrow) + , Located { end = { col = 35, row = 3 }, start = { col = 34, row = 3 } } (Whitespace 1) + , Located { end = { col = 36, row = 3 }, start = { col = 35, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Token "Int") + , Located { end = { col = 40, row = 3 }, start = { col = 39, row = 3 } } (Sigil Comma) + , Located { end = { col = 41, row = 3 }, start = { col = 40, row = 3 } } (Whitespace 1) + , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Token "String") + , Located { end = { col = 48, row = 3 }, start = { col = 47, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 49, row = 3 }, start = { col = 48, row = 3 } } (Whitespace 1) + , Located { end = { col = 50, row = 3 }, start = { col = 49, row = 3 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 50, row = 3 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token "type") + , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) + , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token "alias") + , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token "Function3") + , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Whitespace 1) + , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Sigil Assign) + , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) + , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 27, row = 5 }, start = { col = 26, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 28, row = 5 }, start = { col = 27, row = 5 } } (Whitespace 1) + , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Sigil ThinArrow) + , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Whitespace 1) + , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Token "Int") + , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Sigil Comma) + , Located { end = { col = 37, row = 5 }, start = { col = 36, row = 5 } } (Whitespace 1) + , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Token "String") + , Located { end = { col = 44, row = 5 }, start = { col = 43, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 45, row = 5 }, start = { col = 44, row = 5 } } (Sigil Comma) + , Located { end = { col = 46, row = 5 }, start = { col = 45, row = 5 } } (Whitespace 1) + , Located { end = { col = 47, row = 5 }, start = { col = 46, row = 5 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 48, row = 5 }, start = { col = 47, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 49, row = 5 }, start = { col = 48, row = 5 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 7 }, start = { col = 49, row = 5 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token "type") + , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Whitespace 1) + , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token "alias") + , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Whitespace 1) + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token "Function3") + , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Whitespace 1) + , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Sigil Assign) + , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Whitespace 1) + , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token "Int") + , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Sigil Comma) + , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Whitespace 1) + , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 32, row = 7 }, start = { col = 31, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 33, row = 7 }, start = { col = 32, row = 7 } } (Whitespace 1) + , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Sigil ThinArrow) + , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Whitespace 1) + , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Token "Int") + , Located { end = { col = 41, row = 7 }, start = { col = 40, row = 7 } } (Sigil Comma) + , Located { end = { col = 42, row = 7 }, start = { col = 41, row = 7 } } (Whitespace 1) + , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Token "String") + , Located { end = { col = 49, row = 7 }, start = { col = 48, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 50, row = 7 }, start = { col = 49, row = 7 } } (Sigil Comma) + , Located { end = { col = 51, row = 7 }, start = { col = 50, row = 7 } } (Whitespace 1) + , Located { end = { col = 52, row = 7 }, start = { col = 51, row = 7 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 53, row = 7 }, start = { col = 52, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 54, row = 7 }, start = { col = 53, row = 7 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 8 }, start = { col = 54, row = 7 } } (Newlines [] 0) ] + } + , { name = "type-alias-function-record" + , source = """type alias Function = { a: { b: C}, d: E } -> {} +""" , contextualized = Just [ Ok @@ -801,10 +764,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] - } - , { name = "type-alias-function-tuple" - , source = """type alias Function = () -> (Int, String) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -815,19 +774,37 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 28, row = 1 }, start = { col = 26, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil Comma) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Token "String") - , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Newlines [] 0) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "a") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Colon) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token "b") + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Sigil Colon) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token "C") + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Sigil Comma) + , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) + , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Token "d") + , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Sigil Colon) + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token "E") + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Whitespace 1) + , Located { end = { col = 46, row = 1 }, start = { col = 44, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Whitespace 1) + , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 49, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-function-tuple" + , source = """type alias Function = () -> (Int, String) +""" , contextualized = Just [ Ok @@ -855,11 +832,55 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) + , Located { end = { col = 28, row = 1 }, start = { col = 26, row = 1 } } (Sigil ThinArrow) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil Comma) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) + , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Token "String") + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Newlines [] 0) + ] } , { name = "type-alias-funky-indentation" , source = """type alias Model = List Int """ + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , genericArgs = [] + , ty = TypeOrConstructor "Model" + } + ) + ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -875,6 +896,12 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token "Int") , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 2 } } (Newlines [] 0) ] + } + , { name = "type-alias-funky-indentation-2" + , source = """type alias + Model = + List Int +""" , contextualized = Just [ Ok @@ -896,12 +923,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] - } - , { name = "type-alias-funky-indentation-2" - , source = """type alias - Model = - List Int -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -917,31 +938,45 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Token "Int") , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Newlines [] 0) ] + } + , { name = "type-alias-record-3-entries" + , source = """type alias Ty = { a: A, b: B, c: C } +""" , contextualized = Just [ Ok (TypeAlias { expr = - UserDefinedType - { args = - [ UserDefinedType - { args = [] - , name = "Int" - , qualifiedness = PossiblyQualified Nothing - } + Record + (Dict.fromList + [ ( "a" + , UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ( "b" + , UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ( "c" + , UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + ) ] - , name = "List" - , qualifiedness = PossiblyQualified Nothing - } + ) , genericArgs = [] - , ty = TypeOrConstructor "Model" + , ty = TypeOrConstructor "Ty" } ) ] - } - , { name = "type-alias-record-3-entries" - , source = """type alias Ty = { a: A, b: B, c: C } -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -974,45 +1009,14 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 37, row = 1 } } (Newlines [] 0) ] - , contextualized = - Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "a" - , UserDefinedType - { args = [] - , name = "A" - , qualifiedness = PossiblyQualified Nothing - } - ) - , ( "b" - , UserDefinedType - { args = [] - , name = "B" - , qualifiedness = PossiblyQualified Nothing - } - ) - , ( "c" - , UserDefinedType - { args = [] - , name = "C" - , qualifiedness = PossiblyQualified Nothing - } - ) - ] - ) - , genericArgs = [] - , ty = TypeOrConstructor "Ty" - } - ) - ] } , { name = "type-alias-record-empty" , source = """type alias Ty = {} """ + , contextualized = + Just + [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = TypeOrConstructor "Ty" }) + ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1027,10 +1031,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) ] - , contextualized = - Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = TypeOrConstructor "Ty" }) - ] } , { name = "type-alias-record-empty-multiline" , source = """type alias Ty = { @@ -1038,6 +1038,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) } """ + , contextualized = + Just + [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = TypeOrConstructor "Ty" }) + ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1059,14 +1063,31 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) ] - , contextualized = - Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = TypeOrConstructor "Ty" }) - ] } , { name = "type-alias-record-in-bracket" , source = """type alias Ty = ({ hi: Int }) """ + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Record + (Dict.fromList + [ ( "hi" + , UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + ] + ) + , genericArgs = [] + , ty = TypeOrConstructor "Ty" + } + ) + ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1089,6 +1110,13 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-record-nested" + , source = """type alias Ty = + { hi: { a: Int, b: List String } + , ih: CustomType A B C (D E) + } +""" , contextualized = Just [ Ok @@ -1097,9 +1125,62 @@ type alias Function3 = (Int, () -> (Int, String), ()) Record (Dict.fromList [ ( "hi" + , Record + (Dict.fromList + [ ( "a" + , UserDefinedType + { args = [] + , name = "Int" + , qualifiedness = PossiblyQualified Nothing + } + ) + , ( "b" + , UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "String" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + ) + ] + ) + ) + , ( "ih" , UserDefinedType - { args = [] - , name = "Int" + { args = + [ UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "E" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "CustomType" , qualifiedness = PossiblyQualified Nothing } ) @@ -1110,13 +1191,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] - } - , { name = "type-alias-record-nested" - , source = """type alias Ty = - { hi: { a: Int, b: List String } - , ih: CustomType A B C (D E) - } -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1171,6 +1245,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) ] + } + , { name = "type-alias-record-simple" + , source = """type alias Ty = { hi: Int } +""" , contextualized = Just [ Ok @@ -1179,62 +1257,9 @@ type alias Function3 = (Int, () -> (Int, String), ()) Record (Dict.fromList [ ( "hi" - , Record - (Dict.fromList - [ ( "a" - , UserDefinedType - { args = [] - , name = "Int" - , qualifiedness = PossiblyQualified Nothing - } - ) - , ( "b" - , UserDefinedType - { args = - [ UserDefinedType - { args = [] - , name = "String" - , qualifiedness = PossiblyQualified Nothing - } - ] - , name = "List" - , qualifiedness = PossiblyQualified Nothing - } - ) - ] - ) - ) - , ( "ih" - , UserDefinedType - { args = - [ UserDefinedType - { args = [] - , name = "A" - , qualifiedness = PossiblyQualified Nothing - } - , UserDefinedType - { args = [] - , name = "B" - , qualifiedness = PossiblyQualified Nothing - } - , UserDefinedType - { args = [] - , name = "C" - , qualifiedness = PossiblyQualified Nothing - } - , UserDefinedType - { args = - [ UserDefinedType - { args = [] - , name = "E" - , qualifiedness = PossiblyQualified Nothing - } - ] - , name = "D" - , qualifiedness = PossiblyQualified Nothing - } - ] - , name = "CustomType" + , UserDefinedType + { args = [] + , name = "Int" , qualifiedness = PossiblyQualified Nothing } ) @@ -1245,10 +1270,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] - } - , { name = "type-alias-record-simple" - , source = """type alias Ty = { hi: Int } -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1269,6 +1290,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-record-two-entries" + , source = """type alias Ty = { hi: (), buy: String } +""" , contextualized = Just [ Ok @@ -1276,13 +1301,14 @@ type alias Function3 = (Int, () -> (Int, String), ()) { expr = Record (Dict.fromList - [ ( "hi" + [ ( "buy" , UserDefinedType { args = [] - , name = "Int" + , name = "String" , qualifiedness = PossiblyQualified Nothing } ) + , ( "hi", Unit ) ] ) , genericArgs = [] @@ -1290,10 +1316,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] - } - , { name = "type-alias-record-two-entries" - , source = """type alias Ty = { hi: (), buy: String } -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1321,32 +1343,14 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 40, row = 1 } } (Newlines [] 0) ] - , contextualized = - Just - [ Ok - (TypeAlias - { expr = - Record - (Dict.fromList - [ ( "buy" - , UserDefinedType - { args = [] - , name = "String" - , qualifiedness = PossiblyQualified Nothing - } - ) - , ( "hi", Unit ) - ] - ) - , genericArgs = [] - , ty = TypeOrConstructor "Ty" - } - ) - ] } , { name = "type-alias-unit" , source = """type alias Hi = () """ + , contextualized = + Just + [ Ok (TypeAlias { expr = Unit, genericArgs = [], ty = TypeOrConstructor "Hi" }) + ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1361,29 +1365,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) ] - , contextualized = - Just - [ Ok (TypeAlias { expr = Unit, genericArgs = [], ty = TypeOrConstructor "Hi" }) - ] } , { name = "type-alias-with-bracket" , source = """type alias Hi = (Int) """ - , lexed = - Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) - ] , contextualized = Just [ Ok @@ -1399,10 +1384,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] - } - , { name = "type-alias-with-bracket-2" - , source = """type alias Hi = (List Int) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1414,12 +1395,14 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Token "List") - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Int") - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-with-bracket-2" + , source = """type alias Hi = (List Int) +""" , contextualized = Just [ Ok @@ -1441,11 +1424,6 @@ type alias Function3 = (Int, () -> (Int, String), ()) } ) ] - } - , { name = "type-alias-with-pair" - , source = """type alias Hi = (Int, List String) -type alias Hi = (Int) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1457,27 +1435,17 @@ type alias Hi = (Int) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Token "List") , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token "List") - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Token "String") - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) - , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token "Int") - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Newlines [] 0) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Int") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-with-pair" + , source = """type alias Hi = (Int, List String) +type alias Hi = (Int) +""" , contextualized = Just [ Ok @@ -1519,11 +1487,6 @@ type alias Hi = (Int) } ) ] - } - , { name = "type-alias-with-tripple" - , source = """type alias Hi = (Int, Two, Three) -type alias Hi = ((), (), ()) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1538,12 +1501,11 @@ type alias Hi = ((), (), ()) , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Two") - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Comma) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token "List") , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Token "Three") - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Token "String") + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") @@ -1553,19 +1515,15 @@ type alias Hi = ((), (), ()) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Sigil Comma) - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Whitespace 1) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil Comma) - , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Whitespace 1) - , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 3 }, start = { col = 29, row = 2 } } (Newlines [] 0) + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token "Int") + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Newlines [] 0) ] + } + , { name = "type-alias-with-tripple" + , source = """type alias Hi = (Int, Two, Three) +type alias Hi = ((), (), ()) +""" , contextualized = Just [ Ok @@ -1596,13 +1554,6 @@ type alias Hi = ((), (), ()) ) , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, genericArgs = [], ty = TypeOrConstructor "Hi" }) ] - } - , { name = "type-alias-with-tripple-in-record" - , source = """type alias Hi = - { a: (Int, Int, Int) - , b: ({ good_bye: () }) - } -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1612,42 +1563,46 @@ type alias Hi = ((), (), ()) , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) - , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token "a") - , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Sigil Colon) - , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Token "Int") - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Sigil Comma) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Whitespace 1) - , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Token "Int") - , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil Comma) - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) - , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Token "Int") - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Newlines [] 4) - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) - , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) - , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Token "b") - , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil Colon) - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Token "good_bye") - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Sigil Colon) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Whitespace 1) - , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 5, row = 4 }, start = { col = 28, row = 3 } } (Newlines [] 4) - , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Two") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Comma) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) + , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Token "Three") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Sigil Comma) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Whitespace 1) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil Comma) + , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Whitespace 1) + , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 29, row = 2 } } (Newlines [] 0) ] + } + , { name = "type-alias-with-tripple-in-record" + , source = """type alias Hi = + { a: (Int, Int, Int) + , b: ({ good_bye: () }) + } +""" , contextualized = Just [ Ok @@ -1690,6 +1645,51 @@ type alias Hi = ((), (), ()) } ) ] + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) + , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token "a") + , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Sigil Colon) + , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Token "Int") + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Sigil Comma) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Whitespace 1) + , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Token "Int") + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil Comma) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) + , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Token "Int") + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Newlines [] 4) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) + , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Token "b") + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil Colon) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Token "good_bye") + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Sigil Colon) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Whitespace 1) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 5, row = 4 }, start = { col = 28, row = 3 } } (Newlines [] 4) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + ] } ] @@ -1711,6 +1711,69 @@ type alias Function3 = (() -> , ()) type alias Function3 = (Int, () ->, ()) """ + , contextualized = + Just + [ Err + { error = Error_MissingFunctionReturnType + , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Close))) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function") + [] + { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } + , parents = + [ NestingParentType_Bracket (Stack []) + ] + } + ) + } + , Err + { error = Error_MissingFunctionReturnType + , item = Just (Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Sigil (Bracket Curly Close))) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function2") + [] + { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } + , parents = + [ NestingParentType_PartialRecord { firstEntries = Stack [], lastEntryName = "a" } + ] + } + ) + } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil Comma)) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function3") + [] + { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } + , parents = + [ NestingParentType_Bracket (Stack []) + ] + } + ) + } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Sigil Comma)) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (TypeOrConstructor "Function3") + [] + { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } + , parents = + [ NestingParentType_Bracket + (Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + ) + ] + } + ) + } + ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1807,73 +1870,18 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 40, row = 7 }, start = { col = 39, row = 7 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 8 }, start = { col = 40, row = 7 } } (Newlines [] 0) ] + } + , { name = "type-alias-invalid-multiple-brackets" + , source = """type alias Hi = (Int) () +""" , contextualized = Just [ Err - { error = Error_MissingFunctionReturnType - , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Close))) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function") - [] - { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } - , parents = - [ NestingParentType_Bracket (Stack []) - ] - } - ) - } - , Err - { error = Error_MissingFunctionReturnType - , item = Just (Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Sigil (Bracket Curly Close))) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function2") - [] - { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } - , parents = - [ NestingParentType_PartialRecord { firstEntries = Stack [], lastEntryName = "a" } - ] - } - ) - } - , Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil Comma)) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function3") - [] - { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } - , parents = - [ NestingParentType_Bracket (Stack []) - ] - } - ) - } - , Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Sigil Comma)) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function3") - [] - { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } - , parents = - [ NestingParentType_Bracket - (Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - ) - ] - } - ) + { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) } ] - } - , { name = "type-alias-invalid-multiple-brackets" - , source = """type alias Hi = (Int) () -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1892,18 +1900,18 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-invalid-multiple-brackets-2" + , source = """type alias Hi = () () +""" , contextualized = Just [ Err - { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) - , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) + { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit + , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] - } - , { name = "type-alias-invalid-multiple-brackets-2" - , source = """type alias Hi = () () -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1921,6 +1929,10 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-invalid-multiple-brackets-3" + , source = """type alias Hi = () (Int) +""" , contextualized = Just [ Err @@ -1929,10 +1941,6 @@ type alias Function3 = (Int, () ->, ()) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] - } - , { name = "type-alias-invalid-multiple-brackets-3" - , source = """type alias Hi = () (Int) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -1951,34 +1959,11 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) ] - , contextualized = - Just - [ Err - { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit - , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) - } - ] } , { name = "type-alias-multiline-missing-indentation" , source = """type alias Model = List Int """ - , lexed = - Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "List") - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token "Int") - , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) - ] , contextualized = Just [ Err @@ -1992,17 +1977,25 @@ List Int , state = State_BlockStart } ] - } - , { name = "type-alias-partial" - , source = """type alias -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") - , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "List") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) ] + } + , { name = "type-alias-partial" + , source = """type alias +""" , contextualized = Just [ Err @@ -2011,19 +2004,17 @@ List Int , state = State_BlockTypeAlias BlockTypeAlias_Keywords } ] - } - , { name = "type-alias-partial-2" - , source = """type alias Hi -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") - , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) + , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-partial-2" + , source = """type alias Hi +""" , contextualized = Just [ Err @@ -2032,10 +2023,6 @@ List Int , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi") (Stack [])) } ] - } - , { name = "type-alias-partial-3" - , source = """type alias Hi = -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -2043,10 +2030,12 @@ List Int , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) + , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-partial-3" + , source = """type alias Hi = +""" , contextualized = Just [ Err @@ -2055,10 +2044,6 @@ List Int , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi") []) } ] - } - , { name = "type-alias-partial-with-bracket" - , source = """type alias Hi = ( -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -2068,23 +2053,20 @@ List Int , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) + , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-partial-with-bracket" + , source = """type alias Hi = ( +""" , contextualized = Just [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) - } - ] - } - , { name = "type-alias-partial-with-bracket-2" - , source = """type alias Hi = ( - Int -""" + } + ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -2096,10 +2078,13 @@ List Int , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) - , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token "Int") - , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-partial-with-bracket-2" + , source = """type alias Hi = ( + Int +""" , contextualized = Just [ Err @@ -2117,23 +2102,25 @@ List Int ) } ] - } - , { name = "type-alias-record-half-empty" - , source = """type alias Ty = { -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) + , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token "Int") + , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) ] + } + , { name = "type-alias-record-half-empty" + , source = """type alias Ty = { +""" , contextualized = Just [ Err @@ -2142,10 +2129,6 @@ List Int , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) } ] - } - , { name = "type-alias-record-missing-colon" - , source = """type alias Ty = { hi j7 } -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -2157,14 +2140,12 @@ List Int , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token "j7") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-record-missing-colon" + , source = """type alias Ty = { hi j7 } +""" , contextualized = Just [ Err @@ -2173,84 +2154,30 @@ List Int , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) } ] - } - , { name = "type-alias-with-quadruple" - , source = """type alias Hi = (Int, A, B, C, D) -type alias Hi = (A Int, C D E F, H I (J K), L M () O P) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "A") - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token "B") - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil Comma) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token "C") - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil Comma) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token "D") - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) - , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Token "A") - , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) - , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Token "Int") - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil Comma) - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) - , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Token "C") - , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Whitespace 1) - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token "D") - , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Whitespace 1) - , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Token "E") - , Located { end = { col = 31, row = 2 }, start = { col = 30, row = 2 } } (Whitespace 1) - , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Token "F") - , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Sigil Comma) - , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Whitespace 1) - , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Token "H") - , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Whitespace 1) - , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Token "I") - , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) - , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Token "J") - , Located { end = { col = 41, row = 2 }, start = { col = 40, row = 2 } } (Whitespace 1) - , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Token "K") - , Located { end = { col = 43, row = 2 }, start = { col = 42, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 44, row = 2 }, start = { col = 43, row = 2 } } (Sigil Comma) - , Located { end = { col = 45, row = 2 }, start = { col = 44, row = 2 } } (Whitespace 1) - , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Token "L") - , Located { end = { col = 47, row = 2 }, start = { col = 46, row = 2 } } (Whitespace 1) - , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Token "M") - , Located { end = { col = 49, row = 2 }, start = { col = 48, row = 2 } } (Whitespace 1) - , Located { end = { col = 50, row = 2 }, start = { col = 49, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 51, row = 2 }, start = { col = 50, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 52, row = 2 }, start = { col = 51, row = 2 } } (Whitespace 1) - , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Token "O") - , Located { end = { col = 54, row = 2 }, start = { col = 53, row = 2 } } (Whitespace 1) - , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Token "P") - , Located { end = { col = 56, row = 2 }, start = { col = 55, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token "j7") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-with-quadruple" + , source = """type alias Hi = (Int, A, B, C, D) +type alias Hi = (A Int, C D E F, H I (J K), L M () O P) +""" , contextualized = Just [ Err @@ -2447,10 +2374,6 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) } ] - } - , { name = "type-alias-with-tuple-double-comma" - , source = """type alias Hi = (Int, , A) -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -2465,12 +2388,69 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "A") - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "A") + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token "B") + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil Comma) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token "C") + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil Comma) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token "D") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Token "A") + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) + , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Token "Int") + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil Comma) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) + , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Token "C") + , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Whitespace 1) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token "D") + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Whitespace 1) + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Token "E") + , Located { end = { col = 31, row = 2 }, start = { col = 30, row = 2 } } (Whitespace 1) + , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Token "F") + , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Sigil Comma) + , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Whitespace 1) + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Token "H") + , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Whitespace 1) + , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Token "I") + , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) + , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Token "J") + , Located { end = { col = 41, row = 2 }, start = { col = 40, row = 2 } } (Whitespace 1) + , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Token "K") + , Located { end = { col = 43, row = 2 }, start = { col = 42, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 44, row = 2 }, start = { col = 43, row = 2 } } (Sigil Comma) + , Located { end = { col = 45, row = 2 }, start = { col = 44, row = 2 } } (Whitespace 1) + , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Token "L") + , Located { end = { col = 47, row = 2 }, start = { col = 46, row = 2 } } (Whitespace 1) + , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Token "M") + , Located { end = { col = 49, row = 2 }, start = { col = 48, row = 2 } } (Whitespace 1) + , Located { end = { col = 50, row = 2 }, start = { col = 49, row = 2 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 51, row = 2 }, start = { col = 50, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 52, row = 2 }, start = { col = 51, row = 2 } } (Whitespace 1) + , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Token "O") + , Located { end = { col = 54, row = 2 }, start = { col = 53, row = 2 } } (Whitespace 1) + , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Token "P") + , Located { end = { col = 56, row = 2 }, start = { col = 55, row = 2 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0) ] + } + , { name = "type-alias-with-tuple-double-comma" + , source = """type alias Hi = (Int, , A) +""" , contextualized = Just [ Err @@ -2492,13 +2472,6 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) } ] - } - , { name = "type-alias-with-tuple-not-closed" - , source = """type alias Hi = (Int, - - - -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") @@ -2512,15 +2485,20 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) - , Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } - (Newlines - [ 0 - , 0 - , 0 - ] - 0 - ) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "A") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) ] + } + , { name = "type-alias-with-tuple-not-closed" + , source = """type alias Hi = (Int, + + + +""" , contextualized = Just [ Err @@ -2552,15 +2530,32 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) } ] - } - , { name = "type-partial" - , source = """type -""" , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") - , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + , Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } + (Newlines + [ 0 + , 0 + , 0 + ] + 0 + ) ] + } + , { name = "type-partial" + , source = """type +""" , contextualized = Just [ Err @@ -2569,5 +2564,10 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , state = State_BlockFirstItem BlockFirstItem_Type } ] + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0) + ] } ] From 4da8eeebf3ddd5c8c458c28794c0ef14df7e6d1f Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 11:09:35 +0100 Subject: [PATCH 063/103] delete unused functions --- src/Stage/Parse/Contextualize.elm | 63 ------------------------------- 1 file changed, 63 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 5fdb3199..0c66aa40 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -1484,46 +1484,6 @@ blockFromState state = -- helper functions -type TokenOrType - = TokenOrType_Token String - - -addToPartialRecord : - String - -> PartialRecord - -> Result Error PartialRecord -addToPartialRecord token { firstEntries, lastEntry } = - let - newType = - TypeExpression_NamedType - { name = token - , args = empty - } - in - case lastEntry of - LastEntryOfRecord_Empty -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_Key token - } - |> Ok - - LastEntryOfRecord_Key key -> - Error_ExpectedColonWhilstParsingRecord - |> Err - - LastEntryOfRecord_KeyColon key -> - { firstEntries = firstEntries - , lastEntry = - LastEntryOfRecord_KeyValue key newType - } - |> Ok - - LastEntryOfRecord_KeyValue key value -> - Error_TypeDoesNotTakeArgs value newType - |> Err - - type CollapseLevel = CollapseLevel_TypeWithArgs | CollapseLevel_Function @@ -1698,16 +1658,6 @@ partialTypeExpressionToConcreteType pte = (partialTypeExpressionToConcreteType functionTypeExpr.output) -recoverErrors : ParseResult -> ParseResult -recoverErrors res = - case res of - ParseResult_Err _ -> - ParseResult_Ok State_Error_Recovery - - _ -> - res - - collectList : (a -> Result e o) -> List a -> Result e (List o) collectList = collectListHelp [] @@ -1728,19 +1678,6 @@ collectListHelp new func old = Ok (List.reverse new) -parseResultFromMaybeResult : Maybe (Result Error State) -> ParseResult -parseResultFromMaybeResult x = - case x of - Just (Ok s) -> - ParseResult_Ok s - - Just (Err e) -> - ParseResult_Err e - - Nothing -> - ParseResult_Skip - - -- stacks From 263c9c21fa263d9a6550176a0388c0dcef7e1894 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 11:19:29 +0100 Subject: [PATCH 064/103] share partial results between types and exprs --- src/Stage/Parse/Contextualize.elm | 81 +++++++++++++++++++------------ 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 0c66aa40..0c12dd17 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -217,9 +217,13 @@ type alias PartialTypeExpressionLeaf = } -type TypeExpressionResult - = TypeExpressionResult_Progress PartialTypeExpressionLeaf - | TypeExpressionResult_Done PartialTypeExpression +type PartialResult progress done + = PartialResult_Progress progress + | PartialResult_Done done + + +type alias TypeExpressionResult = + PartialResult PartialTypeExpressionLeaf PartialTypeExpression @@ -243,9 +247,8 @@ type ExpressionNestingLeaf | ExpressionNestingLeafType_Expr Frontend.LocatedExpr -type ExpressionResult - = ExpressionResult_Progress ExpressionNestingLeaf - | ExpressionResult_Done Frontend.LocatedExpr +type alias ExpressionResult = + PartialResult ExpressionNestingLeaf Frontend.LocatedExpr type Error @@ -399,11 +402,11 @@ parseAnything state = let newTypeAliasState aliasName typeArgs res = case res of - TypeExpressionResult_Progress expr -> + PartialResult_Progress expr -> State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs expr) |> ParseResult_Ok - TypeExpressionResult_Done expr -> + PartialResult_Done expr -> case partialTypeExpressionToConcreteType expr of Ok concreteType -> { ty = aliasName @@ -419,7 +422,7 @@ parseAnything state = newExpressionState name args res = case res of - ExpressionResult_Progress expr -> + PartialResult_Progress expr -> State_BlockValueDeclaration (BlockValueDeclaration_Completish { name = name @@ -429,7 +432,7 @@ parseAnything state = ) |> ParseResult_Ok - ExpressionResult_Done expr -> + PartialResult_Done expr -> { name = name , args = args , valueExpr__ = expr @@ -713,14 +716,14 @@ parserTypeExprFromEmpty newState item = , args = empty } } - |> TypeExpressionResult_Progress + |> PartialResult_Progress |> newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> { parents = [] , nesting = NestingLeafType_Bracket empty Nothing } - |> TypeExpressionResult_Progress + |> PartialResult_Progress |> newState Lexer.Sigil (Lexer.Bracket role Lexer.Close) -> @@ -735,7 +738,7 @@ parserTypeExprFromEmpty newState item = } , parents = [] } - |> TypeExpressionResult_Progress + |> PartialResult_Progress |> newState Lexer.Sigil Lexer.Colon -> @@ -774,7 +777,7 @@ parserTypeExpr newState prevExpr item = case Located.unwrap item of Lexer.Token str -> exprAppend prevExpr str - |> partialTypeExpressionToParseResult newState + |> partialExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> leafToParents prevExpr @@ -784,7 +787,7 @@ parserTypeExpr newState prevExpr item = , nesting = NestingLeafType_Bracket empty Nothing } ) - |> partialTypeExpressionToParseResult newState + |> partialExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> let @@ -801,7 +804,7 @@ parserTypeExpr newState prevExpr item = NestingLeafType_Bracket argStack mLastExpression -> closeBracket argStack mLastExpression collapsedLeaf.parents - |> partialTypeExpressionToParseResult newState + |> partialExpressionToParseResult newState NestingLeafType_PartialRecord _ -> Error_WrongClosingBracket @@ -831,15 +834,15 @@ parserTypeExpr newState prevExpr item = , parents = newParents } ) - |> partialTypeExpressionToParseResult newState + |> partialExpressionToParseResult newState Lexer.Sigil Lexer.Colon -> appendColonTo prevExpr - |> partialTypeExpressionToParseResult newState + |> partialExpressionToParseResult newState Lexer.Sigil Lexer.Comma -> appendCommaTo prevExpr - |> partialTypeExpressionToParseResult newState + |> partialExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> let @@ -863,7 +866,7 @@ parserTypeExpr newState prevExpr item = NestingLeafType_PartialRecord pr -> closeRecord pr collapsedLeaf.parents - |> partialTypeExpressionToParseResult newState + |> partialExpressionToParseResult newState NestingLeafType_Function { output } -> case output of @@ -886,7 +889,7 @@ parserTypeExpr newState prevExpr item = , lastEntry = LastEntryOfRecord_Empty } } - |> TypeExpressionResult_Progress + |> PartialResult_Progress |> newState _ -> @@ -906,7 +909,7 @@ parserTypeExpr newState prevExpr item = } , parents = [] } - |> TypeExpressionResult_Progress + |> PartialResult_Progress |> newState NestingLeafType_TypeWithArgs {} -> @@ -927,7 +930,7 @@ parserTypeExpr newState prevExpr item = } , parents = collapsedLeaf.parents } - |> TypeExpressionResult_Progress + |> PartialResult_Progress |> newState NestingLeafType_Bracket argStack (Just expr) -> @@ -939,7 +942,7 @@ parserTypeExpr newState prevExpr item = } , parents = NestingParentType_Bracket argStack :: collapsedLeaf.parents } - |> TypeExpressionResult_Progress + |> PartialResult_Progress |> newState NestingLeafType_Bracket argStack Nothing -> @@ -974,13 +977,13 @@ parserTypeExpr newState prevExpr item = } :: collapsedLeaf.parents } - |> TypeExpressionResult_Progress + |> PartialResult_Progress |> newState Lexer.Newlines _ 0 -> case (autoCollapseNesting CollapseLevel_Function prevExpr).nesting of NestingLeafType_Expr expr -> - TypeExpressionResult_Done expr + PartialResult_Done expr |> newState _ -> @@ -1014,7 +1017,7 @@ parserExpressionFromEmpty newState item = Frontend.Int i |> withCorrectLocation |> ExpressionNestingLeafType_Expr - |> ExpressionResult_Progress + |> PartialResult_Progress |> newState Nothing -> @@ -1043,6 +1046,10 @@ parserExpression : -> ParseResult parserExpression newState prevExpr item = case Located.unwrap item of + Lexer.Sigil (Lexer.Operator op) -> + appendOperatorTo prevExpr op + |> partialExpressionToParseResult newState + Lexer.Newlines _ 0 -> case prevExpr of ExpressionNestingLeaf_Operator {} -> @@ -1051,7 +1058,7 @@ parserExpression newState prevExpr item = ExpressionNestingLeafType_Expr expr -> expr - |> ExpressionResult_Done + |> PartialResult_Done |> newState Lexer.Newlines _ _ -> @@ -1403,6 +1410,15 @@ closeRecord { firstEntries, lastEntry } parents = |> Err + +-- Value expression helpers + + +appendOperatorTo : ExpressionNestingLeaf -> Lexer.LexOperator -> Result Error ExpressionNestingLeaf +appendOperatorTo leaf op = + Debug.todo ("implement operator" ++ Lexer.toString (op |> Lexer.Operator |> Lexer.Sigil)) + + blockFromState : State -> Maybe (Result Error Block) blockFromState state = case state of @@ -1536,11 +1552,14 @@ appropriately. TODO(harry): We can inline this function. -} -partialTypeExpressionToParseResult : (TypeExpressionResult -> ParseResult) -> Result Error PartialTypeExpressionLeaf -> ParseResult -partialTypeExpressionToParseResult newState rnewPartialType = +partialExpressionToParseResult : + (PartialResult progress neverDone -> ParseResult) + -> Result Error progress + -> ParseResult +partialExpressionToParseResult newState rnewPartialType = case rnewPartialType of Ok newPartialType -> - TypeExpressionResult_Progress newPartialType + PartialResult_Progress newPartialType |> newState Err e -> From 270d8fb6a6be09190823121e9f414bdab626364f Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 11:51:44 +0100 Subject: [PATCH 065/103] add type annotations As suggested by new elm vscode release --- tests/InferTypesFuzz.elm | 7 +++++++ tests/LexerTest.elm | 1 + tests/ParserLexerTest.elm | 1 + tests/Shrink/Extra.elm | 3 +++ 4 files changed, 12 insertions(+) diff --git a/tests/InferTypesFuzz.elm b/tests/InferTypesFuzz.elm index 4244a58e..798e979a 100644 --- a/tests/InferTypesFuzz.elm +++ b/tests/InferTypesFuzz.elm @@ -417,6 +417,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkPlus : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} +shrinkPlus : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkPlus left right = ([ Shrink.map2 CanonicalU.Plus (shrinkExpr left) @@ -443,6 +444,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkCons : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} +shrinkCons : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkCons x xs = ([ Shrink.map2 CanonicalU.Cons (shrinkExpr x) @@ -469,6 +471,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkCall : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} +shrinkCall : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkCall fn arg = ([ Shrink.map2 call (shrinkExpr fn) @@ -491,6 +494,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkIf : CanonicalU.Expr -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} +shrinkIf : CanonicalU.Expr -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkIf test then_ else_ = let withTest shrunkTest = @@ -518,6 +522,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkLambda : VarName -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} +shrinkLambda : VarName -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkLambda argument body = body |> shrinkExpr @@ -530,6 +535,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkTuple : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} +shrinkTuple : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkTuple first second = ([ Shrink.map2 CanonicalU.Tuple (shrinkExpr first) @@ -552,6 +558,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkTuple3 : CanonicalU.Expr -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} +shrinkTuple3 : CanonicalU.Expr -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkTuple3 first second third = ([ Shrink.map3 CanonicalU.Tuple3 (shrinkExpr first) diff --git a/tests/LexerTest.elm b/tests/LexerTest.elm index a3f7457f..c24125f6 100644 --- a/tests/LexerTest.elm +++ b/tests/LexerTest.elm @@ -18,6 +18,7 @@ import String.Extra as String import Test exposing (Test, describe, test) +runTest : ( String, String ) -> Test runTest ( description, input ) = test description <| \() -> diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm index f420c453..18a984d7 100644 --- a/tests/ParserLexerTest.elm +++ b/tests/ParserLexerTest.elm @@ -10,6 +10,7 @@ import Stage.Parse.Lexer as Lexer import Test exposing (Test, describe, fuzz, test) +tests : Test tests = describe "parser lexer test" [ describe "helpers" diff --git a/tests/Shrink/Extra.elm b/tests/Shrink/Extra.elm index 53d13bf0..815f198d 100644 --- a/tests/Shrink/Extra.elm +++ b/tests/Shrink/Extra.elm @@ -13,6 +13,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations map2 : (a -> b -> c) -> LazyList a -> LazyList b -> LazyList c -} +map2 : (a -> b -> c) -> LazyList a -> LazyList b -> LazyList c map2 f la lb = Shrink.map f la |> Shrink.andMap lb @@ -28,6 +29,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations map3 : (a -> b -> c -> d) -> LazyList a -> LazyList b -> LazyList c -> LazyList d -} +map3 : (a -> b -> c -> d) -> LazyList a -> LazyList b -> LazyList c -> LazyList d map3 f la lb lc = Shrink.map f la |> Shrink.andMap lb @@ -44,6 +46,7 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations singleton : a -> LazyList a -} +singleton : a -> LazyList a singleton x = x |> const x From 10c68be8224ef5abfb32abac97497a930a359c78 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 13:46:42 +0100 Subject: [PATCH 066/103] Revert "add type annotations" This reverts commit 270d8fb6a6be09190823121e9f414bdab626364f. --- tests/InferTypesFuzz.elm | 7 ------- tests/LexerTest.elm | 1 - tests/ParserLexerTest.elm | 1 - tests/Shrink/Extra.elm | 3 --- 4 files changed, 12 deletions(-) diff --git a/tests/InferTypesFuzz.elm b/tests/InferTypesFuzz.elm index 798e979a..4244a58e 100644 --- a/tests/InferTypesFuzz.elm +++ b/tests/InferTypesFuzz.elm @@ -417,7 +417,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkPlus : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} -shrinkPlus : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkPlus left right = ([ Shrink.map2 CanonicalU.Plus (shrinkExpr left) @@ -444,7 +443,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkCons : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} -shrinkCons : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkCons x xs = ([ Shrink.map2 CanonicalU.Cons (shrinkExpr x) @@ -471,7 +469,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkCall : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} -shrinkCall : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkCall fn arg = ([ Shrink.map2 call (shrinkExpr fn) @@ -494,7 +491,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkIf : CanonicalU.Expr -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} -shrinkIf : CanonicalU.Expr -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkIf test then_ else_ = let withTest shrunkTest = @@ -522,7 +518,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkLambda : VarName -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} -shrinkLambda : VarName -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkLambda argument body = body |> shrinkExpr @@ -535,7 +530,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkTuple : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} -shrinkTuple : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkTuple first second = ([ Shrink.map2 CanonicalU.Tuple (shrinkExpr first) @@ -558,7 +552,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations shrinkTuple3 : CanonicalU.Expr -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} -shrinkTuple3 : CanonicalU.Expr -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr shrinkTuple3 first second third = ([ Shrink.map3 CanonicalU.Tuple3 (shrinkExpr first) diff --git a/tests/LexerTest.elm b/tests/LexerTest.elm index c24125f6..a3f7457f 100644 --- a/tests/LexerTest.elm +++ b/tests/LexerTest.elm @@ -18,7 +18,6 @@ import String.Extra as String import Test exposing (Test, describe, test) -runTest : ( String, String ) -> Test runTest ( description, input ) = test description <| \() -> diff --git a/tests/ParserLexerTest.elm b/tests/ParserLexerTest.elm index 18a984d7..f420c453 100644 --- a/tests/ParserLexerTest.elm +++ b/tests/ParserLexerTest.elm @@ -10,7 +10,6 @@ import Stage.Parse.Lexer as Lexer import Test exposing (Test, describe, fuzz, test) -tests : Test tests = describe "parser lexer test" [ describe "helpers" diff --git a/tests/Shrink/Extra.elm b/tests/Shrink/Extra.elm index 815f198d..53d13bf0 100644 --- a/tests/Shrink/Extra.elm +++ b/tests/Shrink/Extra.elm @@ -13,7 +13,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations map2 : (a -> b -> c) -> LazyList a -> LazyList b -> LazyList c -} -map2 : (a -> b -> c) -> LazyList a -> LazyList b -> LazyList c map2 f la lb = Shrink.map f la |> Shrink.andMap lb @@ -29,7 +28,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations map3 : (a -> b -> c -> d) -> LazyList a -> LazyList b -> LazyList c -> LazyList d -} -map3 : (a -> b -> c -> d) -> LazyList a -> LazyList b -> LazyList c -> LazyList d map3 f la lb lc = Shrink.map f la |> Shrink.andMap lb @@ -46,7 +44,6 @@ The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations singleton : a -> LazyList a -} -singleton : a -> LazyList a singleton x = x |> const x From bd0596e67929c9255b2cd022b5b0d91e88085876 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 13:55:57 +0100 Subject: [PATCH 067/103] extract operators from parsing stage --- src/Elm/Data/Operator.elm | 116 ++++++++++++++++++++++++++++++ src/Stage/Parse/Contextualize.elm | 7 +- src/Stage/Parse/Lexer.elm | 71 ++++++++---------- 3 files changed, 148 insertions(+), 46 deletions(-) create mode 100644 src/Elm/Data/Operator.elm diff --git a/src/Elm/Data/Operator.elm b/src/Elm/Data/Operator.elm new file mode 100644 index 00000000..2bfc428c --- /dev/null +++ b/src/Elm/Data/Operator.elm @@ -0,0 +1,116 @@ +module Elm.Data.Operator exposing (..) + + +type Operator + = Add + | Subtract + | Multiply + | Divide + | Exponentiate + | And + | Or + | Equals + | GreaterThan + | GreaterThanEquals + | LessThan + | LessThanEquals + | Append + + +{-| Operator precedence. + +Constructors are ordered from highest precedence to lowest. High precedence +operators bind more strongly to operands and thus end up deeper in the AST. + +-} +type OperatorPrecedence + = Composition + | Exponentiation + | Multiplication + | Addition + | Concatenation + | Comparison + | AndPrec + | OrPrec + | Pipe + + +type OperatorAssociativity + = ConflictsWithOthers + | ConflictsWithSelf + | RightToLeft + | LeftToRight + + +getOperatorPrecedence : Operator -> OperatorPrecedence +getOperatorPrecedence op = + case op of + Add -> + Addition + + Subtract -> + Addition + + Multiply -> + Multiplication + + Divide -> + Multiplication + + Exponentiate -> + Exponentiation + + And -> + AndPrec + + Or -> + OrPrec + + Equals -> + Comparison + + GreaterThan -> + Comparison + + GreaterThanEquals -> + Comparison + + LessThan -> + Comparison + + LessThanEquals -> + Comparison + + Append -> + Concatenation + + +getOperatorAssociativity : OperatorPrecedence -> OperatorAssociativity +getOperatorAssociativity prec = + case prec of + Composition -> + ConflictsWithOthers + + Exponentiation -> + RightToLeft + + Multiplication -> + LeftToRight + + Addition -> + LeftToRight + + Concatenation -> + RightToLeft + + Comparison -> + ConflictsWithSelf + + AndPrec -> + RightToLeft + + OrPrec -> + RightToLeft + + Pipe -> + ConflictsWithOthers diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 0c12dd17..02acd166 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -17,6 +17,7 @@ import Elm.Data.Exposing import Elm.Data.Located as Located exposing (Located) import Elm.Data.Module exposing (Module, ModuleType(..)) import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Operator as Operator exposing (Operator) import Elm.Data.Qualifiedness as Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type exposing (Type) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) @@ -232,7 +233,7 @@ type alias TypeExpressionResult = type ExpressionNestingParent = ExpressionNestingParent_Operator - { op : Lexer.LexOperator + { op : Operator , lhs : Frontend.LocatedExpr , parent : Maybe ExpressionNestingParent } @@ -240,7 +241,7 @@ type ExpressionNestingParent type ExpressionNestingLeaf = ExpressionNestingLeaf_Operator - { op : Lexer.LexOperator + { op : Operator , lhs : Frontend.LocatedExpr , parent : Maybe ExpressionNestingParent } @@ -1414,7 +1415,7 @@ closeRecord { firstEntries, lastEntry } parents = -- Value expression helpers -appendOperatorTo : ExpressionNestingLeaf -> Lexer.LexOperator -> Result Error ExpressionNestingLeaf +appendOperatorTo : ExpressionNestingLeaf -> Operator -> Result Error ExpressionNestingLeaf appendOperatorTo leaf op = Debug.todo ("implement operator" ++ Lexer.toString (op |> Lexer.Operator |> Lexer.Sigil)) diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index d340342e..128bc96c 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -1,6 +1,7 @@ module Stage.Parse.Lexer exposing (..) import Elm.Data.Located as Located exposing (Located) +import Elm.Data.Operator as Operator exposing (Operator) import Parser.Advanced as P exposing ((|.), (|=), Parser) import Set @@ -27,7 +28,7 @@ type LexSigil | Backslash | Underscore | Colon - | Operator LexOperator + | Operator Operator type LexCommentType @@ -36,22 +37,6 @@ type LexCommentType | DocComment -type LexOperator - = Add - | Subtract - | Multiply - | Divide - | Exponentiate - | And - | Or - | Equals - | GreaterThan - | GreaterThanEquals - | LessThan - | LessThanEquals - | Append - - type BracketType = Round | Square @@ -140,43 +125,43 @@ toString item = Sigil Underscore -> "_" - Sigil (Operator Add) -> + Sigil (Operator Operator.Add) -> "+" - Sigil (Operator Subtract) -> + Sigil (Operator Operator.Subtract) -> "-" - Sigil (Operator Multiply) -> + Sigil (Operator Operator.Multiply) -> "*" - Sigil (Operator Divide) -> + Sigil (Operator Operator.Divide) -> "/" - Sigil (Operator Exponentiate) -> + Sigil (Operator Operator.Exponentiate) -> "^" - Sigil (Operator And) -> + Sigil (Operator Operator.And) -> "&&" - Sigil (Operator Or) -> + Sigil (Operator Operator.Or) -> "||" - Sigil (Operator Equals) -> + Sigil (Operator Operator.Equals) -> "==" - Sigil (Operator GreaterThan) -> + Sigil (Operator Operator.GreaterThan) -> ">" - Sigil (Operator GreaterThanEquals) -> + Sigil (Operator Operator.GreaterThanEquals) -> ">=" - Sigil (Operator LessThan) -> + Sigil (Operator Operator.LessThan) -> "<" - Sigil (Operator LessThanEquals) -> + Sigil (Operator Operator.LessThanEquals) -> "<=" - Sigil (Operator Append) -> + Sigil (Operator Operator.Append) -> "++" Token s -> @@ -408,25 +393,25 @@ sigilParser = P.oneOf [ -- Two character sigils (must come first) P.symbol (P.Token "&&" ExpectingSigil) - |> P.map (\() -> Operator And) + |> P.map (\() -> Operator Operator.And) , P.symbol (P.Token "++" ExpectingSigil) - |> P.map (\() -> Operator Append) + |> P.map (\() -> Operator Operator.Append) , P.symbol (P.Token "==" ExpectingSigil) - |> P.map (\() -> Operator Equals) + |> P.map (\() -> Operator Operator.Equals) , P.symbol (P.Token "||" ExpectingSigil) - |> P.map (\() -> Operator Or) + |> P.map (\() -> Operator Operator.Or) , P.symbol (P.Token ".." ExpectingSigil) |> P.map (\() -> DoubleDot) , P.symbol (P.Token "->" ExpectingSigil) |> P.map (\() -> ThinArrow) , P.symbol (P.Token ">=" ExpectingSigil) - |> P.map (\() -> Operator GreaterThanEquals) + |> P.map (\() -> Operator Operator.GreaterThanEquals) , P.symbol (P.Token "<=" ExpectingSigil) - |> P.map (\() -> Operator LessThanEquals) + |> P.map (\() -> Operator Operator.LessThanEquals) -- Single character sigils , P.symbol (P.Token "^" ExpectingSigil) - |> P.map (\() -> Operator Exponentiate) + |> P.map (\() -> Operator Operator.Exponentiate) , P.symbol (P.Token "\\" ExpectingSigil) |> P.map (\() -> Backslash) , P.symbol (P.Token "_" ExpectingSigil) @@ -436,19 +421,19 @@ sigilParser = , P.symbol (P.Token ")" ExpectingSigil) |> P.map (\() -> Bracket Round Close) , P.symbol (P.Token ">" ExpectingSigil) - |> P.map (\() -> Operator GreaterThan) + |> P.map (\() -> Operator Operator.GreaterThan) , P.symbol (P.Token "<" ExpectingSigil) - |> P.map (\() -> Operator LessThan) + |> P.map (\() -> Operator Operator.LessThan) , P.symbol (P.Token "-" ExpectingSigil) - |> P.map (\() -> Operator Subtract) + |> P.map (\() -> Operator Operator.Subtract) , P.symbol (P.Token "+" ExpectingSigil) - |> P.map (\() -> Operator Add) + |> P.map (\() -> Operator Operator.Add) , P.symbol (P.Token "=" ExpectingSigil) |> P.map (\() -> Assign) , P.symbol (P.Token "/" ExpectingSigil) - |> P.map (\() -> Operator Divide) + |> P.map (\() -> Operator Operator.Divide) , P.symbol (P.Token "*" ExpectingSigil) - |> P.map (\() -> Operator Multiply) + |> P.map (\() -> Operator Operator.Multiply) , P.symbol (P.Token "{" ExpectingSigil) |> P.map (\() -> Bracket Curly Open) , P.symbol (P.Token "[" ExpectingSigil) From 564eaf355ab5b74f9c1c03ba301b196c3e4aefb2 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 14:14:21 +0100 Subject: [PATCH 068/103] start to implement operators --- parser-tests/Update.elm | 5 +- .../snippets/should-parse/expression-int-add | 3 + .../should-parse/expression-int-subtract | 3 + src/Elm/Data/Operator.elm | 8 +- src/Stage/Parse/Contextualize.elm | 110 +++++++++++++- tests/ParserLexerTestCases.elm | 142 ++++++++++++++++++ 6 files changed, 264 insertions(+), 7 deletions(-) create mode 100644 parser-tests/snippets/should-parse/expression-int-add create mode 100644 parser-tests/snippets/should-parse/expression-int-subtract diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 4068585c..4543f46d 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -112,6 +112,8 @@ preFormatElmCode = """ >> String.replace """UserDefinedType {""" """UserDefinedType { """ + >> String.replace """BlockValueDeclaration_Completish {""" """BlockValueDeclaration_Completish { + """ {-| Always run after preformatting. -} resolveCustomTypeConstructors : String -> String @@ -119,7 +121,8 @@ resolveCustomTypeConstructors = String.split "\n" >> List.map ( \line -> - if String.contains "valueExpr__" line then + if String.contains "valueExpr__" line || String.contains "ExpressionNestingParent_Operator" line + || String.contains "ExpressionNestingLeaf_Operator" line then line |> String.replace "Int" "Frontend.Int" |> String.replace "Float" "Frontend.Float" diff --git a/parser-tests/snippets/should-parse/expression-int-add b/parser-tests/snippets/should-parse/expression-int-add new file mode 100644 index 00000000..ee8724ca --- /dev/null +++ b/parser-tests/snippets/should-parse/expression-int-add @@ -0,0 +1,3 @@ +a = 5 + 5 + +b = 78 + 5 + 2+ 4 diff --git a/parser-tests/snippets/should-parse/expression-int-subtract b/parser-tests/snippets/should-parse/expression-int-subtract new file mode 100644 index 00000000..b47cb249 --- /dev/null +++ b/parser-tests/snippets/should-parse/expression-int-subtract @@ -0,0 +1,3 @@ +a = 5 - 5 + +b = 78 + 5 + 2 - 4 + 5 diff --git a/src/Elm/Data/Operator.elm b/src/Elm/Data/Operator.elm index 2bfc428c..b54b948b 100644 --- a/src/Elm/Data/Operator.elm +++ b/src/Elm/Data/Operator.elm @@ -42,8 +42,8 @@ type OperatorAssociativity | LeftToRight -getOperatorPrecedence : Operator -> OperatorPrecedence -getOperatorPrecedence op = +getPrecedence : Operator -> OperatorPrecedence +getPrecedence op = case op of Add -> Addition @@ -85,8 +85,8 @@ getOperatorPrecedence op = Concatenation -getOperatorAssociativity : OperatorPrecedence -> OperatorAssociativity -getOperatorAssociativity prec = +getAssociativity : OperatorPrecedence -> OperatorAssociativity +getAssociativity prec = case prec of Composition -> ConflictsWithOthers diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 02acd166..1395444f 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -243,6 +243,7 @@ type ExpressionNestingLeaf = ExpressionNestingLeaf_Operator { op : Operator , lhs : Frontend.LocatedExpr + , rhs : Maybe Frontend.LocatedExpr , parent : Maybe ExpressionNestingParent } | ExpressionNestingLeafType_Expr Frontend.LocatedExpr @@ -268,6 +269,7 @@ type Error | Error_ExpectedKeyWhilstParsingRecord | Error_TypeDoesNotTakeArgs PartialTypeExpression PartialTypeExpression | Error_TypeDoesNotTakeArgs2 PartialTypeExpression + | Error_ValueDoesNotTakeArgs Frontend.LocatedExpr | Error_ExtraItemAfterBlock PartialTypeExpression Lexer.LexItem | Error_TooManyTupleArgs -- @@ -1046,6 +1048,10 @@ parserExpression : -> Located LexItem -> ParseResult parserExpression newState prevExpr item = + let + withCorrectLocation x = + Located.map (\_ -> x) item + in case Located.unwrap item of Lexer.Sigil (Lexer.Operator op) -> appendOperatorTo prevExpr op @@ -1062,6 +1068,18 @@ parserExpression newState prevExpr item = |> PartialResult_Done |> newState + Lexer.NumericLiteral str -> + case String.toInt str of + Just i -> + Frontend.Int i + |> withCorrectLocation + |> appendValueExprTo prevExpr + |> partialExpressionToParseResult newState + + Nothing -> + Error_InvalidNumericLiteral str + |> ParseResult_Err + Lexer.Newlines _ _ -> ParseResult_Skip @@ -1416,8 +1434,96 @@ closeRecord { firstEntries, lastEntry } parents = appendOperatorTo : ExpressionNestingLeaf -> Operator -> Result Error ExpressionNestingLeaf -appendOperatorTo leaf op = - Debug.todo ("implement operator" ++ Lexer.toString (op |> Lexer.Operator |> Lexer.Sigil)) +appendOperatorTo leaf appendingOp = + case leaf of + ExpressionNestingLeaf_Operator newParent -> + case newParent.rhs of + Nothing -> + Error_InvalidToken Expecting_Unknown + |> Err + + Just parentRhs -> + let + parentPrec = + Operator.getPrecedence newParent.op + + appendingPrec = + Operator.getPrecedence appendingOp + in + if parentPrec == appendingPrec then + case Operator.getAssociativity parentPrec of + Operator.ConflictsWithOthers -> + Debug.todo "" + + Operator.ConflictsWithSelf -> + Debug.todo "" + + Operator.RightToLeft -> + ExpressionNestingLeaf_Operator + { op = appendingOp + , lhs = parentRhs + , rhs = Nothing + , parent = + Just + (ExpressionNestingParent_Operator + { op = newParent.op + , lhs = newParent.lhs + , parent = newParent.parent + } + ) + } + |> Ok + + Operator.LeftToRight -> + ExpressionNestingLeaf_Operator + { op = appendingOp + , lhs = Debug.todo "add to frontend" + , rhs = Nothing + , parent = + Just + (ExpressionNestingParent_Operator + { op = newParent.op + , lhs = newParent.lhs + , parent = newParent.parent + } + ) + } + |> Ok + + else + Debug.todo "" + + ExpressionNestingLeafType_Expr locatedexpr -> + ExpressionNestingLeaf_Operator + { op = appendingOp + , lhs = locatedexpr + , parent = Nothing + , rhs = Nothing + } + |> Ok + + +appendValueExprTo : ExpressionNestingLeaf -> Frontend.LocatedExpr -> Result Error ExpressionNestingLeaf +appendValueExprTo leaf appendingExpr = + case leaf of + ExpressionNestingLeaf_Operator newParent -> + case newParent.rhs of + Nothing -> + ExpressionNestingLeaf_Operator + { op = newParent.op + , lhs = newParent.lhs + , rhs = Just appendingExpr + , parent = newParent.parent + } + |> Ok + + Just parentRhs -> + Error_ValueDoesNotTakeArgs parentRhs + |> Err + + ExpressionNestingLeafType_Expr locatedExpr -> + Error_ValueDoesNotTakeArgs locatedExpr + |> Err blockFromState : State -> Maybe (Result Error Block) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 1742d853..c2a48269 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -3,6 +3,7 @@ module ParserLexerTestCases exposing (shouldNotParseTestCases, shouldParseTestCa import Dict import Elm.AST.Frontend as Frontend import Elm.Data.Located as Located exposing (Located(..)) +import Elm.Data.Operator as Operator exposing (Operator(..)) import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete exposing (ConcreteType(..)) import Stage.Parse.Contextualize as Contextualize exposing (..) @@ -57,6 +58,147 @@ b = 78 , Located { end = { col = 1, row = 4 }, start = { col = 7, row = 3 } } (Newlines [] 0) ] } + , { name = "expression-int-add" + , source = """a = 5 + 5 + +b = 78 + 5 + 2+ 4 +""" + , contextualized = + Just + [ Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5")) + , state = + State_BlockValueDeclaration + (BlockValueDeclaration_Completish + { args = [] + , name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a") + , partialExpr = ExpressionNestingLeaf_Operator { lhs = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5), op = Add, parent = Nothing, rhs = Nothing } + } + ) + } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5")) + , state = + State_BlockValueDeclaration + (BlockValueDeclaration_Completish + { args = [] + , name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b") + , partialExpr = ExpressionNestingLeaf_Operator { lhs = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78), op = Add, parent = Nothing, rhs = Nothing } + } + ) + } + ] + , lexed = + Ok + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Whitespace 1) + , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Sigil (Operator Add)) + , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Whitespace 1) + , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token "b") + , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) + , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) + , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Whitespace 1) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil (Operator Add)) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5") + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Sigil (Operator Add)) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Whitespace 1) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (NumericLiteral "2") + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Sigil (Operator Add)) + , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Whitespace 1) + , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (NumericLiteral "4") + , Located { end = { col = 1, row = 4 }, start = { col = 18, row = 3 } } (Newlines [] 0) + ] + } + , { name = "expression-int-subtract" + , source = """a = 5 - 5 + +b = 78 + 5 + 2 - 4 + 5 +""" + , contextualized = + Just + [ Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5")) + , state = + State_BlockValueDeclaration + (BlockValueDeclaration_Completish + { args = [] + , name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a") + , partialExpr = ExpressionNestingLeaf_Operator { lhs = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5), op = Subtract, parent = Nothing, rhs = Nothing } + } + ) + } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5")) + , state = + State_BlockValueDeclaration + (BlockValueDeclaration_Completish + { args = [] + , name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b") + , partialExpr = ExpressionNestingLeaf_Operator { lhs = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78), op = Add, parent = Nothing, rhs = Nothing } + } + ) + } + ] + , lexed = + Ok + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Whitespace 1) + , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Sigil (Operator Subtract)) + , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Whitespace 1) + , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token "b") + , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) + , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) + , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Whitespace 1) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil (Operator Add)) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5") + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Sigil (Operator Add)) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Whitespace 1) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (NumericLiteral "2") + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Whitespace 1) + , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Sigil (Operator Subtract)) + , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Whitespace 1) + , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (NumericLiteral "4") + , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Sigil (Operator Add)) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Newlines [] 0) + ] + } , { name = "type-alias" , source = """type alias Model = List Int """ From 400c40e452166e79fe90006abfb1cbbb6cc59dd0 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 15:11:50 +0100 Subject: [PATCH 069/103] use operator in AST currently we only support add, cons, and append but it should be straightforward to add support for other operators. --- .../cli/non-zero-exit-error/test.test.js.md | 2 +- .../cli/non-zero-exit-error/test.test.js.snap | Bin 487 -> 493 bytes .../cli/two-source/test.test.js.md | 2 +- .../cli/two-source/test.test.js.snap | Bin 549 -> 556 bytes .../desugar/import/test.test.js.md | 2 +- .../desugar/import/test.test.js.snap | Bin 549 -> 556 bytes .../parser/add-5/test.test.js.md | 4 +- .../parser/add-5/test.test.js.snap | Bin 527 -> 533 bytes .../parser/if-then-else/test.test.js.md | 2 +- .../parser/if-then-else/test.test.js.snap | Bin 639 -> 646 bytes .../test.test.js.md | 2 +- .../test.test.js.snap | Bin 545 -> 549 bytes .../let-body-visibility/test.test.js.md | 2 +- .../let-body-visibility/test.test.js.snap | Bin 552 -> 556 bytes src/Elm/AST/Canonical.elm | 24 +++------ src/Elm/AST/Canonical/Unwrapped.elm | 4 +- src/Elm/AST/Frontend.elm | 32 +++--------- src/Elm/AST/Frontend/Unwrapped.elm | 5 +- src/Elm/AST/Typed.elm | 43 +++++----------- src/Elm/AST/Typed/Unwrapped.elm | 4 +- src/Elm/Compiler.elm | 2 +- src/Elm/Data/Operator.elm | 4 ++ src/Stage/Desugar.elm | 29 +---------- src/Stage/Emit.elm | 10 ++-- src/Stage/Emit/JavaScript.elm | 11 +++- src/Stage/Emit/JsonAST.elm | 9 +++- src/Stage/InferTypes/AssignIds.elm | 20 +++----- src/Stage/InferTypes/GenerateEquations.elm | 47 +++++++----------- src/Stage/Optimize.elm | 5 +- src/Stage/Parse/Lexer.elm | 5 ++ src/Stage/Parse/Parser.elm | 7 +-- tests/DesugarTest.elm | 7 ++- tests/EmitJsonTest.elm | 5 +- tests/EmitTest.elm | 22 ++++---- tests/InferTypesFuzz.elm | 47 ++++-------------- tests/InferTypesTest.elm | 13 ++--- tests/OptimizeTest.elm | 15 +++--- tests/ParserTest.elm | 32 +++++++----- 38 files changed, 172 insertions(+), 246 deletions(-) diff --git a/integration-tests/cli/non-zero-exit-error/test.test.js.md b/integration-tests/cli/non-zero-exit-error/test.test.js.md index b52b158a..dea88a80 100644 --- a/integration-tests/cli/non-zero-exit-error/test.test.js.md +++ b/integration-tests/cli/non-zero-exit-error/test.test.js.md @@ -23,5 +23,5 @@ Generated by [AVA](https://avajs.dev). `---------------------------␊ -- STARTING THE COMPILER --␊ ---------------------------␊ - Main.main: Value { expression = Plus (Int 1) (Var { name = "y", qualifiedness = PossiblyQualified Nothing }), typeAnnotation = Nothing }␊ + Main.main: Value { expression = Operator Add (Int 1) (Var { name = "y", qualifiedness = PossiblyQualified Nothing }), typeAnnotation = Nothing }␊ ` diff --git a/integration-tests/cli/non-zero-exit-error/test.test.js.snap b/integration-tests/cli/non-zero-exit-error/test.test.js.snap index be2cc454b5022d02769cb716cf51318659c8cb84..c1a8e0758828f8282d8de506feff4269eae90204 100644 GIT binary patch literal 493 zcmV>(f&QAXOGoi}fGXWo`k6y1ovji!A4>Zy3}<zm=h^!>YSbFM#j$VJ?s(^k0eW>X(;M7QGGOvr?* z1RW$2oIT5q2v;e_mwBxu-qX@>!6R8gCM>S`PLTY jIM#m2)dF5`Zh@~28z|I?_}|a`O}2jlEna`UtO5W4Vgl;x literal 487 zcmVs;;8)-6 zw+BzQI>Qe?ii`B;=e2SxY|+9A?tFbS+CO>!ZnHdBAA95?Y|%-_=eya)hik#D@HXWl zVlr|Dk$}->$su7fcK&5uCkl6!C>f^(n8aQ>g-`{Jv9CB+=deo(Qq=6s8H=U0rP)pr zpPLi8h?QO>oAKaYJV;b&nP4v{=1Sv~T1z!bs+}i@^x?9A5rlJx6Jw|~akm>?y&Q+# zBd45V*37^Rq_U`)VIG=mCEC7Rqm`HVxy)jWNKMhG z3QUwrTR#vx#GazYT|l2RV~5@UX7@d~rvAtIPL_|44v>%1f6ZJ|fBQ|s9ov`^UQxVs zkC&Pn!<58*On7C`A4`kDI{H(hoj?*n9o1`k8+cX`&gP63(uH`vGQRQV(H|T~$}X8) d;Pv_jY*W%5>E=W1@AQAk?l0`TBqO8(0035!?K=Pf diff --git a/integration-tests/cli/two-source/test.test.js.md b/integration-tests/cli/two-source/test.test.js.md index 8cde26c6..ed8074cd 100644 --- a/integration-tests/cli/two-source/test.test.js.md +++ b/integration-tests/cli/two-source/test.test.js.md @@ -18,7 +18,7 @@ Generated by [AVA](https://avajs.dev). `---------------------------␊ -- STARTING THE COMPILER --␊ ---------------------------␊ - Main.main: Value { expression = Plus (Int 1) (Var { name = "x", qualifiedness = PossiblyQualified (Just "Lib") }), typeAnnotation = Nothing }␊ + Main.main: Value { expression = Operator Add (Int 1) (Var { name = "x", qualifiedness = PossiblyQualified (Just "Lib") }), typeAnnotation = Nothing }␊ Lib.x: Value { expression = Int 4, typeAnnotation = Nothing }␊ Compilation finished, writing output to `out.js`.␊ ---------------------------␊ diff --git a/integration-tests/cli/two-source/test.test.js.snap b/integration-tests/cli/two-source/test.test.js.snap index 58d3ec87bd88bbb4baae262cba578b0ffb9d84f7..6fa6a7d08ee266a2b3b4ea4c29893ab3503de1e7 100644 GIT binary patch literal 556 zcmV+{0@M9LRzVggGJ*wE~5Lvyi3B-Etc(lj*vD1!J$2>u2B0B;5H;H?L5zTH(YhZG!mJ2T(=zPI0dBMig1ZhY|$*!0OGzV+#S zWjZ}}O(R(r#-MXb-o;qT6Nu|G$&%<$Y|g$JLS7h*_EMY0XwD8 zml1TS)--~UMtBQ|NaVr?6%fu5CrVMRoczB=a^FmQ{>s}n?6s?{wzsnZ?admjHygX& zcC7_zZoV$oe*Llp?q*u|k)hJp7A;wG}H3g>BX?6ydB`0(}zFst{5Wo&9S^>LC*YILjl+ z8P9Q)c&J>d&R#6T`%Ex3q<#rT5z|Rt#yX5OXbFdSbdJ=abLE6^vimJB8*CHmdoYum uuj@&H{bDDJV{}(p`vW8cUrYv$pjC#Yj8R;hd2G}DPxWsU!zi6e0{{T+bP5pw literal 549 zcmV+=0^0pSRzVgl=ku)*wZLvyi3q|~I{(lj*92T#82Wtwqkw41HcOjI;Xd zhVx@`_Ul>r;YIW6Q!_(9VO%n5_K-qf z#?Yl&(-iZAW2+1g62e)Z z(LkUi(qL_~u2q85QW^9~MAw9nn&|wE9jS**4B)hgBzHWglC*~E zh3fpLa=gz3Q$re*VH7i+=4GOzM1z)ah+Fqa9l94fgO2XE{M^tc)c0T}H(%G20{g{I n7ROj!b@dOB8oihrji6nDn>nMjI`he<_n+$DP=0=YK?48)GL;R} diff --git a/integration-tests/desugar/import/test.test.js.md b/integration-tests/desugar/import/test.test.js.md index 1f2e6f71..b9efdaab 100644 --- a/integration-tests/desugar/import/test.test.js.md +++ b/integration-tests/desugar/import/test.test.js.md @@ -18,7 +18,7 @@ Generated by [AVA](https://avajs.dev). `---------------------------␊ -- STARTING THE COMPILER --␊ ---------------------------␊ - Main.main: Value { expression = Plus (Int 1) (Var { name = "x", qualifiedness = PossiblyQualified (Just "Lib") }), typeAnnotation = Nothing }␊ + Main.main: Value { expression = Operator Add (Int 1) (Var { name = "x", qualifiedness = PossiblyQualified (Just "Lib") }), typeAnnotation = Nothing }␊ Lib.x: Value { expression = Int 4, typeAnnotation = Nothing }␊ Compilation finished, writing output to `out.js`.␊ ---------------------------␊ diff --git a/integration-tests/desugar/import/test.test.js.snap b/integration-tests/desugar/import/test.test.js.snap index 58d3ec87bd88bbb4baae262cba578b0ffb9d84f7..6fa6a7d08ee266a2b3b4ea4c29893ab3503de1e7 100644 GIT binary patch literal 556 zcmV+{0@M9LRzVggGJ*wE~5Lvyi3B-Etc(lj*vD1!J$2>u2B0B;5H;H?L5zTH(YhZG!mJ2T(=zPI0dBMig1ZhY|$*!0OGzV+#S zWjZ}}O(R(r#-MXb-o;qT6Nu|G$&%<$Y|g$JLS7h*_EMY0XwD8 zml1TS)--~UMtBQ|NaVr?6%fu5CrVMRoczB=a^FmQ{>s}n?6s?{wzsnZ?admjHygX& zcC7_zZoV$oe*Llp?q*u|k)hJp7A;wG}H3g>BX?6ydB`0(}zFst{5Wo&9S^>LC*YILjl+ z8P9Q)c&J>d&R#6T`%Ex3q<#rT5z|Rt#yX5OXbFdSbdJ=abLE6^vimJB8*CHmdoYum uuj@&H{bDDJV{}(p`vW8cUrYv$pjC#Yj8R;hd2G}DPxWsU!zi6e0{{T+bP5pw literal 549 zcmV+=0^0pSRzVgl=ku)*wZLvyi3q|~I{(lj*92T#82Wtwqkw41HcOjI;Xd zhVx@`_Ul>r;YIW6Q!_(9VO%n5_K-qf z#?Yl&(-iZAW2+1g62e)Z z(LkUi(qL_~u2q85QW^9~MAw9nn&|wE9jS**4B)hgBzHWglC*~E zh3fpLa=gz3Q$re*VH7i+=4GOzM1z)ah+Fqa9l94fgO2XE{M^tc)c0T}H(%G20{g{I n7ROj!b@dOB8oihrji6nDn>nMjI`he<_n+$DP=0=YK?48)GL;R} diff --git a/integration-tests/parser/add-5/test.test.js.md b/integration-tests/parser/add-5/test.test.js.md index f6b3a803..a5a61343 100644 --- a/integration-tests/parser/add-5/test.test.js.md +++ b/integration-tests/parser/add-5/test.test.js.md @@ -18,8 +18,8 @@ Generated by [AVA](https://avajs.dev). `---------------------------␊ -- STARTING THE COMPILER --␊ ---------------------------␊ - Main.main: Value { expression = Plus (Int 7) (Int 6), typeAnnotation = Nothing }␊ - Main.f: Value { expression = Lambda { arguments = ["x"], body = Plus (Int 5) (Argument "x") }, typeAnnotation = Nothing }␊ + Main.main: Value { expression = Operator Add (Int 7) (Int 6), typeAnnotation = Nothing }␊ + Main.f: Value { expression = Lambda { arguments = ["x"], body = Operator Add (Int 5) (Argument "x") }, typeAnnotation = Nothing }␊ Compilation finished, writing output to `out.js`.␊ ---------------------------␊ -- WRITING TO FS ----------␊ diff --git a/integration-tests/parser/add-5/test.test.js.snap b/integration-tests/parser/add-5/test.test.js.snap index cb3abe6366f3784317f89eddd7e08bc4e150ae6a..f8dd1389eda0f89b59d031cdd7fcfb5209a242dd 100644 GIT binary patch literal 533 zcmV+w0_y!iRzVGj51)pQzJ0nq z9`E@MN!FZ=mn&Q4+|q}i?5z6x%S=>uQuL#Zo8OODYuoSM&PPLilBZ`*ioVDZa$0*| zcYlpe|Gbu;-!!hia#Hlf#wBtko$SnzYt9WGN>?b?CU7N~xZ~HUP@X+c@J7p8Mk3@4 zgo20FO^}*#4{ACL^$@VnfwDc(u?eA%7?}m%PezAS^*kN-{CTf*-z)h#LLtR-4qY8X zn|8h2=*5aj;fx zLRy>Nm;SS~p9R>Y;ef*k_!MJu_&7|aC<;a(xjcMCi^UsRV*6iTii|^QrEC2Xlxdk}7P(k)^ z8Qv92m_BDk7{&sVx*lLOKtK&UcI)k$9q&S;tifB&AoI5YwGEi4P4DYyWe^fKZY4Hb Xg{AW1#LGI@&*l6D`ehRl90LFVC$0oB literal 527 zcmV+q0`UDoRzVb)Qyy!GJC*ikq zki}-_Wq%fSTY(+I6AELXhdQRlFeTwGZ1KdvQYaB_m2!WxR0cfKv?irOf;nwd;gHDz z9Oni5GpcP6(T#{jNjyjdm1r#Zuy|N}T!yZSj;0#kunlW}d0;suI6k*?KBye;Gs(=5 zMr9bq4AZzuP$vkeVBa47CuZM2R~RekZad8NY(Zlired@6dP*9ERE2A)toDVK>Yb@c Rx|jdU`2)|Awf77I002+z0Ez$r diff --git a/integration-tests/parser/if-then-else/test.test.js.md b/integration-tests/parser/if-then-else/test.test.js.md index 19114c25..1fe4e591 100644 --- a/integration-tests/parser/if-then-else/test.test.js.md +++ b/integration-tests/parser/if-then-else/test.test.js.md @@ -18,7 +18,7 @@ Generated by [AVA](https://avajs.dev). `---------------------------␊ -- STARTING THE COMPILER --␊ ---------------------------␊ - Main.main: Value { expression = Plus (Call { argument = Bool True, fn = Var { name = "f", qualifiedness = PossiblyQualified Nothing } }) (Call { argument = Bool False, fn = Var { name = "f", qualifiedness = PossiblyQualified Nothing } }), typeAnnotation = Nothing }␊ + Main.main: Value { expression = Operator Add (Call { argument = Bool True, fn = Var { name = "f", qualifiedness = PossiblyQualified Nothing } }) (Call { argument = Bool False, fn = Var { name = "f", qualifiedness = PossiblyQualified Nothing } }), typeAnnotation = Nothing }␊ Main.f: Value { expression = Lambda { arguments = ["x"], body = If { else_ = Int 2, test = Argument "x", then_ = Int 18 } }, typeAnnotation = Nothing }␊ Compilation finished, writing output to `out.js`.␊ ---------------------------␊ diff --git a/integration-tests/parser/if-then-else/test.test.js.snap b/integration-tests/parser/if-then-else/test.test.js.snap index 139064a91ba0df5b20bf52830bb158c9deb842da..9d2628238ac81e3c4f2d58c736bb2c0dd091f073 100644 GIT binary patch literal 646 zcmV;10(t#GRzVr54ON>byX_}gbv{1!Pva`v^?9945X%b^ko&tgw zZ-RIf6hZtEg1$@xQwf8@rlfv&W3;s$hLO^aW2XnTQDxhE>Z4TOjx*qey zF^@f=;K~3RR4E#OPXn|(B6PTLAoK|5h?6j+Dzq0Tg~Wfvt=Z3_Wx-A@SFM${)}gjh zfPAIAUD_;EA@a?Ri+c9(m4!Ot9SQ@WJwKpf$fST(sGvroP;$<3Ael#f$RI(h<58i| ze_KipwV*>&;A(!I1V|9Xqi7`DL<$~v2xl&%j=-b{ZcEJF;Qf1J9JZutGtq)0I5KC} zC=wq2uOcZ>eV^upkcy~Lpa0yW6LDu8$0qR_4w;ari|r?Ri3cfYNT-ih$<;w9_MtYg zfn_X5L)}Pj+!F?*^z4W+Cv#m3J5|?c4oA4l1Pj~LNkKPYO8aF;`5gsH!U2BTkHQ1{ z)O*Ky*{zmF<5Gd*4ovxG$2FzER`eNNaZz3}*)w7F79@MHrklvZvT5F&Wa-(8h@+UK g!dWp*xC&#y)fa2(sHy*M{|qbr1=DH(ly?LG07D`-K>z>% literal 639 zcmV-_0)YKNRzV~S|5uD00000000BE zQ_X7=K@{KZ2SP96)zdS0*v0IoA09MPORY&8>6dLt3svkSJDZHm&a6ALZDQ@oQ$X#~4P)Vb(Mwsx?9*R3! zl2Ob!4S)%_TdF}M1L{LraxM=+w)8(rXXX@ zBKDL*C=;ktt!V-=P0)&nFmw@siU{Y36Q!tD{?uS2V<%(Y=x56FV7t1wRjsTqLv^JD zOB-vOmDSP~WWLe7Oml>^DI5W9#|c%6Ndfb)$x{W+68422k~GtZ3XS+3DLGV= zl;$BcaW#@)fFKb?BNyiK@FXRig^UIQlbK8sbJlt1ejkT*sas4m;TVqHku}PMtAAA_ z54sc6MIodnx~K22yLS@dh+|kKQ9U37?U`bGxpwYh9_ljapj8PC37dUn3=}Yn<)|`3 z7W(`{&*_&dJVJ zr8g!UP~L_i-)LS#3Y22b=xT`VIZoS!`P<;MVZn$f!mR7w8jLbCl?C=Vj>cJWUAP8) ZAT$^28rIPNw)Y<^{Q;o$B=Bzp005MAF8lxh diff --git a/integration-tests/parser/indentation/expr-with-indentation-within-let/test.test.js.md b/integration-tests/parser/indentation/expr-with-indentation-within-let/test.test.js.md index 0654162f..f6a3f3d6 100644 --- a/integration-tests/parser/indentation/expr-with-indentation-within-let/test.test.js.md +++ b/integration-tests/parser/indentation/expr-with-indentation-within-let/test.test.js.md @@ -18,7 +18,7 @@ Generated by [AVA](https://avajs.dev). `---------------------------␊ -- STARTING THE COMPILER --␊ ---------------------------␊ - Main.main: Value { expression = Let { bindings = [{ body = Plus (Int 1) (Int 2), name = "x" }], body = Argument "x" }, typeAnnotation = Nothing }␊ + Main.main: Value { expression = Let { bindings = [{ body = Operator Add (Int 1) (Int 2), name = "x" }], body = Argument "x" }, typeAnnotation = Nothing }␊ Compilation finished, writing output to `out.js`.␊ ---------------------------␊ -- WRITING TO FS ----------␊ diff --git a/integration-tests/parser/indentation/expr-with-indentation-within-let/test.test.js.snap b/integration-tests/parser/indentation/expr-with-indentation-within-let/test.test.js.snap index 4be1a40a7eea4f9b8ad212117626aee765c08071..8a6f2d895ecaebe4312a89a5733a03e7ddf21b92 100644 GIT binary patch delta 527 zcmV+q0`UEz1f>KbK~_N^Q*L2!b7*gLAa*he0syuq5G#UywI_e9Nh-!vt}u}zB7e|I zs7V`X8c9Q2P@&W8G#S~MS!QON)R>c}fZ)ZO;90N;#XmyuFHr9V@!+ioZ@%3{Fo$?> z;LUsQdq3vAZ-ix8m#uHDeKvdkIC}8q0EtfXXqKqCF@Go*G-VXY5ttzb5+1WYDg#4f zV!aXsY3qoHfiKk{SoSM-{YoHX!#I0J;Ycbtq{dJMF;(bsBGPgZg61TO5Pv6HQ=|Rj z--8rRZEx`@dLHcb>fK&zdjoo#4Os8AAGWp{UC3gK>$06WUMsLmqJ+W(=r~qXYbFJ( z!WK0M9WoIzG0+G+LQjS#XmxOWVsM*!7=qIh1}bi@Z@FaOp7`1Iex?h(?c4TVWgNz<1#UEV!%i^K+}J!5Bz`b ziTvz!TRA-)XzsvVY;j#*3T+@|>1N6jPUtv}3#)4|$wOm=sx?s5Buc=zHgz4>t<8O% Redj;B{04*z;H4h}003pV_)Y)- delta 523 zcmV+m0`&c*1fc{XK~_N^Q*L2!b7*gLAa*he0stIu1SDd>i4MT=`*(?VfS{2gB7aaN z)TE6xO-VyrP@&W8G#Qy6%g$_*8gud#5WIL3Jb6$QLHr{G{{r=15D(sZ@aEfH1apW7 z2j0B*zVE#^Gv7$dvd&xITKjDF_&&e;<>U3)>^QKkbUA2G*Y~Q0+wZ=IXN{kqm!hhj zp&!t$e0{Rf+<*OYIU1?=C30qGXn$C+tkdS(w)bOl`s=y)^rCa|nVq3;(9T&GvdQ+6 zb;-U=x$v0u(19mF$Niv9nDjB9tDCGT5iw3fU=r>$c0s6+`p{IIs}YzX1ri>!J~{(K zV~ej zunL>hAauxN$mBpHa1S#To?x`i6AeyF8mPFrzvh-f5MyrJVbF09^yNluLss@5Q;CW$4CYg5;8-P+uj**E@k N%5Poxniv-Y005#=2LS*8 diff --git a/integration-tests/typecheck/let-body-visibility/test.test.js.md b/integration-tests/typecheck/let-body-visibility/test.test.js.md index 646ee93a..e7f460c1 100644 --- a/integration-tests/typecheck/let-body-visibility/test.test.js.md +++ b/integration-tests/typecheck/let-body-visibility/test.test.js.md @@ -18,7 +18,7 @@ Generated by [AVA](https://avajs.dev). `---------------------------␊ -- STARTING THE COMPILER --␊ ---------------------------␊ - Main.main: Value { expression = Let { bindings = [{ body = Int 2, name = "x" }], body = Plus (Int 1) (Argument "x") }, typeAnnotation = Nothing }␊ + Main.main: Value { expression = Let { bindings = [{ body = Int 2, name = "x" }], body = Operator Add (Int 1) (Argument "x") }, typeAnnotation = Nothing }␊ Compilation finished, writing output to `out.js`.␊ ---------------------------␊ -- WRITING TO FS ----------␊ diff --git a/integration-tests/typecheck/let-body-visibility/test.test.js.snap b/integration-tests/typecheck/let-body-visibility/test.test.js.snap index fa70cd0ce3135cf47622e25003a2b46217c311dd..4b7421c64f268ac0871da0a65b4938d476b8304a 100644 GIT binary patch literal 556 zcmV+{0@M9LRzVggFg>|%DeX}#DGCDf!{X&OmGTTr3X>@*qKnOSCLo79+-r-0za zo8Vbc1oiA$@E54}f_U)OgE!x95X>Q79C$nPecyX;=6x$H%Q|m;3-{Ud@%{MDmk-yc z)8oLlvgKer-Pl_#+fCoi<;$ zydUG!U(flc7wwDB?413Gan8Dscea_d^QrZEx`^dLHa_>z!`6y#d|L2CTPRcf+kl z2Xbw3T|P6%&l>EKIHfQKI!YAPnn?jQ*rEohLnb07`WlIQh-7qvr%)JJDT5%KA}Wna zFnLh^BeroiVsO-Y6oHeaR$OrEs-JR-0JB|~l);=Nv@V1+#LVv7mS%uA!K66zea0U# z!SsMeWf&@EGF_%7NevhY2YB=!>I46ubD}?cop5GP8=5;Xr!B7QNudp7E?v!B!WTM@ u<3jBwjAzmasg)`yYEmV@slYWDxz&m5xNdds2imp&>h&9PcuE;70{{S#dJWDvwraE<#IF-?+X5fnXxB1!#JiyZ4XQY#6?|%p%_5*3H;!ccJ-prS1OWgo|m=`ecp3L-1C;*(k-{-iAYgK9}ygj z7)L}Y5+fq9M$G4FIS(M2ABLLur6fwa`M)ocdu=-NN8WL;+o`rYjqMF|HfvaKHFp|Y zwKg(seqHuvrl&RR`C&pZ0vSdzk&+6I3bu&S)Dh(Y=5N-&6jWaw_{I zC}I#(mFgl Unwrapped.Argument name - Plus e1 e2 -> - Unwrapped.Plus - (f e1) - (f e2) - - Cons e1 e2 -> - Unwrapped.Cons + Operator op e1 e2 -> + Unwrapped.Operator + op (f e1) (f e2) @@ -299,13 +295,9 @@ fromUnwrapped expr = Unwrapped.Argument name -> Argument name - Unwrapped.Plus e1 e2 -> - Plus - (f e1) - (f e2) - - Unwrapped.Cons e1 e2 -> - Cons + Unwrapped.Operator op e1 e2 -> + Operator + op (f e1) (f e2) diff --git a/src/Elm/AST/Canonical/Unwrapped.elm b/src/Elm/AST/Canonical/Unwrapped.elm index 9bc884e9..be46c091 100644 --- a/src/Elm/AST/Canonical/Unwrapped.elm +++ b/src/Elm/AST/Canonical/Unwrapped.elm @@ -18,6 +18,7 @@ and from it using [`Elm.AST.Canonical.fromUnwrapped`](Elm.AST.Canonical#fromUnwr import Dict exposing (Dict) import Elm.Data.Binding exposing (Binding) import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Operator exposing (Operator) import Elm.Data.VarName exposing (VarName) @@ -30,8 +31,7 @@ type Expr | Bool Bool | Var { module_ : ModuleName, name : VarName } | Argument VarName - | Plus Expr Expr - | Cons Expr Expr + | Operator Operator Expr Expr | Lambda { argument : VarName, body : Expr } | Call { fn : Expr, argument : Expr } | If { test : Expr, then_ : Expr, else_ : Expr } diff --git a/src/Elm/AST/Frontend.elm b/src/Elm/AST/Frontend.elm index f433361d..5df1631e 100644 --- a/src/Elm/AST/Frontend.elm +++ b/src/Elm/AST/Frontend.elm @@ -19,6 +19,7 @@ import Elm.Data.Binding as Binding exposing (Binding) import Elm.Data.Located as Located exposing (Located) import Elm.Data.Module exposing (Module) import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Operator exposing (Operator) import Elm.Data.Qualifiedness exposing (PossiblyQualified) import Elm.Data.TypeAnnotation exposing (TypeAnnotation) import Elm.Data.VarName exposing (VarName) @@ -60,9 +61,7 @@ type Expr | Var { qualifiedness : PossiblyQualified, name : VarName } | -- Both lambda arguments and let..in bindings Argument VarName - | Plus LocatedExpr LocatedExpr - | Cons LocatedExpr LocatedExpr - | ListConcat LocatedExpr LocatedExpr + | Operator Operator LocatedExpr LocatedExpr | Lambda { arguments : List VarName, body : LocatedExpr } | Call { fn : LocatedExpr, argument : LocatedExpr } | If { test : LocatedExpr, then_ : LocatedExpr, else_ : LocatedExpr } @@ -131,19 +130,12 @@ recurse f expr = Argument _ -> expr - Plus e1 e2 -> - Plus + Operator op e1 e2 -> + Operator + op (f_ e1) (f_ e2) - Cons e1 e2 -> - Cons - (f_ e1) - (f_ e2) - - ListConcat e1 e2 -> - ListConcat (f_ e1) (f_ e2) - Lambda ({ body } as lambda_) -> Lambda { lambda_ | body = f_ body } @@ -239,20 +231,12 @@ unwrap expr = Argument name -> Unwrapped.Argument name - Plus e1 e2 -> - Unwrapped.Plus + Operator op e1 e2 -> + Unwrapped.Operator + op (unwrap e1) (unwrap e2) - Cons e1 e2 -> - Unwrapped.Cons - (unwrap e1) - (unwrap e2) - - ListConcat e1 e2 -> - Unwrapped.ListConcat - (unwrap e1) - (unwrap e2) Lambda { arguments, body } -> Unwrapped.Lambda diff --git a/src/Elm/AST/Frontend/Unwrapped.elm b/src/Elm/AST/Frontend/Unwrapped.elm index 69e59632..448a18fb 100644 --- a/src/Elm/AST/Frontend/Unwrapped.elm +++ b/src/Elm/AST/Frontend/Unwrapped.elm @@ -14,6 +14,7 @@ Convert to it using the [`Elm.AST.Frontend.unwrap`](Elm.AST.Frontend#unwrap). -} import Elm.Data.Binding exposing (Binding) +import Elm.Data.Operator exposing (Operator) import Elm.Data.Qualifiedness exposing (PossiblyQualified) import Elm.Data.VarName exposing (VarName) @@ -28,9 +29,7 @@ type Expr | Bool Bool | Var { qualifiedness : PossiblyQualified, name : VarName } | Argument VarName - | Plus Expr Expr - | Cons Expr Expr - | ListConcat Expr Expr + | Operator Operator Expr Expr | Lambda { arguments : List VarName, body : Expr } | Call { fn : Expr, argument : Expr } | If { test : Expr, then_ : Expr, else_ : Expr } diff --git a/src/Elm/AST/Typed.elm b/src/Elm/AST/Typed.elm index 9722b619..32ec1828 100644 --- a/src/Elm/AST/Typed.elm +++ b/src/Elm/AST/Typed.elm @@ -23,6 +23,7 @@ import Elm.Data.Binding as Binding exposing (Binding) import Elm.Data.Located as Located exposing (Located) import Elm.Data.Module exposing (Module) import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Operator exposing (Operator) import Elm.Data.Qualifiedness exposing (Qualified) import Elm.Data.Type as Type exposing (Type, TypeOrId(..)) import Elm.Data.VarName exposing (VarName) @@ -72,8 +73,7 @@ type Expr_ | Bool Bool | Var { module_ : ModuleName, name : VarName } | Argument VarName - | Plus LocatedExpr LocatedExpr - | Cons LocatedExpr LocatedExpr + | Operator Operator LocatedExpr LocatedExpr | Lambda { argument : VarName, body : LocatedExpr } | Call { fn : LocatedExpr, argument : LocatedExpr } | If { test : LocatedExpr, then_ : LocatedExpr, else_ : LocatedExpr } @@ -146,13 +146,9 @@ recurse fn locatedExpr = Argument _ -> expr - Plus e1 e2 -> - Plus - (fn e1) - (fn e2) - - Cons e1 e2 -> - Cons + Operator op e1 e2 -> + Operator + op (fn e1) (fn e2) @@ -266,13 +262,8 @@ recursiveChildren fn locatedExpr = Argument _ -> [] - Plus left right -> - fn left - ++ fn right - - Cons left right -> - fn left - ++ fn right + Operator _ left right -> + fn left ++ fn right Lambda { body } -> fn body @@ -380,13 +371,9 @@ unwrap expr = Argument name -> Unwrapped.Argument name - Plus e1 e2 -> - Unwrapped.Plus - (f e1) - (f e2) - - Cons e1 e2 -> - Unwrapped.Cons + Operator op e1 e2 -> + Unwrapped.Operator + op (f e1) (f e2) @@ -545,13 +532,9 @@ dropTypes locatedExpr = Argument var -> Canonical.Argument var - Plus e1 e2 -> - Canonical.Plus - (f e1) - (f e2) - - Cons e1 e2 -> - Canonical.Cons + Operator op e1 e2 -> + Canonical.Operator + op (f e1) (f e2) diff --git a/src/Elm/AST/Typed/Unwrapped.elm b/src/Elm/AST/Typed/Unwrapped.elm index 651be0fe..4e54d5cd 100644 --- a/src/Elm/AST/Typed/Unwrapped.elm +++ b/src/Elm/AST/Typed/Unwrapped.elm @@ -16,6 +16,7 @@ Convert to it using the [`Elm.AST.Typed.unwrap`](Elm.AST.Typed#unwrap). import Dict exposing (Dict) import Elm.Data.Binding exposing (Binding) import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Operator exposing (Operator) import Elm.Data.Qualifiedness exposing (Qualified) import Elm.Data.Type exposing (TypeOrId) import Elm.Data.VarName exposing (VarName) @@ -37,8 +38,7 @@ type Expr_ | Bool Bool | Var { module_ : ModuleName, name : VarName } | Argument VarName - | Plus Expr Expr - | Cons Expr Expr + | Operator Operator Expr Expr | Lambda { argument : VarName, body : Expr } | Call { fn : Expr, argument : Expr } | If { test : Expr, then_ : Expr, else_ : Expr } diff --git a/src/Elm/Compiler.elm b/src/Elm/Compiler.elm index 55c592c6..2db92ba5 100644 --- a/src/Elm/Compiler.elm +++ b/src/Elm/Compiler.elm @@ -87,7 +87,7 @@ Eg. the `plus` optimization is (conceptually): optimizePlus : Expr -> Maybe Expr optimizePlus expr = case expr of - Plus (Int a) (Int b) -> + Operator Operator.Add (Int a) (Int b) -> Just (Int (a + b)) _ -> diff --git a/src/Elm/Data/Operator.elm b/src/Elm/Data/Operator.elm index b54b948b..41e7afee 100644 --- a/src/Elm/Data/Operator.elm +++ b/src/Elm/Data/Operator.elm @@ -15,6 +15,7 @@ type Operator | LessThan | LessThanEquals | Append + | Cons {-| Operator precedence. @@ -84,6 +85,9 @@ getPrecedence op = Append -> Concatenation + Cons -> + Concatenation + getAssociativity : OperatorPrecedence -> OperatorAssociativity getAssociativity prec = diff --git a/src/Stage/Desugar.elm b/src/Stage/Desugar.elm index 50da640a..2530135f 100644 --- a/src/Stage/Desugar.elm +++ b/src/Stage/Desugar.elm @@ -116,36 +116,11 @@ desugarExpr modules thisModule locatedExpr = Frontend.Argument varName -> return <| Canonical.Argument varName - Frontend.Plus e1 e2 -> - map2 Canonical.Plus + Frontend.Operator op e1 e2 -> + map2 (Canonical.Operator op) (f e1) (f e2) - Frontend.Cons e1 e2 -> - map2 Canonical.Cons - (f e1) - (f e2) - - Frontend.ListConcat e1 e2 -> - let - region = - Located.getRegion locatedExpr - - listConcatVar = - Frontend.Var - { qualifiedness = PossiblyQualified <| Just "List" - , name = "append" - } - |> Located.located region - - firstCall = - Frontend.Call { fn = listConcatVar, argument = e1 } |> Located.located region - - expr = - Frontend.Call { fn = firstCall, argument = e2 } |> Located.located region - in - f expr - Frontend.Lambda { arguments, body } -> f body |> Result.map (curryLambda locatedExpr arguments) diff --git a/src/Stage/Emit.elm b/src/Stage/Emit.elm index 1b4d727d..f0208599 100644 --- a/src/Stage/Emit.elm +++ b/src/Stage/Emit.elm @@ -32,7 +32,7 @@ import AssocList import AssocSet import Dict exposing (Dict) import Dict.Extra as Dict -import Elm.AST.Typed as Typed exposing (Expr_(..)) +import Elm.AST.Typed as Typed exposing (Expr_(..), Pattern_(..)) import Elm.Compiler.Error exposing ( DesugarError(..) @@ -43,6 +43,7 @@ import Elm.Data.Declaration exposing (Declaration, DeclarationBody(..)) import Elm.Data.Exposing as Exposing exposing (ExposedItem(..), Exposing(..)) import Elm.Data.Module exposing (Module) import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Operator as Operator import Elm.Data.Project exposing (Project) import Elm.Data.Qualifiedness exposing (Qualified(..)) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) @@ -489,12 +490,7 @@ findDependenciesOfExpr modules locatedExpr = Argument _ -> Ok [] - Plus e1 e2 -> - Result.map2 (++) - (f e1) - (f e2) - - Cons e1 e2 -> + Operator _ e1 e2 -> Result.map2 (++) (f e1) (f e2) diff --git a/src/Stage/Emit/JavaScript.elm b/src/Stage/Emit/JavaScript.elm index 92ed2b4e..a1a90fbf 100644 --- a/src/Stage/Emit/JavaScript.elm +++ b/src/Stage/Emit/JavaScript.elm @@ -23,6 +23,7 @@ import Elm.Compiler.Error exposing (Error(..)) import Elm.Data.Declaration exposing (Declaration, DeclarationBody(..)) import Elm.Data.FileContents exposing (FileContents) import Elm.Data.FilePath exposing (FilePath) +import Elm.Data.Operator as Operator exposing (Operator) import Elm.Data.Project exposing (Project) import Elm.Data.Qualifiedness exposing (Qualified) import Stage.Emit.Common exposing (mangleQualifiedVar, mangleVarName, prepareProjectFields) @@ -75,12 +76,18 @@ emitExpr located = Argument argument -> mangleVarName argument - Plus e1 e2 -> + Operator Operator.Add e1 e2 -> "(" ++ emitExpr e1 ++ " + " ++ emitExpr e2 ++ ")" - Cons e1 e2 -> + Operator Operator.Cons e1 e2 -> "[" ++ emitExpr e1 ++ "].concat(" ++ emitExpr e2 ++ ")" + Operator Operator.Append e1 e2 -> + emitExpr e1 ++ ".concat(" ++ emitExpr e2 ++ ")" + + Operator _ _ _ -> + Debug.todo "emit js for other operators" + Lambda { argument, body } -> -- TODO are these parentheses needed? "((" ++ mangleVarName argument ++ ") => " ++ emitExpr body ++ ")" diff --git a/src/Stage/Emit/JsonAST.elm b/src/Stage/Emit/JsonAST.elm index d0e68683..88f016b2 100644 --- a/src/Stage/Emit/JsonAST.elm +++ b/src/Stage/Emit/JsonAST.elm @@ -25,6 +25,7 @@ import Elm.Compiler.Error exposing (Error(..)) import Elm.Data.Declaration exposing (Declaration, DeclarationBody(..)) import Elm.Data.FileContents exposing (FileContents) import Elm.Data.FilePath exposing (FilePath) +import Elm.Data.Operator as Operator exposing (Operator) import Elm.Data.Project exposing (Project) import Elm.Data.Qualifiedness exposing (Qualified) import Json.Encode as Encode exposing (Value) @@ -80,18 +81,22 @@ emitExpr located = Argument argument -> encode "arg" [ ( "name", Encode.string argument ) ] - Plus e1 e2 -> + -- TODO(harry): Change this to `{ 'op': '+', lhs: { ... }, rhs: { ... } }` + Operator Operator.Add e1 e2 -> encode "plus" [ ( "e1", emitExpr e1 ) , ( "e2", emitExpr e2 ) ] - Cons e1 e2 -> + Operator Operator.Cons e1 e2 -> encode "cons" [ ( "e1", emitExpr e1 ) , ( "e2", emitExpr e2 ) ] + Operator _ e1 e2 -> + Debug.todo "encode other operators into json" + Lambda { argument, body } -> encode "lambda" [ ( "arg", Encode.string argument ) diff --git a/src/Stage/InferTypes/AssignIds.elm b/src/Stage/InferTypes/AssignIds.elm index 8d50508f..f404b4a4 100644 --- a/src/Stage/InferTypes/AssignIds.elm +++ b/src/Stage/InferTypes/AssignIds.elm @@ -11,7 +11,8 @@ Input (forgive the nonsense AST): Canonical.If { test = - Canonical.Plus + Canonical.Operator + Operator.Add (Canonical.Int 1) (Canonical.Int 2) , then_ = Canonical.Unit @@ -22,7 +23,8 @@ Output: ( Typed.If { test = - ( Typed.Plus + ( Typed.Operator + Operator.Add ( Typed.Int 1 , Var 0 ) @@ -101,7 +103,7 @@ assignIdsHelp currentId located = Canonical.Var name -> assignId currentId (Typed.Var name) - Canonical.Plus e1 e2 -> + Canonical.Operator op e1 e2 -> let ( e1_, id1 ) = f currentId e1 @@ -109,17 +111,7 @@ assignIdsHelp currentId located = ( e2_, id2 ) = f id1 e2 in - assignId id2 (Typed.Plus e1_ e2_) - - Canonical.Cons e1 e2 -> - let - ( e1_, id1 ) = - f currentId e1 - - ( e2_, id2 ) = - f id1 e2 - in - assignId id2 (Typed.Cons e1_ e2_) + assignId id2 (Typed.Operator op e1_ e2_) Canonical.Lambda { argument, body } -> let diff --git a/src/Stage/InferTypes/GenerateEquations.elm b/src/Stage/InferTypes/GenerateEquations.elm index 42c53e41..15889abf 100644 --- a/src/Stage/InferTypes/GenerateEquations.elm +++ b/src/Stage/InferTypes/GenerateEquations.elm @@ -32,6 +32,7 @@ subexpression. import Dict import Elm.AST.Typed as Typed import Elm.Data.Located as Located +import Elm.Data.Operator as Operator exposing (Operator) import Elm.Data.Qualifiedness exposing (Qualified) import Elm.Data.Type as Type exposing (Type(..), TypeOrId(..)) import Elm.Data.VarName exposing (VarName) @@ -92,7 +93,7 @@ generateEquations currentId located = -- we can't make any assumptions here ( [], currentId ) - Typed.Plus left right -> + Typed.Operator op left right -> let ( _, leftType ) = Located.unwrap left @@ -105,35 +106,25 @@ generateEquations currentId located = ( rightEquations, id2 ) = generateEquations id1 right - in - ( -- for expression `a + b`: - [ equals leftType (Type Int) -- type of `a` is Int - , equals rightType (Type Int) -- type of `b` is Int - , equals type_ (Type Int) -- type of `a + b` is Int - ] - ++ leftEquations - ++ rightEquations - , id2 - ) - - Typed.Cons left right -> - let - ( _, leftType ) = - Located.unwrap left - ( _, rightType ) = - Located.unwrap right - - ( leftEquations, id1 ) = - generateEquations currentId left - - ( rightEquations, id2 ) = - generateEquations id1 right + opEquations = + case op of + Operator.Add -> + [ equals leftType (Type Int) -- type of `a` is Int + , equals rightType (Type Int) -- type of `b` is Int + , equals type_ (Type Int) -- type of `a + b` is Int + ] + + Operator.Cons -> + [ equals rightType (Type (List leftType)) -- type of b is a List a + , equals type_ rightType -- a :: [ b ] is a List b + ] + + _ -> + Debug.todo "handle typing of other operators" in - ( -- For expression a :: [ b ]: - [ equals rightType (Type (List leftType)) -- type of b is a List a - , equals type_ rightType -- a :: [ b ] is a List b - ] + ( opEquations + -- for expression `a OP b`: ++ leftEquations ++ rightEquations , id2 diff --git a/src/Stage/Optimize.elm b/src/Stage/Optimize.elm index 9bef00c1..70dd8f15 100644 --- a/src/Stage/Optimize.elm +++ b/src/Stage/Optimize.elm @@ -6,6 +6,7 @@ module Stage.Optimize exposing ) import Elm.AST.Typed as Typed +import Elm.Data.Operator as Operator import Elm.Data.Project exposing (Project) import Stage.Optimize.Boilerplate as Boilerplate @@ -38,7 +39,7 @@ defaultOptimizations = optimizePlus : Typed.LocatedExpr -> Maybe Typed.LocatedExpr optimizePlus located = case Typed.getExpr located of - Typed.Plus l r -> + Typed.Operator Operator.Add l r -> case ( Typed.getExpr l, Typed.getExpr r ) of ( Typed.Int left, Typed.Int right ) -> Just (Typed.setExpr (Typed.Int (left + right)) r) @@ -53,7 +54,7 @@ optimizePlus located = optimizeCons : Typed.LocatedExpr -> Maybe Typed.LocatedExpr optimizeCons located = case Typed.getExpr located of - Typed.Cons l r -> + Typed.Operator Operator.Cons l r -> case Typed.getExpr r of Typed.List list -> Just (Typed.setExpr (Typed.List (l :: list)) r) diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 128bc96c..8a6d6d16 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -161,6 +161,9 @@ toString item = Sigil (Operator Operator.LessThanEquals) -> "<=" + Sigil (Operator Operator.Cons) -> + "::" + Sigil (Operator Operator.Append) -> "++" @@ -396,6 +399,8 @@ sigilParser = |> P.map (\() -> Operator Operator.And) , P.symbol (P.Token "++" ExpectingSigil) |> P.map (\() -> Operator Operator.Append) + , P.symbol (P.Token "::" ExpectingSigil) + |> P.map (\() -> Operator Operator.Cons) , P.symbol (P.Token "==" ExpectingSigil) |> P.map (\() -> Operator Operator.Equals) , P.symbol (P.Token "||" ExpectingSigil) diff --git a/src/Stage/Parse/Parser.elm b/src/Stage/Parse/Parser.elm index 3ecf3e91..65b7cb09 100644 --- a/src/Stage/Parse/Parser.elm +++ b/src/Stage/Parse/Parser.elm @@ -38,6 +38,7 @@ import Elm.Data.Import exposing (Import) import Elm.Data.Located as Located exposing (Located) import Elm.Data.Module exposing (Module, ModuleType(..)) import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) import Elm.Data.TypeAnnotation exposing (TypeAnnotation) @@ -562,17 +563,17 @@ expr = (checkIndent (<) ExpectingIndentation |> P.andThen (\() -> P.symbol (P.Token "++" ExpectingConcatOperator)) ) - (Located.merge ListConcat) + (Located.merge (Operator Operator.Append)) , PP.infixLeft 1 (checkIndent (<) ExpectingIndentation |> P.andThen (\() -> P.symbol (P.Token "+" ExpectingPlusOperator)) ) - (Located.merge Plus) + (Located.merge (Operator Operator.Add)) , PP.infixRight 1 (checkIndent (<) ExpectingIndentation |> P.andThen (\() -> P.symbol (P.Token "::" ExpectingConsOperator)) ) - (Located.merge Cons) + (Located.merge (Operator Operator.Cons)) ] , spaces = ignorables } diff --git a/tests/DesugarTest.elm b/tests/DesugarTest.elm index ff05d99e..12414e36 100644 --- a/tests/DesugarTest.elm +++ b/tests/DesugarTest.elm @@ -11,6 +11,7 @@ import Elm.Data.Import exposing (Import) import Elm.Data.Located as Located import Elm.Data.Module as Module exposing (Module) import Elm.Data.ModuleName exposing (ModuleName) +import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.TypeAnnotation exposing (TypeAnnotation) import Elm.Data.VarName exposing (VarName) @@ -167,7 +168,8 @@ frontendLambda arg1 arg2 = { arguments = [ arg1, arg2 ] , body = located <| - Frontend.Plus + Frontend.Operator + Operator.Add (located <| Frontend.Argument arg1) (located <| Frontend.Argument arg2) } @@ -183,7 +185,8 @@ canonicalLambda arg1 arg2 = CanonicalU.Lambda { argument = arg2 , body = - CanonicalU.Plus + CanonicalU.Operator + Operator.Add (CanonicalU.Argument arg1) (CanonicalU.Argument arg2) } diff --git a/tests/EmitJsonTest.elm b/tests/EmitJsonTest.elm index 1bb2e06c..1e851c59 100644 --- a/tests/EmitJsonTest.elm +++ b/tests/EmitJsonTest.elm @@ -1,5 +1,6 @@ module EmitJsonTest exposing (json) +import Elm.Data.Operator as Operator import Dict import Elm.AST.Typed as Typed exposing (Expr_(..)) import Elm.Data.Declaration exposing (Declaration, DeclarationBody(..)) @@ -91,13 +92,13 @@ json = ) , describe "Plus" (List.map runTest - [ ( "simple", Plus (typedInt 1) (typedInt 2), "{\"type\":\"plus\",\"e1\":{\"type\":\"int\",\"value\":1},\"e2\":{\"type\":\"int\",\"value\":2}}" ) + [ ( "simple", Operator Operator.Add (typedInt 1) (typedInt 2), "{\"type\":\"plus\",\"e1\":{\"type\":\"int\",\"value\":1},\"e2\":{\"type\":\"int\",\"value\":2}}" ) ] ) , describe "Cons" (List.map runTest [ ( "simple" - , Cons (typedInt 1) (typedIntList [ 2, 3 ]) + , Operator Operator.Cons (typedInt 1) (typedIntList [ 2, 3 ]) , "{\"type\":\"cons\",\"e1\":{\"type\":\"int\",\"value\":1},\"e2\":{\"type\":\"list\",\"items\":[{\"type\":\"int\",\"value\":2},{\"type\":\"int\",\"value\":3}]}}" ) ] diff --git a/tests/EmitTest.elm b/tests/EmitTest.elm index 278e9bad..b4872acd 100644 --- a/tests/EmitTest.elm +++ b/tests/EmitTest.elm @@ -3,6 +3,7 @@ module EmitTest exposing (javascript) import Dict import Elm.AST.Typed as Typed exposing (Expr_(..)) import Elm.Data.Declaration exposing (Declaration, DeclarationBody(..)) +import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (Qualified) import Expect import Stage.Emit.JavaScript as JS @@ -85,20 +86,21 @@ javascript = , describe "Plus" (List.map runTest -- We need to give the child `Expr`s a type too - [ ( "simple", Plus (typedInt 1) (typedInt 2), "(1 + 2)" ) - , ( "nested", Plus (typedInt 1) (typed (Plus (typedInt 2) (typedInt 3))), "(1 + (2 + 3))" ) + [ ( "simple", Operator Operator.Add (typedInt 1) (typedInt 2), "(1 + 2)" ) + , ( "nested", Operator Operator.Add (typedInt 1) (typed (Operator Operator.Add (typedInt 2) (typedInt 3))), "(1 + (2 + 3))" ) ] ) , describe "Cons" (List.map runTest [ ( "simple" - , Cons (typedInt 1) (typedIntList [ 2, 3 ]) + , Operator Operator.Cons (typedInt 1) (typedIntList [ 2, 3 ]) , "[1].concat([2, 3])" ) , ( "nested" - , Cons + , Operator + Operator.Cons (typedInt 1) - (typed (Cons (typedInt 2) (typedIntList [ 3, 4 ]))) + (typed (Operator Operator.Cons (typedInt 2) (typedIntList [ 3, 4 ]))) , "[1].concat([2].concat([3, 4]))" ) ] @@ -238,7 +240,8 @@ javascript = } , body = typed - (Plus + (Operator + Operator.Add (typedInt 1) (typed (Argument "x")) ) @@ -258,7 +261,8 @@ javascript = , { name = "y" , body = typed - (Plus + (Operator + Operator.Add (typedInt 1) (typed (Argument "x")) ) @@ -333,14 +337,14 @@ javascript = , describe "Mixed expressions" (List.map runTest [ ( "plus in tuple" - , Tuple (typed (Plus (typedInt 1) (typedInt 41))) (typedString "Hello") + , Tuple (typed (Operator Operator.Add (typedInt 1) (typedInt 41))) (typedString "Hello") , """[(1 + 41),"Hello"]""" ) , ( "tuple and cons in record" , Record (Dict.fromList [ ( "a", { name = "a", body = typed (Tuple (typedInt 2) (typedInt 3)) } ) - , ( "b", { name = "b", body = typed (Cons (typedInt 2) (typedIntList [ 3, 4 ])) } ) + , ( "b", { name = "b", body = typed (Operator Operator.Cons (typedInt 2) (typedIntList [ 3, 4 ])) } ) ] ) , """{a: [2,3], b: [2].concat([3, 4])}""" diff --git a/tests/InferTypesFuzz.elm b/tests/InferTypesFuzz.elm index 4244a58e..3ed5ceb8 100644 --- a/tests/InferTypesFuzz.elm +++ b/tests/InferTypesFuzz.elm @@ -5,6 +5,7 @@ import Elm.AST.Canonical as Canonical import Elm.AST.Canonical.Unwrapped as CanonicalU import Elm.Compiler.Error exposing (TypeError(..)) import Elm.Data.Located as Located +import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (Qualified) import Elm.Data.Type as Type import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType(..)) @@ -248,7 +249,8 @@ intToIntFunctionExpr = let combine argument intPart = lambda argument <| - CanonicalU.Plus + CanonicalU.Operator + Operator.Add (CanonicalU.Argument argument) intPart @@ -361,11 +363,8 @@ shrinkExpr expr = CanonicalU.Argument _ -> nope - CanonicalU.Plus left right -> - shrinkPlus left right - - CanonicalU.Cons x xs -> - shrinkCons x xs + CanonicalU.Operator op x xs -> + shrinkOp op x xs CanonicalU.Lambda { argument, body } -> shrinkLambda argument body @@ -407,47 +406,21 @@ shrinkExpr expr = nope -{-| Shrinks a plus expression. - ---- - -We cannot write a type annotation here. -The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations/test`. - - shrinkPlus : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr - --} -shrinkPlus left right = - ([ Shrink.map2 CanonicalU.Plus - (shrinkExpr left) - (Shrink.singleton right) - , Shrink.map2 CanonicalU.Plus - (Shrink.singleton left) - (shrinkExpr right) - ] - |> List.map always - |> Shrink.mergeMany - ) - -- The value built up to this point is a shrinker. - -- We need to call it with an CanonicalU.Expr to get a lazy list. - left - - -{-| Shrinks a cons expression. +{-| Shrinks a binary operator expression. --- We cannot write a type annotation here. The `LazyList a` type used by shrinkers is not exposed outside `elm-explorations/test`. - shrinkCons : CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr + shrinkCons : Operator -> CanonicalU.Expr -> CanonicalU.Expr -> LazyList CanonicalU.Expr -} -shrinkCons x xs = - ([ Shrink.map2 CanonicalU.Cons +shrinkOp op x xs = + ([ Shrink.map2 (CanonicalU.Operator op) (shrinkExpr x) (Shrink.singleton xs) - , Shrink.map2 CanonicalU.Cons + , Shrink.map2 (CanonicalU.Operator op) (Shrink.singleton x) (shrinkExpr xs) ] diff --git a/tests/InferTypesTest.elm b/tests/InferTypesTest.elm index eed1ff46..64bd2ab3 100644 --- a/tests/InferTypesTest.elm +++ b/tests/InferTypesTest.elm @@ -5,6 +5,7 @@ import Elm.AST.Canonical as Canonical import Elm.AST.Canonical.Unwrapped as CanonicalU import Elm.AST.Typed as Typed import Elm.Compiler.Error as Error exposing (Error(..), TypeError(..)) +import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (PossiblyQualified(..), Qualified(..)) import Elm.Data.Type as Type exposing (Type(..), TypeOrId(..)) import Elm.Data.Type.ToString as TypeToString @@ -115,7 +116,7 @@ typeInference = ] , runSection "plus" [ ( "same types" - , CanonicalU.Plus + , CanonicalU.Operator Operator.Add (CanonicalU.Var { module_ = "Main", name = "age" }) (CanonicalU.Int 1) , Ok Int @@ -123,15 +124,15 @@ typeInference = ] , runSection "cons" [ ( "simple case" - , CanonicalU.Cons + , CanonicalU.Operator Operator.Cons (CanonicalU.Int 1) (CanonicalU.List []) , Ok (List (Type Int)) ) , ( "advanced case" - , CanonicalU.Cons + , CanonicalU.Operator Operator.Cons (CanonicalU.Int 1) - (CanonicalU.Cons + (CanonicalU.Operator Operator.Cons (CanonicalU.Int 2) (CanonicalU.List [ CanonicalU.Int 3 @@ -142,7 +143,7 @@ typeInference = , Ok (List (Type Int)) ) , ( "fail with wrong argument types" - , CanonicalU.Cons + , CanonicalU.Operator Operator.Cons (CanonicalU.List [ CanonicalU.Int 1 , CanonicalU.Int 2 @@ -160,7 +161,7 @@ typeInference = ) ) , ( "variable and list" - , CanonicalU.Cons + , CanonicalU.Operator Operator.Cons (CanonicalU.Var { module_ = "Main", name = "age" }) (CanonicalU.List [ CanonicalU.Int 1 ]) , Ok (List (Type Int)) diff --git a/tests/OptimizeTest.elm b/tests/OptimizeTest.elm index 230ce0e8..0d96069e 100644 --- a/tests/OptimizeTest.elm +++ b/tests/OptimizeTest.elm @@ -1,6 +1,7 @@ module OptimizeTest exposing (optimize) import Elm.AST.Typed as Typed exposing (Expr_(..)) +import Elm.Data.Operator as Operator exposing (Operator) import Elm.Data.Type as Type exposing (TypeOrId(..)) import Expect import Stage.Optimize @@ -31,7 +32,8 @@ optimize = (List.map runTest [ ( "works with two literal ints" , located - ( Plus + ( Operator + Operator.Add (typedInt 2) (typedInt 5) , Type Type.Int @@ -40,13 +42,13 @@ optimize = ) , ( "doesn't work if left is not int" , located - ( Plus + ( Operator Operator.Add (located ( Argument "x", Type Type.Int )) (typedInt 5) , Type Type.Int ) , located - ( Plus + ( Operator Operator.Add (located ( Argument "x", Type Type.Int )) (typedInt 5) , Type Type.Int @@ -54,13 +56,13 @@ optimize = ) , ( "doesn't work if right is not int" , located - ( Plus + ( Operator Operator.Add (typedInt 5) (located ( Argument "x", Type Type.Int )) , Type Type.Int ) , located - ( Plus + ( Operator Operator.Add (typedInt 5) (located ( Argument "x", Type Type.Int )) , Type Type.Int @@ -72,7 +74,8 @@ optimize = (List.map runTest [ ( "works with one value" , located - ( Cons + ( Operator + Operator.Cons (typedInt 1) (typedIntList [ 2, 3 ]) , Type Type.Int diff --git a/tests/ParserTest.elm b/tests/ParserTest.elm index b8a0d4d3..3001f51d 100644 --- a/tests/ParserTest.elm +++ b/tests/ParserTest.elm @@ -18,6 +18,7 @@ import Elm.Compiler.Error exposing (ParseContext, ParseProblem) import Elm.Data.Declaration as Declaration exposing (DeclarationBody) import Elm.Data.Exposing exposing (ExposedItem(..), Exposing(..)) import Elm.Data.Module exposing (ModuleType(..)) +import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) import Elm.Data.TypeAnnotation exposing (TypeAnnotation) @@ -489,7 +490,8 @@ expr = (Lambda { arguments = [ "x" ] , body = - Plus + Operator + Operator.Add (Argument "x") (Int 1) } @@ -506,7 +508,8 @@ expr = (Lambda { arguments = [ "x" ] , body = - Plus + Operator + Operator.Add (Argument "x") (Int 1) } @@ -518,7 +521,8 @@ expr = (Lambda { arguments = [ "x", "y" ] , body = - Plus + Operator + Operator.Add (Argument "x") (Argument "y") } @@ -1049,7 +1053,8 @@ expr = } ] , body = - Plus + Operator + Operator.Add (Int 1) (Argument "x") } @@ -1073,7 +1078,8 @@ expr = } , { name = "y" , body = - Plus + Operator + Operator.Add (Argument "x") (Int 1) } @@ -1123,7 +1129,7 @@ expr = ) , ( "list concat" , "[] ++ []" - , Just (ListConcat (List []) (List [])) + , Just (Operator Operator.Append (List []) (List [])) ) , ( "multiline" , """ @@ -1205,7 +1211,7 @@ expr = , [ ( "simple case" , "1 :: []" , Just - (Cons + (Operator Operator.Cons (Int 1) (List []) ) @@ -1213,9 +1219,9 @@ expr = , ( "multiple values case" , "1 :: 2 :: []" , Just - (Cons + (Operator Operator.Cons (Int 1) - (Cons + (Operator Operator.Cons (Int 2) (List []) ) @@ -1224,7 +1230,7 @@ expr = , ( "no spaces" , "1::[]" , Just - (Cons + (Operator Operator.Cons (Int 1) (List []) ) @@ -1232,7 +1238,7 @@ expr = , ( "multiple spaces" , "1 :: []" , Just - (Cons + (Operator Operator.Cons (Int 1) (List []) ) @@ -1268,7 +1274,7 @@ expr = , ( "multiline" , """ { a = 42 - , b = "hello" + , b = "hello" } """ , Just @@ -1545,7 +1551,7 @@ type_ = , ( "multiline record" , """ { x : Int - , y : String + , y : String } """ |> String.unindent From 08a337a5011111b90c8ae3964c67342725cb38a8 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 18:30:06 +0100 Subject: [PATCH 070/103] parse operators we crash if we mix precedence in a expr but it is a start! --- parser-tests/Update.elm | 3 ++ src/Stage/Parse/Contextualize.elm | 31 +++++++++------- tests/ParserLexerTestCases.elm | 59 ++++--------------------------- 3 files changed, 29 insertions(+), 64 deletions(-) diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 4543f46d..599abb4e 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -127,6 +127,9 @@ resolveCustomTypeConstructors = |> String.replace "Int" "Frontend.Int" |> String.replace "Float" "Frontend.Float" |> String.replace "Unit" "Frontend.Unit" + |> String.replace "Operator" "Frontend.Operator" + |> String.replace "ExpressionNestingLeaf_Frontend.Operator" "ExpressionNestingLeaf_Operator" + |> String.replace "ExpressionNestingParent_Frontend.Operator" "ExpressionNestingParent_Operator" else line diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 1395444f..dc41b300 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -1057,17 +1057,6 @@ parserExpression newState prevExpr item = appendOperatorTo prevExpr op |> partialExpressionToParseResult newState - Lexer.Newlines _ 0 -> - case prevExpr of - ExpressionNestingLeaf_Operator {} -> - Error_PartwayThroughValueDeclaration - |> ParseResult_Err - - ExpressionNestingLeafType_Expr expr -> - expr - |> PartialResult_Done - |> newState - Lexer.NumericLiteral str -> case String.toInt str of Just i -> @@ -1080,6 +1069,24 @@ parserExpression newState prevExpr item = Error_InvalidNumericLiteral str |> ParseResult_Err + Lexer.Newlines _ 0 -> + case prevExpr of + ExpressionNestingLeaf_Operator partialExpr -> + case partialExpr.rhs of + Just rhs -> + Located.merge (Frontend.Operator partialExpr.op) partialExpr.lhs rhs + |> PartialResult_Done + |> newState + + Nothing -> + Error_PartwayThroughValueDeclaration + |> ParseResult_Err + + ExpressionNestingLeafType_Expr expr -> + expr + |> PartialResult_Done + |> newState + Lexer.Newlines _ _ -> ParseResult_Skip @@ -1477,7 +1484,7 @@ appendOperatorTo leaf appendingOp = Operator.LeftToRight -> ExpressionNestingLeaf_Operator { op = appendingOp - , lhs = Debug.todo "add to frontend" + , lhs = Located.merge (Frontend.Operator newParent.op) newParent.lhs parentRhs , rhs = Nothing , parent = Just diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index c2a48269..b59d5c76 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -2,14 +2,13 @@ module ParserLexerTestCases exposing (shouldNotParseTestCases, shouldParseTestCa import Dict import Elm.AST.Frontend as Frontend -import Elm.Data.Located as Located exposing (Located(..)) -import Elm.Data.Operator as Operator exposing (Operator(..)) +import Elm.Data.Located exposing (Located(..)) +import Elm.Data.Operator exposing (Operator(..)) import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete exposing (ConcreteType(..)) import Stage.Parse.Contextualize as Contextualize exposing (..) -import Stage.Parse.Lexer as Lexer exposing (..) +import Stage.Parse.Lexer exposing (..) import Stage.Parse.Token exposing (TypeOrConstructor(..), ValueOrFunctionOrGenericType(..)) -import Test exposing (Test, describe, test) @@ -65,30 +64,8 @@ b = 78 + 5 + 2+ 4 """ , contextualized = Just - [ Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5")) - , state = - State_BlockValueDeclaration - (BlockValueDeclaration_Completish - { args = [] - , name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a") - , partialExpr = ExpressionNestingLeaf_Operator { lhs = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5), op = Add, parent = Nothing, rhs = Nothing } - } - ) - } - , Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5")) - , state = - State_BlockValueDeclaration - (BlockValueDeclaration_Completish - { args = [] - , name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b") - , partialExpr = ExpressionNestingLeaf_Operator { lhs = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78), op = Add, parent = Nothing, rhs = Nothing } - } - ) - } + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Add (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 18, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Frontend.Int 4))) }) ] , lexed = Ok @@ -133,30 +110,8 @@ b = 78 + 5 + 2 - 4 + 5 """ , contextualized = Just - [ Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5")) - , state = - State_BlockValueDeclaration - (BlockValueDeclaration_Completish - { args = [] - , name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a") - , partialExpr = ExpressionNestingLeaf_Operator { lhs = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5), op = Subtract, parent = Nothing, rhs = Nothing } - } - ) - } - , Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5")) - , state = - State_BlockValueDeclaration - (BlockValueDeclaration_Completish - { args = [] - , name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b") - , partialExpr = ExpressionNestingLeaf_Operator { lhs = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78), op = Add, parent = Nothing, rhs = Nothing } - } - ) - } + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Subtract (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Subtract (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) ] , lexed = Ok From 43ebf779884a1537ba342fb9f50c20a504c81e1e Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 18:49:31 +0100 Subject: [PATCH 071/103] add multiply/divide test case --- .../should-parse/expression-int-multiply | 3 ++ tests/ParserLexerTestCases.elm | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 parser-tests/snippets/should-parse/expression-int-multiply diff --git a/parser-tests/snippets/should-parse/expression-int-multiply b/parser-tests/snippets/should-parse/expression-int-multiply new file mode 100644 index 00000000..e34459ec --- /dev/null +++ b/parser-tests/snippets/should-parse/expression-int-multiply @@ -0,0 +1,3 @@ +a = 5 * 5 + +b = 78 * 5 * 2 / 4 * 5 diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index b59d5c76..f8dd1c7b 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -103,6 +103,57 @@ b = 78 + 5 + 2+ 4 , Located { end = { col = 1, row = 4 }, start = { col = 18, row = 3 } } (Newlines [] 0) ] } + , { name = "expression-int-multiply" + , source = """a = 5 * 5 + +b = 78 * 5 * 2 / 4 * 5 +""" + , contextualized = + Just + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Multiply (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Multiply (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Divide (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Multiply (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Multiply (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) + ] + , lexed = + Ok + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Whitespace 1) + , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Sigil (Operator Multiply)) + , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Whitespace 1) + , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token "b") + , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) + , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) + , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Whitespace 1) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil (Operator Multiply)) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5") + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Sigil (Operator Multiply)) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Whitespace 1) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (NumericLiteral "2") + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Whitespace 1) + , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Sigil (Operator Divide)) + , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Whitespace 1) + , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (NumericLiteral "4") + , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Sigil (Operator Multiply)) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Newlines [] 0) + ] + } , { name = "expression-int-subtract" , source = """a = 5 - 5 From ca7c5f7760398210391c2010acaff9edd7d9f63d Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Tue, 6 Oct 2020 18:55:33 +0100 Subject: [PATCH 072/103] format code --- src/Elm/AST/Frontend.elm | 1 - tests/EmitJsonTest.elm | 2 +- tests/EmitTest.elm | 2 +- tests/OptimizeTest.elm | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Elm/AST/Frontend.elm b/src/Elm/AST/Frontend.elm index 5df1631e..fd0e3d25 100644 --- a/src/Elm/AST/Frontend.elm +++ b/src/Elm/AST/Frontend.elm @@ -237,7 +237,6 @@ unwrap expr = (unwrap e1) (unwrap e2) - Lambda { arguments, body } -> Unwrapped.Lambda { arguments = arguments diff --git a/tests/EmitJsonTest.elm b/tests/EmitJsonTest.elm index 1e851c59..52a80e7b 100644 --- a/tests/EmitJsonTest.elm +++ b/tests/EmitJsonTest.elm @@ -1,9 +1,9 @@ module EmitJsonTest exposing (json) -import Elm.Data.Operator as Operator import Dict import Elm.AST.Typed as Typed exposing (Expr_(..)) import Elm.Data.Declaration exposing (Declaration, DeclarationBody(..)) +import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (Qualified) import Expect import Fuzz exposing (bool, char, float, int, string) diff --git a/tests/EmitTest.elm b/tests/EmitTest.elm index b4872acd..7eceec5a 100644 --- a/tests/EmitTest.elm +++ b/tests/EmitTest.elm @@ -262,7 +262,7 @@ javascript = , body = typed (Operator - Operator.Add + Operator.Add (typedInt 1) (typed (Argument "x")) ) diff --git a/tests/OptimizeTest.elm b/tests/OptimizeTest.elm index 0d96069e..7fdb8ac0 100644 --- a/tests/OptimizeTest.elm +++ b/tests/OptimizeTest.elm @@ -33,7 +33,7 @@ optimize = [ ( "works with two literal ints" , located ( Operator - Operator.Add + Operator.Add (typedInt 2) (typedInt 5) , Type Type.Int From 08a388bf4a6aa69eeaf1f43be1d3efb6a5c49b7c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Wed, 7 Oct 2020 10:55:25 +0100 Subject: [PATCH 073/103] add pretty printed AST to test cases to help me inspect the contextualised output. I love sexprs in this context. --- parser-tests/Live.elm | 2 +- parser-tests/Update.elm | 79 +- parser-tests/update.js | 1 + src/Elm/Data/Operator.elm | 46 ++ src/Stage/Parse/Lexer.elm | 43 +- src/Stage/Parse/Pretty.elm | 322 ++++++++ tests/ParserLexerTestCases.elm | 1318 ++++++++++++++++++++++++++++++++ 7 files changed, 1746 insertions(+), 65 deletions(-) create mode 100644 src/Stage/Parse/Pretty.elm diff --git a/parser-tests/Live.elm b/parser-tests/Live.elm index 8788d2de..ef1ff903 100644 --- a/parser-tests/Live.elm +++ b/parser-tests/Live.elm @@ -108,7 +108,7 @@ view model = [ Html.div [ Attributes.style "white-space" "pre-wrap" ] [ Html.text - (Debug.toString (Contextualize.run (lexItems |> List.map Located.unwrap))) + (Debug.toString (Contextualize.run lexItems)) ] ] diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 599abb4e..3dd6ffbe 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -5,6 +5,7 @@ import Parser.Advanced as P import Platform import Stage.Parse.Contextualize as Contextualize import Stage.Parse.Lexer as Lexer +import Stage.Parse.Pretty as Pretty port output : String -> Cmd never @@ -64,18 +65,46 @@ init snippets = , source = \"\"\"""" ++ source ++ """\"\"\" + , pretty = \"\"\" + """ + ++ (case contextualized of + Nothing -> + "Could not lex (a bug)." + + Just c -> + Pretty.printWithIndentationOf 4 + (Pretty.listWith + (\rBlock -> + case rBlock of + Ok block -> + Pretty.Many + [ Pretty.Atom "Ok" + , Pretty.block block + ] + + Err e -> + Pretty.Many + [ Pretty.Atom "Err" + , Pretty.Atom "todo" + ] + ) + c + ) + ++ """ +\"\"\" , contextualized =""" - ++ (Debug.toString contextualized - |> preFormatElmCode - |> resolveCustomTypeConstructors - ) - ++ """ + ++ (Debug.toString contextualized + |> preFormatElmCode + |> resolveCustomTypeConstructors + ) + ++ """ , lexed = """ - ++ (Debug.toString lexed - |> preFormatElmCode - ) - ++ """ + ++ (Debug.toString lexed + |> preFormatElmCode + ) + ++ """ }""" + ) ) snippets rlexed @@ -95,7 +124,6 @@ update () model = ( model, Cmd.none ) - preFormatElmCode : String -> String preFormatElmCode = {- String.replace "}" """ @@ -114,24 +142,29 @@ preFormatElmCode = """ >> String.replace """BlockValueDeclaration_Completish {""" """BlockValueDeclaration_Completish { """ + + {-| Always run after preformatting. -} resolveCustomTypeConstructors : String -> String resolveCustomTypeConstructors = String.split "\n" - >> List.map ( - \line -> - if String.contains "valueExpr__" line || String.contains "ExpressionNestingParent_Operator" line - || String.contains "ExpressionNestingLeaf_Operator" line then - line - |> String.replace "Int" "Frontend.Int" - |> String.replace "Float" "Frontend.Float" - |> String.replace "Unit" "Frontend.Unit" - |> String.replace "Operator" "Frontend.Operator" - |> String.replace "ExpressionNestingLeaf_Frontend.Operator" "ExpressionNestingLeaf_Operator" - |> String.replace "ExpressionNestingParent_Frontend.Operator" "ExpressionNestingParent_Operator" - else + >> List.map + (\line -> + if + String.contains "valueExpr__" line + || String.contains "ExpressionNestingParent_Operator" line + || String.contains "ExpressionNestingLeaf_Operator" line + then line + |> String.replace "Int" "Frontend.Int" + |> String.replace "Float" "Frontend.Float" + |> String.replace "Unit" "Frontend.Unit" + |> String.replace "Operator" "Frontend.Operator" + |> String.replace "ExpressionNestingLeaf_Frontend.Operator" "ExpressionNestingLeaf_Operator" + |> String.replace "ExpressionNestingParent_Frontend.Operator" "ExpressionNestingParent_Operator" - ) + else + line + ) >> String.join "\n" diff --git a/parser-tests/update.js b/parser-tests/update.js index ce8a2c72..a371e752 100755 --- a/parser-tests/update.js +++ b/parser-tests/update.js @@ -20,6 +20,7 @@ const warningCommentLines = ` const TYPE_OF_RESULT_CASES = ` List { contextualized : Maybe (List Contextualize.RunResult) + , pretty : String , lexed : Result Never (List (Located LexItem)) , name : String , source : String diff --git a/src/Elm/Data/Operator.elm b/src/Elm/Data/Operator.elm index 41e7afee..049cb757 100644 --- a/src/Elm/Data/Operator.elm +++ b/src/Elm/Data/Operator.elm @@ -118,3 +118,49 @@ getAssociativity prec = Pipe -> ConflictsWithOthers + + +toString : Operator -> String +toString op = + case op of + Add -> + "+" + + Subtract -> + "-" + + Multiply -> + "*" + + Divide -> + "/" + + Exponentiate -> + "^" + + And -> + "&&" + + Or -> + "||" + + Equals -> + "==" + + GreaterThan -> + ">" + + GreaterThanEquals -> + ">=" + + LessThan -> + "<" + + LessThanEquals -> + "<=" + + Cons -> + "::" + + Append -> + "++" diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 8a6d6d16..707f593b 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -125,47 +125,8 @@ toString item = Sigil Underscore -> "_" - Sigil (Operator Operator.Add) -> - "+" - - Sigil (Operator Operator.Subtract) -> - "-" - - Sigil (Operator Operator.Multiply) -> - "*" - - Sigil (Operator Operator.Divide) -> - "/" - - Sigil (Operator Operator.Exponentiate) -> - "^" - - Sigil (Operator Operator.And) -> - "&&" - - Sigil (Operator Operator.Or) -> - "||" - - Sigil (Operator Operator.Equals) -> - "==" - - Sigil (Operator Operator.GreaterThan) -> - ">" - - Sigil (Operator Operator.GreaterThanEquals) -> - ">=" - - Sigil (Operator Operator.LessThan) -> - "<" - - Sigil (Operator Operator.LessThanEquals) -> - "<=" - - Sigil (Operator Operator.Cons) -> - "::" - - Sigil (Operator Operator.Append) -> - "++" + Sigil (Operator op) -> + Operator.toString op Token s -> s diff --git a/src/Stage/Parse/Pretty.elm b/src/Stage/Parse/Pretty.elm new file mode 100644 index 00000000..0271d236 --- /dev/null +++ b/src/Stage/Parse/Pretty.elm @@ -0,0 +1,322 @@ +module Stage.Parse.Pretty exposing (..) + +import Dict exposing (Dict) +import Elm.AST.Frontend as Frontend +import Elm.Data.Located as Located +import Elm.Data.Module as ModuleType exposing (ModuleType) +import Elm.Data.Operator as Operator +import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) +import Elm.Data.Type.Concrete as Concrete exposing (ConcreteType) +import Stage.Parse.Contextualize exposing (Block(..)) +import Stage.Parse.Token as Token + + +type Sexpr a + = Atom a + | Many (List (Sexpr a)) + + +printWithIndentationOf : Int -> Sexpr String -> String +printWithIndentationOf indent sexpr = + case sexpr of + Atom s -> + s + + Many ls -> + case ls of + [] -> + "()" + + [ first ] -> + "( " + ++ printWithIndentationOf (indent + 1) first + ++ " )" + + [ Atom first, Atom second ] -> + "( " ++ first ++ ", " ++ second ++ " )" + + [ Many [], Atom second ] -> + "( (), " ++ second ++ " )" + + [ Atom first, Many [] ] -> + "( " ++ first ++ ", () )" + + [ Many [], Many [] ] -> + "( (), () )" + + _ -> + printManyItems True indent ls "" + ++ ")" + + +printManyItems : Bool -> Int -> List (Sexpr String) -> String -> String +printManyItems isFirst indent many soFar = + case many of + first :: rest -> + printManyItems + False + indent + rest + (soFar + ++ (if isFirst then + "( " + + else + ", " + ) + ++ printWithIndentationOf (indent + 1) first + ++ "\n" + ++ String.repeat (indent * 2) " " + ) + + [] -> + soFar + + +listWith : (a -> Sexpr String) -> List a -> Sexpr String +listWith f ls = + Many (List.map f ls) + + +dictEntriesWith : (a -> Sexpr String) -> (b -> Sexpr String) -> Dict a b -> Sexpr String +dictEntriesWith keys values d = + Dict.toList d |> listWith (\( k, v ) -> Many [ keys k, values v ]) + + +pair : a -> Sexpr a -> Sexpr a +pair key value = + Many [ Atom key, value ] + + +block : Block -> Sexpr String +block b = + case b of + Module record -> + Many + [ Atom "Module" + , Many + [ Atom "ty" + , moduleType record.ty + ] + ] + + ValueDeclaration record -> + let + (Token.ValueOrFunctionOrGenericType name) = + Located.unwrap record.name + in + Many + [ Atom "ValueDeclaration" + , Many + [ Atom "name" + , Atom name + ] + , Many + [ Atom "args" + , listWith + (\locatedArg -> + let + (Token.ValueOrFunctionOrGenericType arg) = + Located.unwrap locatedArg + in + Atom arg + ) + record.args + ] + , Many + [ Atom "valueExpr__" + , expr record.valueExpr__ + ] + ] + + TypeAlias record -> + let + (Token.TypeOrConstructor ty) = + record.ty + in + Many + [ Atom "ValueDeclaration" + , Many + [ Atom "ty" + , Atom ty + ] + , Many + [ Atom "genericArgs" + , Many + (record.genericArgs + |> List.map (\(Token.ValueOrFunctionOrGenericType arg) -> Atom arg) + ) + ] + , Many + [ Atom "expr" + , typeExpr record.expr + ] + ] + + CustomType record -> + Debug.todo "" + + +expr : Frontend.LocatedExpr -> Sexpr String +expr expr_ = + case Located.unwrap expr_ of + Frontend.Int int -> + pair "Int" (Atom (String.fromInt int)) + + Frontend.HexInt int -> + pair "HexInt" (Atom (String.fromInt int)) + + Frontend.Float float -> + pair "Float" (Atom (String.fromFloat float)) + + Frontend.Char char -> + pair "Char" (Atom (String.fromChar char)) + + Frontend.String string -> + pair "String" (Atom string) + + Frontend.Bool bool -> + pair "Bool" + (Atom + (if bool then + "True" + + else + "False" + ) + ) + + Frontend.Var { qualifiedness, name } -> + pair "Var" + (Many + [ pair "qualifiedness" (Atom "TODO") + , pair "name" (Atom name) + ] + ) + + Frontend.Argument varName -> + pair "Argument" (Atom varName) + + Frontend.Operator operator lhs rhs -> + pair "Operator" + (Many + [ pair "op" (Atom (Operator.toString operator)) + , pair "lhs" (expr lhs) + , pair "rhs" (expr rhs) + ] + ) + + Frontend.Lambda { arguments, body } -> + pair "Lambda" + (Many + [ pair "arguments" (listWith Atom arguments) + , pair "body " (Atom "TODO") + ] + ) + + Frontend.Call record -> + pair "Call" (Atom "TODO") + + Frontend.If record -> + pair "If" (Atom "TODO") + + Frontend.Let record -> + pair "Let" (Atom "TODO") + + Frontend.List locateds -> + pair "List" (Atom "TODO") + + Frontend.Unit -> + Atom "Unit" + + Frontend.Tuple first second -> + pair "Tuple" (Many [ Atom "TODO", Atom "TODO" ]) + + Frontend.Tuple3 first second third -> + pair "Tuple" (Many [ Atom "TODO", Atom "TODO", Atom "TODO" ]) + + Frontend.Record bindings -> + pair "Record" (Atom "TODO") + + Frontend.Case locatedExpr list -> + Debug.todo "" + + +typeExpr : ConcreteType PossiblyQualified -> Sexpr String +typeExpr expr_ = + case expr_ of + Concrete.TypeVar string -> + pair "TypeVar" (Atom string) + + Concrete.Function { from, to } -> + pair "Function" + (Many + [ pair "from" (typeExpr from) + , pair "to" (typeExpr to) + ] + ) + + Concrete.Int -> + Atom "Int" + + Concrete.Float -> + Atom "Float" + + Concrete.Char -> + Atom "Char" + + Concrete.String -> + Atom "String" + + Concrete.Bool -> + Atom "Bool" + + Concrete.List list -> + pair "List" (typeExpr list) + + Concrete.Unit -> + Atom "Unit" + + Concrete.Tuple first second -> + pair "Tuple" (Many [ typeExpr first, typeExpr second ]) + + Concrete.Tuple3 first second third -> + pair "Tuple" (Many [ typeExpr first, typeExpr second, typeExpr third ]) + + Concrete.Record dict -> + pair "Record" (dictEntriesWith Atom typeExpr dict) + + Concrete.UserDefinedType { qualifiedness, name, args } -> + let + (PossiblyQualified q) = + qualifiedness + in + pair "UserDefinedType" + (Many + [ pair "qualifiedness" + (pair "PossiblyQualified" + (case q of + Just moduleName -> + pair "Just" (Atom moduleName) + + Nothing -> + Atom "Nothing" + ) + ) + , pair "name" (Atom name) + , pair "args" (listWith typeExpr args) + ] + ) + + +moduleType : ModuleType -> Sexpr String +moduleType m = + case m of + ModuleType.PlainModule -> + Atom "PlainModule" + + ModuleType.PortModule -> + Atom "PortModule" + + ModuleType.EffectModule -> + Atom "EffectModule" diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index f8dd1c7b..23e2df07 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -21,6 +21,7 @@ import Stage.Parse.Token exposing (TypeOrConstructor(..), ValueOrFunctionOrGener shouldParseTestCases : List { contextualized : Maybe (List Contextualize.RunResult) + , pretty : String , lexed : Result Never (List (Located LexItem)) , name : String , source : String @@ -30,6 +31,27 @@ shouldParseTestCases = , source = """a = 5 b = 78 +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( name, a ) + , ( args, () ) + , ( valueExpr__ + , ( Int, 5 ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b ) + , ( args, () ) + , ( valueExpr__ + , ( Int, 78 ) + ) + ) + ) + ) """ , contextualized = Just @@ -61,6 +83,63 @@ b = 78 , source = """a = 5 + 5 b = 78 + 5 + 2+ 4 +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( name, a ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Int, 5 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Int, 78 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 2 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 4 ) + ) + ) + ) + ) + ) + ) + ) """ , contextualized = Just @@ -107,6 +186,72 @@ b = 78 + 5 + 2+ 4 , source = """a = 5 * 5 b = 78 * 5 * 2 / 4 * 5 +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( name, a ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 5 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Operator + , ( ( op, / ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 78 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 2 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 4 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + ) """ , contextualized = Just @@ -158,6 +303,72 @@ b = 78 * 5 * 2 / 4 * 5 , source = """a = 5 - 5 b = 78 + 5 + 2 - 4 + 5 +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( name, a ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, - ) + , ( lhs + , ( Int, 5 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, - ) + , ( lhs + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Int, 78 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 2 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 4 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + ) """ , contextualized = Just @@ -207,6 +418,33 @@ b = 78 + 5 + 2 - 4 + 5 } , { name = "type-alias" , source = """type alias Model = List Int +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Model ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -249,6 +487,45 @@ b = 78 + 5 + 2 - 4 + 5 , source = """type alias Model = List Int expr hi = 77 +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Model ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, expr ) + , ( args + , ( hi ) + ) + , ( valueExpr__ + , ( Int, 77 ) + ) + ) + ) + ) """ , contextualized = Just @@ -311,6 +588,28 @@ expr hi = 77 } , { name = "type-alias-bracket-in-record" , source = """type alias Ty = { hi: (Int) } +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Ty ) + , ( genericArgs, () ) + , ( expr + , ( Record + , ( ( hi + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + ) ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -358,6 +657,66 @@ expr hi = 77 } , { name = "type-alias-function" , source = """type alias Function = List Int -> List (List Int) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Function ) + , ( genericArgs, () ) + , ( expr + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + , ( to + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) ) + ) + ) + ) ) + ) + ) + ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -430,6 +789,116 @@ expr hi = 77 , { name = "type-alias-function-binding-order" , source = """type alias Function = A -> B -> C type alias Function = A -> B -> C -> D +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Function ) + , ( genericArgs, () ) + , ( expr + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, A ) + , ( args, () ) + ) + ) + ) + , ( to + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, B ) + , ( args, () ) + ) + ) + ) + , ( to + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, C ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( ty, Function ) + , ( genericArgs, () ) + , ( expr + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, A ) + , ( args, () ) + ) + ) + ) + , ( to + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, B ) + , ( args, () ) + ) + ) + ) + , ( to + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, C ) + , ( args, () ) + ) + ) + ) + , ( to + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, D ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) """ , contextualized = Just @@ -549,6 +1018,68 @@ type alias Function = A -> B -> C -> D } , { name = "type-alias-function-generic" , source = """type alias Function a = List Int -> List (List a) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Function ) + , ( genericArgs + , ( a ) + ) + , ( expr + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + , ( to + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, a ) + , ( args, () ) + ) + ) ) + ) + ) + ) ) + ) + ) + ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -630,6 +1161,161 @@ type alias Function2 = { a: () -> (Int, String) } type alias Function3 = (() -> (Int, String), ()) type alias Function3 = (Int, () -> (Int, String), ()) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Function ) + , ( genericArgs, () ) + , ( expr + , ( Function + , ( ( from, Unit ) + , ( to + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, String ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( ty, Function2 ) + , ( genericArgs, () ) + , ( expr + , ( Record + , ( ( a + , ( Function + , ( ( from, Unit ) + , ( to + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, String ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + ) ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( ty, Function3 ) + , ( genericArgs, () ) + , ( expr + , ( Tuple + , ( ( Function + , ( ( from, Unit ) + , ( to + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, String ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + , Unit + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( ty, Function3 ) + , ( genericArgs, () ) + , ( expr + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( Function + , ( ( from, Unit ) + , ( to + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, String ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + , Unit + ) + ) + ) + ) + ) + ) """ , contextualized = Just @@ -873,6 +1559,51 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-function-record" , source = """type alias Function = { a: { b: C}, d: E } -> {} +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Function ) + , ( genericArgs, () ) + , ( expr + , ( Function + , ( ( from + , ( Record + , ( ( a + , ( Record + , ( ( b + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, C ) + , ( args, () ) + ) + ) + ) ) + ) + ) + , ( d + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, E ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + , ( to + , ( Record, () ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -952,6 +1683,41 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-function-tuple" , source = """type alias Function = () -> (Int, String) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Function ) + , ( genericArgs, () ) + , ( expr + , ( Function + , ( ( from, Unit ) + , ( to + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, String ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1007,6 +1773,33 @@ type alias Function3 = (Int, () -> (Int, String), ()) , { name = "type-alias-funky-indentation" , source = """type alias Model = List Int +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Model ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1049,6 +1842,33 @@ type alias Function3 = (Int, () -> (Int, String), ()) , source = """type alias Model = List Int +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Model ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1089,6 +1909,49 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-record-3-entries" , source = """type alias Ty = { a: A, b: B, c: C } +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Ty ) + , ( genericArgs, () ) + , ( expr + , ( Record + , ( ( a + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, A ) + , ( args, () ) + ) + ) + ) + , ( b + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, B ) + , ( args, () ) + ) + ) + ) + , ( c + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, C ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1160,6 +2023,17 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-record-empty" , source = """type alias Ty = {} +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Ty ) + , ( genericArgs, () ) + , ( expr + , ( Record, () ) + ) + ) + ) ) """ , contextualized = Just @@ -1185,6 +2059,17 @@ type alias Function3 = (Int, () -> (Int, String), ()) } +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Ty ) + , ( genericArgs, () ) + , ( expr + , ( Record, () ) + ) + ) + ) ) """ , contextualized = Just @@ -1214,6 +2099,28 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-record-in-bracket" , source = """type alias Ty = ({ hi: Int }) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Ty ) + , ( genericArgs, () ) + , ( expr + , ( Record + , ( ( hi + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + ) ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1264,6 +2171,106 @@ type alias Function3 = (Int, () -> (Int, String), ()) { hi: { a: Int, b: List String } , ih: CustomType A B C (D E) } +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Ty ) + , ( genericArgs, () ) + , ( expr + , ( Record + , ( ( hi + , ( Record + , ( ( a + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + ) + , ( b + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, String ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) + ) + , ( ih + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, CustomType ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, A ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, B ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, C ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, D ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, E ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1396,6 +2403,28 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-record-simple" , source = """type alias Ty = { hi: Int } +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Ty ) + , ( genericArgs, () ) + , ( expr + , ( Record + , ( ( hi + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + ) ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1441,6 +2470,30 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-record-two-entries" , source = """type alias Ty = { hi: (), buy: String } +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Ty ) + , ( genericArgs, () ) + , ( expr + , ( Record + , ( ( buy + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, String ) + , ( args, () ) + ) + ) + ) + , ( hi, Unit ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1494,6 +2547,15 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-unit" , source = """type alias Hi = () +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Hi ) + , ( genericArgs, () ) + , ( expr, Unit ) + ) + ) ) """ , contextualized = Just @@ -1516,6 +2578,24 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-with-bracket" , source = """type alias Hi = (Int) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Hi ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1550,6 +2630,33 @@ type alias Function3 = (Int, () -> (Int, String), ()) } , { name = "type-alias-with-bracket-2" , source = """type alias Hi = (List Int) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Hi ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1593,6 +2700,61 @@ type alias Function3 = (Int, () -> (Int, String), ()) , { name = "type-alias-with-pair" , source = """type alias Hi = (Int, List String) type alias Hi = (Int) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Hi ) + , ( genericArgs, () ) + , ( expr + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, String ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( ty, Hi ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + ) + ) + ) + ) """ , contextualized = Just @@ -1671,6 +2833,58 @@ type alias Hi = (Int) , { name = "type-alias-with-tripple" , source = """type alias Hi = (Int, Two, Three) type alias Hi = ((), (), ()) +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Hi ) + , ( genericArgs, () ) + , ( expr + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Two ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Three ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( ty, Hi ) + , ( genericArgs, () ) + , ( expr + , ( Tuple + , ( Unit + , Unit + , Unit + ) + ) + ) + ) + ) + ) """ , contextualized = Just @@ -1750,6 +2964,53 @@ type alias Hi = ((), (), ()) { a: (Int, Int, Int) , b: ({ good_bye: () }) } +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( ty, Hi ) + , ( genericArgs, () ) + , ( expr + , ( Record + , ( ( a + , ( Tuple + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, Int ) + , ( args, () ) + ) + ) + ) + ) + ) + , ( b + , ( Record + , ( ( good_bye, Unit ) ) + ) + ) + ) + ) + ) + ) + ) ) """ , contextualized = Just @@ -1845,6 +3106,7 @@ type alias Hi = ((), (), ()) shouldNotParseTestCases : List { contextualized : Maybe (List Contextualize.RunResult) + , pretty : String , lexed : Result Never (List (Located LexItem)) , name : String , source : String @@ -1858,6 +3120,13 @@ type alias Function2 = { a: () -> } type alias Function3 = (() -> , ()) type alias Function3 = (Int, () ->, ()) +""" + , pretty = """ + ( ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + ) """ , contextualized = Just @@ -2021,6 +3290,9 @@ type alias Function3 = (Int, () ->, ()) } , { name = "type-alias-invalid-multiple-brackets" , source = """type alias Hi = (Int) () +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2051,6 +3323,9 @@ type alias Function3 = (Int, () ->, ()) } , { name = "type-alias-invalid-multiple-brackets-2" , source = """type alias Hi = () () +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2080,6 +3355,9 @@ type alias Function3 = (Int, () ->, ()) } , { name = "type-alias-invalid-multiple-brackets-3" , source = """type alias Hi = () (Int) +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2111,6 +3389,11 @@ type alias Function3 = (Int, () ->, ()) , { name = "type-alias-multiline-missing-indentation" , source = """type alias Model = List Int +""" + , pretty = """ + ( ( Err, todo ) + , ( Err, todo ) + ) """ , contextualized = Just @@ -2143,6 +3426,9 @@ List Int } , { name = "type-alias-partial" , source = """type alias +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2162,6 +3448,9 @@ List Int } , { name = "type-alias-partial-2" , source = """type alias Hi +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2183,6 +3472,9 @@ List Int } , { name = "type-alias-partial-3" , source = """type alias Hi = +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2206,6 +3498,9 @@ List Int } , { name = "type-alias-partial-with-bracket" , source = """type alias Hi = ( +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2232,6 +3527,9 @@ List Int , { name = "type-alias-partial-with-bracket-2" , source = """type alias Hi = ( Int +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2268,6 +3566,9 @@ List Int } , { name = "type-alias-record-half-empty" , source = """type alias Ty = { +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2293,6 +3594,9 @@ List Int } , { name = "type-alias-record-missing-colon" , source = """type alias Ty = { hi j7 } +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2325,6 +3629,11 @@ List Int , { name = "type-alias-with-quadruple" , source = """type alias Hi = (Int, A, B, C, D) type alias Hi = (A Int, C D E F, H I (J K), L M () O P) +""" + , pretty = """ + ( ( Err, todo ) + , ( Err, todo ) + ) """ , contextualized = Just @@ -2598,6 +3907,9 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) } , { name = "type-alias-with-tuple-double-comma" , source = """type alias Hi = (Int, , A) +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2646,6 +3958,9 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just @@ -2703,6 +4018,9 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) } , { name = "type-partial" , source = """type +""" + , pretty = """ + ( ( Err, todo ) ) """ , contextualized = Just From 12df300e4a3f5c59e617e7441ebc6a6807bc9841 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Wed, 7 Oct 2020 13:12:45 +0100 Subject: [PATCH 074/103] proper comparison of operator precedence --- src/Elm/Data/Operator.elm | 79 ++++++++++++++++++++++++++ src/Stage/Parse/Contextualize.elm | 92 ++++++++++++++++--------------- 2 files changed, 127 insertions(+), 44 deletions(-) diff --git a/src/Elm/Data/Operator.elm b/src/Elm/Data/Operator.elm index 049cb757..339e2c49 100644 --- a/src/Elm/Data/Operator.elm +++ b/src/Elm/Data/Operator.elm @@ -164,3 +164,82 @@ toString op = Append -> "++" + + +comparePrec : { lhs : OperatorPrecedence, rhs : OperatorPrecedence } -> Order +comparePrec { lhs, rhs } = + case ( lhs, rhs ) of + ( Composition, Composition ) -> + EQ + + ( Composition, _ ) -> + GT + + ( _, Composition ) -> + LT + + ( Exponentiation, Exponentiation ) -> + EQ + + ( Exponentiation, _ ) -> + GT + + ( _, Exponentiation ) -> + LT + + ( Multiplication, Multiplication ) -> + EQ + + ( Multiplication, _ ) -> + GT + + ( _, Multiplication ) -> + LT + + ( Addition, Addition ) -> + EQ + + ( Addition, _ ) -> + GT + + ( _, Addition ) -> + LT + + ( Concatenation, Concatenation ) -> + EQ + + ( Concatenation, _ ) -> + GT + + ( _, Concatenation ) -> + LT + + ( Comparison, Comparison ) -> + EQ + + ( Comparison, _ ) -> + GT + + ( _, Comparison ) -> + LT + + ( AndPrec, AndPrec ) -> + EQ + + ( AndPrec, _ ) -> + GT + + ( _, AndPrec ) -> + LT + + ( OrPrec, OrPrec ) -> + EQ + + ( OrPrec, _ ) -> + GT + + ( _, OrPrec ) -> + LT + + ( Pipe, Pipe ) -> + EQ diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index dc41b300..db7c131f 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -1457,48 +1457,52 @@ appendOperatorTo leaf appendingOp = appendingPrec = Operator.getPrecedence appendingOp in - if parentPrec == appendingPrec then - case Operator.getAssociativity parentPrec of - Operator.ConflictsWithOthers -> - Debug.todo "" - - Operator.ConflictsWithSelf -> - Debug.todo "" - - Operator.RightToLeft -> - ExpressionNestingLeaf_Operator - { op = appendingOp - , lhs = parentRhs - , rhs = Nothing - , parent = - Just - (ExpressionNestingParent_Operator - { op = newParent.op - , lhs = newParent.lhs - , parent = newParent.parent - } - ) - } - |> Ok - - Operator.LeftToRight -> - ExpressionNestingLeaf_Operator - { op = appendingOp - , lhs = Located.merge (Frontend.Operator newParent.op) newParent.lhs parentRhs - , rhs = Nothing - , parent = - Just - (ExpressionNestingParent_Operator - { op = newParent.op - , lhs = newParent.lhs - , parent = newParent.parent - } - ) - } - |> Ok + case Operator.comparePrec { lhs = parentPrec, rhs = appendingPrec } of + EQ -> + case Operator.getAssociativity parentPrec of + Operator.ConflictsWithOthers -> + Debug.todo "" + + Operator.ConflictsWithSelf -> + Debug.todo "" + + Operator.RightToLeft -> + ExpressionNestingLeaf_Operator + { op = appendingOp + , lhs = parentRhs + , rhs = Nothing + , parent = + Just + (ExpressionNestingParent_Operator + { op = newParent.op + , lhs = newParent.lhs + , parent = newParent.parent + } + ) + } + |> Ok + + Operator.LeftToRight -> + ExpressionNestingLeaf_Operator + { op = appendingOp + , lhs = Located.merge (Frontend.Operator newParent.op) newParent.lhs parentRhs + , rhs = Nothing + , parent = + Just + (ExpressionNestingParent_Operator + { op = newParent.op + , lhs = newParent.lhs + , parent = newParent.parent + } + ) + } + |> Ok + + GT -> + Debug.todo "" - else - Debug.todo "" + LT -> + Debug.todo "" ExpressionNestingLeafType_Expr locatedexpr -> ExpressionNestingLeaf_Operator @@ -1583,19 +1587,19 @@ blockFromState state = State_BlockCustomType firstItem -> Debug.todo "handle incomplete block" - State_BlockValueDeclaration (BlockValueDeclaration_Named {}) -> + State_BlockValueDeclaration (BlockValueDeclaration_Named _) -> Error_PartwayThroughValueDeclaration |> Err |> Just - State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns {}) -> + State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns _) -> Error_PartwayThroughValueDeclaration |> Err |> Just State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> case partialExpr of - ExpressionNestingLeaf_Operator {} -> + ExpressionNestingLeaf_Operator _ -> Error_PartwayThroughValueDeclaration |> Err |> Just From ca09eedda739fff9f90169e1d5bdfd0ee65f1043 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Wed, 7 Oct 2020 14:07:21 +0100 Subject: [PATCH 075/103] proper collapsing of operators --- src/Stage/Parse/Contextualize.elm | 33 +++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index db7c131f..01b24e82 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -915,7 +915,7 @@ parserTypeExpr newState prevExpr item = |> PartialResult_Progress |> newState - NestingLeafType_TypeWithArgs {} -> + NestingLeafType_TypeWithArgs _ -> Debug.todo "make state impossible" NestingLeafType_Function { firstInput, otherInputs, output } -> @@ -1074,7 +1074,7 @@ parserExpression newState prevExpr item = ExpressionNestingLeaf_Operator partialExpr -> case partialExpr.rhs of Just rhs -> - Located.merge (Frontend.Operator partialExpr.op) partialExpr.lhs rhs + collapseOperators { op = partialExpr.op, lhs = partialExpr.lhs, parent = partialExpr.parent } rhs |> PartialResult_Done |> newState @@ -1487,14 +1487,7 @@ appendOperatorTo leaf appendingOp = { op = appendingOp , lhs = Located.merge (Frontend.Operator newParent.op) newParent.lhs parentRhs , rhs = Nothing - , parent = - Just - (ExpressionNestingParent_Operator - { op = newParent.op - , lhs = newParent.lhs - , parent = newParent.parent - } - ) + , parent = newParent.parent } |> Ok @@ -1537,6 +1530,26 @@ appendValueExprTo leaf appendingExpr = |> Err +collapseOperators : + { op : Operator + , lhs : Frontend.LocatedExpr + , parent : Maybe ExpressionNestingParent + } + -> Frontend.LocatedExpr + -> Frontend.LocatedExpr +collapseOperators opData rhs = + let + expr = + Located.merge (Frontend.Operator opData.op) opData.lhs rhs + in + case opData.parent of + Just (ExpressionNestingParent_Operator parentData) -> + collapseOperators parentData expr + + Nothing -> + expr + + blockFromState : State -> Maybe (Result Error Block) blockFromState state = case state of From a5c948ba30db40462e70f63d9f1c6871a7fc1829 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Wed, 7 Oct 2020 14:13:13 +0100 Subject: [PATCH 076/103] parse operators with different precedence --- parser-tests/Update.elm | 22 +- .../expression-int-multiply-and-add | 13 + src/Stage/Parse/Contextualize.elm | 59 +- src/Stage/Parse/Lexer.elm | 2 + tests/ParserLexerTestCases.elm | 612 ++++++++++++++++++ 5 files changed, 679 insertions(+), 29 deletions(-) create mode 100644 parser-tests/snippets/should-parse/expression-int-multiply-and-add diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 3dd6ffbe..4cc7ad43 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -90,21 +90,21 @@ init snippets = ) c ) - ++ """ + ) + ++ """ \"\"\" , contextualized =""" - ++ (Debug.toString contextualized - |> preFormatElmCode - |> resolveCustomTypeConstructors - ) - ++ """ + ++ (Debug.toString contextualized + |> preFormatElmCode + |> resolveCustomTypeConstructors + ) + ++ """ , lexed = """ - ++ (Debug.toString lexed - |> preFormatElmCode - ) - ++ """ - }""" + ++ (Debug.toString lexed + |> preFormatElmCode ) + ++ """ + }""" ) snippets rlexed diff --git a/parser-tests/snippets/should-parse/expression-int-multiply-and-add b/parser-tests/snippets/should-parse/expression-int-multiply-and-add new file mode 100644 index 00000000..f694f9e2 --- /dev/null +++ b/parser-tests/snippets/should-parse/expression-int-multiply-and-add @@ -0,0 +1,13 @@ +a = 5 * 5 + 6 +a1 = 7 + 5 * 5 +a11 = 7 + 5 * 5 + 6 +a2 = 100 + 5 * 5 +a3 = 345 * 2234 + 2342 * 1010 + + +b = 78 + 5 * 2 / 4 * 5 +b1 = 78 * 5 * 2 / 4 - 5 +b2 = 78 * 5 - 2 / 4 * 5 +b3 = 78 - 5 + 2 / 4 * 5 +b4 = 78 / 5 / 2 / 4 + 5 + diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 01b24e82..e0661472 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -1443,23 +1443,23 @@ closeRecord { firstEntries, lastEntry } parents = appendOperatorTo : ExpressionNestingLeaf -> Operator -> Result Error ExpressionNestingLeaf appendOperatorTo leaf appendingOp = case leaf of - ExpressionNestingLeaf_Operator newParent -> - case newParent.rhs of + ExpressionNestingLeaf_Operator oldLeaf -> + case oldLeaf.rhs of Nothing -> Error_InvalidToken Expecting_Unknown |> Err Just parentRhs -> let - parentPrec = - Operator.getPrecedence newParent.op + prevPrec = + Operator.getPrecedence oldLeaf.op appendingPrec = Operator.getPrecedence appendingOp in - case Operator.comparePrec { lhs = parentPrec, rhs = appendingPrec } of + case Operator.comparePrec { lhs = prevPrec, rhs = appendingPrec } of EQ -> - case Operator.getAssociativity parentPrec of + case Operator.getAssociativity prevPrec of Operator.ConflictsWithOthers -> Debug.todo "" @@ -1474,9 +1474,9 @@ appendOperatorTo leaf appendingOp = , parent = Just (ExpressionNestingParent_Operator - { op = newParent.op - , lhs = newParent.lhs - , parent = newParent.parent + { op = oldLeaf.op + , lhs = oldLeaf.lhs + , parent = oldLeaf.parent } ) } @@ -1485,17 +1485,40 @@ appendOperatorTo leaf appendingOp = Operator.LeftToRight -> ExpressionNestingLeaf_Operator { op = appendingOp - , lhs = Located.merge (Frontend.Operator newParent.op) newParent.lhs parentRhs + , lhs = Located.merge (Frontend.Operator oldLeaf.op) oldLeaf.lhs parentRhs , rhs = Nothing - , parent = newParent.parent + , parent = oldLeaf.parent } |> Ok GT -> - Debug.todo "" + -- Prev operator has higher precedence than the appending operator. We bundle the previous + -- nesting context into the child's lhs. + ExpressionNestingLeaf_Operator + { op = appendingOp + , lhs = Located.merge (Frontend.Operator oldLeaf.op) oldLeaf.lhs parentRhs + , rhs = Nothing + , parent = oldLeaf.parent + } + |> Ok LT -> - Debug.todo "" + -- Prev operator has lower precedence than the appending operator. We steal the previous + -- operators's rhs and start a new layer of nesting with the previous rhs as our new lhs. + ExpressionNestingLeaf_Operator + { op = appendingOp + , lhs = parentRhs + , rhs = Nothing + , parent = + Just + (ExpressionNestingParent_Operator + { op = oldLeaf.op + , lhs = oldLeaf.lhs + , parent = oldLeaf.parent + } + ) + } + |> Ok ExpressionNestingLeafType_Expr locatedexpr -> ExpressionNestingLeaf_Operator @@ -1510,14 +1533,14 @@ appendOperatorTo leaf appendingOp = appendValueExprTo : ExpressionNestingLeaf -> Frontend.LocatedExpr -> Result Error ExpressionNestingLeaf appendValueExprTo leaf appendingExpr = case leaf of - ExpressionNestingLeaf_Operator newParent -> - case newParent.rhs of + ExpressionNestingLeaf_Operator oldLeaf -> + case oldLeaf.rhs of Nothing -> ExpressionNestingLeaf_Operator - { op = newParent.op - , lhs = newParent.lhs + { op = oldLeaf.op + , lhs = oldLeaf.lhs , rhs = Just appendingExpr - , parent = newParent.parent + , parent = oldLeaf.parent } |> Ok diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 707f593b..7114ebdf 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -212,6 +212,8 @@ parser = |> P.map (\count -> Whitespace (count + 1)) , newlinesParser |> P.map (\( emptyLines, indentation ) -> Newlines emptyLines indentation) + , P.getChompedString (P.chompIf (\_ -> True) ExpectingAnything) + |> P.map (\s -> Invalid s) ] |> List.map (located >> P.map (\t -> P.Loop (t :: reversed))) ) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 23e2df07..118f01a3 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -299,6 +299,618 @@ b = 78 * 5 * 2 / 4 * 5 , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Newlines [] 0) ] } + , { name = "expression-int-multiply-and-add" + , source = """a = 5 * 5 + 6 +a1 = 7 + 5 * 5 +a11 = 7 + 5 * 5 + 6 +a2 = 100 + 5 * 5 +a3 = 345 * 2234 + 2342 * 1010 + + +b = 78 + 5 * 2 / 4 * 5 +b1 = 78 * 5 * 2 / 4 - 5 +b2 = 78 * 5 - 2 / 4 * 5 +b3 = 78 - 5 + 2 / 4 * 5 +b4 = 78 / 5 / 2 / 4 + 5 + +""" + , pretty = """ + ( ( Ok + , ( ValueDeclaration + , ( name, a ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 5 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 6 ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, a1 ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Int, 7 ) + ) + , ( rhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 5 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, a11 ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Int, 7 ) + ) + , ( rhs + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 5 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 6 ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, a2 ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Int, 100 ) + ) + , ( rhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 5 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, a3 ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 345 ) + ) + , ( rhs + , ( Int, 2234 ) + ) + ) + ) + ) + , ( rhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 2342 ) + ) + , ( rhs + , ( Int, 1010 ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Int, 78 ) + ) + , ( rhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Operator + , ( ( op, / ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 5 ) + ) + , ( rhs + , ( Int, 2 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 4 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b1 ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, - ) + , ( lhs + , ( Operator + , ( ( op, / ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 78 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 2 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 4 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b2 ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, - ) + , ( lhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Int, 78 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Operator + , ( ( op, / ) + , ( lhs + , ( Int, 2 ) + ) + , ( rhs + , ( Int, 4 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b3 ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, - ) + , ( lhs + , ( Int, 78 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Operator + , ( ( op, * ) + , ( lhs + , ( Operator + , ( ( op, / ) + , ( lhs + , ( Int, 2 ) + ) + , ( rhs + , ( Int, 4 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + , ( Ok + , ( ValueDeclaration + , ( name, b4 ) + , ( args, () ) + , ( valueExpr__ + , ( Operator + , ( ( op, + ) + , ( lhs + , ( Operator + , ( ( op, / ) + , ( lhs + , ( Operator + , ( ( op, / ) + , ( lhs + , ( Operator + , ( ( op, / ) + , ( lhs + , ( Int, 78 ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 2 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 4 ) + ) + ) + ) + ) + , ( rhs + , ( Int, 5 ) + ) + ) + ) + ) + ) + ) + ) +""" + , contextualized = + Just + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 14, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Add (Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Multiply (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5)))) (Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Frontend.Int 6))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (ValueOrFunctionOrGenericType "a1"), valueExpr__ = Located { end = { col = 16, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Operator Add (Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Int 7)) (Located { end = { col = 16, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Operator Multiply (Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Int 5)) (Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "a11"), valueExpr__ = Located { end = { col = 21, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Operator Add (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Int 7)) (Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator Add (Located { end = { col = 17, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator Multiply (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Int 5)) (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Frontend.Int 6))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (ValueOrFunctionOrGenericType "a2"), valueExpr__ = Located { end = { col = 18, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Operator Add (Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Int 100)) (Located { end = { col = 18, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Operator Multiply (Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Int 5)) (Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (ValueOrFunctionOrGenericType "a3"), valueExpr__ = Located { end = { col = 30, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator Add (Located { end = { col = 16, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator Multiply (Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Int 345)) (Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (Frontend.Int 2234)))) (Located { end = { col = 30, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Operator Multiply (Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Int 2342)) (Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Frontend.Int 1010))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Operator Add (Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Int 78)) (Located { end = { col = 23, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator Multiply (Located { end = { col = 19, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator Divide (Located { end = { col = 15, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator Multiply (Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Int 5)) (Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (ValueOrFunctionOrGenericType "b1"), valueExpr__ = Located { end = { col = 24, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator Subtract (Located { end = { col = 20, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator Divide (Located { end = { col = 16, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator Multiply (Located { end = { col = 12, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator Multiply (Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (ValueOrFunctionOrGenericType "b2"), valueExpr__ = Located { end = { col = 24, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator Subtract (Located { end = { col = 12, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator Multiply (Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator Multiply (Located { end = { col = 20, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator Divide (Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (ValueOrFunctionOrGenericType "b3"), valueExpr__ = Located { end = { col = 24, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator Add (Located { end = { col = 12, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator Subtract (Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator Multiply (Located { end = { col = 20, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator Divide (Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (ValueOrFunctionOrGenericType "b4"), valueExpr__ = Located { end = { col = 24, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator Add (Located { end = { col = 20, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator Divide (Located { end = { col = 16, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator Divide (Located { end = { col = 12, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator Divide (Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Frontend.Int 5))) }) + ] + , lexed = + Ok + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Whitespace 1) + , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Sigil (Operator Multiply)) + , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Whitespace 1) + , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5") + , Located { end = { col = 11, row = 1 }, start = { col = 10, row = 1 } } (Whitespace 1) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Sigil (Operator Add)) + , Located { end = { col = 13, row = 1 }, start = { col = 12, row = 1 } } (Whitespace 1) + , Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (NumericLiteral "6") + , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) + , Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (Token "a1") + , Located { end = { col = 4, row = 2 }, start = { col = 3, row = 2 } } (Whitespace 1) + , Located { end = { col = 5, row = 2 }, start = { col = 4, row = 2 } } (Sigil Assign) + , Located { end = { col = 7, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 2) + , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (NumericLiteral "7") + , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Whitespace 1) + , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Sigil (Operator Add)) + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 1) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (NumericLiteral "5") + , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Whitespace 1) + , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Sigil (Operator Multiply)) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 3 }, start = { col = 16, row = 2 } } (Newlines [] 0) + , Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (Token "a11") + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Assign) + , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 2) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (NumericLiteral "7") + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Sigil (Operator Add)) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (NumericLiteral "5") + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Whitespace 1) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Sigil (Operator Multiply)) + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Whitespace 1) + , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (NumericLiteral "5") + , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Whitespace 1) + , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Sigil (Operator Add)) + , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Whitespace 1) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (NumericLiteral "6") + , Located { end = { col = 1, row = 4 }, start = { col = 21, row = 3 } } (Newlines [] 0) + , Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (Token "a2") + , Located { end = { col = 4, row = 4 }, start = { col = 3, row = 4 } } (Whitespace 1) + , Located { end = { col = 5, row = 4 }, start = { col = 4, row = 4 } } (Sigil Assign) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Whitespace 1) + , Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (NumericLiteral "100") + , Located { end = { col = 11, row = 4 }, start = { col = 9, row = 4 } } (Whitespace 2) + , Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } (Sigil (Operator Add)) + , Located { end = { col = 13, row = 4 }, start = { col = 12, row = 4 } } (Whitespace 1) + , Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (NumericLiteral "5") + , Located { end = { col = 15, row = 4 }, start = { col = 14, row = 4 } } (Whitespace 1) + , Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } (Sigil (Operator Multiply)) + , Located { end = { col = 17, row = 4 }, start = { col = 16, row = 4 } } (Whitespace 1) + , Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 5 }, start = { col = 18, row = 4 } } (Newlines [] 0) + , Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (Token "a3") + , Located { end = { col = 4, row = 5 }, start = { col = 3, row = 5 } } (Whitespace 1) + , Located { end = { col = 5, row = 5 }, start = { col = 4, row = 5 } } (Sigil Assign) + , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) + , Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (NumericLiteral "345") + , Located { end = { col = 10, row = 5 }, start = { col = 9, row = 5 } } (Whitespace 1) + , Located { end = { col = 11, row = 5 }, start = { col = 10, row = 5 } } (Sigil (Operator Multiply)) + , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) + , Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (NumericLiteral "2234") + , Located { end = { col = 17, row = 5 }, start = { col = 16, row = 5 } } (Whitespace 1) + , Located { end = { col = 18, row = 5 }, start = { col = 17, row = 5 } } (Sigil (Operator Add)) + , Located { end = { col = 19, row = 5 }, start = { col = 18, row = 5 } } (Whitespace 1) + , Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (NumericLiteral "2342") + , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) + , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Sigil (Operator Multiply)) + , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Whitespace 1) + , Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (NumericLiteral "1010") + , Located { end = { col = 1, row = 8 }, start = { col = 30, row = 5 } } + (Newlines + [ 0 + , 0 + ] + 0 + ) + , Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (Token "b") + , Located { end = { col = 3, row = 8 }, start = { col = 2, row = 8 } } (Whitespace 1) + , Located { end = { col = 4, row = 8 }, start = { col = 3, row = 8 } } (Sigil Assign) + , Located { end = { col = 5, row = 8 }, start = { col = 4, row = 8 } } (Whitespace 1) + , Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (NumericLiteral "78") + , Located { end = { col = 8, row = 8 }, start = { col = 7, row = 8 } } (Whitespace 1) + , Located { end = { col = 9, row = 8 }, start = { col = 8, row = 8 } } (Sigil (Operator Add)) + , Located { end = { col = 10, row = 8 }, start = { col = 9, row = 8 } } (Whitespace 1) + , Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (NumericLiteral "5") + , Located { end = { col = 12, row = 8 }, start = { col = 11, row = 8 } } (Whitespace 1) + , Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } (Sigil (Operator Multiply)) + , Located { end = { col = 14, row = 8 }, start = { col = 13, row = 8 } } (Whitespace 1) + , Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (NumericLiteral "2") + , Located { end = { col = 16, row = 8 }, start = { col = 15, row = 8 } } (Whitespace 1) + , Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } (Sigil (Operator Divide)) + , Located { end = { col = 18, row = 8 }, start = { col = 17, row = 8 } } (Whitespace 1) + , Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (NumericLiteral "4") + , Located { end = { col = 20, row = 8 }, start = { col = 19, row = 8 } } (Whitespace 1) + , Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } (Sigil (Operator Multiply)) + , Located { end = { col = 22, row = 8 }, start = { col = 21, row = 8 } } (Whitespace 1) + , Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 9 }, start = { col = 23, row = 8 } } (Newlines [] 0) + , Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (Token "b1") + , Located { end = { col = 4, row = 9 }, start = { col = 3, row = 9 } } (Whitespace 1) + , Located { end = { col = 5, row = 9 }, start = { col = 4, row = 9 } } (Sigil Assign) + , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Whitespace 1) + , Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (NumericLiteral "78") + , Located { end = { col = 9, row = 9 }, start = { col = 8, row = 9 } } (Whitespace 1) + , Located { end = { col = 10, row = 9 }, start = { col = 9, row = 9 } } (Sigil (Operator Multiply)) + , Located { end = { col = 11, row = 9 }, start = { col = 10, row = 9 } } (Whitespace 1) + , Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (NumericLiteral "5") + , Located { end = { col = 13, row = 9 }, start = { col = 12, row = 9 } } (Whitespace 1) + , Located { end = { col = 14, row = 9 }, start = { col = 13, row = 9 } } (Sigil (Operator Multiply)) + , Located { end = { col = 15, row = 9 }, start = { col = 14, row = 9 } } (Whitespace 1) + , Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (NumericLiteral "2") + , Located { end = { col = 17, row = 9 }, start = { col = 16, row = 9 } } (Whitespace 1) + , Located { end = { col = 18, row = 9 }, start = { col = 17, row = 9 } } (Sigil (Operator Divide)) + , Located { end = { col = 19, row = 9 }, start = { col = 18, row = 9 } } (Whitespace 1) + , Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (NumericLiteral "4") + , Located { end = { col = 21, row = 9 }, start = { col = 20, row = 9 } } (Whitespace 1) + , Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } (Sigil (Operator Subtract)) + , Located { end = { col = 23, row = 9 }, start = { col = 22, row = 9 } } (Whitespace 1) + , Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 10 }, start = { col = 24, row = 9 } } (Newlines [] 0) + , Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (Token "b2") + , Located { end = { col = 4, row = 10 }, start = { col = 3, row = 10 } } (Whitespace 1) + , Located { end = { col = 5, row = 10 }, start = { col = 4, row = 10 } } (Sigil Assign) + , Located { end = { col = 6, row = 10 }, start = { col = 5, row = 10 } } (Whitespace 1) + , Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (NumericLiteral "78") + , Located { end = { col = 9, row = 10 }, start = { col = 8, row = 10 } } (Whitespace 1) + , Located { end = { col = 10, row = 10 }, start = { col = 9, row = 10 } } (Sigil (Operator Multiply)) + , Located { end = { col = 11, row = 10 }, start = { col = 10, row = 10 } } (Whitespace 1) + , Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (NumericLiteral "5") + , Located { end = { col = 13, row = 10 }, start = { col = 12, row = 10 } } (Whitespace 1) + , Located { end = { col = 14, row = 10 }, start = { col = 13, row = 10 } } (Sigil (Operator Subtract)) + , Located { end = { col = 15, row = 10 }, start = { col = 14, row = 10 } } (Whitespace 1) + , Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (NumericLiteral "2") + , Located { end = { col = 17, row = 10 }, start = { col = 16, row = 10 } } (Whitespace 1) + , Located { end = { col = 18, row = 10 }, start = { col = 17, row = 10 } } (Sigil (Operator Divide)) + , Located { end = { col = 19, row = 10 }, start = { col = 18, row = 10 } } (Whitespace 1) + , Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (NumericLiteral "4") + , Located { end = { col = 21, row = 10 }, start = { col = 20, row = 10 } } (Whitespace 1) + , Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } (Sigil (Operator Multiply)) + , Located { end = { col = 23, row = 10 }, start = { col = 22, row = 10 } } (Whitespace 1) + , Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 11 }, start = { col = 24, row = 10 } } (Newlines [] 0) + , Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (Token "b3") + , Located { end = { col = 4, row = 11 }, start = { col = 3, row = 11 } } (Whitespace 1) + , Located { end = { col = 5, row = 11 }, start = { col = 4, row = 11 } } (Sigil Assign) + , Located { end = { col = 6, row = 11 }, start = { col = 5, row = 11 } } (Whitespace 1) + , Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (NumericLiteral "78") + , Located { end = { col = 9, row = 11 }, start = { col = 8, row = 11 } } (Whitespace 1) + , Located { end = { col = 10, row = 11 }, start = { col = 9, row = 11 } } (Sigil (Operator Subtract)) + , Located { end = { col = 11, row = 11 }, start = { col = 10, row = 11 } } (Whitespace 1) + , Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (NumericLiteral "5") + , Located { end = { col = 13, row = 11 }, start = { col = 12, row = 11 } } (Whitespace 1) + , Located { end = { col = 14, row = 11 }, start = { col = 13, row = 11 } } (Sigil (Operator Add)) + , Located { end = { col = 15, row = 11 }, start = { col = 14, row = 11 } } (Whitespace 1) + , Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (NumericLiteral "2") + , Located { end = { col = 17, row = 11 }, start = { col = 16, row = 11 } } (Whitespace 1) + , Located { end = { col = 18, row = 11 }, start = { col = 17, row = 11 } } (Sigil (Operator Divide)) + , Located { end = { col = 19, row = 11 }, start = { col = 18, row = 11 } } (Whitespace 1) + , Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (NumericLiteral "4") + , Located { end = { col = 21, row = 11 }, start = { col = 20, row = 11 } } (Whitespace 1) + , Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } (Sigil (Operator Multiply)) + , Located { end = { col = 23, row = 11 }, start = { col = 22, row = 11 } } (Whitespace 1) + , Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 12 }, start = { col = 24, row = 11 } } (Newlines [] 0) + , Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (Token "b4") + , Located { end = { col = 4, row = 12 }, start = { col = 3, row = 12 } } (Whitespace 1) + , Located { end = { col = 5, row = 12 }, start = { col = 4, row = 12 } } (Sigil Assign) + , Located { end = { col = 6, row = 12 }, start = { col = 5, row = 12 } } (Whitespace 1) + , Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (NumericLiteral "78") + , Located { end = { col = 9, row = 12 }, start = { col = 8, row = 12 } } (Whitespace 1) + , Located { end = { col = 10, row = 12 }, start = { col = 9, row = 12 } } (Sigil (Operator Divide)) + , Located { end = { col = 11, row = 12 }, start = { col = 10, row = 12 } } (Whitespace 1) + , Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (NumericLiteral "5") + , Located { end = { col = 13, row = 12 }, start = { col = 12, row = 12 } } (Whitespace 1) + , Located { end = { col = 14, row = 12 }, start = { col = 13, row = 12 } } (Sigil (Operator Divide)) + , Located { end = { col = 15, row = 12 }, start = { col = 14, row = 12 } } (Whitespace 1) + , Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (NumericLiteral "2") + , Located { end = { col = 17, row = 12 }, start = { col = 16, row = 12 } } (Whitespace 1) + , Located { end = { col = 18, row = 12 }, start = { col = 17, row = 12 } } (Sigil (Operator Divide)) + , Located { end = { col = 19, row = 12 }, start = { col = 18, row = 12 } } (Whitespace 1) + , Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (NumericLiteral "4") + , Located { end = { col = 21, row = 12 }, start = { col = 20, row = 12 } } (Whitespace 1) + , Located { end = { col = 22, row = 12 }, start = { col = 21, row = 12 } } (Sigil (Operator Add)) + , Located { end = { col = 23, row = 12 }, start = { col = 22, row = 12 } } (Whitespace 1) + , Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (NumericLiteral "5") + , Located { end = { col = 1, row = 14 }, start = { col = 24, row = 12 } } + (Newlines + [ 0 + ] + 0 + ) + ] + } , { name = "expression-int-subtract" , source = """a = 5 - 5 From 878d58d7e020d391e9366bfd639ef7d82b9e84ec Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sun, 18 Oct 2020 18:59:41 +0100 Subject: [PATCH 077/103] add locations to operators --- src/Elm/AST/Canonical.elm | 6 ++-- src/Elm/AST/Frontend.elm | 4 +-- src/Elm/AST/Typed.elm | 4 +-- src/Elm/Data/Located.elm | 13 +++++++-- src/Stage/Emit/JavaScript.elm | 19 +++++++------ src/Stage/Emit/JsonAST.elm | 31 +++++++++++---------- src/Stage/InferTypes/GenerateEquations.elm | 2 +- src/Stage/Optimize.elm | 27 ++++++++++++------ src/Stage/Parse/Contextualize.elm | 32 +++++++++++++++------- src/Stage/Parse/Parser.elm | 6 ++-- src/Stage/Parse/Pretty.elm | 2 +- tests/DesugarTest.elm | 2 +- tests/EmitJsonTest.elm | 7 +++-- tests/EmitTest.elm | 30 +++++++++++++------- tests/OptimizeTest.elm | 16 +++++++---- tests/ParserLexerTestCases.elm | 32 +++++++++++----------- tests/TestHelpers.elm | 1 + 17 files changed, 144 insertions(+), 90 deletions(-) diff --git a/src/Elm/AST/Canonical.elm b/src/Elm/AST/Canonical.elm index 18887a51..d56785a4 100644 --- a/src/Elm/AST/Canonical.elm +++ b/src/Elm/AST/Canonical.elm @@ -74,7 +74,7 @@ type Expr | Bool Bool | Var { module_ : ModuleName, name : VarName } | Argument VarName - | Operator Operator LocatedExpr LocatedExpr + | Operator (Located Operator) LocatedExpr LocatedExpr | Lambda { argument : VarName, body : LocatedExpr } | Call { fn : LocatedExpr, argument : LocatedExpr } | If { test : LocatedExpr, then_ : LocatedExpr, else_ : LocatedExpr } @@ -142,7 +142,7 @@ unwrap expr = Operator op e1 e2 -> Unwrapped.Operator - op + (Located.unwrap op) (f e1) (f e2) @@ -297,7 +297,7 @@ fromUnwrapped expr = Unwrapped.Operator op e1 e2 -> Operator - op + (Located.located Located.dummyRegion op) (f e1) (f e2) diff --git a/src/Elm/AST/Frontend.elm b/src/Elm/AST/Frontend.elm index fd0e3d25..05cf12ec 100644 --- a/src/Elm/AST/Frontend.elm +++ b/src/Elm/AST/Frontend.elm @@ -61,7 +61,7 @@ type Expr | Var { qualifiedness : PossiblyQualified, name : VarName } | -- Both lambda arguments and let..in bindings Argument VarName - | Operator Operator LocatedExpr LocatedExpr + | Operator (Located Operator) LocatedExpr LocatedExpr | Lambda { arguments : List VarName, body : LocatedExpr } | Call { fn : LocatedExpr, argument : LocatedExpr } | If { test : LocatedExpr, then_ : LocatedExpr, else_ : LocatedExpr } @@ -233,7 +233,7 @@ unwrap expr = Operator op e1 e2 -> Unwrapped.Operator - op + (Located.unwrap op) (unwrap e1) (unwrap e2) diff --git a/src/Elm/AST/Typed.elm b/src/Elm/AST/Typed.elm index 32ec1828..f853444d 100644 --- a/src/Elm/AST/Typed.elm +++ b/src/Elm/AST/Typed.elm @@ -73,7 +73,7 @@ type Expr_ | Bool Bool | Var { module_ : ModuleName, name : VarName } | Argument VarName - | Operator Operator LocatedExpr LocatedExpr + | Operator (Located Operator) LocatedExpr LocatedExpr | Lambda { argument : VarName, body : LocatedExpr } | Call { fn : LocatedExpr, argument : LocatedExpr } | If { test : LocatedExpr, then_ : LocatedExpr, else_ : LocatedExpr } @@ -373,7 +373,7 @@ unwrap expr = Operator op e1 e2 -> Unwrapped.Operator - op + (Located.unwrap op) (f e1) (f e2) diff --git a/src/Elm/Data/Located.elm b/src/Elm/Data/Located.elm index 44ce3aa0..f02b4c7d 100644 --- a/src/Elm/Data/Located.elm +++ b/src/Elm/Data/Located.elm @@ -1,6 +1,6 @@ module Elm.Data.Located exposing ( Located(..), Region, Position - , located, unwrap, getRegion, map, merge, replaceWith + , located, unwrap, getRegion, map, merge, merge3, replaceWith , dummyRegion, mergeRegions, regionToComparable , positionToComparable, comparePosition ) @@ -18,7 +18,7 @@ Useful for error messages, but hopefully for stuff like source maps etc. too. # Located -@docs located, unwrap, getRegion, map, merge, replaceWith +@docs located, unwrap, getRegion, map, merge, merge3, replaceWith # Region @@ -97,6 +97,15 @@ merge fn l1 l2 = (fn l1 l2) +{-| Merge the regions of the three wrappers. +-} +merge3 : (Located a -> Located b -> Located c -> d) -> Located a -> Located b -> Located c -> Located d +merge3 fn l1 l2 l3 = + Located + (mergeRegions (mergeRegions (getRegion l1) (getRegion l2)) (getRegion l3)) + (fn l1 l2 l3) + + {-| Merge the regions: the resulting region is always bigger or equal than the input regions. diff --git a/src/Stage/Emit/JavaScript.elm b/src/Stage/Emit/JavaScript.elm index a1a90fbf..2944a52b 100644 --- a/src/Stage/Emit/JavaScript.elm +++ b/src/Stage/Emit/JavaScript.elm @@ -23,6 +23,7 @@ import Elm.Compiler.Error exposing (Error(..)) import Elm.Data.Declaration exposing (Declaration, DeclarationBody(..)) import Elm.Data.FileContents exposing (FileContents) import Elm.Data.FilePath exposing (FilePath) +import Elm.Data.Located as Located import Elm.Data.Operator as Operator exposing (Operator) import Elm.Data.Project exposing (Project) import Elm.Data.Qualifiedness exposing (Qualified) @@ -76,17 +77,19 @@ emitExpr located = Argument argument -> mangleVarName argument - Operator Operator.Add e1 e2 -> - "(" ++ emitExpr e1 ++ " + " ++ emitExpr e2 ++ ")" + Operator op e1 e2 -> + case Located.unwrap op of + Operator.Add -> + "(" ++ emitExpr e1 ++ " + " ++ emitExpr e2 ++ ")" - Operator Operator.Cons e1 e2 -> - "[" ++ emitExpr e1 ++ "].concat(" ++ emitExpr e2 ++ ")" + Operator.Cons -> + "[" ++ emitExpr e1 ++ "].concat(" ++ emitExpr e2 ++ ")" - Operator Operator.Append e1 e2 -> - emitExpr e1 ++ ".concat(" ++ emitExpr e2 ++ ")" + Operator.Append -> + emitExpr e1 ++ ".concat(" ++ emitExpr e2 ++ ")" - Operator _ _ _ -> - Debug.todo "emit js for other operators" + _ -> + Debug.todo "emit js for other operators" Lambda { argument, body } -> -- TODO are these parentheses needed? diff --git a/src/Stage/Emit/JsonAST.elm b/src/Stage/Emit/JsonAST.elm index 88f016b2..4f334d31 100644 --- a/src/Stage/Emit/JsonAST.elm +++ b/src/Stage/Emit/JsonAST.elm @@ -25,6 +25,7 @@ import Elm.Compiler.Error exposing (Error(..)) import Elm.Data.Declaration exposing (Declaration, DeclarationBody(..)) import Elm.Data.FileContents exposing (FileContents) import Elm.Data.FilePath exposing (FilePath) +import Elm.Data.Located as Located import Elm.Data.Operator as Operator exposing (Operator) import Elm.Data.Project exposing (Project) import Elm.Data.Qualifiedness exposing (Qualified) @@ -82,20 +83,22 @@ emitExpr located = encode "arg" [ ( "name", Encode.string argument ) ] -- TODO(harry): Change this to `{ 'op': '+', lhs: { ... }, rhs: { ... } }` - Operator Operator.Add e1 e2 -> - encode "plus" - [ ( "e1", emitExpr e1 ) - , ( "e2", emitExpr e2 ) - ] - - Operator Operator.Cons e1 e2 -> - encode "cons" - [ ( "e1", emitExpr e1 ) - , ( "e2", emitExpr e2 ) - ] - - Operator _ e1 e2 -> - Debug.todo "encode other operators into json" + Operator op e1 e2 -> + case Located.unwrap op of + Operator.Add -> + encode "plus" + [ ( "e1", emitExpr e1 ) + , ( "e2", emitExpr e2 ) + ] + + Operator.Cons -> + encode "cons" + [ ( "e1", emitExpr e1 ) + , ( "e2", emitExpr e2 ) + ] + + _ -> + Debug.todo "encode other operators into json" Lambda { argument, body } -> encode "lambda" diff --git a/src/Stage/InferTypes/GenerateEquations.elm b/src/Stage/InferTypes/GenerateEquations.elm index 15889abf..efc87415 100644 --- a/src/Stage/InferTypes/GenerateEquations.elm +++ b/src/Stage/InferTypes/GenerateEquations.elm @@ -108,7 +108,7 @@ generateEquations currentId located = generateEquations id1 right opEquations = - case op of + case Located.unwrap op of Operator.Add -> [ equals leftType (Type Int) -- type of `a` is Int , equals rightType (Type Int) -- type of `b` is Int diff --git a/src/Stage/Optimize.elm b/src/Stage/Optimize.elm index 70dd8f15..29b9d861 100644 --- a/src/Stage/Optimize.elm +++ b/src/Stage/Optimize.elm @@ -6,6 +6,7 @@ module Stage.Optimize exposing ) import Elm.AST.Typed as Typed +import Elm.Data.Located as Located import Elm.Data.Operator as Operator import Elm.Data.Project exposing (Project) import Stage.Optimize.Boilerplate as Boilerplate @@ -39,10 +40,15 @@ defaultOptimizations = optimizePlus : Typed.LocatedExpr -> Maybe Typed.LocatedExpr optimizePlus located = case Typed.getExpr located of - Typed.Operator Operator.Add l r -> - case ( Typed.getExpr l, Typed.getExpr r ) of - ( Typed.Int left, Typed.Int right ) -> - Just (Typed.setExpr (Typed.Int (left + right)) r) + Typed.Operator op l r -> + case Located.unwrap op of + Operator.Add -> + case ( Typed.getExpr l, Typed.getExpr r ) of + ( Typed.Int left, Typed.Int right ) -> + Just (Typed.setExpr (Typed.Int (left + right)) r) + + _ -> + Nothing _ -> Nothing @@ -54,10 +60,15 @@ optimizePlus located = optimizeCons : Typed.LocatedExpr -> Maybe Typed.LocatedExpr optimizeCons located = case Typed.getExpr located of - Typed.Operator Operator.Cons l r -> - case Typed.getExpr r of - Typed.List list -> - Just (Typed.setExpr (Typed.List (l :: list)) r) + Typed.Operator op l r -> + case Located.unwrap op of + Operator.Cons -> + case Typed.getExpr r of + Typed.List list -> + Just (Typed.setExpr (Typed.List (l :: list)) r) + + _ -> + Nothing _ -> Nothing diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index e0661472..4adf8637 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -233,7 +233,7 @@ type alias TypeExpressionResult = type ExpressionNestingParent = ExpressionNestingParent_Operator - { op : Operator + { op : Located Operator , lhs : Frontend.LocatedExpr , parent : Maybe ExpressionNestingParent } @@ -241,7 +241,7 @@ type ExpressionNestingParent type ExpressionNestingLeaf = ExpressionNestingLeaf_Operator - { op : Operator + { op : Located Operator , lhs : Frontend.LocatedExpr , rhs : Maybe Frontend.LocatedExpr , parent : Maybe ExpressionNestingParent @@ -280,6 +280,7 @@ type Error (List (ConcreteType PossiblyQualified)) -- Expressions -- | Error_InvalidNumericLiteral String + | Error_ConflictingOperators (Located Operator) (Located Operator) -- Incomplete parsing -- | Error_PartwayThroughTypeAlias | Error_PartwayThroughValueDeclaration @@ -1054,7 +1055,7 @@ parserExpression newState prevExpr item = in case Located.unwrap item of Lexer.Sigil (Lexer.Operator op) -> - appendOperatorTo prevExpr op + appendOperatorTo prevExpr (withCorrectLocation op) |> partialExpressionToParseResult newState Lexer.NumericLiteral str -> @@ -1440,7 +1441,7 @@ closeRecord { firstEntries, lastEntry } parents = -- Value expression helpers -appendOperatorTo : ExpressionNestingLeaf -> Operator -> Result Error ExpressionNestingLeaf +appendOperatorTo : ExpressionNestingLeaf -> Located Operator -> Result Error ExpressionNestingLeaf appendOperatorTo leaf appendingOp = case leaf of ExpressionNestingLeaf_Operator oldLeaf -> @@ -1452,10 +1453,10 @@ appendOperatorTo leaf appendingOp = Just parentRhs -> let prevPrec = - Operator.getPrecedence oldLeaf.op + Operator.getPrecedence (Located.unwrap oldLeaf.op) appendingPrec = - Operator.getPrecedence appendingOp + Operator.getPrecedence (Located.unwrap appendingOp) in case Operator.comparePrec { lhs = prevPrec, rhs = appendingPrec } of EQ -> @@ -1464,7 +1465,8 @@ appendOperatorTo leaf appendingOp = Debug.todo "" Operator.ConflictsWithSelf -> - Debug.todo "" + Error_ConflictingOperators oldLeaf.op appendingOp + |> Err Operator.RightToLeft -> ExpressionNestingLeaf_Operator @@ -1496,7 +1498,17 @@ appendOperatorTo leaf appendingOp = -- nesting context into the child's lhs. ExpressionNestingLeaf_Operator { op = appendingOp - , lhs = Located.merge (Frontend.Operator oldLeaf.op) oldLeaf.lhs parentRhs + , lhs = + Located.merge + (\op args -> + let + ( lhs, rhs ) = + Located.unwrap args + in + Frontend.Operator op lhs rhs + ) + oldLeaf.op + (Located.merge Tuple.pair oldLeaf.lhs parentRhs) , rhs = Nothing , parent = oldLeaf.parent } @@ -1504,7 +1516,7 @@ appendOperatorTo leaf appendingOp = LT -> -- Prev operator has lower precedence than the appending operator. We steal the previous - -- operators's rhs and start a new layer of nesting with the previous rhs as our new lhs. + -- operator's rhs and start a new layer of nesting with the previous rhs as our new lhs. ExpressionNestingLeaf_Operator { op = appendingOp , lhs = parentRhs @@ -1554,7 +1566,7 @@ appendValueExprTo leaf appendingExpr = collapseOperators : - { op : Operator + { op : Located Operator , lhs : Frontend.LocatedExpr , parent : Maybe ExpressionNestingParent } diff --git a/src/Stage/Parse/Parser.elm b/src/Stage/Parse/Parser.elm index 65b7cb09..8a5b9d77 100644 --- a/src/Stage/Parse/Parser.elm +++ b/src/Stage/Parse/Parser.elm @@ -563,17 +563,17 @@ expr = (checkIndent (<) ExpectingIndentation |> P.andThen (\() -> P.symbol (P.Token "++" ExpectingConcatOperator)) ) - (Located.merge (Operator Operator.Append)) + (Located.merge3 Operator (Located.located Located.dummyRegion Operator.Append)) , PP.infixLeft 1 (checkIndent (<) ExpectingIndentation |> P.andThen (\() -> P.symbol (P.Token "+" ExpectingPlusOperator)) ) - (Located.merge (Operator Operator.Add)) + (Located.merge3 Operator (Located.located Located.dummyRegion Operator.Add)) , PP.infixRight 1 (checkIndent (<) ExpectingIndentation |> P.andThen (\() -> P.symbol (P.Token "::" ExpectingConsOperator)) ) - (Located.merge (Operator Operator.Cons)) + (Located.merge (Operator (Located.located Located.dummyRegion Operator.Cons))) ] , spaces = ignorables } diff --git a/src/Stage/Parse/Pretty.elm b/src/Stage/Parse/Pretty.elm index 0271d236..968d0a26 100644 --- a/src/Stage/Parse/Pretty.elm +++ b/src/Stage/Parse/Pretty.elm @@ -200,7 +200,7 @@ expr expr_ = Frontend.Operator operator lhs rhs -> pair "Operator" (Many - [ pair "op" (Atom (Operator.toString operator)) + [ pair "op" (operator |> Located.unwrap |> Operator.toString |> Atom) , pair "lhs" (expr lhs) , pair "rhs" (expr rhs) ] diff --git a/tests/DesugarTest.elm b/tests/DesugarTest.elm index 12414e36..d19caf3c 100644 --- a/tests/DesugarTest.elm +++ b/tests/DesugarTest.elm @@ -169,7 +169,7 @@ frontendLambda arg1 arg2 = , body = located <| Frontend.Operator - Operator.Add + (located Operator.Add) (located <| Frontend.Argument arg1) (located <| Frontend.Argument arg2) } diff --git a/tests/EmitJsonTest.elm b/tests/EmitJsonTest.elm index 52a80e7b..9ea3ff18 100644 --- a/tests/EmitJsonTest.elm +++ b/tests/EmitJsonTest.elm @@ -12,7 +12,8 @@ import Stage.Emit.JsonAST as JSON import Test exposing (Test, describe, fuzz, test) import TestHelpers exposing - ( typed + ( located + , typed , typedInt , typedIntList , typedString @@ -92,13 +93,13 @@ json = ) , describe "Plus" (List.map runTest - [ ( "simple", Operator Operator.Add (typedInt 1) (typedInt 2), "{\"type\":\"plus\",\"e1\":{\"type\":\"int\",\"value\":1},\"e2\":{\"type\":\"int\",\"value\":2}}" ) + [ ( "simple", Operator (located Operator.Add) (typedInt 1) (typedInt 2), "{\"type\":\"plus\",\"e1\":{\"type\":\"int\",\"value\":1},\"e2\":{\"type\":\"int\",\"value\":2}}" ) ] ) , describe "Cons" (List.map runTest [ ( "simple" - , Operator Operator.Cons (typedInt 1) (typedIntList [ 2, 3 ]) + , Operator (located Operator.Cons) (typedInt 1) (typedIntList [ 2, 3 ]) , "{\"type\":\"cons\",\"e1\":{\"type\":\"int\",\"value\":1},\"e2\":{\"type\":\"list\",\"items\":[{\"type\":\"int\",\"value\":2},{\"type\":\"int\",\"value\":3}]}}" ) ] diff --git a/tests/EmitTest.elm b/tests/EmitTest.elm index 7eceec5a..7b310a1e 100644 --- a/tests/EmitTest.elm +++ b/tests/EmitTest.elm @@ -10,7 +10,8 @@ import Stage.Emit.JavaScript as JS import Test exposing (Test, describe, test) import TestHelpers exposing - ( typed + ( located + , typed , typedBool , typedInt , typedIntList @@ -86,21 +87,30 @@ javascript = , describe "Plus" (List.map runTest -- We need to give the child `Expr`s a type too - [ ( "simple", Operator Operator.Add (typedInt 1) (typedInt 2), "(1 + 2)" ) - , ( "nested", Operator Operator.Add (typedInt 1) (typed (Operator Operator.Add (typedInt 2) (typedInt 3))), "(1 + (2 + 3))" ) + [ ( "simple" + , Operator (located Operator.Add) (typedInt 1) (typedInt 2) + , "(1 + 2)" + ) + , ( "nested" + , Operator + (located Operator.Add) + (typedInt 1) + (typed (Operator (located Operator.Add) (typedInt 2) (typedInt 3))) + , "(1 + (2 + 3))" + ) ] ) , describe "Cons" (List.map runTest [ ( "simple" - , Operator Operator.Cons (typedInt 1) (typedIntList [ 2, 3 ]) + , Operator (located Operator.Cons) (typedInt 1) (typedIntList [ 2, 3 ]) , "[1].concat([2, 3])" ) , ( "nested" , Operator - Operator.Cons + (located Operator.Cons) (typedInt 1) - (typed (Operator Operator.Cons (typedInt 2) (typedIntList [ 3, 4 ]))) + (typed (Operator (located Operator.Cons) (typedInt 2) (typedIntList [ 3, 4 ]))) , "[1].concat([2].concat([3, 4]))" ) ] @@ -241,7 +251,7 @@ javascript = , body = typed (Operator - Operator.Add + (located Operator.Add) (typedInt 1) (typed (Argument "x")) ) @@ -262,7 +272,7 @@ javascript = , body = typed (Operator - Operator.Add + (located Operator.Add) (typedInt 1) (typed (Argument "x")) ) @@ -337,14 +347,14 @@ javascript = , describe "Mixed expressions" (List.map runTest [ ( "plus in tuple" - , Tuple (typed (Operator Operator.Add (typedInt 1) (typedInt 41))) (typedString "Hello") + , Tuple (typed (Operator (located Operator.Add) (typedInt 1) (typedInt 41))) (typedString "Hello") , """[(1 + 41),"Hello"]""" ) , ( "tuple and cons in record" , Record (Dict.fromList [ ( "a", { name = "a", body = typed (Tuple (typedInt 2) (typedInt 3)) } ) - , ( "b", { name = "b", body = typed (Operator Operator.Cons (typedInt 2) (typedIntList [ 3, 4 ])) } ) + , ( "b", { name = "b", body = typed (Operator (located Operator.Cons) (typedInt 2) (typedIntList [ 3, 4 ])) } ) ] ) , """{a: [2,3], b: [2].concat([3, 4])}""" diff --git a/tests/OptimizeTest.elm b/tests/OptimizeTest.elm index 7fdb8ac0..7253ece4 100644 --- a/tests/OptimizeTest.elm +++ b/tests/OptimizeTest.elm @@ -33,7 +33,7 @@ optimize = [ ( "works with two literal ints" , located ( Operator - Operator.Add + (located Operator.Add) (typedInt 2) (typedInt 5) , Type Type.Int @@ -42,13 +42,15 @@ optimize = ) , ( "doesn't work if left is not int" , located - ( Operator Operator.Add + ( Operator + (located Operator.Add) (located ( Argument "x", Type Type.Int )) (typedInt 5) , Type Type.Int ) , located - ( Operator Operator.Add + ( Operator + (located Operator.Add) (located ( Argument "x", Type Type.Int )) (typedInt 5) , Type Type.Int @@ -56,13 +58,15 @@ optimize = ) , ( "doesn't work if right is not int" , located - ( Operator Operator.Add + ( Operator + (located Operator.Add) (typedInt 5) (located ( Argument "x", Type Type.Int )) , Type Type.Int ) , located - ( Operator Operator.Add + ( Operator + (located Operator.Add) (typedInt 5) (located ( Argument "x", Type Type.Int )) , Type Type.Int @@ -75,7 +79,7 @@ optimize = [ ( "works with one value" , located ( Operator - Operator.Cons + (located Operator.Cons) (typedInt 1) (typedIntList [ 2, 3 ]) , Type Type.Int diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 118f01a3..6b42cea9 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -143,8 +143,8 @@ b = 78 + 5 + 2+ 4 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Add (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 18, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Frontend.Int 4))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Add) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 18, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } Add) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Frontend.Int 4))) }) ] , lexed = Ok @@ -255,8 +255,8 @@ b = 78 * 5 * 2 / 4 * 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Multiply (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Multiply (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Divide (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Multiply (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Multiply (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Multiply) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Divide) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Multiply) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Multiply) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) ] , lexed = Ok @@ -697,16 +697,16 @@ b4 = 78 / 5 / 2 / 4 + 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 14, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Add (Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Multiply (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5)))) (Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Frontend.Int 6))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (ValueOrFunctionOrGenericType "a1"), valueExpr__ = Located { end = { col = 16, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Operator Add (Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Int 7)) (Located { end = { col = 16, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Operator Multiply (Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Int 5)) (Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "a11"), valueExpr__ = Located { end = { col = 21, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Operator Add (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Int 7)) (Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator Add (Located { end = { col = 17, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator Multiply (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Int 5)) (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Frontend.Int 6))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (ValueOrFunctionOrGenericType "a2"), valueExpr__ = Located { end = { col = 18, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Operator Add (Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Int 100)) (Located { end = { col = 18, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Operator Multiply (Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Int 5)) (Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (ValueOrFunctionOrGenericType "a3"), valueExpr__ = Located { end = { col = 30, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator Add (Located { end = { col = 16, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator Multiply (Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Int 345)) (Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (Frontend.Int 2234)))) (Located { end = { col = 30, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Operator Multiply (Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Int 2342)) (Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Frontend.Int 1010))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Operator Add (Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Int 78)) (Located { end = { col = 23, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator Multiply (Located { end = { col = 19, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator Divide (Located { end = { col = 15, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator Multiply (Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Int 5)) (Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (ValueOrFunctionOrGenericType "b1"), valueExpr__ = Located { end = { col = 24, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator Subtract (Located { end = { col = 20, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator Divide (Located { end = { col = 16, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator Multiply (Located { end = { col = 12, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator Multiply (Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (ValueOrFunctionOrGenericType "b2"), valueExpr__ = Located { end = { col = 24, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator Subtract (Located { end = { col = 12, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator Multiply (Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator Multiply (Located { end = { col = 20, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator Divide (Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (ValueOrFunctionOrGenericType "b3"), valueExpr__ = Located { end = { col = 24, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator Add (Located { end = { col = 12, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator Subtract (Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator Multiply (Located { end = { col = 20, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator Divide (Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (ValueOrFunctionOrGenericType "b4"), valueExpr__ = Located { end = { col = 24, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator Add (Located { end = { col = 20, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator Divide (Located { end = { col = 16, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator Divide (Located { end = { col = 12, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator Divide (Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 14, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } Add) (Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5)))) (Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Frontend.Int 6))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (ValueOrFunctionOrGenericType "a1"), valueExpr__ = Located { end = { col = 16, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Operator (Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } Add) (Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Int 7)) (Located { end = { col = 16, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Operator (Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } Multiply) (Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Int 5)) (Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "a11"), valueExpr__ = Located { end = { col = 21, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Operator (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } Add) (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Int 7)) (Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } Add) (Located { end = { col = 17, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } Multiply) (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Int 5)) (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Frontend.Int 6))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (ValueOrFunctionOrGenericType "a2"), valueExpr__ = Located { end = { col = 18, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Operator (Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } Add) (Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Int 100)) (Located { end = { col = 18, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Operator (Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } Multiply) (Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Int 5)) (Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (ValueOrFunctionOrGenericType "a3"), valueExpr__ = Located { end = { col = 30, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 18, row = 5 }, start = { col = 17, row = 5 } } Add) (Located { end = { col = 16, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 11, row = 5 }, start = { col = 10, row = 5 } } Multiply) (Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Int 345)) (Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (Frontend.Int 2234)))) (Located { end = { col = 30, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Operator (Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } Multiply) (Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Int 2342)) (Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Frontend.Int 1010))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Operator (Located { end = { col = 9, row = 8 }, start = { col = 8, row = 8 } } Add) (Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Int 78)) (Located { end = { col = 23, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } Multiply) (Located { end = { col = 19, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } Divide) (Located { end = { col = 15, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } Multiply) (Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Int 5)) (Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (ValueOrFunctionOrGenericType "b1"), valueExpr__ = Located { end = { col = 24, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } Subtract) (Located { end = { col = 20, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 18, row = 9 }, start = { col = 17, row = 9 } } Divide) (Located { end = { col = 16, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 14, row = 9 }, start = { col = 13, row = 9 } } Multiply) (Located { end = { col = 12, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 10, row = 9 }, start = { col = 9, row = 9 } } Multiply) (Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (ValueOrFunctionOrGenericType "b2"), valueExpr__ = Located { end = { col = 24, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 14, row = 10 }, start = { col = 13, row = 10 } } Subtract) (Located { end = { col = 12, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 10, row = 10 }, start = { col = 9, row = 10 } } Multiply) (Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } Multiply) (Located { end = { col = 20, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 18, row = 10 }, start = { col = 17, row = 10 } } Divide) (Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (ValueOrFunctionOrGenericType "b3"), valueExpr__ = Located { end = { col = 24, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 14, row = 11 }, start = { col = 13, row = 11 } } Add) (Located { end = { col = 12, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 10, row = 11 }, start = { col = 9, row = 11 } } Subtract) (Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } Multiply) (Located { end = { col = 20, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 18, row = 11 }, start = { col = 17, row = 11 } } Divide) (Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (ValueOrFunctionOrGenericType "b4"), valueExpr__ = Located { end = { col = 24, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 22, row = 12 }, start = { col = 21, row = 12 } } Add) (Located { end = { col = 20, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 18, row = 12 }, start = { col = 17, row = 12 } } Divide) (Located { end = { col = 16, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 14, row = 12 }, start = { col = 13, row = 12 } } Divide) (Located { end = { col = 12, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 10, row = 12 }, start = { col = 9, row = 12 } } Divide) (Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Frontend.Int 5))) }) ] , lexed = Ok @@ -984,8 +984,8 @@ b = 78 + 5 + 2 - 4 + 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator Subtract (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Subtract (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator Add (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Subtract) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Add) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Subtract) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) ] , lexed = Ok diff --git a/tests/TestHelpers.elm b/tests/TestHelpers.elm index c6a0f029..3d4ac57d 100644 --- a/tests/TestHelpers.elm +++ b/tests/TestHelpers.elm @@ -12,6 +12,7 @@ module TestHelpers exposing import Elm.AST.Typed as Typed exposing (Expr_(..)) import Elm.Data.Located as Located exposing (Located) +import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (Qualified) import Elm.Data.Type as Type exposing (Type, TypeOrId(..)) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) From a6ee783a85d5d3f1ef6de4913a2c322797035123 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 18:18:23 +0100 Subject: [PATCH 078/103] lex X.Y.z as single items --- parser-tests/snippets/should-not-parse/dots | 29 + src/Stage/Parse/Contextualize.elm | 181 +-- src/Stage/Parse/Lexer.elm | 113 +- src/Stage/Parse/Pretty.elm | 20 +- tests/LexerTest.elm | 3 - tests/ParserLexerTestCases.elm | 1096 +++++++++++++------ 6 files changed, 956 insertions(+), 486 deletions(-) create mode 100644 parser-tests/snippets/should-not-parse/dots diff --git a/parser-tests/snippets/should-not-parse/dots b/parser-tests/snippets/should-not-parse/dots new file mode 100644 index 00000000..f4eed37a --- /dev/null +++ b/parser-tests/snippets/should-not-parse/dots @@ -0,0 +1,29 @@ +Foo. + +Foo.Bar + +Foo.Bar.baz + +Boor.Bing. + +Bor. Big. + +.sf + +sfsdf .sdfsd + +asfasf.sdgsghj + +(shdf).hellp + +(sjhsf) .hello + +sfhsdf(.hello) + +case.hi + +Hi.case + +case .hi + +Hi. case \ No newline at end of file diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 4adf8637..891e3612 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -66,17 +66,17 @@ type Block , exposingList : Elm.Data.Exposing.Exposing } | ValueDeclaration - { name : Located Token.ValueOrFunctionOrGenericType + { name : Located String -- TODO(harry): these could be patterns! - , args : List (Located Token.ValueOrFunctionOrGenericType) + , args : List (Located String) -- This key's name is hard coded into parser-tests/Update.elm , valueExpr__ : Frontend.LocatedExpr } | TypeAlias - { ty : Token.TypeOrConstructor - , genericArgs : List Token.ValueOrFunctionOrGenericType + { ty : String + , genericArgs : List String , expr : ConcreteType PossiblyQualified } | CustomType @@ -115,28 +115,28 @@ type BlockFirstItem type BlockTypeAlias = BlockTypeAlias_Keywords - | BlockTypeAlias_Named Token.TypeOrConstructor (Stack Token.ValueOrFunctionOrGenericType) - | BlockTypeAlias_NamedAssigns Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) - | BlockTypeAlias_Completish Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) PartialTypeExpressionLeaf + | BlockTypeAlias_Named String (Stack String) + | BlockTypeAlias_NamedAssigns String (List String) + | BlockTypeAlias_Completish String (List String) PartialTypeExpressionLeaf type BlockCustomType - = BlockCustomType_Named Token.TypeOrConstructor (Stack Token.ValueOrFunctionOrGenericType) - | BlockCustomType_NamedAssigns Token.TypeOrConstructor (List Token.ValueOrFunctionOrGenericType) + = BlockCustomType_Named String (Stack String) + | BlockCustomType_NamedAssigns String (List String) type BlockValueDeclaration = BlockValueDeclaration_Named - { name : Located Token.ValueOrFunctionOrGenericType - , args : Stack (Located Token.ValueOrFunctionOrGenericType) + { name : Located String + , args : Stack (Located String) } | BlockValueDeclaration_NamedAssigns - { name : Located Token.ValueOrFunctionOrGenericType - , args : List (Located Token.ValueOrFunctionOrGenericType) + { name : Located String + , args : List (Located String) } | BlockValueDeclaration_Completish - { name : Located Token.ValueOrFunctionOrGenericType - , args : List (Located Token.ValueOrFunctionOrGenericType) + { name : Located String + , args : List (Located String) , partialExpr : ExpressionNestingLeaf } @@ -257,8 +257,12 @@ type Error = Error_InvalidToken Expecting | Error_MisplacedKeyword Keyword | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor + | Error_BlockStartsWithQualifiedName + { qualifiers : List String + , name : String + } -- Type Expressions -- - | Error_TypeNameStartsWithLowerCase Token.ValueOrFunctionOrGenericType + | Error_TypeNameStartsWithLowerCase String | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole | Error_WrongClosingBracket { expecting : Lexer.BracketType @@ -555,29 +559,28 @@ parseBlockStart item = Located.map (\_ -> x) item in case Located.unwrap item of - Lexer.Token str -> - case Token.classifyToken str of - Token.TokenKeyword Token.Type -> - ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Type) - - Token.TokenKeyword Token.Module -> - ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Module) - - Token.TokenKeyword other -> - ParseResult_Err (Error_MisplacedKeyword other) - - Token.TokenValueOrFunction valOrFunc -> - ParseResult_Ok - (State_BlockValueDeclaration - (BlockValueDeclaration_Named - { name = withCorrectLocation valOrFunc - , args = empty - } - ) - ) + Lexer.Keyword Token.Type -> + ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Type) + + Lexer.Keyword Token.Module -> + ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Module) + + Lexer.Keyword other -> + ParseResult_Err (Error_MisplacedKeyword other) - Token.TokenTypeOrConstructor typeOrConstructor -> - ParseResult_Err (Error_BlockStartsWithTypeOrConstructor typeOrConstructor) + Lexer.Identifier ({ qualifiers, name } as identitfier) -> + if qualifiers /= [] then + ParseResult_Err (Error_BlockStartsWithQualifiedName identitfier) + + else + ParseResult_Ok + (State_BlockValueDeclaration + (BlockValueDeclaration_Named + { name = withCorrectLocation name + , args = empty + } + ) + ) Lexer.Newlines _ 0 -> ParseResult_Ok State_BlockStart @@ -595,23 +598,21 @@ parseBlockStart item = parseTypeBlock : Located LexItem -> ParseResult parseTypeBlock item = case Located.unwrap item of - Lexer.Token str -> - case Token.classifyToken str of - Token.TokenKeyword Token.Alias -> - State_BlockTypeAlias BlockTypeAlias_Keywords - |> ParseResult_Ok + Lexer.Keyword Token.Alias -> + State_BlockTypeAlias BlockTypeAlias_Keywords + |> ParseResult_Ok - Token.TokenKeyword other -> - Error_MisplacedKeyword other - |> ParseResult_Err + Lexer.Keyword other -> + Error_MisplacedKeyword other + |> ParseResult_Err - Token.TokenTypeOrConstructor typeOrConstructor -> - State_BlockCustomType (BlockCustomType_Named typeOrConstructor empty) - |> ParseResult_Ok + Lexer.Identifier ({ qualifiers, name } as identifier) -> + if qualifiers /= [] then + ParseResult_Err (Error_BlockStartsWithQualifiedName identifier) - Token.TokenValueOrFunction valOrFunc -> - Error_TypeNameStartsWithLowerCase valOrFunc - |> ParseResult_Err + else + State_BlockCustomType (BlockCustomType_Named name empty) + |> ParseResult_Ok Lexer.Newlines _ 0 -> -- TODO(harry): we might be partway through a custom type here, @@ -635,19 +636,17 @@ parseTypeBlock item = parseTypeAliasName : Located LexItem -> ParseResult parseTypeAliasName item = case Located.unwrap item of - Lexer.Token str -> - case Token.classifyToken str of - Token.TokenKeyword other -> - Error_MisplacedKeyword other - |> ParseResult_Err + Lexer.Keyword other -> + Error_MisplacedKeyword other + |> ParseResult_Err - Token.TokenTypeOrConstructor typeOrConstructor -> - State_BlockTypeAlias (BlockTypeAlias_Named typeOrConstructor empty) - |> ParseResult_Ok + Lexer.Identifier ({ qualifiers, name } as identifier) -> + if qualifiers /= [] then + ParseResult_Err (Error_BlockStartsWithQualifiedName identifier) - Token.TokenValueOrFunction valOrFunc -> - Error_TypeNameStartsWithLowerCase valOrFunc - |> ParseResult_Err + else + State_BlockTypeAlias (BlockTypeAlias_Named name empty) + |> ParseResult_Ok Lexer.Newlines _ 0 -> Error_PartwayThroughTypeAlias @@ -664,26 +663,24 @@ parseTypeAliasName item = |> ParseResult_Err -parseLowercaseArgsOrAssignment : (Located Token.ValueOrFunctionOrGenericType -> State) -> State -> Located LexItem -> ParseResult +parseLowercaseArgsOrAssignment : (Located String -> State) -> State -> Located LexItem -> ParseResult parseLowercaseArgsOrAssignment onTypeArg onAssignment item = let withCorrectLocation x = Located.map (\_ -> x) item in case Located.unwrap item of - Lexer.Token str -> - case Token.classifyToken str of - Token.TokenKeyword kw -> - Error_MisplacedKeyword kw - |> ParseResult_Err + Lexer.Keyword kw -> + Error_MisplacedKeyword kw + |> ParseResult_Err - Token.TokenTypeOrConstructor _ -> - Error_InvalidToken (Expecting_Sigil Lexer.Assign) - |> ParseResult_Err + Lexer.Identifier ({ qualifiers, name } as identifier) -> + if qualifiers /= [] then + ParseResult_Err (Error_BlockStartsWithQualifiedName identifier) - Token.TokenValueOrFunction argName -> - onTypeArg (withCorrectLocation argName) - |> ParseResult_Ok + else + onTypeArg (withCorrectLocation name) + |> ParseResult_Ok Lexer.Sigil Lexer.Assign -> onAssignment @@ -712,16 +709,20 @@ parserTypeExprFromEmpty : -> ParseResult parserTypeExprFromEmpty newState item = case Located.unwrap item of - Lexer.Token str -> - { parents = [] - , nesting = - NestingLeafType_TypeWithArgs - { name = str - , args = empty - } - } - |> PartialResult_Progress - |> newState + Lexer.Identifier ({ qualifiers, name } as identifier) -> + if qualifiers /= [] then + Debug.todo "" + + else + { parents = [] + , nesting = + NestingLeafType_TypeWithArgs + { name = name + , args = empty + } + } + |> PartialResult_Progress + |> newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> { parents = [] @@ -779,9 +780,13 @@ parserTypeExpr : -> ParseResult parserTypeExpr newState prevExpr item = case Located.unwrap item of - Lexer.Token str -> - exprAppend prevExpr str - |> partialExpressionToParseResult newState + Lexer.Identifier ({ qualifiers, name } as identifier) -> + if qualifiers /= [] then + Debug.todo "" + + else + exprAppend prevExpr name + |> partialExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> leafToParents prevExpr diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 7114ebdf..74bbf1a8 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -4,16 +4,25 @@ import Elm.Data.Located as Located exposing (Located) import Elm.Data.Operator as Operator exposing (Operator) import Parser.Advanced as P exposing ((|.), (|=), Parser) import Set +import Stage.Parse.Token as Token type LexItem = Sigil LexSigil - | Token String + | Identifier + { qualifiers : List String + , name : String + } + | Keyword Token.Keyword | NumericLiteral String | TextLiteral LexLiteralType String | Whitespace Int | Newlines (List Int) Int | Comment LexCommentType String + | IdentifierWithTrailingDot + { qualifiers : List String + , name : String + } | Invalid String @@ -22,6 +31,7 @@ type LexSigil | Assign | Pipe | Comma + -- TODO(harry): remove and replace by property-accessor etc. | SingleDot | DoubleDot | ThinArrow @@ -70,6 +80,7 @@ type LexProblem | ExpectingLineComment | ExpectingNumericLiteral | ExpectingEscape + | ExpectingKeyword | ExpectingEnd @@ -128,8 +139,12 @@ toString item = Sigil (Operator op) -> Operator.toString op - Token s -> - s + Identifier { qualifiers, name } -> + (qualifiers ++ [ name ]) + |> String.join "." + + Keyword k -> + Token.keywordToString k NumericLiteral s -> s @@ -157,6 +172,10 @@ toString item = Comment DocComment s -> "{-|" ++ s ++ "-}" + IdentifierWithTrailingDot { qualifiers, name } -> + (qualifiers ++ [ name, "" ]) + |> String.join "." + Invalid s -> s @@ -184,14 +203,8 @@ parser = P.oneOf [ P.oneOf ([ -- commentParser must come before sigil parser as the sigil - -- parser will try to interpret "--" as a sigil - P.variable - { start = Char.isAlpha - , inner = \c -> Char.isAlphaNum c || c == '_' - , reserved = Set.empty - , expecting = ExpectingToken - } - |> P.map Token + -- parser will try to interpret "--" as two "-" sigils. + identifierParser , numericLiteralParser |> P.map NumericLiteral , textLiteralParser @@ -223,6 +236,69 @@ parser = ) +identifierParser : Parser_ LexItem +identifierParser = + let + word = + P.variable + { start = Char.isAlpha + , inner = \c -> Char.isAlphaNum c || c == '_' + , reserved = Set.empty + , expecting = ExpectingToken + } + + loopHelp { reversedQualifiers, name } = + P.oneOf + [ P.succeed (\x -> x) + |. P.symbol (P.Token "." ExpectingSigil) + |= P.oneOf + [ word + |> P.map + (\new -> + P.Loop + { reversedQualifiers = name :: reversedQualifiers + , name = new + } + ) + , { qualifiers = List.reverse reversedQualifiers + , name = name + } + |> IdentifierWithTrailingDot + |> P.Done + |> P.succeed + ] + , { qualifiers = List.reverse reversedQualifiers + , name = name + } + |> Identifier + |> P.Done + |> P.succeed + ] + in + P.oneOf + [ P.token (P.Token "module" ExpectingKeyword) + |> P.map (\() -> Keyword Token.Module) + , P.token (P.Token "type" ExpectingKeyword) + |> P.map (\() -> Keyword Token.Type) + , P.token (P.Token "alias" ExpectingKeyword) + |> P.map (\() -> Keyword Token.Alias) + , P.token (P.Token "exposing" ExpectingKeyword) + |> P.map (\() -> Keyword Token.Exposing) + , P.token (P.Token "case" ExpectingKeyword) + |> P.map (\() -> Keyword Token.Case) + , P.token (P.Token "of" ExpectingKeyword) + |> P.map (\() -> Keyword Token.Of) + , P.token (P.Token "if" ExpectingKeyword) + |> P.map (\() -> Keyword Token.If) + , P.token (P.Token "then" ExpectingKeyword) + |> P.map (\() -> Keyword Token.Then) + , P.token (P.Token "else" ExpectingKeyword) + |> P.map (\() -> Keyword Token.Else) + , word + |> P.andThen (\first -> P.loop { reversedQualifiers = [], name = first } loopHelp) + ] + + newlinesParser : Parser_ ( List Int, Int ) newlinesParser = let @@ -263,11 +339,6 @@ chompSpacesAndCount = |> P.map String.length -alphaOrNumOr_ : Char -> Bool -alphaOrNumOr_ c = - Char.isAlphaNum c || c == '_' - - textLiteralParser : Parser_ ( LexLiteralType, Bool, String ) textLiteralParser = P.oneOf @@ -327,7 +398,7 @@ delimitedLiteral ty = |> P.map (\() -> P.Done True) , P.token (P.Token "\\" ExpectingEscape) |> P.andThen - (\() -> P.chompIf (\c -> True) ExpectingAnything) + (\() -> P.chompIf (\_ -> True) ExpectingAnything) |> P.map P.Loop , P.chompIf (\_ -> True) ExpectingAnything |> P.map P.Loop @@ -340,15 +411,19 @@ delimitedLiteral ty = numericLiteralParser : Parser_ String numericLiteralParser = + let + isValidNumericLiteralChar c = + Char.isAlphaNum c || c == '_' || c == '.' + in P.getChompedString (P.oneOf [ P.chompIf Char.isDigit ExpectingNumericLiteral - |> P.andThen (\() -> P.chompWhile (\c -> Char.isAlphaNum c || c == '_')) + |> P.andThen (\() -> P.chompWhile isValidNumericLiteralChar) , P.backtrackable (P.succeed () |. P.chompIf (\c -> c == '-') ExpectingNumericLiteral |. P.chompIf Char.isDigit ExpectingNumericLiteral - |. P.chompWhile (\c -> Char.isAlphaNum c || c == '_') + |. P.chompWhile isValidNumericLiteralChar ) ] ) diff --git a/src/Stage/Parse/Pretty.elm b/src/Stage/Parse/Pretty.elm index 968d0a26..885e490a 100644 --- a/src/Stage/Parse/Pretty.elm +++ b/src/Stage/Parse/Pretty.elm @@ -101,25 +101,17 @@ block b = ] ValueDeclaration record -> - let - (Token.ValueOrFunctionOrGenericType name) = - Located.unwrap record.name - in Many [ Atom "ValueDeclaration" , Many [ Atom "name" - , Atom name + , Atom (Located.unwrap record.name) ] , Many [ Atom "args" , listWith (\locatedArg -> - let - (Token.ValueOrFunctionOrGenericType arg) = - Located.unwrap locatedArg - in - Atom arg + Atom (Located.unwrap locatedArg) ) record.args ] @@ -130,21 +122,17 @@ block b = ] TypeAlias record -> - let - (Token.TypeOrConstructor ty) = - record.ty - in Many [ Atom "ValueDeclaration" , Many [ Atom "ty" - , Atom ty + , Atom record.ty ] , Many [ Atom "genericArgs" , Many (record.genericArgs - |> List.map (\(Token.ValueOrFunctionOrGenericType arg) -> Atom arg) + |> List.map Atom ) ] , Many diff --git a/tests/LexerTest.elm b/tests/LexerTest.elm index a3f7457f..69c342fa 100644 --- a/tests/LexerTest.elm +++ b/tests/LexerTest.elm @@ -22,9 +22,6 @@ runTest ( description, input ) = test description <| \() -> input - -- |> P.run ((located (Stage.Parse.Lexer.literalParser - -- |> P.map (\( ty, literalBody ) -> Literal ty literalBody ))) - -- |> P.map List.singleton) |> P.run Stage.Parse.Lexer.parser |> Expect.all [ Result.map (List.map (Located.unwrap >> toString) >> String.join "") diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 6b42cea9..527ce385 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -8,7 +8,7 @@ import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete exposing (ConcreteType(..)) import Stage.Parse.Contextualize as Contextualize exposing (..) import Stage.Parse.Lexer exposing (..) -import Stage.Parse.Token exposing (TypeOrConstructor(..), ValueOrFunctionOrGenericType(..)) +import Stage.Parse.Token exposing (Keyword(..), TypeOrConstructor(..), ValueOrFunctionOrGenericType(..)) @@ -55,12 +55,12 @@ b = 78 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } "b", valueExpr__ = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) @@ -71,7 +71,7 @@ b = 78 ] 0 ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token "b") + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) @@ -143,12 +143,12 @@ b = 78 + 5 + 2+ 4 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Add) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 18, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } Add) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Frontend.Int 4))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Add) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } "b", valueExpr__ = Located { end = { col = 18, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } Add) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Frontend.Int 4))) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) @@ -163,7 +163,7 @@ b = 78 + 5 + 2+ 4 ] 0 ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token "b") + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) @@ -255,12 +255,12 @@ b = 78 * 5 * 2 / 4 * 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Multiply) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Divide) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Multiply) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Multiply) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } "b", valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Multiply) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Divide) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Multiply) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Multiply) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) @@ -275,7 +275,7 @@ b = 78 * 5 * 2 / 4 * 5 ] 0 ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token "b") + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) @@ -697,20 +697,20 @@ b4 = 78 / 5 / 2 / 4 + 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 14, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } Add) (Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5)))) (Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Frontend.Int 6))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (ValueOrFunctionOrGenericType "a1"), valueExpr__ = Located { end = { col = 16, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Operator (Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } Add) (Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Int 7)) (Located { end = { col = 16, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Operator (Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } Multiply) (Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Int 5)) (Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "a11"), valueExpr__ = Located { end = { col = 21, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Operator (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } Add) (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Int 7)) (Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } Add) (Located { end = { col = 17, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } Multiply) (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Int 5)) (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Frontend.Int 6))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (ValueOrFunctionOrGenericType "a2"), valueExpr__ = Located { end = { col = 18, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Operator (Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } Add) (Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Int 100)) (Located { end = { col = 18, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Operator (Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } Multiply) (Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Int 5)) (Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (ValueOrFunctionOrGenericType "a3"), valueExpr__ = Located { end = { col = 30, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 18, row = 5 }, start = { col = 17, row = 5 } } Add) (Located { end = { col = 16, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 11, row = 5 }, start = { col = 10, row = 5 } } Multiply) (Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Int 345)) (Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (Frontend.Int 2234)))) (Located { end = { col = 30, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Operator (Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } Multiply) (Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Int 2342)) (Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Frontend.Int 1010))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Operator (Located { end = { col = 9, row = 8 }, start = { col = 8, row = 8 } } Add) (Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Int 78)) (Located { end = { col = 23, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } Multiply) (Located { end = { col = 19, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } Divide) (Located { end = { col = 15, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } Multiply) (Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Int 5)) (Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (ValueOrFunctionOrGenericType "b1"), valueExpr__ = Located { end = { col = 24, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } Subtract) (Located { end = { col = 20, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 18, row = 9 }, start = { col = 17, row = 9 } } Divide) (Located { end = { col = 16, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 14, row = 9 }, start = { col = 13, row = 9 } } Multiply) (Located { end = { col = 12, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 10, row = 9 }, start = { col = 9, row = 9 } } Multiply) (Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (ValueOrFunctionOrGenericType "b2"), valueExpr__ = Located { end = { col = 24, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 14, row = 10 }, start = { col = 13, row = 10 } } Subtract) (Located { end = { col = 12, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 10, row = 10 }, start = { col = 9, row = 10 } } Multiply) (Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } Multiply) (Located { end = { col = 20, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 18, row = 10 }, start = { col = 17, row = 10 } } Divide) (Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (ValueOrFunctionOrGenericType "b3"), valueExpr__ = Located { end = { col = 24, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 14, row = 11 }, start = { col = 13, row = 11 } } Add) (Located { end = { col = 12, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 10, row = 11 }, start = { col = 9, row = 11 } } Subtract) (Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } Multiply) (Located { end = { col = 20, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 18, row = 11 }, start = { col = 17, row = 11 } } Divide) (Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (ValueOrFunctionOrGenericType "b4"), valueExpr__ = Located { end = { col = 24, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 22, row = 12 }, start = { col = 21, row = 12 } } Add) (Located { end = { col = 20, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 18, row = 12 }, start = { col = 17, row = 12 } } Divide) (Located { end = { col = 16, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 14, row = 12 }, start = { col = 13, row = 12 } } Divide) (Located { end = { col = 12, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 10, row = 12 }, start = { col = 9, row = 12 } } Divide) (Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 14, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } Add) (Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5)))) (Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Frontend.Int 6))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } "a1", valueExpr__ = Located { end = { col = 16, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Operator (Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } Add) (Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Int 7)) (Located { end = { col = 16, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Operator (Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } Multiply) (Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Int 5)) (Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } "a11", valueExpr__ = Located { end = { col = 21, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Operator (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } Add) (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Int 7)) (Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } Add) (Located { end = { col = 17, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } Multiply) (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Int 5)) (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Frontend.Int 6))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } "a2", valueExpr__ = Located { end = { col = 18, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Operator (Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } Add) (Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Int 100)) (Located { end = { col = 18, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Operator (Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } Multiply) (Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Int 5)) (Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } "a3", valueExpr__ = Located { end = { col = 30, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 18, row = 5 }, start = { col = 17, row = 5 } } Add) (Located { end = { col = 16, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 11, row = 5 }, start = { col = 10, row = 5 } } Multiply) (Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Int 345)) (Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (Frontend.Int 2234)))) (Located { end = { col = 30, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Operator (Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } Multiply) (Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Int 2342)) (Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Frontend.Int 1010))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } "b", valueExpr__ = Located { end = { col = 23, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Operator (Located { end = { col = 9, row = 8 }, start = { col = 8, row = 8 } } Add) (Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Int 78)) (Located { end = { col = 23, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } Multiply) (Located { end = { col = 19, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } Divide) (Located { end = { col = 15, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } Multiply) (Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Int 5)) (Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } "b1", valueExpr__ = Located { end = { col = 24, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } Subtract) (Located { end = { col = 20, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 18, row = 9 }, start = { col = 17, row = 9 } } Divide) (Located { end = { col = 16, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 14, row = 9 }, start = { col = 13, row = 9 } } Multiply) (Located { end = { col = 12, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 10, row = 9 }, start = { col = 9, row = 9 } } Multiply) (Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } "b2", valueExpr__ = Located { end = { col = 24, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 14, row = 10 }, start = { col = 13, row = 10 } } Subtract) (Located { end = { col = 12, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 10, row = 10 }, start = { col = 9, row = 10 } } Multiply) (Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } Multiply) (Located { end = { col = 20, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 18, row = 10 }, start = { col = 17, row = 10 } } Divide) (Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } "b3", valueExpr__ = Located { end = { col = 24, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 14, row = 11 }, start = { col = 13, row = 11 } } Add) (Located { end = { col = 12, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 10, row = 11 }, start = { col = 9, row = 11 } } Subtract) (Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } Multiply) (Located { end = { col = 20, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 18, row = 11 }, start = { col = 17, row = 11 } } Divide) (Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } "b4", valueExpr__ = Located { end = { col = 24, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 22, row = 12 }, start = { col = 21, row = 12 } } Add) (Located { end = { col = 20, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 18, row = 12 }, start = { col = 17, row = 12 } } Divide) (Located { end = { col = 16, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 14, row = 12 }, start = { col = 13, row = 12 } } Divide) (Located { end = { col = 12, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 10, row = 12 }, start = { col = 9, row = 12 } } Divide) (Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Frontend.Int 5))) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) @@ -724,7 +724,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 13, row = 1 }, start = { col = 12, row = 1 } } (Whitespace 1) , Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (NumericLiteral "6") , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) - , Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (Token "a1") + , Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (Identifier { name = "a1", qualifiers = [] }) , Located { end = { col = 4, row = 2 }, start = { col = 3, row = 2 } } (Whitespace 1) , Located { end = { col = 5, row = 2 }, start = { col = 4, row = 2 } } (Sigil Assign) , Located { end = { col = 7, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 2) @@ -738,7 +738,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (NumericLiteral "5") , Located { end = { col = 1, row = 3 }, start = { col = 16, row = 2 } } (Newlines [] 0) - , Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (Token "a11") + , Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "a11", qualifiers = [] }) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Assign) , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 2) @@ -756,7 +756,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Whitespace 1) , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (NumericLiteral "6") , Located { end = { col = 1, row = 4 }, start = { col = 21, row = 3 } } (Newlines [] 0) - , Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (Token "a2") + , Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (Identifier { name = "a2", qualifiers = [] }) , Located { end = { col = 4, row = 4 }, start = { col = 3, row = 4 } } (Whitespace 1) , Located { end = { col = 5, row = 4 }, start = { col = 4, row = 4 } } (Sigil Assign) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Whitespace 1) @@ -770,7 +770,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 17, row = 4 }, start = { col = 16, row = 4 } } (Whitespace 1) , Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (NumericLiteral "5") , Located { end = { col = 1, row = 5 }, start = { col = 18, row = 4 } } (Newlines [] 0) - , Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (Token "a3") + , Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (Identifier { name = "a3", qualifiers = [] }) , Located { end = { col = 4, row = 5 }, start = { col = 3, row = 5 } } (Whitespace 1) , Located { end = { col = 5, row = 5 }, start = { col = 4, row = 5 } } (Sigil Assign) , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) @@ -794,7 +794,7 @@ b4 = 78 / 5 / 2 / 4 + 5 ] 0 ) - , Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (Token "b") + , Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 3, row = 8 }, start = { col = 2, row = 8 } } (Whitespace 1) , Located { end = { col = 4, row = 8 }, start = { col = 3, row = 8 } } (Sigil Assign) , Located { end = { col = 5, row = 8 }, start = { col = 4, row = 8 } } (Whitespace 1) @@ -816,7 +816,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 22, row = 8 }, start = { col = 21, row = 8 } } (Whitespace 1) , Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (NumericLiteral "5") , Located { end = { col = 1, row = 9 }, start = { col = 23, row = 8 } } (Newlines [] 0) - , Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (Token "b1") + , Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (Identifier { name = "b1", qualifiers = [] }) , Located { end = { col = 4, row = 9 }, start = { col = 3, row = 9 } } (Whitespace 1) , Located { end = { col = 5, row = 9 }, start = { col = 4, row = 9 } } (Sigil Assign) , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Whitespace 1) @@ -838,7 +838,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 23, row = 9 }, start = { col = 22, row = 9 } } (Whitespace 1) , Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (NumericLiteral "5") , Located { end = { col = 1, row = 10 }, start = { col = 24, row = 9 } } (Newlines [] 0) - , Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (Token "b2") + , Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (Identifier { name = "b2", qualifiers = [] }) , Located { end = { col = 4, row = 10 }, start = { col = 3, row = 10 } } (Whitespace 1) , Located { end = { col = 5, row = 10 }, start = { col = 4, row = 10 } } (Sigil Assign) , Located { end = { col = 6, row = 10 }, start = { col = 5, row = 10 } } (Whitespace 1) @@ -860,7 +860,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 23, row = 10 }, start = { col = 22, row = 10 } } (Whitespace 1) , Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (NumericLiteral "5") , Located { end = { col = 1, row = 11 }, start = { col = 24, row = 10 } } (Newlines [] 0) - , Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (Token "b3") + , Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (Identifier { name = "b3", qualifiers = [] }) , Located { end = { col = 4, row = 11 }, start = { col = 3, row = 11 } } (Whitespace 1) , Located { end = { col = 5, row = 11 }, start = { col = 4, row = 11 } } (Sigil Assign) , Located { end = { col = 6, row = 11 }, start = { col = 5, row = 11 } } (Whitespace 1) @@ -882,7 +882,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 23, row = 11 }, start = { col = 22, row = 11 } } (Whitespace 1) , Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (NumericLiteral "5") , Located { end = { col = 1, row = 12 }, start = { col = 24, row = 11 } } (Newlines [] 0) - , Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (Token "b4") + , Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (Identifier { name = "b4", qualifiers = [] }) , Located { end = { col = 4, row = 12 }, start = { col = 3, row = 12 } } (Whitespace 1) , Located { end = { col = 5, row = 12 }, start = { col = 4, row = 12 } } (Sigil Assign) , Located { end = { col = 6, row = 12 }, start = { col = 5, row = 12 } } (Whitespace 1) @@ -984,12 +984,12 @@ b = 78 + 5 + 2 - 4 + 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (ValueOrFunctionOrGenericType "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Subtract) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Add) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Subtract) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Subtract) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } "b", valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Add) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Subtract) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token "a") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) @@ -1004,7 +1004,7 @@ b = 78 + 5 + 2 - 4 + 5 ] 0 ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token "b") + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) @@ -1075,23 +1075,23 @@ b = 78 + 5 + 2 - 4 + 5 , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = TypeOrConstructor "Model" + , ty = "Model" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Model", qualifiers = [] }) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List") + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int") + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) ] } @@ -1156,41 +1156,41 @@ expr hi = 77 , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = TypeOrConstructor "Model" + , ty = "Model" } ) , Ok (ValueDeclaration { args = - [ Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (ValueOrFunctionOrGenericType "hi") + [ Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } "hi" ] - , name = Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (ValueOrFunctionOrGenericType "expr") + , name = Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } "expr" , valueExpr__ = Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (Frontend.Int 77) } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Model", qualifiers = [] }) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token "List") + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token "Int") + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 1, row = 3 }, start = { col = 28, row = 1 } } (Newlines [ 0 ] 0 ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "expr") + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "expr", qualifiers = [] }) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) - , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Token "hi") + , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Identifier { name = "hi", qualifiers = [] }) , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Whitespace 1) , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Assign) , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) @@ -1240,27 +1240,27 @@ expr hi = 77 ] ) , genericArgs = [] - , ty = TypeOrConstructor "Ty" + , ty = "Ty" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token "Int") + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Curly Close)) @@ -1368,32 +1368,32 @@ expr hi = 77 } } , genericArgs = [] - , ty = TypeOrConstructor "Function" + , ty = "Function" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token "List") + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Token "Int") + , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) , Located { end = { col = 34, row = 1 }, start = { col = 32, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) - , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Token "List") + , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Token "List") + , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Whitespace 1) - , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Token "Int") + , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) ] @@ -1541,7 +1541,7 @@ type alias Function = A -> B -> C -> D } } , genericArgs = [] - , ty = TypeOrConstructor "Function" + , ty = "Function" } ) , Ok @@ -1580,51 +1580,51 @@ type alias Function = A -> B -> C -> D } } , genericArgs = [] - , ty = TypeOrConstructor "Function" + , ty = "Function" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "A") + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "A", qualifiers = [] }) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) , Located { end = { col = 27, row = 1 }, start = { col = 25, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token "B") + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "B", qualifiers = [] }) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token "C") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Identifier { name = "C", qualifiers = [] }) , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Keyword Type) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Keyword Alias) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Token "Function") + , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Identifier { name = "Function", qualifiers = [] }) , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Assign) , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token "A") + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Identifier { name = "A", qualifiers = [] }) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) , Located { end = { col = 27, row = 2 }, start = { col = 25, row = 2 } } (Sigil ThinArrow) , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) - , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token "B") + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Identifier { name = "B", qualifiers = [] }) , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Whitespace 1) , Located { end = { col = 32, row = 2 }, start = { col = 30, row = 2 } } (Sigil ThinArrow) , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Whitespace 1) - , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Token "C") + , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Identifier { name = "C", qualifiers = [] }) , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) , Located { end = { col = 37, row = 2 }, start = { col = 35, row = 2 } } (Sigil ThinArrow) , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) - , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token "D") + , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Identifier { name = "D", qualifiers = [] }) , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Newlines [] 0) ] } @@ -1731,36 +1731,36 @@ type alias Function = A -> B -> C -> D } } , genericArgs = - [ ValueOrFunctionOrGenericType "a" + [ "a" ] - , ty = TypeOrConstructor "Function" + , ty = "Function" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token "a") + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Assign) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Token "List") + , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) , Located { end = { col = 36, row = 1 }, start = { col = 34, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Token "List") + , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Token "List") + , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Whitespace 1) - , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token "a") + , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) ] @@ -1952,7 +1952,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) } , genericArgs = [] - , ty = TypeOrConstructor "Function" + , ty = "Function" } ) , Ok @@ -1982,7 +1982,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = TypeOrConstructor "Function2" + , ty = "Function2" } ) , Ok @@ -2009,7 +2009,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) Unit , genericArgs = [] - , ty = TypeOrConstructor "Function3" + , ty = "Function3" } ) , Ok @@ -2042,17 +2042,17 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) Unit , genericArgs = [] - , ty = TypeOrConstructor "Function3" + , ty = "Function3" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) @@ -2063,10 +2063,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Token "Int") + , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil Comma) , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Whitespace 1) - , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Token "String") + , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Identifier { name = "String", qualifiers = [] }) , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 3 }, start = { col = 44, row = 1 } } @@ -2075,17 +2075,17 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] 0 ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "type") + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Keyword Type) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token "alias") + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Keyword Alias) , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token "Function2") + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Identifier { name = "Function2", qualifiers = [] }) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Sigil Assign) , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "a") + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil Colon) , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Whitespace 1) , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Sigil (Bracket Round Open)) @@ -2094,10 +2094,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Sigil ThinArrow) , Located { end = { col = 35, row = 3 }, start = { col = 34, row = 3 } } (Whitespace 1) , Located { end = { col = 36, row = 3 }, start = { col = 35, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Token "Int") + , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 40, row = 3 }, start = { col = 39, row = 3 } } (Sigil Comma) , Located { end = { col = 41, row = 3 }, start = { col = 40, row = 3 } } (Whitespace 1) - , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Token "String") + , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Identifier { name = "String", qualifiers = [] }) , Located { end = { col = 48, row = 3 }, start = { col = 47, row = 3 } } (Sigil (Bracket Round Close)) , Located { end = { col = 49, row = 3 }, start = { col = 48, row = 3 } } (Whitespace 1) , Located { end = { col = 50, row = 3 }, start = { col = 49, row = 3 } } (Sigil (Bracket Curly Close)) @@ -2107,11 +2107,11 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] 0 ) - , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token "type") + , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Keyword Type) , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) - , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token "alias") + , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Keyword Alias) , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) - , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token "Function3") + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Identifier { name = "Function3", qualifiers = [] }) , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Whitespace 1) , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Sigil Assign) , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) @@ -2122,10 +2122,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Sigil ThinArrow) , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Whitespace 1) , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Token "Int") + , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Sigil Comma) , Located { end = { col = 37, row = 5 }, start = { col = 36, row = 5 } } (Whitespace 1) - , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Token "String") + , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Identifier { name = "String", qualifiers = [] }) , Located { end = { col = 44, row = 5 }, start = { col = 43, row = 5 } } (Sigil (Bracket Round Close)) , Located { end = { col = 45, row = 5 }, start = { col = 44, row = 5 } } (Sigil Comma) , Located { end = { col = 46, row = 5 }, start = { col = 45, row = 5 } } (Whitespace 1) @@ -2138,16 +2138,16 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] 0 ) - , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token "type") + , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Keyword Type) , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Whitespace 1) - , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token "alias") + , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Keyword Alias) , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Whitespace 1) - , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token "Function3") + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Identifier { name = "Function3", qualifiers = [] }) , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Whitespace 1) , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Sigil Assign) , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Whitespace 1) , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token "Int") + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Sigil Comma) , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Whitespace 1) , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Sigil (Bracket Round Open)) @@ -2156,10 +2156,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Sigil ThinArrow) , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Whitespace 1) , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Token "Int") + , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 41, row = 7 }, start = { col = 40, row = 7 } } (Sigil Comma) , Located { end = { col = 42, row = 7 }, start = { col = 41, row = 7 } } (Whitespace 1) - , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Token "String") + , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Identifier { name = "String", qualifiers = [] }) , Located { end = { col = 49, row = 7 }, start = { col = 48, row = 7 } } (Sigil (Bracket Round Close)) , Located { end = { col = 50, row = 7 }, start = { col = 49, row = 7 } } (Sigil Comma) , Located { end = { col = 51, row = 7 }, start = { col = 50, row = 7 } } (Whitespace 1) @@ -2251,38 +2251,38 @@ type alias Function3 = (Int, () -> (Int, String), ()) , to = Record (Dict.fromList []) } , genericArgs = [] - , ty = TypeOrConstructor "Function" + , ty = "Function" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "a") + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Colon) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token "b") + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Sigil Colon) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token "C") + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Identifier { name = "C", qualifiers = [] }) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Sigil Comma) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) - , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Token "d") + , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Identifier { name = "d", qualifiers = [] }) , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Sigil Colon) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token "E") + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Identifier { name = "E", qualifiers = [] }) , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Whitespace 1) @@ -2354,17 +2354,17 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) } , genericArgs = [] - , ty = TypeOrConstructor "Function" + , ty = "Function" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) @@ -2374,10 +2374,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 28, row = 1 }, start = { col = 26, row = 1 } } (Sigil ThinArrow) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token "Int") + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil Comma) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Token "String") + , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Identifier { name = "String", qualifiers = [] }) , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Newlines [] 0) ] @@ -2430,23 +2430,23 @@ type alias Function3 = (Int, () -> (Int, String), ()) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = TypeOrConstructor "Model" + , ty = "Model" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) - , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token "Model") + , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Identifier { name = "Model", qualifiers = [] }) , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 1) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Sigil Assign) , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Whitespace 1) - , Located { end = { col = 17, row = 2 }, start = { col = 13, row = 2 } } (Token "List") + , Located { end = { col = 17, row = 2 }, start = { col = 13, row = 2 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Whitespace 1) - , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token "Int") + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 2 } } (Newlines [] 0) ] } @@ -2499,23 +2499,23 @@ type alias Function3 = (Int, () -> (Int, String), ()) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = TypeOrConstructor "Model" + , ty = "Model" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) - , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token "Model") + , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Identifier { name = "Model", qualifiers = [] }) , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 1) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Sigil Assign) , Located { end = { col = 2, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 1) - , Located { end = { col = 6, row = 3 }, start = { col = 2, row = 3 } } (Token "List") + , Located { end = { col = 6, row = 3 }, start = { col = 2, row = 3 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) - , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Token "Int") + , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Newlines [] 0) ] } @@ -2596,38 +2596,38 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = TypeOrConstructor "Ty" + , ty = "Ty" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Token "a") + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil Colon) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Token "A") + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Identifier { name = "A", qualifiers = [] }) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "b") + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Colon) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token "B") + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "B", qualifiers = [] }) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil Comma) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Whitespace 1) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token "c") + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Identifier { name = "c", qualifiers = [] }) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Sigil Colon) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token "C") + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Identifier { name = "C", qualifiers = [] }) , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Whitespace 1) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 37, row = 1 } } (Newlines [] 0) @@ -2649,15 +2649,15 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , contextualized = Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = TypeOrConstructor "Ty" }) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = "Ty" }) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) @@ -2685,15 +2685,15 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , contextualized = Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = TypeOrConstructor "Ty" }) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = "Ty" }) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) @@ -2751,27 +2751,27 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = TypeOrConstructor "Ty" + , ty = "Ty" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token "hi") + , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Sigil Colon) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token "Int") + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Close)) @@ -2954,59 +2954,59 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = TypeOrConstructor "Ty" + , ty = "Ty" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) - , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Token "hi") + , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Identifier { name = "hi", qualifiers = [] }) , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Sigil Colon) , Located { end = { col = 12, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 2) , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Whitespace 1) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token "a") + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Colon) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 20, row = 2 }, start = { col = 17, row = 2 } } (Token "Int") + , Located { end = { col = 20, row = 2 }, start = { col = 17, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Sigil Comma) , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Whitespace 1) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Token "b") + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil Colon) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) - , Located { end = { col = 29, row = 2 }, start = { col = 25, row = 2 } } (Token "List") + , Located { end = { col = 29, row = 2 }, start = { col = 25, row = 2 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Whitespace 1) - , Located { end = { col = 36, row = 2 }, start = { col = 30, row = 2 } } (Token "String") + , Located { end = { col = 36, row = 2 }, start = { col = 30, row = 2 } } (Identifier { name = "String", qualifiers = [] }) , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Whitespace 1) , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 5, row = 3 }, start = { col = 38, row = 2 } } (Newlines [] 4) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) - , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token "ih") + , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Identifier { name = "ih", qualifiers = [] }) , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Colon) , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Token "CustomType") + , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Identifier { name = "CustomType", qualifiers = [] }) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token "A") + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Identifier { name = "A", qualifiers = [] }) , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token "B") + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Identifier { name = "B", qualifiers = [] }) , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "C") + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Identifier { name = "C", qualifiers = [] }) , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Whitespace 1) , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token "D") + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Identifier { name = "D", qualifiers = [] }) , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Whitespace 1) - , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Token "E") + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Identifier { name = "E", qualifiers = [] }) , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Sigil (Bracket Round Close)) , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Newlines [] 4) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) @@ -3055,26 +3055,26 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = TypeOrConstructor "Ty" + , ty = "Ty" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Int") + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) @@ -3125,33 +3125,33 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = TypeOrConstructor "Ty" + , ty = "Ty" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil Comma) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 27, row = 1 } } (Token "buy") + , Located { end = { col = 30, row = 1 }, start = { col = 27, row = 1 } } (Identifier { name = "buy", qualifiers = [] }) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil Colon) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) - , Located { end = { col = 38, row = 1 }, start = { col = 32, row = 1 } } (Token "String") + , Located { end = { col = 38, row = 1 }, start = { col = 32, row = 1 } } (Identifier { name = "String", qualifiers = [] }) , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Whitespace 1) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 40, row = 1 } } (Newlines [] 0) @@ -3171,15 +3171,15 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , contextualized = Just - [ Ok (TypeAlias { expr = Unit, genericArgs = [], ty = TypeOrConstructor "Hi" }) + [ Ok (TypeAlias { expr = Unit, genericArgs = [], ty = "Hi" }) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) @@ -3220,22 +3220,22 @@ type alias Function3 = (Int, () -> (Int, String), ()) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = TypeOrConstructor "Hi" + , ty = "Hi" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) ] @@ -3287,24 +3287,24 @@ type alias Function3 = (Int, () -> (Int, String), ()) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = TypeOrConstructor "Hi" + , ty = "Hi" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Token "List") + , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Int") + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) ] @@ -3393,7 +3393,7 @@ type alias Hi = (Int) } ) , genericArgs = [] - , ty = TypeOrConstructor "Hi" + , ty = "Hi" } ) , Ok @@ -3405,39 +3405,39 @@ type alias Hi = (Int) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = TypeOrConstructor "Hi" + , ty = "Hi" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token "List") + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Token "String") + , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "String", qualifiers = [] }) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Keyword Type) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Keyword Alias) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token "Int") + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Newlines [] 0) ] @@ -3523,36 +3523,36 @@ type alias Hi = ((), (), ()) } ) , genericArgs = [] - , ty = TypeOrConstructor "Hi" + , ty = "Hi" } ) - , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, genericArgs = [], ty = TypeOrConstructor "Hi" }) + , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, genericArgs = [], ty = "Hi" }) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token "Two") + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "Two", qualifiers = [] }) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Comma) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Token "Three") + , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "Three", qualifiers = [] }) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Keyword Type) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Keyword Alias) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) @@ -3662,44 +3662,44 @@ type alias Hi = ((), (), ()) ] ) , genericArgs = [] - , ty = TypeOrConstructor "Hi" + , ty = "Hi" } ) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) - , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token "a") + , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Sigil Colon) , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Whitespace 1) , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Token "Int") + , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Sigil Comma) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Whitespace 1) - , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Token "Int") + , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil Comma) , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) - , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Token "Int") + , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil (Bracket Round Close)) , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Newlines [] 4) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) - , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Token "b") + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Identifier { name = "b", qualifiers = [] }) , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil Colon) , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Sigil (Bracket Round Open)) , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Token "good_bye") + , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Identifier { name = "good_bye", qualifiers = [] }) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Sigil Colon) , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Whitespace 1) , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Sigil (Bracket Round Open)) @@ -3724,7 +3724,374 @@ shouldNotParseTestCases : , source : String } shouldNotParseTestCases = - [ { name = "type-alias-function-nested-missing-return" + [ { name = "dots" + , source = """Foo. + +Foo.Bar + +Foo.Bar.baz + +Boor.Bing. + +Bor. Big. + +.sf + +sfsdf .sdfsd + +asfasf.sdgsghj + +(shdf).hellp + +(sjhsf) .hello + +sfhsdf(.hello) + +case.hi + +Hi.case + +case .hi + +Hi. case""" + , pretty = """ + ( ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + ) +""" + , contextualized = + Just + [ Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] })) + , state = State_BlockStart + } + , Err + { error = + Error_BlockStartsWithQualifiedName + { name = "Bar" + , qualifiers = + [ "Foo" + ] + } + , item = + Just + (Located { end = { col = 8, row = 3 }, start = { col = 1, row = 3 } } + (Identifier + { name = "Bar" + , qualifiers = + [ "Foo" + ] + } + ) + ) + , state = State_BlockStart + } + , Err + { error = + Error_BlockStartsWithQualifiedName + { name = "baz" + , qualifiers = + [ "Foo" + , "Bar" + ] + } + , item = + Just + (Located { end = { col = 12, row = 5 }, start = { col = 1, row = 5 } } + (Identifier + { name = "baz" + , qualifiers = + [ "Foo" + , "Bar" + ] + } + ) + ) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken Expecting_Block + , item = + Just + (Located { end = { col = 11, row = 7 }, start = { col = 1, row = 7 } } + (IdentifierWithTrailingDot + { name = "Bing" + , qualifiers = + [ "Boor" + ] + } + ) + ) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] })) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 2, row = 11 }, start = { col = 1, row = 11 } } (Sigil SingleDot)) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken (Expecting_Sigil Assign) + , item = Just (Located { end = { col = 8, row = 13 }, start = { col = 7, row = 13 } } (Sigil SingleDot)) + , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } "sfsdf" }) + } + , Err + { error = + Error_BlockStartsWithQualifiedName + { name = "sdgsghj" + , qualifiers = + [ "asfasf" + ] + } + , item = + Just + (Located { end = { col = 15, row = 15 }, start = { col = 1, row = 15 } } + (Identifier + { name = "sdgsghj" + , qualifiers = + [ "asfasf" + ] + } + ) + ) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Sigil (Bracket Round Open))) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Sigil (Bracket Round Open))) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken (Expecting_Sigil Assign) + , item = Just (Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Sigil (Bracket Round Open))) + , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } "sfhsdf" }) + } + , Err + { error = Error_MisplacedKeyword Case + , item = Just (Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Keyword Case)) + , state = State_BlockStart + } + , Err + { error = + Error_BlockStartsWithQualifiedName + { name = "case" + , qualifiers = + [ "Hi" + ] + } + , item = + Just + (Located { end = { col = 8, row = 25 }, start = { col = 1, row = 25 } } + (Identifier + { name = "case" + , qualifiers = + [ "Hi" + ] + } + ) + ) + , state = State_BlockStart + } + , Err + { error = Error_MisplacedKeyword Case + , item = Just (Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Keyword Case)) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] })) + , state = State_BlockStart + } + ] + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] }) + , Located { end = { col = 1, row = 3 }, start = { col = 5, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 8, row = 3 }, start = { col = 1, row = 3 } } + (Identifier + { name = "Bar" + , qualifiers = + [ "Foo" + ] + } + ) + , Located { end = { col = 1, row = 5 }, start = { col = 8, row = 3 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 12, row = 5 }, start = { col = 1, row = 5 } } + (Identifier + { name = "baz" + , qualifiers = + [ "Foo" + , "Bar" + ] + } + ) + , Located { end = { col = 1, row = 7 }, start = { col = 12, row = 5 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 11, row = 7 }, start = { col = 1, row = 7 } } + (IdentifierWithTrailingDot + { name = "Bing" + , qualifiers = + [ "Boor" + ] + } + ) + , Located { end = { col = 1, row = 9 }, start = { col = 11, row = 7 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] }) + , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Whitespace 1) + , Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (IdentifierWithTrailingDot { name = "Big", qualifiers = [] }) + , Located { end = { col = 1, row = 11 }, start = { col = 10, row = 9 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 2, row = 11 }, start = { col = 1, row = 11 } } (Sigil SingleDot) + , Located { end = { col = 4, row = 11 }, start = { col = 2, row = 11 } } (Identifier { name = "sf", qualifiers = [] }) + , Located { end = { col = 1, row = 13 }, start = { col = 4, row = 11 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } (Identifier { name = "sfsdf", qualifiers = [] }) + , Located { end = { col = 7, row = 13 }, start = { col = 6, row = 13 } } (Whitespace 1) + , Located { end = { col = 8, row = 13 }, start = { col = 7, row = 13 } } (Sigil SingleDot) + , Located { end = { col = 13, row = 13 }, start = { col = 8, row = 13 } } (Identifier { name = "sdfsd", qualifiers = [] }) + , Located { end = { col = 1, row = 15 }, start = { col = 13, row = 13 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 15, row = 15 }, start = { col = 1, row = 15 } } + (Identifier + { name = "sdgsghj" + , qualifiers = + [ "asfasf" + ] + } + ) + , Located { end = { col = 1, row = 17 }, start = { col = 15, row = 15 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 6, row = 17 }, start = { col = 2, row = 17 } } (Identifier { name = "shdf", qualifiers = [] }) + , Located { end = { col = 7, row = 17 }, start = { col = 6, row = 17 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 8, row = 17 }, start = { col = 7, row = 17 } } (Sigil SingleDot) + , Located { end = { col = 13, row = 17 }, start = { col = 8, row = 17 } } (Identifier { name = "hellp", qualifiers = [] }) + , Located { end = { col = 1, row = 19 }, start = { col = 13, row = 17 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 7, row = 19 }, start = { col = 2, row = 19 } } (Identifier { name = "sjhsf", qualifiers = [] }) + , Located { end = { col = 8, row = 19 }, start = { col = 7, row = 19 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 9, row = 19 }, start = { col = 8, row = 19 } } (Whitespace 1) + , Located { end = { col = 10, row = 19 }, start = { col = 9, row = 19 } } (Sigil SingleDot) + , Located { end = { col = 15, row = 19 }, start = { col = 10, row = 19 } } (Identifier { name = "hello", qualifiers = [] }) + , Located { end = { col = 1, row = 21 }, start = { col = 15, row = 19 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } (Identifier { name = "sfhsdf", qualifiers = [] }) + , Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Sigil (Bracket Round Open)) + , Located { end = { col = 9, row = 21 }, start = { col = 8, row = 21 } } (Sigil SingleDot) + , Located { end = { col = 14, row = 21 }, start = { col = 9, row = 21 } } (Identifier { name = "hello", qualifiers = [] }) + , Located { end = { col = 15, row = 21 }, start = { col = 14, row = 21 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 23 }, start = { col = 15, row = 21 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Keyword Case) + , Located { end = { col = 6, row = 23 }, start = { col = 5, row = 23 } } (Sigil SingleDot) + , Located { end = { col = 8, row = 23 }, start = { col = 6, row = 23 } } (Identifier { name = "hi", qualifiers = [] }) + , Located { end = { col = 1, row = 25 }, start = { col = 8, row = 23 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 8, row = 25 }, start = { col = 1, row = 25 } } + (Identifier + { name = "case" + , qualifiers = + [ "Hi" + ] + } + ) + , Located { end = { col = 1, row = 27 }, start = { col = 8, row = 25 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Keyword Case) + , Located { end = { col = 6, row = 27 }, start = { col = 5, row = 27 } } (Whitespace 1) + , Located { end = { col = 7, row = 27 }, start = { col = 6, row = 27 } } (Sigil SingleDot) + , Located { end = { col = 9, row = 27 }, start = { col = 7, row = 27 } } (Identifier { name = "hi", qualifiers = [] }) + , Located { end = { col = 1, row = 29 }, start = { col = 9, row = 27 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] }) + , Located { end = { col = 5, row = 29 }, start = { col = 4, row = 29 } } (Whitespace 1) + , Located { end = { col = 9, row = 29 }, start = { col = 5, row = 29 } } (Keyword Case) + ] + } + , { name = "type-alias-function-nested-missing-return" , source = """type alias Function = (() -> ) type alias Function2 = { a: () -> } @@ -3747,7 +4114,7 @@ type alias Function3 = (Int, () ->, ()) , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Close))) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function") + (BlockTypeAlias_Completish "Function" [] { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } , parents = @@ -3761,7 +4128,7 @@ type alias Function3 = (Int, () ->, ()) , item = Just (Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Sigil (Bracket Curly Close))) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function2") + (BlockTypeAlias_Completish "Function2" [] { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } , parents = @@ -3775,7 +4142,7 @@ type alias Function3 = (Int, () ->, ()) , item = Just (Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil Comma)) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function3") + (BlockTypeAlias_Completish "Function3" [] { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } , parents = @@ -3789,7 +4156,7 @@ type alias Function3 = (Int, () ->, ()) , item = Just (Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Sigil Comma)) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Function3") + (BlockTypeAlias_Completish "Function3" [] { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } , parents = @@ -3805,11 +4172,11 @@ type alias Function3 = (Int, () ->, ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token "Function") + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) @@ -3826,17 +4193,17 @@ type alias Function3 = (Int, () ->, ()) ] 0 ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token "type") + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Keyword Type) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token "alias") + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Keyword Alias) , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token "Function2") + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Identifier { name = "Function2", qualifiers = [] }) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Sigil Assign) , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token "a") + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Identifier { name = "a", qualifiers = [] }) , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil Colon) , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Whitespace 1) , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Sigil (Bracket Round Open)) @@ -3851,11 +4218,11 @@ type alias Function3 = (Int, () ->, ()) ] 0 ) - , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token "type") + , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Keyword Type) , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) - , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token "alias") + , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Keyword Alias) , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) - , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token "Function3") + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Identifier { name = "Function3", qualifiers = [] }) , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Whitespace 1) , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Sigil Assign) , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) @@ -3876,16 +4243,16 @@ type alias Function3 = (Int, () ->, ()) ] 0 ) - , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token "type") + , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Keyword Type) , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Whitespace 1) - , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token "alias") + , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Keyword Alias) , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Whitespace 1) - , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token "Function3") + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Identifier { name = "Function3", qualifiers = [] }) , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Whitespace 1) , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Sigil Assign) , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Whitespace 1) , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token "Int") + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Sigil Comma) , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Whitespace 1) , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Sigil (Bracket Round Open)) @@ -3911,21 +4278,21 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) @@ -3944,16 +4311,16 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) @@ -3976,16 +4343,16 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) @@ -3993,7 +4360,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Token "Int") + , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) ] @@ -4012,27 +4379,36 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Model") []) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns "Model" []) } , Err - { error = Error_BlockStartsWithTypeOrConstructor (TypeOrConstructor "List") - , item = Just (Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "List")) - , state = State_BlockStart + { error = Error_PartwayThroughTypeAlias + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0)) + , state = + State_BlockValueDeclaration + (BlockValueDeclaration_Named + { args = + Stack + [ Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } "Int" + ] + , name = Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } "List" + } + ) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token "Model") + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Model", qualifiers = [] }) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "List") + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Identifier { name = "List", qualifiers = [] }) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token "Int") + , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) ] } @@ -4052,9 +4428,9 @@ List Int ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) ] } @@ -4069,16 +4445,16 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Named (TypeOrConstructor "Hi") (Stack [])) + , state = State_BlockTypeAlias (BlockTypeAlias_Named "Hi" (Stack [])) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) ] } @@ -4093,16 +4469,16 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (TypeOrConstructor "Hi") []) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns "Hi" []) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) @@ -4119,16 +4495,16 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Hi") [] { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) @@ -4150,7 +4526,7 @@ List Int , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0)) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_TypeWithArgs { args = Stack [], name = "Int" } , parents = @@ -4162,17 +4538,17 @@ List Int ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) - , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token "Int") + , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) ] } @@ -4187,16 +4563,16 @@ List Int [ Err { error = Error_PartwayThroughTypeAlias , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) @@ -4214,25 +4590,25 @@ List Int Just [ Err { error = Error_ExpectedColonWhilstParsingRecord - , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token "j7")) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (TypeOrConstructor "Ty") [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Identifier { name = "j7", qualifiers = [] })) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Ty") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token "hi") + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token "j7") + , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Identifier { name = "j7", qualifiers = [] }) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) @@ -4285,7 +4661,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr @@ -4387,7 +4763,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0)) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr @@ -4445,74 +4821,74 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token "A") + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "A", qualifiers = [] }) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token "B") + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Identifier { name = "B", qualifiers = [] }) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil Comma) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token "C") + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Identifier { name = "C", qualifiers = [] }) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil Comma) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token "D") + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Identifier { name = "D", qualifiers = [] }) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token "type") + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Keyword Type) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token "alias") + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Keyword Alias) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token "Hi") + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Token "A") + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Identifier { name = "A", qualifiers = [] }) , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) - , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Token "Int") + , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil Comma) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) - , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Token "C") + , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Identifier { name = "C", qualifiers = [] }) , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Whitespace 1) - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token "D") + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Identifier { name = "D", qualifiers = [] }) , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Whitespace 1) - , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Token "E") + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Identifier { name = "E", qualifiers = [] }) , Located { end = { col = 31, row = 2 }, start = { col = 30, row = 2 } } (Whitespace 1) - , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Token "F") + , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Identifier { name = "F", qualifiers = [] }) , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Sigil Comma) , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Whitespace 1) - , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Token "H") + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Identifier { name = "H", qualifiers = [] }) , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Whitespace 1) - , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Token "I") + , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Identifier { name = "I", qualifiers = [] }) , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Token "J") + , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Identifier { name = "J", qualifiers = [] }) , Located { end = { col = 41, row = 2 }, start = { col = 40, row = 2 } } (Whitespace 1) - , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Token "K") + , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Identifier { name = "K", qualifiers = [] }) , Located { end = { col = 43, row = 2 }, start = { col = 42, row = 2 } } (Sigil (Bracket Round Close)) , Located { end = { col = 44, row = 2 }, start = { col = 43, row = 2 } } (Sigil Comma) , Located { end = { col = 45, row = 2 }, start = { col = 44, row = 2 } } (Whitespace 1) - , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Token "L") + , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Identifier { name = "L", qualifiers = [] }) , Located { end = { col = 47, row = 2 }, start = { col = 46, row = 2 } } (Whitespace 1) - , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Token "M") + , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Identifier { name = "M", qualifiers = [] }) , Located { end = { col = 49, row = 2 }, start = { col = 48, row = 2 } } (Whitespace 1) , Located { end = { col = 50, row = 2 }, start = { col = 49, row = 2 } } (Sigil (Bracket Round Open)) , Located { end = { col = 51, row = 2 }, start = { col = 50, row = 2 } } (Sigil (Bracket Round Close)) , Located { end = { col = 52, row = 2 }, start = { col = 51, row = 2 } } (Whitespace 1) - , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Token "O") + , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Identifier { name = "O", qualifiers = [] }) , Located { end = { col = 54, row = 2 }, start = { col = 53, row = 2 } } (Whitespace 1) - , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Token "P") + , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Identifier { name = "P", qualifiers = [] }) , Located { end = { col = 56, row = 2 }, start = { col = 55, row = 2 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0) ] @@ -4530,7 +4906,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma)) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Bracket @@ -4546,21 +4922,21 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token "A") + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "A", qualifiers = [] }) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) ] @@ -4591,7 +4967,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish (TypeOrConstructor "Hi") + (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Bracket @@ -4607,16 +4983,16 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token "alias") + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token "Hi") + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token "Int") + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) , Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } (Newlines @@ -4644,7 +5020,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token "type") + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0) ] } From b06273712392d7dda76b224fa9cceb515d178385 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 19:03:11 +0100 Subject: [PATCH 079/103] lex .thing as a record accessor literal or function. --- parser-tests/Live.elm | 3 +- parser-tests/snippets/should-not-parse/dots | 6 +- src/Stage/Parse/Lexer.elm | 74 +++++++++++++++------ tests/LexerTest.elm | 3 - tests/ParserLexerTestCases.elm | 39 +++++------ 5 files changed, 73 insertions(+), 52 deletions(-) diff --git a/parser-tests/Live.elm b/parser-tests/Live.elm index ef1ff903..37db6bf2 100644 --- a/parser-tests/Live.elm +++ b/parser-tests/Live.elm @@ -91,7 +91,8 @@ view model = ++ String.padLeft 3 '0' (String.fromInt end.col) ++ "): \"" ++ (item |> Located.unwrap |> Lexer.toString |> String.replace " " "·") - ++ "\"" + ++ "\" " + ++ (item |> Located.unwrap |> Debug.toString) ) ] ) diff --git a/parser-tests/snippets/should-not-parse/dots b/parser-tests/snippets/should-not-parse/dots index f4eed37a..a7150e54 100644 --- a/parser-tests/snippets/should-not-parse/dots +++ b/parser-tests/snippets/should-not-parse/dots @@ -14,11 +14,11 @@ sfsdf .sdfsd asfasf.sdgsghj -(shdf).hellp +(shdf).helloLiteral -(sjhsf) .hello +(sjhsf) .helloFunction -sfhsdf(.hello) +sfhsdf(.helloFunction) case.hi diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 74bbf1a8..3b7829a0 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -13,6 +13,8 @@ type LexItem { qualifiers : List String , name : String } + | RecordAccessorLiteral String + | RecordAccessorFunction String | Keyword Token.Keyword | NumericLiteral String | TextLiteral LexLiteralType String @@ -31,8 +33,6 @@ type LexSigil | Assign | Pipe | Comma - -- TODO(harry): remove and replace by property-accessor etc. - | SingleDot | DoubleDot | ThinArrow | Backslash @@ -118,9 +118,6 @@ toString item = Sigil Comma -> "," - Sigil SingleDot -> - "." - Sigil DoubleDot -> ".." @@ -143,6 +140,12 @@ toString item = (qualifiers ++ [ name ]) |> String.join "." + RecordAccessorLiteral name -> + "." ++ name + + RecordAccessorFunction name -> + "." ++ name + Keyword k -> Token.keywordToString k @@ -202,9 +205,16 @@ parser = (\reversed -> P.oneOf [ P.oneOf - ([ -- commentParser must come before sigil parser as the sigil - -- parser will try to interpret "--" as two "-" sigils. - identifierParser + ([ -- 1. commentParser must come before sigil parser as the sigil + -- parser will try to interpret "--" as two "-" sigils. + -- 2. sigilParser must come before recordAccessorLiteralParser so that ".." is parsed as the + -- DoubleDot sigil. + commentParser + |> P.map (\( ty, commentBody ) -> Comment ty commentBody) + , sigilParser + |> P.map Sigil + , identifierParser + , recordAccessorParser (List.head reversed |> Maybe.map Located.unwrap) , numericLiteralParser |> P.map NumericLiteral , textLiteralParser @@ -216,10 +226,6 @@ parser = else Invalid (delimiterFor ty ++ literalBody) ) - , commentParser - |> P.map (\( ty, commentBody ) -> Comment ty commentBody) - , sigilParser - |> P.map Sigil , P.symbol (P.Token " " ExpectingWhitespace) |> P.andThen (\() -> chompSpacesAndCount) |> P.map (\count -> Whitespace (count + 1)) @@ -236,17 +242,19 @@ parser = ) +word : Parser_ String +word = + P.variable + { start = Char.isAlpha + , inner = \c -> Char.isAlphaNum c || c == '_' + , reserved = Set.empty + , expecting = ExpectingToken + } + + identifierParser : Parser_ LexItem identifierParser = let - word = - P.variable - { start = Char.isAlpha - , inner = \c -> Char.isAlphaNum c || c == '_' - , reserved = Set.empty - , expecting = ExpectingToken - } - loopHelp { reversedQualifiers, name } = P.oneOf [ P.succeed (\x -> x) @@ -299,6 +307,30 @@ identifierParser = ] +recordAccessorParser : Maybe LexItem -> Parser_ LexItem +recordAccessorParser previous = + P.succeed (\x -> x) + |. P.symbol (P.Token "." ExpectingSigil) + |= P.oneOf + [ word + |> P.map + (case previous of + Just (Sigil (Bracket Round Close)) -> + RecordAccessorLiteral + + Just (Sigil (Bracket Curly Close)) -> + RecordAccessorLiteral + + Just (Identifier _) -> + \_ -> Debug.todo "impossible state: add ICE here" + + _ -> + RecordAccessorFunction + ) + , P.succeed (Invalid ".") + ] + + newlinesParser : Parser_ ( List Int, Int ) newlinesParser = let @@ -489,8 +521,6 @@ sigilParser = |> P.map (\() -> Colon) , P.symbol (P.Token "," ExpectingSigil) |> P.map (\() -> Comma) - , P.symbol (P.Token "." ExpectingSigil) - |> P.map (\() -> SingleDot) , P.symbol (P.Token "|" ExpectingSigil) |> P.map (\() -> Pipe) ] diff --git a/tests/LexerTest.elm b/tests/LexerTest.elm index 69c342fa..8a0c7ac5 100644 --- a/tests/LexerTest.elm +++ b/tests/LexerTest.elm @@ -449,9 +449,6 @@ expr = , ( "Zero - exhibit 2" , "0e5" ) - , ( "starting with dot disallowed" - , ".123" - ) , ( "ending with dot disallowed" , "123." ) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 527ce385..3b4da7fd 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -3741,11 +3741,11 @@ sfsdf .sdfsd asfasf.sdgsghj -(shdf).hellp +(shdf).helloLiteral -(sjhsf) .hello +(sjhsf) .helloFunction -sfhsdf(.hello) +sfhsdf(.helloFunction) case.hi @@ -3845,12 +3845,12 @@ Hi. case""" } , Err { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 2, row = 11 }, start = { col = 1, row = 11 } } (Sigil SingleDot)) + , item = Just (Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (RecordAccessorFunction "sf")) , state = State_BlockStart } , Err { error = Error_InvalidToken (Expecting_Sigil Assign) - , item = Just (Located { end = { col = 8, row = 13 }, start = { col = 7, row = 13 } } (Sigil SingleDot)) + , item = Just (Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (RecordAccessorFunction "sdfsd")) , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } "sfsdf" }) } , Err @@ -3987,8 +3987,7 @@ Hi. case""" ] 0 ) - , Located { end = { col = 2, row = 11 }, start = { col = 1, row = 11 } } (Sigil SingleDot) - , Located { end = { col = 4, row = 11 }, start = { col = 2, row = 11 } } (Identifier { name = "sf", qualifiers = [] }) + , Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (RecordAccessorFunction "sf") , Located { end = { col = 1, row = 13 }, start = { col = 4, row = 11 } } (Newlines [ 0 @@ -3997,8 +3996,7 @@ Hi. case""" ) , Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } (Identifier { name = "sfsdf", qualifiers = [] }) , Located { end = { col = 7, row = 13 }, start = { col = 6, row = 13 } } (Whitespace 1) - , Located { end = { col = 8, row = 13 }, start = { col = 7, row = 13 } } (Sigil SingleDot) - , Located { end = { col = 13, row = 13 }, start = { col = 8, row = 13 } } (Identifier { name = "sdfsd", qualifiers = [] }) + , Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (RecordAccessorFunction "sdfsd") , Located { end = { col = 1, row = 15 }, start = { col = 13, row = 13 } } (Newlines [ 0 @@ -4022,9 +4020,8 @@ Hi. case""" , Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Sigil (Bracket Round Open)) , Located { end = { col = 6, row = 17 }, start = { col = 2, row = 17 } } (Identifier { name = "shdf", qualifiers = [] }) , Located { end = { col = 7, row = 17 }, start = { col = 6, row = 17 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 8, row = 17 }, start = { col = 7, row = 17 } } (Sigil SingleDot) - , Located { end = { col = 13, row = 17 }, start = { col = 8, row = 17 } } (Identifier { name = "hellp", qualifiers = [] }) - , Located { end = { col = 1, row = 19 }, start = { col = 13, row = 17 } } + , Located { end = { col = 20, row = 17 }, start = { col = 7, row = 17 } } (RecordAccessorLiteral "helloLiteral") + , Located { end = { col = 1, row = 19 }, start = { col = 20, row = 17 } } (Newlines [ 0 ] @@ -4034,9 +4031,8 @@ Hi. case""" , Located { end = { col = 7, row = 19 }, start = { col = 2, row = 19 } } (Identifier { name = "sjhsf", qualifiers = [] }) , Located { end = { col = 8, row = 19 }, start = { col = 7, row = 19 } } (Sigil (Bracket Round Close)) , Located { end = { col = 9, row = 19 }, start = { col = 8, row = 19 } } (Whitespace 1) - , Located { end = { col = 10, row = 19 }, start = { col = 9, row = 19 } } (Sigil SingleDot) - , Located { end = { col = 15, row = 19 }, start = { col = 10, row = 19 } } (Identifier { name = "hello", qualifiers = [] }) - , Located { end = { col = 1, row = 21 }, start = { col = 15, row = 19 } } + , Located { end = { col = 23, row = 19 }, start = { col = 9, row = 19 } } (RecordAccessorFunction "helloFunction") + , Located { end = { col = 1, row = 21 }, start = { col = 23, row = 19 } } (Newlines [ 0 ] @@ -4044,18 +4040,16 @@ Hi. case""" ) , Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } (Identifier { name = "sfhsdf", qualifiers = [] }) , Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 9, row = 21 }, start = { col = 8, row = 21 } } (Sigil SingleDot) - , Located { end = { col = 14, row = 21 }, start = { col = 9, row = 21 } } (Identifier { name = "hello", qualifiers = [] }) - , Located { end = { col = 15, row = 21 }, start = { col = 14, row = 21 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 23 }, start = { col = 15, row = 21 } } + , Located { end = { col = 22, row = 21 }, start = { col = 8, row = 21 } } (RecordAccessorFunction "helloFunction") + , Located { end = { col = 23, row = 21 }, start = { col = 22, row = 21 } } (Sigil (Bracket Round Close)) + , Located { end = { col = 1, row = 23 }, start = { col = 23, row = 21 } } (Newlines [ 0 ] 0 ) , Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Keyword Case) - , Located { end = { col = 6, row = 23 }, start = { col = 5, row = 23 } } (Sigil SingleDot) - , Located { end = { col = 8, row = 23 }, start = { col = 6, row = 23 } } (Identifier { name = "hi", qualifiers = [] }) + , Located { end = { col = 8, row = 23 }, start = { col = 5, row = 23 } } (RecordAccessorFunction "hi") , Located { end = { col = 1, row = 25 }, start = { col = 8, row = 23 } } (Newlines [ 0 @@ -4078,8 +4072,7 @@ Hi. case""" ) , Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Keyword Case) , Located { end = { col = 6, row = 27 }, start = { col = 5, row = 27 } } (Whitespace 1) - , Located { end = { col = 7, row = 27 }, start = { col = 6, row = 27 } } (Sigil SingleDot) - , Located { end = { col = 9, row = 27 }, start = { col = 7, row = 27 } } (Identifier { name = "hi", qualifiers = [] }) + , Located { end = { col = 9, row = 27 }, start = { col = 6, row = 27 } } (RecordAccessorFunction "hi") , Located { end = { col = 1, row = 29 }, start = { col = 9, row = 27 } } (Newlines [ 0 From a3551846778ac02dc77ab6d16496325b570a3840 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 20:02:41 +0100 Subject: [PATCH 080/103] restructure lexer adds some classes of item --- src/Stage/Parse/Contextualize.elm | 243 ++- src/Stage/Parse/Lexer.elm | 183 +- tests/LexerTest.elm | 5 +- tests/ParserLexerTestCases.elm | 3040 +++++++++++++++-------------- 4 files changed, 1812 insertions(+), 1659 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 891e3612..533f8bcf 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -355,7 +355,7 @@ runHelp items state = :: state.previousBlocks , state = case Located.unwrap item of - Lexer.Newlines _ 0 -> + Lexer.Token (Lexer.Newlines _ 0) -> State_BlockStart _ -> @@ -405,8 +405,8 @@ runHelp items state = -- parsers -parseAnything : State -> Located LexItem -> ParseResult -parseAnything state = +parseAnything : State -> Located Lexer.LexItem -> ParseResult +parseAnything state item = let newTypeAliasState aliasName typeArgs res = case res of @@ -447,101 +447,116 @@ parseAnything state = } |> ValueDeclaration |> ParseResult_Complete - in - case state of - State_Error_Recovery -> - \item -> - case Located.unwrap item of - Lexer.Newlines _ 0 -> - State_BlockStart - |> ParseResult_Ok - _ -> - State_Error_Recovery - |> ParseResult_Ok + region = + Located.getRegion item + in + case Located.unwrap item of + Lexer.Ignorable _ -> + ParseResult_Skip - State_BlockStart -> - parseBlockStart + Lexer.Invalid _ -> + ParseResult_Err (Error_InvalidToken Expecting_Unknown) - State_BlockFirstItem BlockFirstItem_Type -> - parseTypeBlock + Lexer.Token token -> + case state of + State_Error_Recovery -> + case token of + Lexer.Newlines _ 0 -> + State_BlockStart + |> ParseResult_Ok - State_BlockFirstItem BlockFirstItem_Module -> - Debug.todo "BlockFirstItem_Module" + _ -> + State_Error_Recovery + |> ParseResult_Ok - State_BlockValueDeclaration (BlockValueDeclaration_Named { name, args }) -> - parseLowercaseArgsOrAssignment - (\newArg -> - State_BlockValueDeclaration - (BlockValueDeclaration_Named - { name = name - , args = newArg |> pushOnto args - } - ) - ) - (State_BlockValueDeclaration - (BlockValueDeclaration_NamedAssigns - { name = name - , args = args |> toList (\x -> x) - } - ) - ) + State_BlockStart -> + parseBlockStart region token - State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> - parserExpressionFromEmpty - (newExpressionState name args) + State_BlockFirstItem BlockFirstItem_Type -> + parseTypeBlock token - State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> - parserExpression - (newExpressionState name args) - partialExpr + State_BlockFirstItem BlockFirstItem_Module -> + Debug.todo "BlockFirstItem_Module" - State_BlockTypeAlias BlockTypeAlias_Keywords -> - parseTypeAliasName - - State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> - parseLowercaseArgsOrAssignment - (\newTypeArg -> - State_BlockTypeAlias - (BlockTypeAlias_Named - name - (Located.unwrap newTypeArg |> pushOnto typeArgs) + State_BlockValueDeclaration (BlockValueDeclaration_Named { name, args }) -> + parseLowercaseArgsOrAssignment + (\newArg -> + State_BlockValueDeclaration + (BlockValueDeclaration_Named + { name = name + , args = newArg |> pushOnto args + } + ) ) - ) - (State_BlockTypeAlias - (BlockTypeAlias_NamedAssigns - name - (typeArgs |> toList (\x -> x)) - ) - ) - - State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> - parserTypeExprFromEmpty - (newTypeAliasState name typeArgs) - - State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> - parserTypeExpr - (newTypeAliasState name typeArgs) - exprSoFar - - State_BlockCustomType (BlockCustomType_Named name typeArgs) -> - parseLowercaseArgsOrAssignment - (\newTypeArg -> - State_BlockCustomType - (BlockCustomType_Named - name - (Located.unwrap newTypeArg |> pushOnto typeArgs) + (State_BlockValueDeclaration + (BlockValueDeclaration_NamedAssigns + { name = name + , args = args |> toList (\x -> x) + } + ) ) - ) - (State_BlockCustomType - (BlockCustomType_NamedAssigns - name - (typeArgs |> toList (\x -> x)) - ) - ) + (Located.located region token) + + State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> + parserExpressionFromEmpty (newExpressionState name args) (Located.located region token) + + State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> + parserExpression + (newExpressionState name args) + partialExpr + (Located.located region token) + + State_BlockTypeAlias BlockTypeAlias_Keywords -> + parseTypeAliasName token + + State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> + parseLowercaseArgsOrAssignment + (\newTypeArg -> + State_BlockTypeAlias + (BlockTypeAlias_Named + name + (Located.unwrap newTypeArg |> pushOnto typeArgs) + ) + ) + (State_BlockTypeAlias + (BlockTypeAlias_NamedAssigns + name + (typeArgs |> toList (\x -> x)) + ) + ) + (Located.located region token) + + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> + parserTypeExprFromEmpty + (newTypeAliasState name typeArgs) + (Located.located region token) + + State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> + parserTypeExpr + (newTypeAliasState name typeArgs) + exprSoFar + (Located.located region token) + + State_BlockCustomType (BlockCustomType_Named name typeArgs) -> + parseLowercaseArgsOrAssignment + (\newTypeArg -> + State_BlockCustomType + (BlockCustomType_Named + name + (Located.unwrap newTypeArg |> pushOnto typeArgs) + ) + ) + (State_BlockCustomType + (BlockCustomType_NamedAssigns + name + (typeArgs |> toList (\x -> x)) + ) + ) + (Located.located region token) - State_BlockCustomType (BlockCustomType_NamedAssigns name typeArgs) -> - Debug.todo "BlockCustomType_NamedAssigns" + State_BlockCustomType (BlockCustomType_NamedAssigns name typeArgs) -> + Debug.todo "BlockCustomType_NamedAssigns" {-| @@ -552,13 +567,13 @@ parseAnything state = If the LexItem is a `Newlines` with indentation or is `Whitespace`. -} -parseBlockStart : Located LexItem -> ParseResult -parseBlockStart item = +parseBlockStart : Located.Region -> Lexer.LexToken -> ParseResult +parseBlockStart region item = let - withCorrectLocation x = - Located.map (\_ -> x) item + withCorrectLocation = + Located.located region in - case Located.unwrap item of + case item of Lexer.Keyword Token.Type -> ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Type) @@ -588,16 +603,13 @@ parseBlockStart item = Lexer.Newlines _ _ -> ParseResult_Panic "parseBlockStart expects a block but found some indented content." - Lexer.Whitespace _ -> - ParseResult_Panic "parseBlockStart expects a block but found some whitespace" - _ -> ParseResult_Err (Error_InvalidToken Expecting_Block) -parseTypeBlock : Located LexItem -> ParseResult +parseTypeBlock : Lexer.LexToken -> ParseResult parseTypeBlock item = - case Located.unwrap item of + case item of Lexer.Keyword Token.Alias -> State_BlockTypeAlias BlockTypeAlias_Keywords |> ParseResult_Ok @@ -623,9 +635,6 @@ parseTypeBlock item = Lexer.Newlines _ _ -> ParseResult_Skip - Whitespace _ -> - ParseResult_Skip - _ -> -- TODO(harry) indicate that we could also be expecting the `alias` -- keyword. @@ -633,9 +642,9 @@ parseTypeBlock item = |> ParseResult_Err -parseTypeAliasName : Located LexItem -> ParseResult +parseTypeAliasName : Lexer.LexToken -> ParseResult parseTypeAliasName item = - case Located.unwrap item of + case item of Lexer.Keyword other -> Error_MisplacedKeyword other |> ParseResult_Err @@ -655,15 +664,12 @@ parseTypeAliasName item = Lexer.Newlines _ _ -> ParseResult_Skip - Lexer.Whitespace _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_TypeName |> ParseResult_Err -parseLowercaseArgsOrAssignment : (Located String -> State) -> State -> Located LexItem -> ParseResult +parseLowercaseArgsOrAssignment : (Located String -> State) -> State -> Located Lexer.LexToken -> ParseResult parseLowercaseArgsOrAssignment onTypeArg onAssignment item = let withCorrectLocation x = @@ -695,9 +701,6 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = Lexer.Newlines _ _ -> ParseResult_Skip - Lexer.Whitespace _ -> - ParseResult_Skip - _ -> Error_InvalidToken (Expecting_Sigil Lexer.Assign) |> ParseResult_Err @@ -705,7 +708,7 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = parserTypeExprFromEmpty : (TypeExpressionResult -> ParseResult) - -> Located LexItem + -> Located Lexer.LexToken -> ParseResult parserTypeExprFromEmpty newState item = case Located.unwrap item of @@ -765,9 +768,6 @@ parserTypeExprFromEmpty newState item = Lexer.Newlines _ _ -> ParseResult_Skip - Lexer.Whitespace _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -776,7 +776,7 @@ parserTypeExprFromEmpty newState item = parserTypeExpr : (TypeExpressionResult -> ParseResult) -> PartialTypeExpressionLeaf - -> Located LexItem + -> Located Lexer.LexToken -> ParseResult parserTypeExpr newState prevExpr item = case Located.unwrap item of @@ -1002,9 +1002,6 @@ parserTypeExpr newState prevExpr item = Lexer.Newlines _ _ -> ParseResult_Skip - Lexer.Whitespace _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -1012,7 +1009,7 @@ parserTypeExpr newState prevExpr item = parserExpressionFromEmpty : (ExpressionResult -> ParseResult) - -> Located LexItem + -> Located Lexer.LexToken -> ParseResult parserExpressionFromEmpty newState item = let @@ -1040,9 +1037,6 @@ parserExpressionFromEmpty newState item = Lexer.Newlines _ _ -> ParseResult_Skip - Lexer.Whitespace _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -1051,7 +1045,7 @@ parserExpressionFromEmpty newState item = parserExpression : (ExpressionResult -> ParseResult) -> ExpressionNestingLeaf - -> Located LexItem + -> Located Lexer.LexToken -> ParseResult parserExpression newState prevExpr item = let @@ -1096,9 +1090,6 @@ parserExpression newState prevExpr item = Lexer.Newlines _ _ -> ParseResult_Skip - Lexer.Whitespace _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -1230,7 +1221,7 @@ exprAppend ({ parents, nesting } as currentLeaf) token = ) Just existingRoot -> - Error_TypeDoesNotTakeArgs TypeExpression_Unit newType + Error_TypeDoesNotTakeArgs existingRoot newType |> Err NestingLeafType_Expr expr -> diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 3b7829a0..16117977 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -8,6 +8,12 @@ import Stage.Parse.Token as Token type LexItem + = Token LexToken + | Ignorable LexIgnorable + | Invalid LexInvalid + + +type LexToken = Sigil LexSigil | Identifier { qualifiers : List String @@ -18,14 +24,21 @@ type LexItem | Keyword Token.Keyword | NumericLiteral String | TextLiteral LexLiteralType String - | Whitespace Int | Newlines (List Int) Int + + +type LexIgnorable + = Whitespace Int | Comment LexCommentType String - | IdentifierWithTrailingDot + + +type LexInvalid + = IdentifierWithTrailingDot { qualifiers : List String , name : String } - | Invalid String + | IllegalCharacter Char + | OtherInvalid String type LexSigil @@ -91,74 +104,74 @@ type alias Parser_ a = toString : LexItem -> String toString item = case item of - Sigil (Bracket Round Open) -> + Token (Sigil (Bracket Round Open)) -> "(" - Sigil (Bracket Round Close) -> + Token (Sigil (Bracket Round Close)) -> ")" - Sigil (Bracket Square Open) -> + Token (Sigil (Bracket Square Open)) -> "[" - Sigil (Bracket Square Close) -> + Token (Sigil (Bracket Square Close)) -> "]" - Sigil (Bracket Curly Open) -> + Token (Sigil (Bracket Curly Open)) -> "{" - Sigil (Bracket Curly Close) -> + Token (Sigil (Bracket Curly Close)) -> "}" - Sigil Assign -> + Token (Sigil Assign) -> "=" - Sigil Pipe -> + Token (Sigil Pipe) -> "|" - Sigil Comma -> + Token (Sigil Comma) -> "," - Sigil DoubleDot -> + Token (Sigil DoubleDot) -> ".." - Sigil ThinArrow -> + Token (Sigil ThinArrow) -> "->" - Sigil Backslash -> + Token (Sigil Backslash) -> "\\" - Sigil Colon -> + Token (Sigil Colon) -> ":" - Sigil Underscore -> + Token (Sigil Underscore) -> "_" - Sigil (Operator op) -> + Token (Sigil (Operator op)) -> Operator.toString op - Identifier { qualifiers, name } -> + Token (Identifier { qualifiers, name }) -> (qualifiers ++ [ name ]) |> String.join "." - RecordAccessorLiteral name -> + Token (RecordAccessorLiteral name) -> "." ++ name - RecordAccessorFunction name -> + Token (RecordAccessorFunction name) -> "." ++ name - Keyword k -> + Token (Keyword k) -> Token.keywordToString k - NumericLiteral s -> + Token (NumericLiteral s) -> s - TextLiteral ty s -> + Token (TextLiteral ty s) -> delimiterFor ty ++ s ++ delimiterFor ty - Whitespace i -> + Ignorable (Whitespace i) -> String.repeat i " " - Newlines empties identationSpaces -> + Token (Newlines empties identationSpaces) -> (empties |> List.map (\spacesInEmptyLine -> "\n" ++ String.repeat spacesInEmptyLine " ") |> String.join "" @@ -166,20 +179,23 @@ toString item = ++ "\n" ++ String.repeat identationSpaces " " - Comment LineComment s -> + Ignorable (Comment LineComment s) -> "//" ++ s - Comment MutlilineComment s -> + Ignorable (Comment MutlilineComment s) -> "{-" ++ s ++ "-}" - Comment DocComment s -> + Ignorable (Comment DocComment s) -> "{-|" ++ s ++ "-}" - IdentifierWithTrailingDot { qualifiers, name } -> + Invalid (IdentifierWithTrailingDot { qualifiers, name }) -> (qualifiers ++ [ name, "" ]) |> String.join "." - Invalid s -> + Invalid (IllegalCharacter c) -> + String.fromChar c + + Invalid (OtherInvalid s) -> s @@ -210,29 +226,39 @@ parser = -- 2. sigilParser must come before recordAccessorLiteralParser so that ".." is parsed as the -- DoubleDot sigil. commentParser - |> P.map (\( ty, commentBody ) -> Comment ty commentBody) + |> P.map (\( ty, commentBody ) -> Comment ty commentBody |> Ignorable) , sigilParser - |> P.map Sigil + |> P.map (Sigil >> Token) , identifierParser , recordAccessorParser (List.head reversed |> Maybe.map Located.unwrap) , numericLiteralParser - |> P.map NumericLiteral + |> P.map (NumericLiteral >> Token) , textLiteralParser |> P.map (\( ty, terminates, literalBody ) -> if terminates then - TextLiteral ty literalBody + TextLiteral ty literalBody |> Token else - Invalid (delimiterFor ty ++ literalBody) + (delimiterFor ty ++ literalBody) + |> OtherInvalid + |> Invalid ) , P.symbol (P.Token " " ExpectingWhitespace) |> P.andThen (\() -> chompSpacesAndCount) - |> P.map (\count -> Whitespace (count + 1)) + |> P.map (\count -> (count + 1) |> Whitespace |> Ignorable) , newlinesParser - |> P.map (\( emptyLines, indentation ) -> Newlines emptyLines indentation) + |> P.map (\( emptyLines, indentation ) -> Newlines emptyLines indentation |> Token) , P.getChompedString (P.chompIf (\_ -> True) ExpectingAnything) - |> P.map (\s -> Invalid s) + |> P.map + (\s -> + case String.toList s of + [ c ] -> + c |> IllegalCharacter |> Invalid + + _ -> + Debug.todo "ICE here" + ) ] |> List.map (located >> P.map (\t -> P.Loop (t :: reversed))) ) @@ -272,6 +298,7 @@ identifierParser = , name = name } |> IdentifierWithTrailingDot + |> Invalid |> P.Done |> P.succeed ] @@ -279,29 +306,75 @@ identifierParser = , name = name } |> Identifier + |> Token |> P.Done |> P.succeed ] in P.oneOf [ P.token (P.Token "module" ExpectingKeyword) - |> P.map (\() -> Keyword Token.Module) + |> P.map + (\() -> + Token.Module + |> Keyword + |> Token + ) , P.token (P.Token "type" ExpectingKeyword) - |> P.map (\() -> Keyword Token.Type) + |> P.map + (\() -> + Token.Type + |> Keyword + |> Token + ) , P.token (P.Token "alias" ExpectingKeyword) - |> P.map (\() -> Keyword Token.Alias) + |> P.map + (\() -> + Token.Alias + |> Keyword + |> Token + ) , P.token (P.Token "exposing" ExpectingKeyword) - |> P.map (\() -> Keyword Token.Exposing) + |> P.map + (\() -> + Token.Exposing + |> Keyword + |> Token + ) , P.token (P.Token "case" ExpectingKeyword) - |> P.map (\() -> Keyword Token.Case) + |> P.map + (\() -> + Token.Case + |> Keyword + |> Token + ) , P.token (P.Token "of" ExpectingKeyword) - |> P.map (\() -> Keyword Token.Of) + |> P.map + (\() -> + Token.Of + |> Keyword + |> Token + ) , P.token (P.Token "if" ExpectingKeyword) - |> P.map (\() -> Keyword Token.If) + |> P.map + (\() -> + Token.If + |> Keyword + |> Token + ) , P.token (P.Token "then" ExpectingKeyword) - |> P.map (\() -> Keyword Token.Then) + |> P.map + (\() -> + Token.Then + |> Keyword + |> Token + ) , P.token (P.Token "else" ExpectingKeyword) - |> P.map (\() -> Keyword Token.Else) + |> P.map + (\() -> + Token.Else + |> Keyword + |> Token + ) , word |> P.andThen (\first -> P.loop { reversedQualifiers = [], name = first } loopHelp) ] @@ -315,19 +388,19 @@ recordAccessorParser previous = [ word |> P.map (case previous of - Just (Sigil (Bracket Round Close)) -> - RecordAccessorLiteral + Just (Token (Sigil (Bracket Round Close))) -> + RecordAccessorLiteral >> Token - Just (Sigil (Bracket Curly Close)) -> - RecordAccessorLiteral + Just (Token (Sigil (Bracket Curly Close))) -> + RecordAccessorLiteral >> Token - Just (Identifier _) -> + Just (Token (Identifier _)) -> \_ -> Debug.todo "impossible state: add ICE here" _ -> - RecordAccessorFunction + RecordAccessorFunction >> Token ) - , P.succeed (Invalid ".") + , P.succeed ('.' |> IllegalCharacter |> Invalid) ] diff --git a/tests/LexerTest.elm b/tests/LexerTest.elm index 8a0c7ac5..3c205f5f 100644 --- a/tests/LexerTest.elm +++ b/tests/LexerTest.elm @@ -30,9 +30,12 @@ runTest ( description, input ) = (List.filterMap (\item -> case Located.unwrap item of - Invalid s -> + Invalid (OtherInvalid s) -> Just s + Invalid (IllegalCharacter c) -> + Just (String.fromChar c) + _ -> Nothing ) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 3b4da7fd..6e7133aa 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -60,23 +60,25 @@ b = 78 ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) - , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 6, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) - , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) - , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) - , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") - , Located { end = { col = 1, row = 4 }, start = { col = 7, row = 3 } } (Newlines [] 0) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Token (NumericLiteral "78")) + , Located { end = { col = 1, row = 4 }, start = { col = 7, row = 3 } } (Token (Newlines [] 0)) ] } , { name = "expression-int-add" @@ -148,38 +150,40 @@ b = 78 + 5 + 2+ 4 ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) - , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") - , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Whitespace 1) - , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Sigil (Operator Add)) - , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Whitespace 1) - , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Token (NumericLiteral "5")) + , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) - , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) - , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) - , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") - , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Whitespace 1) - , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil (Operator Add)) - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5") - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Sigil (Operator Add)) - , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Whitespace 1) - , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (NumericLiteral "2") - , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Sigil (Operator Add)) - , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Whitespace 1) - , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (NumericLiteral "4") - , Located { end = { col = 1, row = 4 }, start = { col = 18, row = 3 } } (Newlines [] 0) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Token (NumericLiteral "78")) + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Token (NumericLiteral "5")) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Token (NumericLiteral "2")) + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Token (NumericLiteral "4")) + , Located { end = { col = 1, row = 4 }, start = { col = 18, row = 3 } } (Token (Newlines [] 0)) ] } , { name = "expression-int-multiply" @@ -260,43 +264,45 @@ b = 78 * 5 * 2 / 4 * 5 ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) - , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") - , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Whitespace 1) - , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Sigil (Operator Multiply)) - , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Whitespace 1) - , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Token (NumericLiteral "5")) + , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) - , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) - , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) - , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") - , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Whitespace 1) - , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil (Operator Multiply)) - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5") - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Sigil (Operator Multiply)) - , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Whitespace 1) - , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (NumericLiteral "2") - , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Whitespace 1) - , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Sigil (Operator Divide)) - , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Whitespace 1) - , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (NumericLiteral "4") - , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Sigil (Operator Multiply)) - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (NumericLiteral "5") - , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Newlines [] 0) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Token (NumericLiteral "78")) + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Token (NumericLiteral "5")) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Token (NumericLiteral "2")) + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Token (Sigil (Operator Divide))) + , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Token (NumericLiteral "4")) + , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (NumericLiteral "5")) + , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Token (Newlines [] 0)) ] } , { name = "expression-int-multiply-and-add" @@ -710,204 +716,208 @@ b4 = 78 / 5 / 2 / 4 + 5 ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) - , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") - , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Whitespace 1) - , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Sigil (Operator Multiply)) - , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Whitespace 1) - , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5") - , Located { end = { col = 11, row = 1 }, start = { col = 10, row = 1 } } (Whitespace 1) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Sigil (Operator Add)) - , Located { end = { col = 13, row = 1 }, start = { col = 12, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (NumericLiteral "6") - , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) - , Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (Identifier { name = "a1", qualifiers = [] }) - , Located { end = { col = 4, row = 2 }, start = { col = 3, row = 2 } } (Whitespace 1) - , Located { end = { col = 5, row = 2 }, start = { col = 4, row = 2 } } (Sigil Assign) - , Located { end = { col = 7, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 2) - , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (NumericLiteral "7") - , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Whitespace 1) - , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Sigil (Operator Add)) - , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 1) - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (NumericLiteral "5") - , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Sigil (Operator Multiply)) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (NumericLiteral "5") - , Located { end = { col = 1, row = 3 }, start = { col = 16, row = 2 } } (Newlines [] 0) - , Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "a11", qualifiers = [] }) - , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Assign) - , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 2) - , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (NumericLiteral "7") - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Sigil (Operator Add)) - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (NumericLiteral "5") - , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Whitespace 1) - , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Sigil (Operator Multiply)) - , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Whitespace 1) - , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (NumericLiteral "5") - , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Whitespace 1) - , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Sigil (Operator Add)) - , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (NumericLiteral "6") - , Located { end = { col = 1, row = 4 }, start = { col = 21, row = 3 } } (Newlines [] 0) - , Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (Identifier { name = "a2", qualifiers = [] }) - , Located { end = { col = 4, row = 4 }, start = { col = 3, row = 4 } } (Whitespace 1) - , Located { end = { col = 5, row = 4 }, start = { col = 4, row = 4 } } (Sigil Assign) - , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Whitespace 1) - , Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (NumericLiteral "100") - , Located { end = { col = 11, row = 4 }, start = { col = 9, row = 4 } } (Whitespace 2) - , Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } (Sigil (Operator Add)) - , Located { end = { col = 13, row = 4 }, start = { col = 12, row = 4 } } (Whitespace 1) - , Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (NumericLiteral "5") - , Located { end = { col = 15, row = 4 }, start = { col = 14, row = 4 } } (Whitespace 1) - , Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } (Sigil (Operator Multiply)) - , Located { end = { col = 17, row = 4 }, start = { col = 16, row = 4 } } (Whitespace 1) - , Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (NumericLiteral "5") - , Located { end = { col = 1, row = 5 }, start = { col = 18, row = 4 } } (Newlines [] 0) - , Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (Identifier { name = "a3", qualifiers = [] }) - , Located { end = { col = 4, row = 5 }, start = { col = 3, row = 5 } } (Whitespace 1) - , Located { end = { col = 5, row = 5 }, start = { col = 4, row = 5 } } (Sigil Assign) - , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) - , Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (NumericLiteral "345") - , Located { end = { col = 10, row = 5 }, start = { col = 9, row = 5 } } (Whitespace 1) - , Located { end = { col = 11, row = 5 }, start = { col = 10, row = 5 } } (Sigil (Operator Multiply)) - , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) - , Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (NumericLiteral "2234") - , Located { end = { col = 17, row = 5 }, start = { col = 16, row = 5 } } (Whitespace 1) - , Located { end = { col = 18, row = 5 }, start = { col = 17, row = 5 } } (Sigil (Operator Add)) - , Located { end = { col = 19, row = 5 }, start = { col = 18, row = 5 } } (Whitespace 1) - , Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (NumericLiteral "2342") - , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) - , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Sigil (Operator Multiply)) - , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Whitespace 1) - , Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (NumericLiteral "1010") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Token (NumericLiteral "5")) + , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Token (NumericLiteral "5")) + , Located { end = { col = 11, row = 1 }, start = { col = 10, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 13, row = 1 }, start = { col = 12, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Token (NumericLiteral "6")) + , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = "a1", qualifiers = [] })) + , Located { end = { col = 4, row = 2 }, start = { col = 3, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 5, row = 2 }, start = { col = 4, row = 2 } } (Token (Sigil Assign)) + , Located { end = { col = 7, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 2)) + , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token (NumericLiteral "7")) + , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Token (NumericLiteral "5")) + , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (NumericLiteral "5")) + , Located { end = { col = 1, row = 3 }, start = { col = 16, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "a11", qualifiers = [] })) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 2)) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Token (NumericLiteral "7")) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Token (NumericLiteral "5")) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Token (NumericLiteral "5")) + , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Token (NumericLiteral "6")) + , Located { end = { col = 1, row = 4 }, start = { col = 21, row = 3 } } (Token (Newlines [] 0)) + , Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (Token (Identifier { name = "a2", qualifiers = [] })) + , Located { end = { col = 4, row = 4 }, start = { col = 3, row = 4 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 5, row = 4 }, start = { col = 4, row = 4 } } (Token (Sigil Assign)) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (Token (NumericLiteral "100")) + , Located { end = { col = 11, row = 4 }, start = { col = 9, row = 4 } } (Ignorable (Whitespace 2)) + , Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 13, row = 4 }, start = { col = 12, row = 4 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (Token (NumericLiteral "5")) + , Located { end = { col = 15, row = 4 }, start = { col = 14, row = 4 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 17, row = 4 }, start = { col = 16, row = 4 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Token (NumericLiteral "5")) + , Located { end = { col = 1, row = 5 }, start = { col = 18, row = 4 } } (Token (Newlines [] 0)) + , Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (Token (Identifier { name = "a3", qualifiers = [] })) + , Located { end = { col = 4, row = 5 }, start = { col = 3, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 5, row = 5 }, start = { col = 4, row = 5 } } (Token (Sigil Assign)) + , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (Token (NumericLiteral "345")) + , Located { end = { col = 10, row = 5 }, start = { col = 9, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 5 }, start = { col = 10, row = 5 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (Token (NumericLiteral "2234")) + , Located { end = { col = 17, row = 5 }, start = { col = 16, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 5 }, start = { col = 17, row = 5 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 19, row = 5 }, start = { col = 18, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (Token (NumericLiteral "2342")) + , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Token (NumericLiteral "1010")) , Located { end = { col = 1, row = 8 }, start = { col = 30, row = 5 } } - (Newlines - [ 0 - , 0 - ] - 0 - ) - , Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 3, row = 8 }, start = { col = 2, row = 8 } } (Whitespace 1) - , Located { end = { col = 4, row = 8 }, start = { col = 3, row = 8 } } (Sigil Assign) - , Located { end = { col = 5, row = 8 }, start = { col = 4, row = 8 } } (Whitespace 1) - , Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (NumericLiteral "78") - , Located { end = { col = 8, row = 8 }, start = { col = 7, row = 8 } } (Whitespace 1) - , Located { end = { col = 9, row = 8 }, start = { col = 8, row = 8 } } (Sigil (Operator Add)) - , Located { end = { col = 10, row = 8 }, start = { col = 9, row = 8 } } (Whitespace 1) - , Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (NumericLiteral "5") - , Located { end = { col = 12, row = 8 }, start = { col = 11, row = 8 } } (Whitespace 1) - , Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } (Sigil (Operator Multiply)) - , Located { end = { col = 14, row = 8 }, start = { col = 13, row = 8 } } (Whitespace 1) - , Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (NumericLiteral "2") - , Located { end = { col = 16, row = 8 }, start = { col = 15, row = 8 } } (Whitespace 1) - , Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } (Sigil (Operator Divide)) - , Located { end = { col = 18, row = 8 }, start = { col = 17, row = 8 } } (Whitespace 1) - , Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (NumericLiteral "4") - , Located { end = { col = 20, row = 8 }, start = { col = 19, row = 8 } } (Whitespace 1) - , Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } (Sigil (Operator Multiply)) - , Located { end = { col = 22, row = 8 }, start = { col = 21, row = 8 } } (Whitespace 1) - , Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (NumericLiteral "5") - , Located { end = { col = 1, row = 9 }, start = { col = 23, row = 8 } } (Newlines [] 0) - , Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (Identifier { name = "b1", qualifiers = [] }) - , Located { end = { col = 4, row = 9 }, start = { col = 3, row = 9 } } (Whitespace 1) - , Located { end = { col = 5, row = 9 }, start = { col = 4, row = 9 } } (Sigil Assign) - , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Whitespace 1) - , Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (NumericLiteral "78") - , Located { end = { col = 9, row = 9 }, start = { col = 8, row = 9 } } (Whitespace 1) - , Located { end = { col = 10, row = 9 }, start = { col = 9, row = 9 } } (Sigil (Operator Multiply)) - , Located { end = { col = 11, row = 9 }, start = { col = 10, row = 9 } } (Whitespace 1) - , Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (NumericLiteral "5") - , Located { end = { col = 13, row = 9 }, start = { col = 12, row = 9 } } (Whitespace 1) - , Located { end = { col = 14, row = 9 }, start = { col = 13, row = 9 } } (Sigil (Operator Multiply)) - , Located { end = { col = 15, row = 9 }, start = { col = 14, row = 9 } } (Whitespace 1) - , Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (NumericLiteral "2") - , Located { end = { col = 17, row = 9 }, start = { col = 16, row = 9 } } (Whitespace 1) - , Located { end = { col = 18, row = 9 }, start = { col = 17, row = 9 } } (Sigil (Operator Divide)) - , Located { end = { col = 19, row = 9 }, start = { col = 18, row = 9 } } (Whitespace 1) - , Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (NumericLiteral "4") - , Located { end = { col = 21, row = 9 }, start = { col = 20, row = 9 } } (Whitespace 1) - , Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } (Sigil (Operator Subtract)) - , Located { end = { col = 23, row = 9 }, start = { col = 22, row = 9 } } (Whitespace 1) - , Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (NumericLiteral "5") - , Located { end = { col = 1, row = 10 }, start = { col = 24, row = 9 } } (Newlines [] 0) - , Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (Identifier { name = "b2", qualifiers = [] }) - , Located { end = { col = 4, row = 10 }, start = { col = 3, row = 10 } } (Whitespace 1) - , Located { end = { col = 5, row = 10 }, start = { col = 4, row = 10 } } (Sigil Assign) - , Located { end = { col = 6, row = 10 }, start = { col = 5, row = 10 } } (Whitespace 1) - , Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (NumericLiteral "78") - , Located { end = { col = 9, row = 10 }, start = { col = 8, row = 10 } } (Whitespace 1) - , Located { end = { col = 10, row = 10 }, start = { col = 9, row = 10 } } (Sigil (Operator Multiply)) - , Located { end = { col = 11, row = 10 }, start = { col = 10, row = 10 } } (Whitespace 1) - , Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (NumericLiteral "5") - , Located { end = { col = 13, row = 10 }, start = { col = 12, row = 10 } } (Whitespace 1) - , Located { end = { col = 14, row = 10 }, start = { col = 13, row = 10 } } (Sigil (Operator Subtract)) - , Located { end = { col = 15, row = 10 }, start = { col = 14, row = 10 } } (Whitespace 1) - , Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (NumericLiteral "2") - , Located { end = { col = 17, row = 10 }, start = { col = 16, row = 10 } } (Whitespace 1) - , Located { end = { col = 18, row = 10 }, start = { col = 17, row = 10 } } (Sigil (Operator Divide)) - , Located { end = { col = 19, row = 10 }, start = { col = 18, row = 10 } } (Whitespace 1) - , Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (NumericLiteral "4") - , Located { end = { col = 21, row = 10 }, start = { col = 20, row = 10 } } (Whitespace 1) - , Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } (Sigil (Operator Multiply)) - , Located { end = { col = 23, row = 10 }, start = { col = 22, row = 10 } } (Whitespace 1) - , Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (NumericLiteral "5") - , Located { end = { col = 1, row = 11 }, start = { col = 24, row = 10 } } (Newlines [] 0) - , Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (Identifier { name = "b3", qualifiers = [] }) - , Located { end = { col = 4, row = 11 }, start = { col = 3, row = 11 } } (Whitespace 1) - , Located { end = { col = 5, row = 11 }, start = { col = 4, row = 11 } } (Sigil Assign) - , Located { end = { col = 6, row = 11 }, start = { col = 5, row = 11 } } (Whitespace 1) - , Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (NumericLiteral "78") - , Located { end = { col = 9, row = 11 }, start = { col = 8, row = 11 } } (Whitespace 1) - , Located { end = { col = 10, row = 11 }, start = { col = 9, row = 11 } } (Sigil (Operator Subtract)) - , Located { end = { col = 11, row = 11 }, start = { col = 10, row = 11 } } (Whitespace 1) - , Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (NumericLiteral "5") - , Located { end = { col = 13, row = 11 }, start = { col = 12, row = 11 } } (Whitespace 1) - , Located { end = { col = 14, row = 11 }, start = { col = 13, row = 11 } } (Sigil (Operator Add)) - , Located { end = { col = 15, row = 11 }, start = { col = 14, row = 11 } } (Whitespace 1) - , Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (NumericLiteral "2") - , Located { end = { col = 17, row = 11 }, start = { col = 16, row = 11 } } (Whitespace 1) - , Located { end = { col = 18, row = 11 }, start = { col = 17, row = 11 } } (Sigil (Operator Divide)) - , Located { end = { col = 19, row = 11 }, start = { col = 18, row = 11 } } (Whitespace 1) - , Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (NumericLiteral "4") - , Located { end = { col = 21, row = 11 }, start = { col = 20, row = 11 } } (Whitespace 1) - , Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } (Sigil (Operator Multiply)) - , Located { end = { col = 23, row = 11 }, start = { col = 22, row = 11 } } (Whitespace 1) - , Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (NumericLiteral "5") - , Located { end = { col = 1, row = 12 }, start = { col = 24, row = 11 } } (Newlines [] 0) - , Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (Identifier { name = "b4", qualifiers = [] }) - , Located { end = { col = 4, row = 12 }, start = { col = 3, row = 12 } } (Whitespace 1) - , Located { end = { col = 5, row = 12 }, start = { col = 4, row = 12 } } (Sigil Assign) - , Located { end = { col = 6, row = 12 }, start = { col = 5, row = 12 } } (Whitespace 1) - , Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (NumericLiteral "78") - , Located { end = { col = 9, row = 12 }, start = { col = 8, row = 12 } } (Whitespace 1) - , Located { end = { col = 10, row = 12 }, start = { col = 9, row = 12 } } (Sigil (Operator Divide)) - , Located { end = { col = 11, row = 12 }, start = { col = 10, row = 12 } } (Whitespace 1) - , Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (NumericLiteral "5") - , Located { end = { col = 13, row = 12 }, start = { col = 12, row = 12 } } (Whitespace 1) - , Located { end = { col = 14, row = 12 }, start = { col = 13, row = 12 } } (Sigil (Operator Divide)) - , Located { end = { col = 15, row = 12 }, start = { col = 14, row = 12 } } (Whitespace 1) - , Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (NumericLiteral "2") - , Located { end = { col = 17, row = 12 }, start = { col = 16, row = 12 } } (Whitespace 1) - , Located { end = { col = 18, row = 12 }, start = { col = 17, row = 12 } } (Sigil (Operator Divide)) - , Located { end = { col = 19, row = 12 }, start = { col = 18, row = 12 } } (Whitespace 1) - , Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (NumericLiteral "4") - , Located { end = { col = 21, row = 12 }, start = { col = 20, row = 12 } } (Whitespace 1) - , Located { end = { col = 22, row = 12 }, start = { col = 21, row = 12 } } (Sigil (Operator Add)) - , Located { end = { col = 23, row = 12 }, start = { col = 22, row = 12 } } (Whitespace 1) - , Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (NumericLiteral "5") + (Token + (Newlines + [ 0 + , 0 + ] + 0 + ) + ) + , Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 3, row = 8 }, start = { col = 2, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 8 }, start = { col = 3, row = 8 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 8 }, start = { col = 4, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (Token (NumericLiteral "78")) + , Located { end = { col = 8, row = 8 }, start = { col = 7, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 8 }, start = { col = 8, row = 8 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 10, row = 8 }, start = { col = 9, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (Token (NumericLiteral "5")) + , Located { end = { col = 12, row = 8 }, start = { col = 11, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 14, row = 8 }, start = { col = 13, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Token (NumericLiteral "2")) + , Located { end = { col = 16, row = 8 }, start = { col = 15, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } (Token (Sigil (Operator Divide))) + , Located { end = { col = 18, row = 8 }, start = { col = 17, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (Token (NumericLiteral "4")) + , Located { end = { col = 20, row = 8 }, start = { col = 19, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 22, row = 8 }, start = { col = 21, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Token (NumericLiteral "5")) + , Located { end = { col = 1, row = 9 }, start = { col = 23, row = 8 } } (Token (Newlines [] 0)) + , Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (Token (Identifier { name = "b1", qualifiers = [] })) + , Located { end = { col = 4, row = 9 }, start = { col = 3, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 5, row = 9 }, start = { col = 4, row = 9 } } (Token (Sigil Assign)) + , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (Token (NumericLiteral "78")) + , Located { end = { col = 9, row = 9 }, start = { col = 8, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 9 }, start = { col = 9, row = 9 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 11, row = 9 }, start = { col = 10, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (Token (NumericLiteral "5")) + , Located { end = { col = 13, row = 9 }, start = { col = 12, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 9 }, start = { col = 13, row = 9 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 15, row = 9 }, start = { col = 14, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (Token (NumericLiteral "2")) + , Located { end = { col = 17, row = 9 }, start = { col = 16, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 9 }, start = { col = 17, row = 9 } } (Token (Sigil (Operator Divide))) + , Located { end = { col = 19, row = 9 }, start = { col = 18, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (Token (NumericLiteral "4")) + , Located { end = { col = 21, row = 9 }, start = { col = 20, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } (Token (Sigil (Operator Subtract))) + , Located { end = { col = 23, row = 9 }, start = { col = 22, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Token (NumericLiteral "5")) + , Located { end = { col = 1, row = 10 }, start = { col = 24, row = 9 } } (Token (Newlines [] 0)) + , Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (Token (Identifier { name = "b2", qualifiers = [] })) + , Located { end = { col = 4, row = 10 }, start = { col = 3, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 5, row = 10 }, start = { col = 4, row = 10 } } (Token (Sigil Assign)) + , Located { end = { col = 6, row = 10 }, start = { col = 5, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (Token (NumericLiteral "78")) + , Located { end = { col = 9, row = 10 }, start = { col = 8, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 10 }, start = { col = 9, row = 10 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 11, row = 10 }, start = { col = 10, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (Token (NumericLiteral "5")) + , Located { end = { col = 13, row = 10 }, start = { col = 12, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 10 }, start = { col = 13, row = 10 } } (Token (Sigil (Operator Subtract))) + , Located { end = { col = 15, row = 10 }, start = { col = 14, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (Token (NumericLiteral "2")) + , Located { end = { col = 17, row = 10 }, start = { col = 16, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 10 }, start = { col = 17, row = 10 } } (Token (Sigil (Operator Divide))) + , Located { end = { col = 19, row = 10 }, start = { col = 18, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (Token (NumericLiteral "4")) + , Located { end = { col = 21, row = 10 }, start = { col = 20, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 23, row = 10 }, start = { col = 22, row = 10 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Token (NumericLiteral "5")) + , Located { end = { col = 1, row = 11 }, start = { col = 24, row = 10 } } (Token (Newlines [] 0)) + , Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (Token (Identifier { name = "b3", qualifiers = [] })) + , Located { end = { col = 4, row = 11 }, start = { col = 3, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 5, row = 11 }, start = { col = 4, row = 11 } } (Token (Sigil Assign)) + , Located { end = { col = 6, row = 11 }, start = { col = 5, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (Token (NumericLiteral "78")) + , Located { end = { col = 9, row = 11 }, start = { col = 8, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 11 }, start = { col = 9, row = 11 } } (Token (Sigil (Operator Subtract))) + , Located { end = { col = 11, row = 11 }, start = { col = 10, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (Token (NumericLiteral "5")) + , Located { end = { col = 13, row = 11 }, start = { col = 12, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 11 }, start = { col = 13, row = 11 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 15, row = 11 }, start = { col = 14, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (Token (NumericLiteral "2")) + , Located { end = { col = 17, row = 11 }, start = { col = 16, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 11 }, start = { col = 17, row = 11 } } (Token (Sigil (Operator Divide))) + , Located { end = { col = 19, row = 11 }, start = { col = 18, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (Token (NumericLiteral "4")) + , Located { end = { col = 21, row = 11 }, start = { col = 20, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } (Token (Sigil (Operator Multiply))) + , Located { end = { col = 23, row = 11 }, start = { col = 22, row = 11 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Token (NumericLiteral "5")) + , Located { end = { col = 1, row = 12 }, start = { col = 24, row = 11 } } (Token (Newlines [] 0)) + , Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (Token (Identifier { name = "b4", qualifiers = [] })) + , Located { end = { col = 4, row = 12 }, start = { col = 3, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 5, row = 12 }, start = { col = 4, row = 12 } } (Token (Sigil Assign)) + , Located { end = { col = 6, row = 12 }, start = { col = 5, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (Token (NumericLiteral "78")) + , Located { end = { col = 9, row = 12 }, start = { col = 8, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 12 }, start = { col = 9, row = 12 } } (Token (Sigil (Operator Divide))) + , Located { end = { col = 11, row = 12 }, start = { col = 10, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (Token (NumericLiteral "5")) + , Located { end = { col = 13, row = 12 }, start = { col = 12, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 12 }, start = { col = 13, row = 12 } } (Token (Sigil (Operator Divide))) + , Located { end = { col = 15, row = 12 }, start = { col = 14, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (Token (NumericLiteral "2")) + , Located { end = { col = 17, row = 12 }, start = { col = 16, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 12 }, start = { col = 17, row = 12 } } (Token (Sigil (Operator Divide))) + , Located { end = { col = 19, row = 12 }, start = { col = 18, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (Token (NumericLiteral "4")) + , Located { end = { col = 21, row = 12 }, start = { col = 20, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 12 }, start = { col = 21, row = 12 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 23, row = 12 }, start = { col = 22, row = 12 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 14 }, start = { col = 24, row = 12 } } - (Newlines - [ 0 - ] - 0 + (Token + (Newlines + [ 0 + ] + 0 + ) ) ] } @@ -989,43 +999,45 @@ b = 78 + 5 + 2 - 4 + 5 ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Whitespace 1) - , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Whitespace 1) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (NumericLiteral "5") - , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Whitespace 1) - , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Sigil (Operator Subtract)) - , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Whitespace 1) - , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (NumericLiteral "5") + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Token (NumericLiteral "5")) + , Located { end = { col = 7, row = 1 }, start = { col = 6, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } (Token (Sigil (Operator Subtract))) + , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Whitespace 1) - , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Sigil Assign) - , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Whitespace 1) - , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (NumericLiteral "78") - , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Whitespace 1) - , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil (Operator Add)) - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (NumericLiteral "5") - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Sigil (Operator Add)) - , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Whitespace 1) - , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (NumericLiteral "2") - , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Whitespace 1) - , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Sigil (Operator Subtract)) - , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Whitespace 1) - , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (NumericLiteral "4") - , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Sigil (Operator Add)) - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (NumericLiteral "5") - , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Newlines [] 0) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Token (NumericLiteral "78")) + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Token (NumericLiteral "5")) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Token (NumericLiteral "2")) + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Token (Sigil (Operator Subtract))) + , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Token (NumericLiteral "4")) + , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Token (Sigil (Operator Add))) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (NumericLiteral "5")) + , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Token (Newlines [] 0)) ] } , { name = "type-alias" @@ -1081,18 +1093,18 @@ b = 78 + 5 + 2 - 4 + 5 ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Model", qualifiers = [] }) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-and-expression" @@ -1171,31 +1183,33 @@ expr hi = 77 ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Model", qualifiers = [] }) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 28, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Identifier { name = "expr", qualifiers = [] }) - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) - , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Identifier { name = "hi", qualifiers = [] }) - , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Whitespace 1) - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Assign) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) - , Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (NumericLiteral "77") - , Located { end = { col = 1, row = 4 }, start = { col = 13, row = 3 } } (Newlines [] 0) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "expr", qualifiers = [] })) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (Token (NumericLiteral "77")) + , Located { end = { col = 1, row = 4 }, start = { col = 13, row = 3 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-bracket-in-record" @@ -1246,25 +1260,25 @@ expr hi = 77 ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-function" @@ -1374,28 +1388,28 @@ expr hi = 77 ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 32, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) - , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Whitespace 1) - , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 34, row = 1 }, start = { col = 32, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-function-binding-order" @@ -1586,46 +1600,46 @@ type alias Function = A -> B -> C -> D ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "A", qualifiers = [] }) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 25, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "B", qualifiers = [] }) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Identifier { name = "C", qualifiers = [] }) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Keyword Type) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Keyword Alias) - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Identifier { name = "Function", qualifiers = [] }) - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil Assign) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Whitespace 1) - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Identifier { name = "A", qualifiers = [] }) - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) - , Located { end = { col = 27, row = 2 }, start = { col = 25, row = 2 } } (Sigil ThinArrow) - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Whitespace 1) - , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Identifier { name = "B", qualifiers = [] }) - , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Whitespace 1) - , Located { end = { col = 32, row = 2 }, start = { col = 30, row = 2 } } (Sigil ThinArrow) - , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Whitespace 1) - , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Identifier { name = "C", qualifiers = [] }) - , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Whitespace 1) - , Located { end = { col = 37, row = 2 }, start = { col = 35, row = 2 } } (Sigil ThinArrow) - , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) - , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Identifier { name = "D", qualifiers = [] }) - , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Token (Sigil Assign)) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 2 }, start = { col = 25, row = 2 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 32, row = 2 }, start = { col = 30, row = 2 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 37, row = 2 }, start = { col = 35, row = 2 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-function-generic" @@ -1739,30 +1753,30 @@ type alias Function = A -> B -> C -> D ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Assign) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) - , Located { end = { col = 36, row = 1 }, start = { col = 34, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) - , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Whitespace 1) - , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 36, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-function-nested" @@ -2048,125 +2062,131 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil Comma) - , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Whitespace 1) - , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Identifier { name = "String", qualifiers = [] }) - , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Sigil (Bracket Round Close)) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 3 }, start = { col = 44, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Keyword Type) - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Keyword Alias) - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Identifier { name = "Function2", qualifiers = [] }) - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Sigil Assign) - , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil Colon) - , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Whitespace 1) - , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Whitespace 1) - , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Sigil ThinArrow) - , Located { end = { col = 35, row = 3 }, start = { col = 34, row = 3 } } (Whitespace 1) - , Located { end = { col = 36, row = 3 }, start = { col = 35, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 40, row = 3 }, start = { col = 39, row = 3 } } (Sigil Comma) - , Located { end = { col = 41, row = 3 }, start = { col = 40, row = 3 } } (Whitespace 1) - , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Identifier { name = "String", qualifiers = [] }) - , Located { end = { col = 48, row = 3 }, start = { col = 47, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 49, row = 3 }, start = { col = 48, row = 3 } } (Whitespace 1) - , Located { end = { col = 50, row = 3 }, start = { col = 49, row = 3 } } (Sigil (Bracket Curly Close)) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = "Function2", qualifiers = [] })) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Token (Sigil Colon)) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 35, row = 3 }, start = { col = 34, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 36, row = 3 }, start = { col = 35, row = 3 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 40, row = 3 }, start = { col = 39, row = 3 } } (Token (Sigil Comma)) + , Located { end = { col = 41, row = 3 }, start = { col = 40, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 48, row = 3 }, start = { col = 47, row = 3 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 49, row = 3 }, start = { col = 48, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 50, row = 3 }, start = { col = 49, row = 3 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 1, row = 5 }, start = { col = 50, row = 3 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Keyword Type) - , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) - , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Keyword Alias) - , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) - , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Identifier { name = "Function3", qualifiers = [] }) - , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Whitespace 1) - , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Sigil Assign) - , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) - , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 27, row = 5 }, start = { col = 26, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 28, row = 5 }, start = { col = 27, row = 5 } } (Whitespace 1) - , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Sigil ThinArrow) - , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Whitespace 1) - , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Sigil Comma) - , Located { end = { col = 37, row = 5 }, start = { col = 36, row = 5 } } (Whitespace 1) - , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Identifier { name = "String", qualifiers = [] }) - , Located { end = { col = 44, row = 5 }, start = { col = 43, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 45, row = 5 }, start = { col = 44, row = 5 } } (Sigil Comma) - , Located { end = { col = 46, row = 5 }, start = { col = 45, row = 5 } } (Whitespace 1) - , Located { end = { col = 47, row = 5 }, start = { col = 46, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 48, row = 5 }, start = { col = 47, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 49, row = 5 }, start = { col = 48, row = 5 } } (Sigil (Bracket Round Close)) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token (Identifier { name = "Function3", qualifiers = [] })) + , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Token (Sigil Assign)) + , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 27, row = 5 }, start = { col = 26, row = 5 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 28, row = 5 }, start = { col = 27, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Token (Sigil Comma)) + , Located { end = { col = 37, row = 5 }, start = { col = 36, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 44, row = 5 }, start = { col = 43, row = 5 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 45, row = 5 }, start = { col = 44, row = 5 } } (Token (Sigil Comma)) + , Located { end = { col = 46, row = 5 }, start = { col = 45, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 47, row = 5 }, start = { col = 46, row = 5 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 48, row = 5 }, start = { col = 47, row = 5 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 49, row = 5 }, start = { col = 48, row = 5 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 7 }, start = { col = 49, row = 5 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Keyword Type) - , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Whitespace 1) - , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Keyword Alias) - , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Whitespace 1) - , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Identifier { name = "Function3", qualifiers = [] }) - , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Whitespace 1) - , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Sigil Assign) - , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Whitespace 1) - , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Sigil Comma) - , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Whitespace 1) - , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 32, row = 7 }, start = { col = 31, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 33, row = 7 }, start = { col = 32, row = 7 } } (Whitespace 1) - , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Sigil ThinArrow) - , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Whitespace 1) - , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 41, row = 7 }, start = { col = 40, row = 7 } } (Sigil Comma) - , Located { end = { col = 42, row = 7 }, start = { col = 41, row = 7 } } (Whitespace 1) - , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Identifier { name = "String", qualifiers = [] }) - , Located { end = { col = 49, row = 7 }, start = { col = 48, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 50, row = 7 }, start = { col = 49, row = 7 } } (Sigil Comma) - , Located { end = { col = 51, row = 7 }, start = { col = 50, row = 7 } } (Whitespace 1) - , Located { end = { col = 52, row = 7 }, start = { col = 51, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 53, row = 7 }, start = { col = 52, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 54, row = 7 }, start = { col = 53, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 8 }, start = { col = 54, row = 7 } } (Newlines [] 0) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token (Identifier { name = "Function3", qualifiers = [] })) + , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Token (Sigil Assign)) + , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Token (Sigil Comma)) + , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 32, row = 7 }, start = { col = 31, row = 7 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 33, row = 7 }, start = { col = 32, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 41, row = 7 }, start = { col = 40, row = 7 } } (Token (Sigil Comma)) + , Located { end = { col = 42, row = 7 }, start = { col = 41, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 49, row = 7 }, start = { col = 48, row = 7 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 50, row = 7 }, start = { col = 49, row = 7 } } (Token (Sigil Comma)) + , Located { end = { col = 51, row = 7 }, start = { col = 50, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 52, row = 7 }, start = { col = 51, row = 7 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 53, row = 7 }, start = { col = 52, row = 7 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 54, row = 7 }, start = { col = 53, row = 7 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 8 }, start = { col = 54, row = 7 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-function-record" @@ -2257,40 +2277,40 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Colon) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Sigil Colon) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Identifier { name = "C", qualifiers = [] }) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Sigil Comma) - , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Whitespace 1) - , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Identifier { name = "d", qualifiers = [] }) - , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Sigil Colon) - , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Identifier { name = "E", qualifiers = [] }) - , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Whitespace 1) - , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Whitespace 1) - , Located { end = { col = 46, row = 1 }, start = { col = 44, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Whitespace 1) - , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 49, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Token (Identifier { name = "d", qualifiers = [] })) + , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token (Identifier { name = "E", qualifiers = [] })) + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 46, row = 1 }, start = { col = 44, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 49, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-function-tuple" @@ -2360,26 +2380,26 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 28, row = 1 }, start = { col = 26, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil Comma) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Whitespace 1) - , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Identifier { name = "String", qualifiers = [] }) - , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 28, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-funky-indentation" @@ -2436,18 +2456,18 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) - , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Identifier { name = "Model", qualifiers = [] }) - , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 1) - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Sigil Assign) - , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Whitespace 1) - , Located { end = { col = 17, row = 2 }, start = { col = 13, row = 2 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Whitespace 1) - , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 2 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Token (Newlines [] 4)) + , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Token (Sigil Assign)) + , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 2 }, start = { col = 13, row = 2 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 2 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-funky-indentation-2" @@ -2505,18 +2525,18 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) - , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Identifier { name = "Model", qualifiers = [] }) - , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 1) - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Sigil Assign) - , Located { end = { col = 2, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 1) - , Located { end = { col = 6, row = 3 }, start = { col = 2, row = 3 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) - , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Token (Newlines [] 4)) + , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Token (Sigil Assign)) + , Located { end = { col = 2, row = 3 }, start = { col = 12, row = 2 } } (Token (Newlines [] 1)) + , Located { end = { col = 6, row = 3 }, start = { col = 2, row = 3 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-3-entries" @@ -2602,35 +2622,35 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil Colon) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Identifier { name = "A", qualifiers = [] }) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Colon) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "B", qualifiers = [] }) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil Comma) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Whitespace 1) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Identifier { name = "c", qualifiers = [] }) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Sigil Colon) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Whitespace 1) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Identifier { name = "C", qualifiers = [] }) - , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Whitespace 1) - , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 37, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token (Identifier { name = "c", qualifiers = [] })) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 37, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-empty" @@ -2653,17 +2673,17 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-empty-multiline" @@ -2689,24 +2709,26 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 5, row = 4 }, start = { col = 18, row = 1 } } - (Newlines - [ 0 - , 0 - ] - 4 - ) - , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + (Token + (Newlines + [ 0 + , 0 + ] + 4 + ) + ) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-in-bracket" @@ -2757,25 +2779,25 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Sigil Colon) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-nested" @@ -2960,57 +2982,57 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) - , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Identifier { name = "hi", qualifiers = [] }) - , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Sigil Colon) - , Located { end = { col = 12, row = 2 }, start = { col = 10, row = 2 } } (Whitespace 2) - , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Whitespace 1) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Colon) - , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 20, row = 2 }, start = { col = 17, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Sigil Comma) - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Whitespace 1) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil Colon) - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) - , Located { end = { col = 29, row = 2 }, start = { col = 25, row = 2 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Whitespace 1) - , Located { end = { col = 36, row = 2 }, start = { col = 30, row = 2 } } (Identifier { name = "String", qualifiers = [] }) - , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Whitespace 1) - , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 5, row = 3 }, start = { col = 38, row = 2 } } (Newlines [] 4) - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) - , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) - , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Identifier { name = "ih", qualifiers = [] }) - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Sigil Colon) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Identifier { name = "CustomType", qualifiers = [] }) - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Identifier { name = "A", qualifiers = [] }) - , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Identifier { name = "B", qualifiers = [] }) - , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Identifier { name = "C", qualifiers = [] }) - , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Whitespace 1) - , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Identifier { name = "D", qualifiers = [] }) - , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Whitespace 1) - , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Identifier { name = "E", qualifiers = [] }) - , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Newlines [] 4) - , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Token (Newlines [] 4)) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Token (Sigil Colon)) + , Located { end = { col = 12, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 2)) + , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (Sigil Colon)) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 2 }, start = { col = 17, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Token (Sigil Comma)) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token (Sigil Colon)) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 2 }, start = { col = 25, row = 2 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 36, row = 2 }, start = { col = 30, row = 2 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 5, row = 3 }, start = { col = 38, row = 2 } } (Token (Newlines [] 4)) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Comma)) + , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "ih", qualifiers = [] })) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Token (Sigil Colon)) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Token (Identifier { name = "CustomType", qualifiers = [] })) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Token (Identifier { name = "E", qualifiers = [] })) + , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Token (Newlines [] 4)) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-simple" @@ -3061,23 +3083,23 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-two-entries" @@ -3131,30 +3153,30 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Colon) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil Comma) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 27, row = 1 } } (Identifier { name = "buy", qualifiers = [] }) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil Colon) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) - , Located { end = { col = 38, row = 1 }, start = { col = 32, row = 1 } } (Identifier { name = "String", qualifiers = [] }) - , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Whitespace 1) - , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 40, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 1 }, start = { col = 27, row = 1 } } (Token (Identifier { name = "buy", qualifiers = [] })) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil Colon)) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 38, row = 1 }, start = { col = 32, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 40, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-unit" @@ -3175,17 +3197,17 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-with-bracket" @@ -3226,18 +3248,18 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-with-bracket-2" @@ -3293,20 +3315,20 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-with-pair" @@ -3411,35 +3433,35 @@ type alias Hi = (Int) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "String", qualifiers = [] }) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Keyword Type) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Keyword Alias) - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) - , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-with-tripple" @@ -3530,45 +3552,45 @@ type alias Hi = ((), (), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "Two", qualifiers = [] }) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil Comma) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Identifier { name = "Three", qualifiers = [] }) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Keyword Type) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Keyword Alias) - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) - , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Sigil Comma) - , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Whitespace 1) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil Comma) - , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Whitespace 1) - , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 3 }, start = { col = 29, row = 2 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "Two", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "Three", qualifiers = [] })) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Token (Sigil Comma)) + , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Token (Sigil Comma)) + , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 3 }, start = { col = 29, row = 2 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-with-tripple-in-record" @@ -3668,48 +3690,48 @@ type alias Hi = ((), (), ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Whitespace 1) - , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Sigil Colon) - , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Sigil Comma) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Whitespace 1) - , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Sigil Comma) - , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Whitespace 1) - , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Newlines [] 4) - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Sigil Comma) - , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Whitespace 1) - , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Identifier { name = "b", qualifiers = [] }) - , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Sigil Colon) - , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Identifier { name = "good_bye", qualifiers = [] }) - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Sigil Colon) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Whitespace 1) - , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 5, row = 4 }, start = { col = 28, row = 3 } } (Newlines [] 4) - , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Token (Newlines [] 4)) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Token (Sigil Colon)) + , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token (Sigil Comma)) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Token (Sigil Comma)) + , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Token (Newlines [] 4)) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Comma)) + , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Token (Sigil Colon)) + , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Token (Identifier { name = "good_bye", qualifiers = [] })) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Token (Sigil Colon)) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 5, row = 4 }, start = { col = 28, row = 3 } } (Token (Newlines [] 4)) + , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Token (Newlines [] 0)) ] } ] @@ -3770,13 +3792,14 @@ Hi. case""" , ( Err, todo ) , ( Err, todo ) , ( Err, todo ) + , ( Err, todo ) ) """ , contextualized = Just [ Err - { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] })) + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] }))) , state = State_BlockStart } , Err @@ -3790,12 +3813,14 @@ Hi. case""" , item = Just (Located { end = { col = 8, row = 3 }, start = { col = 1, row = 3 } } - (Identifier - { name = "Bar" - , qualifiers = - [ "Foo" - ] - } + (Token + (Identifier + { name = "Bar" + , qualifiers = + [ "Foo" + ] + } + ) ) ) , state = State_BlockStart @@ -3812,45 +3837,54 @@ Hi. case""" , item = Just (Located { end = { col = 12, row = 5 }, start = { col = 1, row = 5 } } - (Identifier - { name = "baz" - , qualifiers = - [ "Foo" - , "Bar" - ] - } + (Token + (Identifier + { name = "baz" + , qualifiers = + [ "Foo" + , "Bar" + ] + } + ) ) ) , state = State_BlockStart } , Err - { error = Error_InvalidToken Expecting_Block + { error = Error_InvalidToken Expecting_Unknown , item = Just (Located { end = { col = 11, row = 7 }, start = { col = 1, row = 7 } } - (IdentifierWithTrailingDot - { name = "Bing" - , qualifiers = - [ "Boor" - ] - } + (Invalid + (IdentifierWithTrailingDot + { name = "Bing" + , qualifiers = + [ "Boor" + ] + } + ) ) ) , state = State_BlockStart } , Err - { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] })) + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] }))) , state = State_BlockStart } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Big", qualifiers = [] }))) + , state = State_Error_Recovery + } , Err { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (RecordAccessorFunction "sf")) + , item = Just (Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (Token (RecordAccessorFunction "sf"))) , state = State_BlockStart } , Err { error = Error_InvalidToken (Expecting_Sigil Assign) - , item = Just (Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (RecordAccessorFunction "sdfsd")) + , item = Just (Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (Token (RecordAccessorFunction "sdfsd"))) , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } "sfsdf" }) } , Err @@ -3864,34 +3898,36 @@ Hi. case""" , item = Just (Located { end = { col = 15, row = 15 }, start = { col = 1, row = 15 } } - (Identifier - { name = "sdgsghj" - , qualifiers = - [ "asfasf" - ] - } + (Token + (Identifier + { name = "sdgsghj" + , qualifiers = + [ "asfasf" + ] + } + ) ) ) , state = State_BlockStart } , Err { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Sigil (Bracket Round Open))) + , item = Just (Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockStart } , Err { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Sigil (Bracket Round Open))) + , item = Just (Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockStart } , Err { error = Error_InvalidToken (Expecting_Sigil Assign) - , item = Just (Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Sigil (Bracket Round Open))) + , item = Just (Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } "sfhsdf" }) } , Err { error = Error_MisplacedKeyword Case - , item = Just (Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Keyword Case)) + , item = Just (Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Token (Keyword Case))) , state = State_BlockStart } , Err @@ -3905,183 +3941,223 @@ Hi. case""" , item = Just (Located { end = { col = 8, row = 25 }, start = { col = 1, row = 25 } } - (Identifier - { name = "case" - , qualifiers = - [ "Hi" - ] - } + (Token + (Identifier + { name = "case" + , qualifiers = + [ "Hi" + ] + } + ) ) ) , state = State_BlockStart } , Err { error = Error_MisplacedKeyword Case - , item = Just (Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Keyword Case)) + , item = Just (Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Token (Keyword Case))) , state = State_BlockStart } , Err - { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] })) + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] }))) , state = State_BlockStart } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] }) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 5, row = 1 } } - (Newlines - [ 0 - ] - 0 + (Token + (Newlines + [ 0 + ] + 0 + ) ) , Located { end = { col = 8, row = 3 }, start = { col = 1, row = 3 } } - (Identifier - { name = "Bar" - , qualifiers = - [ "Foo" - ] - } + (Token + (Identifier + { name = "Bar" + , qualifiers = + [ "Foo" + ] + } + ) ) , Located { end = { col = 1, row = 5 }, start = { col = 8, row = 3 } } - (Newlines - [ 0 - ] - 0 + (Token + (Newlines + [ 0 + ] + 0 + ) ) , Located { end = { col = 12, row = 5 }, start = { col = 1, row = 5 } } - (Identifier - { name = "baz" - , qualifiers = - [ "Foo" - , "Bar" - ] - } + (Token + (Identifier + { name = "baz" + , qualifiers = + [ "Foo" + , "Bar" + ] + } + ) ) , Located { end = { col = 1, row = 7 }, start = { col = 12, row = 5 } } - (Newlines - [ 0 - ] - 0 + (Token + (Newlines + [ 0 + ] + 0 + ) ) , Located { end = { col = 11, row = 7 }, start = { col = 1, row = 7 } } - (IdentifierWithTrailingDot - { name = "Bing" - , qualifiers = - [ "Boor" - ] - } + (Invalid + (IdentifierWithTrailingDot + { name = "Bing" + , qualifiers = + [ "Boor" + ] + } + ) ) , Located { end = { col = 1, row = 9 }, start = { col = 11, row = 7 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] }) - , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Whitespace 1) - , Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (IdentifierWithTrailingDot { name = "Big", qualifiers = [] }) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] })) + , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Big", qualifiers = [] })) , Located { end = { col = 1, row = 11 }, start = { col = 10, row = 9 } } - (Newlines - [ 0 - ] - 0 + (Token + (Newlines + [ 0 + ] + 0 + ) ) - , Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (RecordAccessorFunction "sf") + , Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (Token (RecordAccessorFunction "sf")) , Located { end = { col = 1, row = 13 }, start = { col = 4, row = 11 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } (Identifier { name = "sfsdf", qualifiers = [] }) - , Located { end = { col = 7, row = 13 }, start = { col = 6, row = 13 } } (Whitespace 1) - , Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (RecordAccessorFunction "sdfsd") + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } (Token (Identifier { name = "sfsdf", qualifiers = [] })) + , Located { end = { col = 7, row = 13 }, start = { col = 6, row = 13 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (Token (RecordAccessorFunction "sdfsd")) , Located { end = { col = 1, row = 15 }, start = { col = 13, row = 13 } } - (Newlines - [ 0 - ] - 0 + (Token + (Newlines + [ 0 + ] + 0 + ) ) , Located { end = { col = 15, row = 15 }, start = { col = 1, row = 15 } } - (Identifier - { name = "sdgsghj" - , qualifiers = - [ "asfasf" - ] - } + (Token + (Identifier + { name = "sdgsghj" + , qualifiers = + [ "asfasf" + ] + } + ) ) , Located { end = { col = 1, row = 17 }, start = { col = 15, row = 15 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 6, row = 17 }, start = { col = 2, row = 17 } } (Identifier { name = "shdf", qualifiers = [] }) - , Located { end = { col = 7, row = 17 }, start = { col = 6, row = 17 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 20, row = 17 }, start = { col = 7, row = 17 } } (RecordAccessorLiteral "helloLiteral") + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 6, row = 17 }, start = { col = 2, row = 17 } } (Token (Identifier { name = "shdf", qualifiers = [] })) + , Located { end = { col = 7, row = 17 }, start = { col = 6, row = 17 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 20, row = 17 }, start = { col = 7, row = 17 } } (Token (RecordAccessorLiteral "helloLiteral")) , Located { end = { col = 1, row = 19 }, start = { col = 20, row = 17 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 7, row = 19 }, start = { col = 2, row = 19 } } (Identifier { name = "sjhsf", qualifiers = [] }) - , Located { end = { col = 8, row = 19 }, start = { col = 7, row = 19 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 9, row = 19 }, start = { col = 8, row = 19 } } (Whitespace 1) - , Located { end = { col = 23, row = 19 }, start = { col = 9, row = 19 } } (RecordAccessorFunction "helloFunction") + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 7, row = 19 }, start = { col = 2, row = 19 } } (Token (Identifier { name = "sjhsf", qualifiers = [] })) + , Located { end = { col = 8, row = 19 }, start = { col = 7, row = 19 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 9, row = 19 }, start = { col = 8, row = 19 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 19 }, start = { col = 9, row = 19 } } (Token (RecordAccessorFunction "helloFunction")) , Located { end = { col = 1, row = 21 }, start = { col = 23, row = 19 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } (Identifier { name = "sfhsdf", qualifiers = [] }) - , Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 22, row = 21 }, start = { col = 8, row = 21 } } (RecordAccessorFunction "helloFunction") - , Located { end = { col = 23, row = 21 }, start = { col = 22, row = 21 } } (Sigil (Bracket Round Close)) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } (Token (Identifier { name = "sfhsdf", qualifiers = [] })) + , Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 22, row = 21 }, start = { col = 8, row = 21 } } (Token (RecordAccessorFunction "helloFunction")) + , Located { end = { col = 23, row = 21 }, start = { col = 22, row = 21 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 23 }, start = { col = 23, row = 21 } } - (Newlines - [ 0 - ] - 0 + (Token + (Newlines + [ 0 + ] + 0 + ) ) - , Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Keyword Case) - , Located { end = { col = 8, row = 23 }, start = { col = 5, row = 23 } } (RecordAccessorFunction "hi") + , Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Token (Keyword Case)) + , Located { end = { col = 8, row = 23 }, start = { col = 5, row = 23 } } (Token (RecordAccessorFunction "hi")) , Located { end = { col = 1, row = 25 }, start = { col = 8, row = 23 } } - (Newlines - [ 0 - ] - 0 + (Token + (Newlines + [ 0 + ] + 0 + ) ) , Located { end = { col = 8, row = 25 }, start = { col = 1, row = 25 } } - (Identifier - { name = "case" - , qualifiers = - [ "Hi" - ] - } + (Token + (Identifier + { name = "case" + , qualifiers = + [ "Hi" + ] + } + ) ) , Located { end = { col = 1, row = 27 }, start = { col = 8, row = 25 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Keyword Case) - , Located { end = { col = 6, row = 27 }, start = { col = 5, row = 27 } } (Whitespace 1) - , Located { end = { col = 9, row = 27 }, start = { col = 6, row = 27 } } (RecordAccessorFunction "hi") + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Token (Keyword Case)) + , Located { end = { col = 6, row = 27 }, start = { col = 5, row = 27 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 27 }, start = { col = 6, row = 27 } } (Token (RecordAccessorFunction "hi")) , Located { end = { col = 1, row = 29 }, start = { col = 9, row = 27 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] }) - , Located { end = { col = 5, row = 29 }, start = { col = 4, row = 29 } } (Whitespace 1) - , Located { end = { col = 9, row = 29 }, start = { col = 5, row = 29 } } (Keyword Case) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] })) + , Located { end = { col = 5, row = 29 }, start = { col = 4, row = 29 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 29 }, start = { col = 5, row = 29 } } (Token (Keyword Case)) ] } , { name = "type-alias-function-nested-missing-return" @@ -4104,7 +4180,7 @@ type alias Function3 = (Int, () ->, ()) Just [ Err { error = Error_MissingFunctionReturnType - , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Close))) + , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil (Bracket Round Close)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Function" @@ -4118,7 +4194,7 @@ type alias Function3 = (Int, () ->, ()) } , Err { error = Error_MissingFunctionReturnType - , item = Just (Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Sigil (Bracket Curly Close))) + , item = Just (Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Token (Sigil (Bracket Curly Close)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Function2" @@ -4132,7 +4208,7 @@ type alias Function3 = (Int, () ->, ()) } , Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil Comma)) + , item = Just (Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Token (Sigil Comma))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Function3" @@ -4146,7 +4222,7 @@ type alias Function3 = (Int, () ->, ()) } , Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Sigil Comma)) + , item = Just (Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Token (Sigil Comma))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Function3" @@ -4165,99 +4241,105 @@ type alias Function3 = (Int, () ->, ()) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Function", qualifiers = [] }) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Whitespace 1) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Assign) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Whitespace 1) - , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Sigil ThinArrow) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Whitespace 1) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil (Bracket Round Close)) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 3 }, start = { col = 31, row = 1 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Keyword Type) - , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Whitespace 1) - , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Keyword Alias) - , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Whitespace 1) - , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Identifier { name = "Function2", qualifiers = [] }) - , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Whitespace 1) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Sigil Assign) - , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Whitespace 1) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Whitespace 1) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Identifier { name = "a", qualifiers = [] }) - , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Sigil Colon) - , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Whitespace 1) - , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Whitespace 1) - , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Sigil ThinArrow) - , Located { end = { col = 36, row = 3 }, start = { col = 34, row = 3 } } (Whitespace 2) - , Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Sigil (Bracket Curly Close)) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = "Function2", qualifiers = [] })) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Token (Sigil Colon)) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 36, row = 3 }, start = { col = 34, row = 3 } } (Ignorable (Whitespace 2)) + , Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 1, row = 5 }, start = { col = 37, row = 3 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Keyword Type) - , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Whitespace 1) - , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Keyword Alias) - , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Whitespace 1) - , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Identifier { name = "Function3", qualifiers = [] }) - , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Whitespace 1) - , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Sigil Assign) - , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Whitespace 1) - , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 27, row = 5 }, start = { col = 26, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 28, row = 5 }, start = { col = 27, row = 5 } } (Whitespace 1) - , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Sigil ThinArrow) - , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Whitespace 1) - , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Sigil Comma) - , Located { end = { col = 33, row = 5 }, start = { col = 32, row = 5 } } (Whitespace 1) - , Located { end = { col = 34, row = 5 }, start = { col = 33, row = 5 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 35, row = 5 }, start = { col = 34, row = 5 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Sigil (Bracket Round Close)) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token (Identifier { name = "Function3", qualifiers = [] })) + , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Token (Sigil Assign)) + , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 27, row = 5 }, start = { col = 26, row = 5 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 28, row = 5 }, start = { col = 27, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Token (Sigil Comma)) + , Located { end = { col = 33, row = 5 }, start = { col = 32, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 34, row = 5 }, start = { col = 33, row = 5 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 35, row = 5 }, start = { col = 34, row = 5 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 7 }, start = { col = 36, row = 5 } } - (Newlines - [ 0 - ] - 0 - ) - , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Keyword Type) - , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Whitespace 1) - , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Keyword Alias) - , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Whitespace 1) - , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Identifier { name = "Function3", qualifiers = [] }) - , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Whitespace 1) - , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Sigil Assign) - , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Whitespace 1) - , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Sigil Comma) - , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Whitespace 1) - , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 32, row = 7 }, start = { col = 31, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 33, row = 7 }, start = { col = 32, row = 7 } } (Whitespace 1) - , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Sigil ThinArrow) - , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Sigil Comma) - , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Whitespace 1) - , Located { end = { col = 38, row = 7 }, start = { col = 37, row = 7 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 39, row = 7 }, start = { col = 38, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 40, row = 7 }, start = { col = 39, row = 7 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 8 }, start = { col = 40, row = 7 } } (Newlines [] 0) + (Token + (Newlines + [ 0 + ] + 0 + ) + ) + , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token (Identifier { name = "Function3", qualifiers = [] })) + , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Token (Sigil Assign)) + , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Token (Sigil Comma)) + , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 32, row = 7 }, start = { col = 31, row = 7 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 33, row = 7 }, start = { col = 32, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Token (Sigil Comma)) + , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 38, row = 7 }, start = { col = 37, row = 7 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 39, row = 7 }, start = { col = 38, row = 7 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 40, row = 7 }, start = { col = 39, row = 7 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 8 }, start = { col = 40, row = 7 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-invalid-multiple-brackets" @@ -4270,27 +4352,27 @@ type alias Function3 = (Int, () ->, ()) Just [ Err { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) - , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open))) + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-invalid-multiple-brackets-2" @@ -4303,26 +4385,26 @@ type alias Function3 = (Int, () ->, ()) Just [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit - , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open))) + , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-invalid-multiple-brackets-3" @@ -4335,27 +4417,27 @@ type alias Function3 = (Int, () ->, ()) Just [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit - , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open))) + , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-multiline-missing-indentation" @@ -4371,12 +4453,12 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns "Model" []) } , Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Token (Newlines [] 0))) , state = State_BlockValueDeclaration (BlockValueDeclaration_Named @@ -4391,18 +4473,18 @@ List Int ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Model", qualifiers = [] }) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Whitespace 1) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Sigil Assign) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Identifier { name = "List", qualifiers = [] }) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-partial" @@ -4415,16 +4497,16 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias BlockTypeAlias_Keywords } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-partial-2" @@ -4437,18 +4519,18 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias (BlockTypeAlias_Named "Hi" (Stack [])) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-partial-3" @@ -4461,20 +4543,20 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns "Hi" []) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-partial-with-bracket" @@ -4487,22 +4569,22 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-partial-with-bracket-2" @@ -4516,7 +4598,7 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" @@ -4531,18 +4613,18 @@ List Int ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) - , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 8)) + , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-half-empty" @@ -4555,22 +4637,22 @@ List Int Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-record-missing-colon" @@ -4583,28 +4665,28 @@ List Int Just [ Err { error = Error_ExpectedColonWhilstParsingRecord - , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Identifier { name = "j7", qualifiers = [] })) + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = "j7", qualifiers = [] }))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Ty", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Curly Open)) - , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Whitespace 1) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Identifier { name = "hi", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Identifier { name = "j7", qualifiers = [] }) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Sigil (Bracket Curly Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) + , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = "j7", qualifiers = [] })) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil (Bracket Curly Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-with-quadruple" @@ -4651,7 +4733,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , qualifiedness = PossiblyQualified Nothing } ] - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" @@ -4753,7 +4835,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) } ) [] - , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Token (Newlines [] 0))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" @@ -4814,76 +4896,76 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Identifier { name = "A", qualifiers = [] }) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Sigil Comma) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Whitespace 1) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Identifier { name = "B", qualifiers = [] }) - , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Sigil Comma) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Whitespace 1) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Identifier { name = "C", qualifiers = [] }) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Sigil Comma) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Whitespace 1) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Identifier { name = "D", qualifiers = [] }) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Keyword Type) - , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Whitespace 1) - , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Keyword Alias) - , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Whitespace 1) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Whitespace 1) - , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Sigil Assign) - , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Whitespace 1) - , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Identifier { name = "A", qualifiers = [] }) - , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Whitespace 1) - , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Sigil Comma) - , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Whitespace 1) - , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Identifier { name = "C", qualifiers = [] }) - , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Whitespace 1) - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Identifier { name = "D", qualifiers = [] }) - , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Whitespace 1) - , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Identifier { name = "E", qualifiers = [] }) - , Located { end = { col = 31, row = 2 }, start = { col = 30, row = 2 } } (Whitespace 1) - , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Identifier { name = "F", qualifiers = [] }) - , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Sigil Comma) - , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Whitespace 1) - , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Identifier { name = "H", qualifiers = [] }) - , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Whitespace 1) - , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Identifier { name = "I", qualifiers = [] }) - , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Whitespace 1) - , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Identifier { name = "J", qualifiers = [] }) - , Located { end = { col = 41, row = 2 }, start = { col = 40, row = 2 } } (Whitespace 1) - , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Identifier { name = "K", qualifiers = [] }) - , Located { end = { col = 43, row = 2 }, start = { col = 42, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 44, row = 2 }, start = { col = 43, row = 2 } } (Sigil Comma) - , Located { end = { col = 45, row = 2 }, start = { col = 44, row = 2 } } (Whitespace 1) - , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Identifier { name = "L", qualifiers = [] }) - , Located { end = { col = 47, row = 2 }, start = { col = 46, row = 2 } } (Whitespace 1) - , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Identifier { name = "M", qualifiers = [] }) - , Located { end = { col = 49, row = 2 }, start = { col = 48, row = 2 } } (Whitespace 1) - , Located { end = { col = 50, row = 2 }, start = { col = 49, row = 2 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 51, row = 2 }, start = { col = 50, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 52, row = 2 }, start = { col = 51, row = 2 } } (Whitespace 1) - , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Identifier { name = "O", qualifiers = [] }) - , Located { end = { col = 54, row = 2 }, start = { col = 53, row = 2 } } (Whitespace 1) - , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Identifier { name = "P", qualifiers = [] }) - , Located { end = { col = 56, row = 2 }, start = { col = 55, row = 2 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token (Sigil Comma)) + , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Token (Identifier { name = "E", qualifiers = [] })) + , Located { end = { col = 31, row = 2 }, start = { col = 30, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Token (Identifier { name = "F", qualifiers = [] })) + , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Token (Sigil Comma)) + , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Token (Identifier { name = "H", qualifiers = [] })) + , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Token (Identifier { name = "I", qualifiers = [] })) + , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Token (Identifier { name = "J", qualifiers = [] })) + , Located { end = { col = 41, row = 2 }, start = { col = 40, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Token (Identifier { name = "K", qualifiers = [] })) + , Located { end = { col = 43, row = 2 }, start = { col = 42, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 44, row = 2 }, start = { col = 43, row = 2 } } (Token (Sigil Comma)) + , Located { end = { col = 45, row = 2 }, start = { col = 44, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Token (Identifier { name = "L", qualifiers = [] })) + , Located { end = { col = 47, row = 2 }, start = { col = 46, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Token (Identifier { name = "M", qualifiers = [] })) + , Located { end = { col = 49, row = 2 }, start = { col = 48, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 50, row = 2 }, start = { col = 49, row = 2 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 51, row = 2 }, start = { col = 50, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 52, row = 2 }, start = { col = 51, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Token (Identifier { name = "O", qualifiers = [] })) + , Located { end = { col = 54, row = 2 }, start = { col = 53, row = 2 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Token (Identifier { name = "P", qualifiers = [] })) + , Located { end = { col = 56, row = 2 }, start = { col = 55, row = 2 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-with-tuple-double-comma" @@ -4896,7 +4978,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) Just [ Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma)) + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil Comma))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" @@ -4915,23 +4997,23 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Whitespace 1) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Sigil Comma) - , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Whitespace 1) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Identifier { name = "A", qualifiers = [] }) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Sigil (Bracket Round Close)) - , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil Comma)) + , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil (Bracket Round Close))) + , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Token (Newlines [] 0)) ] } , { name = "type-alias-with-tuple-not-closed" @@ -4950,12 +5032,14 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } - (Newlines - [ 0 - , 0 - , 0 - ] - 0 + (Token + (Newlines + [ 0 + , 0 + , 0 + ] + 0 + ) ) ) , state = @@ -4976,24 +5060,26 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Whitespace 1) - , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Keyword Alias) - , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Whitespace 1) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Identifier { name = "Hi", qualifiers = [] }) - , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Whitespace 1) - , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Sigil Assign) - , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Whitespace 1) - , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Sigil (Bracket Round Open)) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Identifier { name = "Int", qualifiers = [] }) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Sigil Comma) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } - (Newlines - [ 0 - , 0 - , 0 - ] - 0 + (Token + (Newlines + [ 0 + , 0 + , 0 + ] + 0 + ) ) ] } @@ -5007,14 +5093,14 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) Just [ Err { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0)) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Token (Newlines [] 0))) , state = State_BlockFirstItem BlockFirstItem_Type } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Keyword Type) - , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Token (Newlines [] 0)) ] } ] From 1d9c0e18cb27bdc4f649950e1a941cfdc695130a Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 20:57:58 +0100 Subject: [PATCH 081/103] make newlines a top level lex thing --- src/Stage/Parse/Contextualize.elm | 180 ++++---- src/Stage/Parse/Lexer.elm | 14 +- tests/ParserLexerTestCases.elm | 684 ++++++++++-------------------- 3 files changed, 309 insertions(+), 569 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 533f8bcf..b496bc29 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -286,7 +286,7 @@ type Error | Error_InvalidNumericLiteral String | Error_ConflictingOperators (Located Operator) (Located Operator) -- Incomplete parsing -- - | Error_PartwayThroughTypeAlias + | Error_PartwayThroughBlock | Error_PartwayThroughValueDeclaration -- Bugs in the parser -- | Error_Panic String @@ -355,7 +355,7 @@ runHelp items state = :: state.previousBlocks , state = case Located.unwrap item of - Lexer.Token (Lexer.Newlines _ 0) -> + Lexer.Newlines _ 0 -> State_BlockStart _ -> @@ -452,23 +452,92 @@ parseAnything state item = Located.getRegion item in case Located.unwrap item of - Lexer.Ignorable _ -> - ParseResult_Skip - Lexer.Invalid _ -> ParseResult_Err (Error_InvalidToken Expecting_Unknown) - Lexer.Token token -> + Lexer.Newlines _ 0 -> case state of State_Error_Recovery -> - case token of - Lexer.Newlines _ 0 -> - State_BlockStart - |> ParseResult_Ok + State_Error_Recovery + |> ParseResult_Ok + + State_BlockStart -> + ParseResult_Ok State_BlockStart + + State_BlockFirstItem BlockFirstItem_Type -> + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockFirstItem BlockFirstItem_Module -> + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockValueDeclaration (BlockValueDeclaration_Named _) -> + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns _) -> + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> + case partialExpr of + ExpressionNestingLeaf_Operator { rhs, lhs, op, parent } -> + case rhs of + Just rhs_ -> + collapseOperators { op = op, lhs = lhs, parent = parent } rhs_ + |> PartialResult_Done + |> newExpressionState name args + + Nothing -> + Error_PartwayThroughBlock + |> ParseResult_Err + + ExpressionNestingLeafType_Expr expr -> + expr + |> PartialResult_Done + |> newExpressionState name args + + State_BlockTypeAlias BlockTypeAlias_Keywords -> + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> + case (autoCollapseNesting CollapseLevel_Function exprSoFar).nesting of + NestingLeafType_Expr expr -> + PartialResult_Done expr + |> newTypeAliasState name typeArgs _ -> - State_Error_Recovery - |> ParseResult_Ok + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockCustomType (BlockCustomType_Named name typeArgs) -> + Error_PartwayThroughBlock + |> ParseResult_Err + + State_BlockCustomType (BlockCustomType_NamedAssigns name typeArgs) -> + Debug.todo "BlockCustomType_NamedAssigns" + + Lexer.Newlines _ _ -> + ParseResult_Skip + + Lexer.Ignorable _ -> + ParseResult_Skip + + Lexer.Token token -> + case state of + State_Error_Recovery -> + State_Error_Recovery + |> ParseResult_Ok State_BlockStart -> parseBlockStart region token @@ -597,12 +666,6 @@ parseBlockStart region item = ) ) - Lexer.Newlines _ 0 -> - ParseResult_Ok State_BlockStart - - Lexer.Newlines _ _ -> - ParseResult_Panic "parseBlockStart expects a block but found some indented content." - _ -> ParseResult_Err (Error_InvalidToken Expecting_Block) @@ -626,15 +689,6 @@ parseTypeBlock item = State_BlockCustomType (BlockCustomType_Named name empty) |> ParseResult_Ok - Lexer.Newlines _ 0 -> - -- TODO(harry): we might be partway through a custom type here, - -- adjust error accordingly. - Error_PartwayThroughTypeAlias - |> ParseResult_Err - - Lexer.Newlines _ _ -> - ParseResult_Skip - _ -> -- TODO(harry) indicate that we could also be expecting the `alias` -- keyword. @@ -657,13 +711,6 @@ parseTypeAliasName item = State_BlockTypeAlias (BlockTypeAlias_Named name empty) |> ParseResult_Ok - Lexer.Newlines _ 0 -> - Error_PartwayThroughTypeAlias - |> ParseResult_Err - - Lexer.Newlines _ _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_TypeName |> ParseResult_Err @@ -692,15 +739,6 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = onAssignment |> ParseResult_Ok - Lexer.Newlines _ 0 -> - -- TODO(harry): we might be partway through almsot anything here, - -- adjust error accordingly. - Error_PartwayThroughTypeAlias - |> ParseResult_Err - - Lexer.Newlines _ _ -> - ParseResult_Skip - _ -> Error_InvalidToken (Expecting_Sigil Lexer.Assign) |> ParseResult_Err @@ -761,13 +799,6 @@ parserTypeExprFromEmpty newState item = Error_InvalidToken Expecting_Unknown |> ParseResult_Err - Lexer.Newlines _ 0 -> - Error_PartwayThroughTypeAlias - |> ParseResult_Err - - Lexer.Newlines _ _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -989,19 +1020,6 @@ parserTypeExpr newState prevExpr item = |> PartialResult_Progress |> newState - Lexer.Newlines _ 0 -> - case (autoCollapseNesting CollapseLevel_Function prevExpr).nesting of - NestingLeafType_Expr expr -> - PartialResult_Done expr - |> newState - - _ -> - Error_PartwayThroughTypeAlias - |> ParseResult_Err - - Lexer.Newlines _ _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -1030,13 +1048,6 @@ parserExpressionFromEmpty newState item = Error_InvalidNumericLiteral str |> ParseResult_Err - Lexer.Newlines _ 0 -> - Error_PartwayThroughTypeAlias - |> ParseResult_Err - - Lexer.Newlines _ _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -1069,27 +1080,6 @@ parserExpression newState prevExpr item = Error_InvalidNumericLiteral str |> ParseResult_Err - Lexer.Newlines _ 0 -> - case prevExpr of - ExpressionNestingLeaf_Operator partialExpr -> - case partialExpr.rhs of - Just rhs -> - collapseOperators { op = partialExpr.op, lhs = partialExpr.lhs, parent = partialExpr.parent } rhs - |> PartialResult_Done - |> newState - - Nothing -> - Error_PartwayThroughValueDeclaration - |> ParseResult_Err - - ExpressionNestingLeafType_Expr expr -> - expr - |> PartialResult_Done - |> newState - - Lexer.Newlines _ _ -> - ParseResult_Skip - _ -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -1594,17 +1584,17 @@ blockFromState state = Debug.todo "handle incomplete block" State_BlockTypeAlias BlockTypeAlias_Keywords -> - Error_PartwayThroughTypeAlias + Error_PartwayThroughBlock |> Err |> Just State_BlockTypeAlias (BlockTypeAlias_Named _ _) -> - Error_PartwayThroughTypeAlias + Error_PartwayThroughBlock |> Err |> Just State_BlockTypeAlias (BlockTypeAlias_NamedAssigns _ _) -> - Error_PartwayThroughTypeAlias + Error_PartwayThroughBlock |> Err |> Just @@ -1624,7 +1614,7 @@ blockFromState state = |> Just _ -> - Error_PartwayThroughTypeAlias + Error_PartwayThroughBlock |> Err |> Just diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 16117977..31896b79 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -11,6 +11,7 @@ type LexItem = Token LexToken | Ignorable LexIgnorable | Invalid LexInvalid + | Newlines (List Int) Int type LexToken @@ -24,7 +25,6 @@ type LexToken | Keyword Token.Keyword | NumericLiteral String | TextLiteral LexLiteralType String - | Newlines (List Int) Int type LexIgnorable @@ -56,7 +56,7 @@ type LexSigil type LexCommentType = LineComment - | MutlilineComment + | MultilineComment | DocComment @@ -171,18 +171,18 @@ toString item = Ignorable (Whitespace i) -> String.repeat i " " - Token (Newlines empties identationSpaces) -> + Newlines empties indentationSpaces -> (empties |> List.map (\spacesInEmptyLine -> "\n" ++ String.repeat spacesInEmptyLine " ") |> String.join "" ) ++ "\n" - ++ String.repeat identationSpaces " " + ++ String.repeat indentationSpaces " " Ignorable (Comment LineComment s) -> "//" ++ s - Ignorable (Comment MutlilineComment s) -> + Ignorable (Comment MultilineComment s) -> "{-" ++ s ++ "-}" Ignorable (Comment DocComment s) -> @@ -248,7 +248,7 @@ parser = |> P.andThen (\() -> chompSpacesAndCount) |> P.map (\count -> (count + 1) |> Whitespace |> Ignorable) , newlinesParser - |> P.map (\( emptyLines, indentation ) -> Newlines emptyLines indentation |> Token) + |> P.map (\( emptyLines, indentation ) -> Newlines emptyLines indentation) , P.getChompedString (P.chompIf (\_ -> True) ExpectingAnything) |> P.map (\s -> @@ -447,7 +447,7 @@ chompSpacesAndCount = textLiteralParser : Parser_ ( LexLiteralType, Bool, String ) textLiteralParser = P.oneOf - [ -- order matters! We must try parsing a tripple delimited string first! + [ -- order matters! We must try parsing a triple delimited string first! delimitedLiteral (StringL Triple) , delimitedLiteral (StringL Single) , delimitedLiteral CharL diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 6e7133aa..eaa63472 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -66,19 +66,17 @@ b = 78 , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 6, row = 1 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Token (NumericLiteral "78")) - , Located { end = { col = 1, row = 4 }, start = { col = 7, row = 3 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 4 }, start = { col = 7, row = 3 } } (Newlines [] 0) ] } , { name = "expression-int-add" @@ -160,12 +158,10 @@ b = 78 + 5 + 2+ 4 , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) @@ -183,7 +179,7 @@ b = 78 + 5 + 2+ 4 , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Token (Sigil (Operator Add))) , Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Token (NumericLiteral "4")) - , Located { end = { col = 1, row = 4 }, start = { col = 18, row = 3 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 4 }, start = { col = 18, row = 3 } } (Newlines [] 0) ] } , { name = "expression-int-multiply" @@ -274,12 +270,10 @@ b = 78 * 5 * 2 / 4 * 5 , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) @@ -302,7 +296,7 @@ b = 78 * 5 * 2 / 4 * 5 , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Token (Sigil (Operator Multiply))) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (NumericLiteral "5")) - , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Newlines [] 0) ] } , { name = "expression-int-multiply-and-add" @@ -729,7 +723,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Token (Sigil (Operator Add))) , Located { end = { col = 13, row = 1 }, start = { col = 12, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Token (NumericLiteral "6")) - , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) , Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = "a1", qualifiers = [] })) , Located { end = { col = 4, row = 2 }, start = { col = 3, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 2 }, start = { col = 4, row = 2 } } (Token (Sigil Assign)) @@ -743,7 +737,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Token (Sigil (Operator Multiply))) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (NumericLiteral "5")) - , Located { end = { col = 1, row = 3 }, start = { col = 16, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 3 }, start = { col = 16, row = 2 } } (Newlines [] 0) , Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "a11", qualifiers = [] })) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Assign)) @@ -761,7 +755,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Token (Sigil (Operator Add))) , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Token (NumericLiteral "6")) - , Located { end = { col = 1, row = 4 }, start = { col = 21, row = 3 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 4 }, start = { col = 21, row = 3 } } (Newlines [] 0) , Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (Token (Identifier { name = "a2", qualifiers = [] })) , Located { end = { col = 4, row = 4 }, start = { col = 3, row = 4 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 4 }, start = { col = 4, row = 4 } } (Token (Sigil Assign)) @@ -775,7 +769,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } (Token (Sigil (Operator Multiply))) , Located { end = { col = 17, row = 4 }, start = { col = 16, row = 4 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Token (NumericLiteral "5")) - , Located { end = { col = 1, row = 5 }, start = { col = 18, row = 4 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 5 }, start = { col = 18, row = 4 } } (Newlines [] 0) , Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (Token (Identifier { name = "a3", qualifiers = [] })) , Located { end = { col = 4, row = 5 }, start = { col = 3, row = 5 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 5 }, start = { col = 4, row = 5 } } (Token (Sigil Assign)) @@ -794,13 +788,11 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 26, row = 5 }, start = { col = 25, row = 5 } } (Ignorable (Whitespace 1)) , Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Token (NumericLiteral "1010")) , Located { end = { col = 1, row = 8 }, start = { col = 30, row = 5 } } - (Token - (Newlines - [ 0 - , 0 - ] - 0 - ) + (Newlines + [ 0 + , 0 + ] + 0 ) , Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (Token (Identifier { name = "b", qualifiers = [] })) , Located { end = { col = 3, row = 8 }, start = { col = 2, row = 8 } } (Ignorable (Whitespace 1)) @@ -823,7 +815,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } (Token (Sigil (Operator Multiply))) , Located { end = { col = 22, row = 8 }, start = { col = 21, row = 8 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Token (NumericLiteral "5")) - , Located { end = { col = 1, row = 9 }, start = { col = 23, row = 8 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 9 }, start = { col = 23, row = 8 } } (Newlines [] 0) , Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (Token (Identifier { name = "b1", qualifiers = [] })) , Located { end = { col = 4, row = 9 }, start = { col = 3, row = 9 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 9 }, start = { col = 4, row = 9 } } (Token (Sigil Assign)) @@ -845,7 +837,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } (Token (Sigil (Operator Subtract))) , Located { end = { col = 23, row = 9 }, start = { col = 22, row = 9 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Token (NumericLiteral "5")) - , Located { end = { col = 1, row = 10 }, start = { col = 24, row = 9 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 10 }, start = { col = 24, row = 9 } } (Newlines [] 0) , Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (Token (Identifier { name = "b2", qualifiers = [] })) , Located { end = { col = 4, row = 10 }, start = { col = 3, row = 10 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 10 }, start = { col = 4, row = 10 } } (Token (Sigil Assign)) @@ -867,7 +859,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } (Token (Sigil (Operator Multiply))) , Located { end = { col = 23, row = 10 }, start = { col = 22, row = 10 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Token (NumericLiteral "5")) - , Located { end = { col = 1, row = 11 }, start = { col = 24, row = 10 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 11 }, start = { col = 24, row = 10 } } (Newlines [] 0) , Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (Token (Identifier { name = "b3", qualifiers = [] })) , Located { end = { col = 4, row = 11 }, start = { col = 3, row = 11 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 11 }, start = { col = 4, row = 11 } } (Token (Sigil Assign)) @@ -889,7 +881,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } (Token (Sigil (Operator Multiply))) , Located { end = { col = 23, row = 11 }, start = { col = 22, row = 11 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Token (NumericLiteral "5")) - , Located { end = { col = 1, row = 12 }, start = { col = 24, row = 11 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 12 }, start = { col = 24, row = 11 } } (Newlines [] 0) , Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (Token (Identifier { name = "b4", qualifiers = [] })) , Located { end = { col = 4, row = 12 }, start = { col = 3, row = 12 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 12 }, start = { col = 4, row = 12 } } (Token (Sigil Assign)) @@ -912,12 +904,10 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 23, row = 12 }, start = { col = 22, row = 12 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 14 }, start = { col = 24, row = 12 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) ] } @@ -1009,12 +999,10 @@ b = 78 + 5 + 2 - 4 + 5 , Located { end = { col = 9, row = 1 }, start = { col = 8, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 10, row = 1 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) @@ -1037,7 +1025,7 @@ b = 78 + 5 + 2 - 4 + 5 , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Token (Sigil (Operator Add))) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (NumericLiteral "5")) - , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 4 }, start = { col = 23, row = 3 } } (Newlines [] 0) ] } , { name = "type-alias" @@ -1104,7 +1092,7 @@ b = 78 + 5 + 2 - 4 + 5 , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) - , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-and-expression" @@ -1195,12 +1183,10 @@ expr hi = 77 , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 28, row = 1 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "expr", qualifiers = [] })) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) @@ -1209,7 +1195,7 @@ expr hi = 77 , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (Token (NumericLiteral "77")) - , Located { end = { col = 1, row = 4 }, start = { col = 13, row = 3 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 4 }, start = { col = 13, row = 3 } } (Newlines [] 0) ] } , { name = "type-alias-bracket-in-record" @@ -1278,7 +1264,7 @@ expr hi = 77 , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-function" @@ -1409,7 +1395,7 @@ expr hi = 77 , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-function-binding-order" @@ -1617,7 +1603,7 @@ type alias Function = A -> B -> C -> D , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) @@ -1639,7 +1625,7 @@ type alias Function = A -> B -> C -> D , Located { end = { col = 37, row = 2 }, start = { col = 35, row = 2 } } (Token (Sigil ThinArrow)) , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token (Identifier { name = "D", qualifiers = [] })) - , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Newlines [] 0) ] } , { name = "type-alias-function-generic" @@ -1776,7 +1762,7 @@ type alias Function = A -> B -> C -> D , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-function-nested" @@ -2084,12 +2070,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 3 }, start = { col = 44, row = 1 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) @@ -2118,12 +2102,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 49, row = 3 }, start = { col = 48, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 50, row = 3 }, start = { col = 49, row = 3 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 1, row = 5 }, start = { col = 50, row = 3 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) @@ -2151,12 +2133,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 48, row = 5 }, start = { col = 47, row = 5 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 49, row = 5 }, start = { col = 48, row = 5 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 7 }, start = { col = 49, row = 5 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Ignorable (Whitespace 1)) @@ -2186,7 +2166,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 52, row = 7 }, start = { col = 51, row = 7 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 53, row = 7 }, start = { col = 52, row = 7 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 54, row = 7 }, start = { col = 53, row = 7 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 8 }, start = { col = 54, row = 7 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 8 }, start = { col = 54, row = 7 } } (Newlines [] 0) ] } , { name = "type-alias-function-record" @@ -2310,7 +2290,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 49, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 49, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-function-tuple" @@ -2399,7 +2379,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-funky-indentation" @@ -2459,7 +2439,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) - , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Token (Newlines [] 4)) + , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token (Identifier { name = "Model", qualifiers = [] })) , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Token (Sigil Assign)) @@ -2467,7 +2447,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 17, row = 2 }, start = { col = 13, row = 2 } } (Token (Identifier { name = "List", qualifiers = [] })) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) - , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 2 } } (Newlines [] 0) ] } , { name = "type-alias-funky-indentation-2" @@ -2528,15 +2508,15 @@ type alias Function3 = (Int, () -> (Int, String), ()) [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) - , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Token (Newlines [] 4)) + , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token (Identifier { name = "Model", qualifiers = [] })) , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Token (Sigil Assign)) - , Located { end = { col = 2, row = 3 }, start = { col = 12, row = 2 } } (Token (Newlines [] 1)) + , Located { end = { col = 2, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 1) , Located { end = { col = 6, row = 3 }, start = { col = 2, row = 3 } } (Token (Identifier { name = "List", qualifiers = [] })) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "Int", qualifiers = [] })) - , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Newlines [] 0) ] } , { name = "type-alias-record-3-entries" @@ -2650,7 +2630,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 37, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 37, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-record-empty" @@ -2683,7 +2663,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-record-empty-multiline" @@ -2719,16 +2699,14 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 5, row = 4 }, start = { col = 18, row = 1 } } - (Token - (Newlines - [ 0 - , 0 - ] - 4 - ) + (Newlines + [ 0 + , 0 + ] + 4 ) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) ] } , { name = "type-alias-record-in-bracket" @@ -2797,7 +2775,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 30, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-record-nested" @@ -2989,7 +2967,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) - , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Token (Newlines [] 4)) + , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Token (Identifier { name = "hi", qualifiers = [] })) @@ -3011,7 +2989,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 36, row = 2 }, start = { col = 30, row = 2 } } (Token (Identifier { name = "String", qualifiers = [] })) , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 5, row = 3 }, start = { col = 38, row = 2 } } (Token (Newlines [] 4)) + , Located { end = { col = 5, row = 3 }, start = { col = 38, row = 2 } } (Newlines [] 4) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Comma)) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "ih", qualifiers = [] })) @@ -3030,9 +3008,9 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Token (Identifier { name = "E", qualifiers = [] })) , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Token (Newlines [] 4)) + , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Newlines [] 4) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) ] } , { name = "type-alias-record-simple" @@ -3099,7 +3077,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-record-two-entries" @@ -3176,7 +3154,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 38, row = 1 }, start = { col = 32, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 40, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 40, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-unit" @@ -3207,7 +3185,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-with-bracket" @@ -3259,7 +3237,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-with-bracket-2" @@ -3328,7 +3306,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-with-pair" @@ -3449,7 +3427,7 @@ type alias Hi = (Int) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) @@ -3461,7 +3439,7 @@ type alias Hi = (Int) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Newlines [] 0) ] } , { name = "type-alias-with-tripple" @@ -3569,7 +3547,7 @@ type alias Hi = ((), (), ()) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "Three", qualifiers = [] })) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) @@ -3590,7 +3568,7 @@ type alias Hi = ((), (), ()) , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 3 }, start = { col = 29, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 3 }, start = { col = 29, row = 2 } } (Newlines [] 0) ] } , { name = "type-alias-with-tripple-in-record" @@ -3697,7 +3675,7 @@ type alias Hi = ((), (), ()) , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) - , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Token (Newlines [] 4)) + , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token (Identifier { name = "a", qualifiers = [] })) @@ -3712,7 +3690,7 @@ type alias Hi = ((), (), ()) , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Token (Newlines [] 4)) + , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Newlines [] 4) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Comma)) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) @@ -3729,9 +3707,9 @@ type alias Hi = ((), (), ()) , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 5, row = 4 }, start = { col = 28, row = 3 } } (Token (Newlines [] 4)) + , Located { end = { col = 5, row = 4 }, start = { col = 28, row = 3 } } (Newlines [] 4) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 5 }, start = { col = 6, row = 4 } } (Newlines [] 0) ] } ] @@ -3782,17 +3760,6 @@ Hi. case""" , ( Err, todo ) , ( Err, todo ) , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) ) """ , contextualized = @@ -3802,54 +3769,6 @@ Hi. case""" , item = Just (Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] }))) , state = State_BlockStart } - , Err - { error = - Error_BlockStartsWithQualifiedName - { name = "Bar" - , qualifiers = - [ "Foo" - ] - } - , item = - Just - (Located { end = { col = 8, row = 3 }, start = { col = 1, row = 3 } } - (Token - (Identifier - { name = "Bar" - , qualifiers = - [ "Foo" - ] - } - ) - ) - ) - , state = State_BlockStart - } - , Err - { error = - Error_BlockStartsWithQualifiedName - { name = "baz" - , qualifiers = - [ "Foo" - , "Bar" - ] - } - , item = - Just - (Located { end = { col = 12, row = 5 }, start = { col = 1, row = 5 } } - (Token - (Identifier - { name = "baz" - , qualifiers = - [ "Foo" - , "Bar" - ] - } - ) - ) - ) - , state = State_BlockStart - } , Err { error = Error_InvalidToken Expecting_Unknown , item = @@ -3865,115 +3784,32 @@ Hi. case""" ) ) ) - , state = State_BlockStart + , state = State_Error_Recovery } , Err { error = Error_InvalidToken Expecting_Unknown , item = Just (Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] }))) - , state = State_BlockStart + , state = State_Error_Recovery } , Err { error = Error_InvalidToken Expecting_Unknown , item = Just (Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Big", qualifiers = [] }))) , state = State_Error_Recovery } - , Err - { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (Token (RecordAccessorFunction "sf"))) - , state = State_BlockStart - } - , Err - { error = Error_InvalidToken (Expecting_Sigil Assign) - , item = Just (Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (Token (RecordAccessorFunction "sdfsd"))) - , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } "sfsdf" }) - } - , Err - { error = - Error_BlockStartsWithQualifiedName - { name = "sdgsghj" - , qualifiers = - [ "asfasf" - ] - } - , item = - Just - (Located { end = { col = 15, row = 15 }, start = { col = 1, row = 15 } } - (Token - (Identifier - { name = "sdgsghj" - , qualifiers = - [ "asfasf" - ] - } - ) - ) - ) - , state = State_BlockStart - } - , Err - { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockStart - } - , Err - { error = Error_InvalidToken Expecting_Block - , item = Just (Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockStart - } - , Err - { error = Error_InvalidToken (Expecting_Sigil Assign) - , item = Just (Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } "sfhsdf" }) - } - , Err - { error = Error_MisplacedKeyword Case - , item = Just (Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Token (Keyword Case))) - , state = State_BlockStart - } - , Err - { error = - Error_BlockStartsWithQualifiedName - { name = "case" - , qualifiers = - [ "Hi" - ] - } - , item = - Just - (Located { end = { col = 8, row = 25 }, start = { col = 1, row = 25 } } - (Token - (Identifier - { name = "case" - , qualifiers = - [ "Hi" - ] - } - ) - ) - ) - , state = State_BlockStart - } - , Err - { error = Error_MisplacedKeyword Case - , item = Just (Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Token (Keyword Case))) - , state = State_BlockStart - } , Err { error = Error_InvalidToken Expecting_Unknown , item = Just (Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] }))) - , state = State_BlockStart + , state = State_Error_Recovery } ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 5, row = 1 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 8, row = 3 }, start = { col = 1, row = 3 } } (Token @@ -3986,12 +3822,10 @@ Hi. case""" ) ) , Located { end = { col = 1, row = 5 }, start = { col = 8, row = 3 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 12, row = 5 }, start = { col = 1, row = 5 } } (Token @@ -4005,12 +3839,10 @@ Hi. case""" ) ) , Located { end = { col = 1, row = 7 }, start = { col = 12, row = 5 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 11, row = 7 }, start = { col = 1, row = 7 } } (Invalid @@ -4023,43 +3855,35 @@ Hi. case""" ) ) , Located { end = { col = 1, row = 9 }, start = { col = 11, row = 7 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] })) , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Ignorable (Whitespace 1)) , Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Big", qualifiers = [] })) , Located { end = { col = 1, row = 11 }, start = { col = 10, row = 9 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (Token (RecordAccessorFunction "sf")) , Located { end = { col = 1, row = 13 }, start = { col = 4, row = 11 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } (Token (Identifier { name = "sfsdf", qualifiers = [] })) , Located { end = { col = 7, row = 13 }, start = { col = 6, row = 13 } } (Ignorable (Whitespace 1)) , Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (Token (RecordAccessorFunction "sdfsd")) , Located { end = { col = 1, row = 15 }, start = { col = 13, row = 13 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 15, row = 15 }, start = { col = 1, row = 15 } } (Token @@ -4072,24 +3896,20 @@ Hi. case""" ) ) , Located { end = { col = 1, row = 17 }, start = { col = 15, row = 15 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 6, row = 17 }, start = { col = 2, row = 17 } } (Token (Identifier { name = "shdf", qualifiers = [] })) , Located { end = { col = 7, row = 17 }, start = { col = 6, row = 17 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 20, row = 17 }, start = { col = 7, row = 17 } } (Token (RecordAccessorLiteral "helloLiteral")) , Located { end = { col = 1, row = 19 }, start = { col = 20, row = 17 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 7, row = 19 }, start = { col = 2, row = 19 } } (Token (Identifier { name = "sjhsf", qualifiers = [] })) @@ -4097,34 +3917,28 @@ Hi. case""" , Located { end = { col = 9, row = 19 }, start = { col = 8, row = 19 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 19 }, start = { col = 9, row = 19 } } (Token (RecordAccessorFunction "helloFunction")) , Located { end = { col = 1, row = 21 }, start = { col = 23, row = 19 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } (Token (Identifier { name = "sfhsdf", qualifiers = [] })) , Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 22, row = 21 }, start = { col = 8, row = 21 } } (Token (RecordAccessorFunction "helloFunction")) , Located { end = { col = 23, row = 21 }, start = { col = 22, row = 21 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 23 }, start = { col = 23, row = 21 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Token (Keyword Case)) , Located { end = { col = 8, row = 23 }, start = { col = 5, row = 23 } } (Token (RecordAccessorFunction "hi")) , Located { end = { col = 1, row = 25 }, start = { col = 8, row = 23 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 8, row = 25 }, start = { col = 1, row = 25 } } (Token @@ -4137,23 +3951,19 @@ Hi. case""" ) ) , Located { end = { col = 1, row = 27 }, start = { col = 8, row = 25 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Token (Keyword Case)) , Located { end = { col = 6, row = 27 }, start = { col = 5, row = 27 } } (Ignorable (Whitespace 1)) , Located { end = { col = 9, row = 27 }, start = { col = 6, row = 27 } } (Token (RecordAccessorFunction "hi")) , Located { end = { col = 1, row = 29 }, start = { col = 9, row = 27 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] })) , Located { end = { col = 5, row = 29 }, start = { col = 4, row = 29 } } (Ignorable (Whitespace 1)) @@ -4170,11 +3980,7 @@ type alias Function3 = (() -> , ()) type alias Function3 = (Int, () ->, ()) """ , pretty = """ - ( ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - , ( Err, todo ) - ) + ( ( Err, todo ) ) """ , contextualized = Just @@ -4192,52 +3998,6 @@ type alias Function3 = (Int, () ->, ()) } ) } - , Err - { error = Error_MissingFunctionReturnType - , item = Just (Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Token (Sigil (Bracket Curly Close)))) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish "Function2" - [] - { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } - , parents = - [ NestingParentType_PartialRecord { firstEntries = Stack [], lastEntryName = "a" } - ] - } - ) - } - , Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Token (Sigil Comma))) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish "Function3" - [] - { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } - , parents = - [ NestingParentType_Bracket (Stack []) - ] - } - ) - } - , Err - { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Token (Sigil Comma))) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish "Function3" - [] - { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } - , parents = - [ NestingParentType_Bracket - (Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - ) - ] - } - ) - } ] , lexed = Ok @@ -4257,12 +4017,10 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 3 }, start = { col = 31, row = 1 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) @@ -4284,12 +4042,10 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 36, row = 3 }, start = { col = 34, row = 3 } } (Ignorable (Whitespace 2)) , Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 1, row = 5 }, start = { col = 37, row = 3 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) @@ -4311,12 +4067,10 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 35, row = 5 }, start = { col = 34, row = 5 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 7 }, start = { col = 36, row = 5 } } - (Token - (Newlines - [ 0 - ] - 0 - ) + (Newlines + [ 0 + ] + 0 ) , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Ignorable (Whitespace 1)) @@ -4339,7 +4093,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 38, row = 7 }, start = { col = 37, row = 7 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 39, row = 7 }, start = { col = 38, row = 7 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 40, row = 7 }, start = { col = 39, row = 7 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 8 }, start = { col = 40, row = 7 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 8 }, start = { col = 40, row = 7 } } (Newlines [] 0) ] } , { name = "type-alias-invalid-multiple-brackets" @@ -4372,7 +4126,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-invalid-multiple-brackets-2" @@ -4404,7 +4158,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-invalid-multiple-brackets-3" @@ -4437,7 +4191,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-multiline-missing-indentation" @@ -4452,13 +4206,13 @@ List Int , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns "Model" []) } , Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0)) , state = State_BlockValueDeclaration (BlockValueDeclaration_Named @@ -4480,11 +4234,11 @@ List Int , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Model", qualifiers = [] })) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil Assign)) - , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = "List", qualifiers = [] })) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) - , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) ] } , { name = "type-alias-partial" @@ -4496,8 +4250,8 @@ List Int , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias BlockTypeAlias_Keywords } ] @@ -4506,7 +4260,7 @@ List Int [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) - , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-partial-2" @@ -4518,8 +4272,8 @@ List Int , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Named "Hi" (Stack [])) } ] @@ -4530,7 +4284,7 @@ List Int , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) - , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-partial-3" @@ -4542,8 +4296,8 @@ List Int , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns "Hi" []) } ] @@ -4556,7 +4310,7 @@ List Int , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) - , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-partial-with-bracket" @@ -4568,8 +4322,8 @@ List Int , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) } ] @@ -4584,7 +4338,7 @@ List Int , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-partial-with-bracket-2" @@ -4597,8 +4351,8 @@ List Int , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" @@ -4622,9 +4376,9 @@ List Int , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 8)) + , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) - , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) ] } , { name = "type-alias-record-half-empty" @@ -4636,8 +4390,8 @@ List Int , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) } ] @@ -4652,7 +4406,7 @@ List Int , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) - , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-record-missing-colon" @@ -4686,7 +4440,7 @@ List Int , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = "j7", qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil (Bracket Curly Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-with-quadruple" @@ -4733,7 +4487,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , qualifiedness = PossiblyQualified Nothing } ] - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Token (Newlines [] 0))) + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" @@ -4835,7 +4589,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) } ) [] - , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Token (Newlines [] 0))) + , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0)) , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" @@ -4919,7 +4673,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token (Identifier { name = "D", qualifiers = [] })) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) @@ -4965,7 +4719,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 54, row = 2 }, start = { col = 53, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Token (Identifier { name = "P", qualifiers = [] })) , Located { end = { col = 56, row = 2 }, start = { col = 55, row = 2 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0) ] } , { name = "type-alias-with-tuple-double-comma" @@ -5013,7 +4767,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) ] } , { name = "type-alias-with-tuple-not-closed" @@ -5028,18 +4782,16 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias + { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } - (Token - (Newlines - [ 0 - , 0 - , 0 - ] - 0 - ) + (Newlines + [ 0 + , 0 + , 0 + ] + 0 ) ) , state = @@ -5072,14 +4824,12 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } - (Token - (Newlines - [ 0 - , 0 - , 0 - ] - 0 - ) + (Newlines + [ 0 + , 0 + , 0 + ] + 0 ) ] } @@ -5092,15 +4842,15 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , contextualized = Just [ Err - { error = Error_PartwayThroughTypeAlias - , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Token (Newlines [] 0))) + { error = Error_PartwayThroughBlock + , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0)) , state = State_BlockFirstItem BlockFirstItem_Type } ] , lexed = Ok [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) - , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Token (Newlines [] 0)) + , Located { end = { col = 1, row = 2 }, start = { col = 5, row = 1 } } (Newlines [] 0) ] } ] From 3c040198c485bc299e49a622a2dac627cdb567e7 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 21:04:28 +0100 Subject: [PATCH 082/103] apply intellij suggestions --- src/Stage/Parse/Contextualize.elm | 71 +++++++------------------------ 1 file changed, 16 insertions(+), 55 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index b496bc29..35cc6c2b 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -19,13 +19,9 @@ import Elm.Data.Module exposing (Module, ModuleType(..)) import Elm.Data.ModuleName exposing (ModuleName) import Elm.Data.Operator as Operator exposing (Operator) import Elm.Data.Qualifiedness as Qualifiedness exposing (PossiblyQualified(..)) -import Elm.Data.Type exposing (Type) import Elm.Data.Type.Concrete as ConcreteType exposing (ConcreteType) -import Elm.Data.TypeAnnotation exposing (TypeAnnotation) import Elm.Data.VarName exposing (VarName) -import List.NonEmpty.Zipper exposing (prev) -import Parser exposing (oneOf) -import Stage.Parse.Lexer as Lexer exposing (LexItem(..), LexSigil(..), newlinesParser) +import Stage.Parse.Lexer as Lexer exposing (LexItem(..), LexSigil(..)) import Stage.Parse.Token as Token exposing (Keyword) @@ -502,11 +498,11 @@ parseAnything state item = Error_PartwayThroughBlock |> ParseResult_Err - State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> + State_BlockTypeAlias (BlockTypeAlias_Named _ _) -> Error_PartwayThroughBlock |> ParseResult_Err - State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns _ _) -> Error_PartwayThroughBlock |> ParseResult_Err @@ -520,11 +516,11 @@ parseAnything state item = Error_PartwayThroughBlock |> ParseResult_Err - State_BlockCustomType (BlockCustomType_Named name typeArgs) -> + State_BlockCustomType (BlockCustomType_Named _ _) -> Error_PartwayThroughBlock |> ParseResult_Err - State_BlockCustomType (BlockCustomType_NamedAssigns name typeArgs) -> + State_BlockCustomType (BlockCustomType_NamedAssigns _ _) -> Debug.todo "BlockCustomType_NamedAssigns" Lexer.Newlines _ _ -> @@ -624,7 +620,7 @@ parseAnything state item = ) (Located.located region token) - State_BlockCustomType (BlockCustomType_NamedAssigns name typeArgs) -> + State_BlockCustomType (BlockCustomType_NamedAssigns _ _) -> Debug.todo "BlockCustomType_NamedAssigns" @@ -750,7 +746,7 @@ parserTypeExprFromEmpty : -> ParseResult parserTypeExprFromEmpty newState item = case Located.unwrap item of - Lexer.Identifier ({ qualifiers, name } as identifier) -> + Lexer.Identifier { qualifiers, name } -> if qualifiers /= [] then Debug.todo "" @@ -811,7 +807,7 @@ parserTypeExpr : -> ParseResult parserTypeExpr newState prevExpr item = case Located.unwrap item of - Lexer.Identifier ({ qualifiers, name } as identifier) -> + Lexer.Identifier { qualifiers, name } -> if qualifiers /= [] then Debug.todo "" @@ -835,7 +831,7 @@ parserTypeExpr newState prevExpr item = autoCollapseNesting CollapseLevel_Function prevExpr in case collapsedLeaf.nesting of - NestingLeafType_Expr expr -> + NestingLeafType_Expr _ -> Error_UnmatchedBracket Lexer.Round Lexer.Close |> ParseResult_Err @@ -890,14 +886,14 @@ parserTypeExpr newState prevExpr item = autoCollapseNesting CollapseLevel_Function prevExpr in case collapsedLeaf.nesting of - NestingLeafType_Expr expr -> + NestingLeafType_Expr _ -> Error_UnmatchedBracket Lexer.Curly Lexer.Close |> ParseResult_Err NestingLeafType_TypeWithArgs { name, args } -> Debug.todo "Make this state impossible" - NestingLeafType_Bracket argStack mLastExpression -> + NestingLeafType_Bracket _ _ -> Error_WrongClosingBracket { expecting = Lexer.Round , found = Lexer.Curly @@ -919,23 +915,6 @@ parserTypeExpr newState prevExpr item = Lexer.Sigil Lexer.ThinArrow -> let - getNewPartialRecord parents { firstEntries, lastEntry } = - case lastEntry of - LastEntryOfRecord_KeyValue key value -> - { parents = parents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = ( key, value ) |> pushOnto firstEntries - , lastEntry = LastEntryOfRecord_Empty - } - } - |> PartialResult_Progress - |> newState - - _ -> - Error_InvalidToken Expecting_Unknown - |> ParseResult_Err - collapsedLeaf = autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr in @@ -985,7 +964,7 @@ parserTypeExpr newState prevExpr item = |> PartialResult_Progress |> newState - NestingLeafType_Bracket argStack Nothing -> + NestingLeafType_Bracket _ Nothing -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err @@ -1195,7 +1174,7 @@ exprAppend ({ parents, nesting } as currentLeaf) token = in case nesting of -- We are within a nested bracket. - NestingLeafType_Bracket argStack mostNested -> + NestingLeafType_Bracket _ mostNested -> case mostNested of Nothing -> leafToParents currentLeaf @@ -1255,7 +1234,7 @@ exprAppend ({ parents, nesting } as currentLeaf) token = } |> Ok - (NestingLeafType_Function { firstInput, output }) as lt -> + NestingLeafType_Function { firstInput, output } -> Result.map2 (\newOutput newParents -> { parents = newParents @@ -1580,7 +1559,7 @@ blockFromState state = State_BlockStart -> Nothing - State_BlockFirstItem firstItem -> + State_BlockFirstItem _ -> Debug.todo "handle incomplete block" State_BlockTypeAlias BlockTypeAlias_Keywords -> @@ -1618,7 +1597,7 @@ blockFromState state = |> Err |> Just - State_BlockCustomType firstItem -> + State_BlockCustomType _ -> Debug.todo "handle incomplete block" State_BlockValueDeclaration (BlockValueDeclaration_Named _) -> @@ -1792,19 +1771,6 @@ partialTypeExpressionToConcreteType pte = ) TypeExpression_Function functionTypeExpr -> - let - folder : - ConcreteType a - -> (ConcreteType a -> ConcreteType a) - -> (ConcreteType a -> ConcreteType a) - folder nextArg createConcreteFunction someOutput = - createConcreteFunction - (ConcreteType.Function - { from = nextArg - , to = someOutput - } - ) - in Result.map3 (\concreteFirstInput concreteOtherInputs concreteOutput -> ConcreteType.Function @@ -1888,8 +1854,3 @@ toList mapper (Stack ls) = (\curr prev -> mapper curr :: prev) [] ls - - -reverseToList : Stack a -> List a -reverseToList (Stack ls) = - ls From 4090dd0da9ac1d5b575e62c356e5eee0785df20c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 21:09:56 +0100 Subject: [PATCH 083/103] fix printy printing --- src/Stage/Parse/Pretty.elm | 2 +- tests/ParserLexerTestCases.elm | 60 +++++++++++++++++----------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Stage/Parse/Pretty.elm b/src/Stage/Parse/Pretty.elm index 885e490a..53677c5c 100644 --- a/src/Stage/Parse/Pretty.elm +++ b/src/Stage/Parse/Pretty.elm @@ -123,7 +123,7 @@ block b = TypeAlias record -> Many - [ Atom "ValueDeclaration" + [ Atom "TypeAlias" , Many [ Atom "ty" , Atom record.ty diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index eaa63472..8c10724b 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -1033,7 +1033,7 @@ b = 78 + 5 + 2 - 4 + 5 """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Model ) , ( genericArgs, () ) , ( expr @@ -1102,7 +1102,7 @@ expr hi = 77 """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Model ) , ( genericArgs, () ) , ( expr @@ -1203,7 +1203,7 @@ expr hi = 77 """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Ty ) , ( genericArgs, () ) , ( expr @@ -1272,7 +1272,7 @@ expr hi = 77 """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function ) , ( genericArgs, () ) , ( expr @@ -1404,7 +1404,7 @@ type alias Function = A -> B -> C -> D """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function ) , ( genericArgs, () ) , ( expr @@ -1450,7 +1450,7 @@ type alias Function = A -> B -> C -> D ) ) , ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function ) , ( genericArgs, () ) , ( expr @@ -1633,7 +1633,7 @@ type alias Function = A -> B -> C -> D """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function ) , ( genericArgs , ( a ) @@ -1776,7 +1776,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function ) , ( genericArgs, () ) , ( expr @@ -1809,7 +1809,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ) , ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function2 ) , ( genericArgs, () ) , ( expr @@ -1846,7 +1846,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ) , ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function3 ) , ( genericArgs, () ) , ( expr @@ -1883,7 +1883,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) ) , ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function3 ) , ( genericArgs, () ) , ( expr @@ -2174,7 +2174,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function ) , ( genericArgs, () ) , ( expr @@ -2298,7 +2298,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Function ) , ( genericArgs, () ) , ( expr @@ -2388,7 +2388,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Model ) , ( genericArgs, () ) , ( expr @@ -2457,7 +2457,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Model ) , ( genericArgs, () ) , ( expr @@ -2524,7 +2524,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Ty ) , ( genericArgs, () ) , ( expr @@ -2638,7 +2638,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Ty ) , ( genericArgs, () ) , ( expr @@ -2674,7 +2674,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Ty ) , ( genericArgs, () ) , ( expr @@ -2714,7 +2714,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Ty ) , ( genericArgs, () ) , ( expr @@ -2786,7 +2786,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Ty ) , ( genericArgs, () ) , ( expr @@ -3018,7 +3018,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Ty ) , ( genericArgs, () ) , ( expr @@ -3085,7 +3085,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Ty ) , ( genericArgs, () ) , ( expr @@ -3162,7 +3162,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Hi ) , ( genericArgs, () ) , ( expr, Unit ) @@ -3193,7 +3193,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Hi ) , ( genericArgs, () ) , ( expr @@ -3245,7 +3245,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Hi ) , ( genericArgs, () ) , ( expr @@ -3315,7 +3315,7 @@ type alias Hi = (Int) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Hi ) , ( genericArgs, () ) , ( expr @@ -3351,7 +3351,7 @@ type alias Hi = (Int) ) ) , ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Hi ) , ( genericArgs, () ) , ( expr @@ -3448,7 +3448,7 @@ type alias Hi = ((), (), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Hi ) , ( genericArgs, () ) , ( expr @@ -3483,7 +3483,7 @@ type alias Hi = ((), (), ()) ) ) , ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Hi ) , ( genericArgs, () ) , ( expr @@ -3579,7 +3579,7 @@ type alias Hi = ((), (), ()) """ , pretty = """ ( ( Ok - , ( ValueDeclaration + , ( TypeAlias , ( ty, Hi ) , ( genericArgs, () ) , ( expr From fe884e8172edf201a022bcb1b4dde3ceec102b71 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 21:18:39 +0100 Subject: [PATCH 084/103] stop not using value --- .../type-alias-function-type-args | 1 + src/Stage/Parse/Contextualize.elm | 6 +- tests/ParserLexerTestCases.elm | 219 ++++++++++++++++++ 3 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 parser-tests/snippets/should-parse/type-alias-function-type-args diff --git a/parser-tests/snippets/should-parse/type-alias-function-type-args b/parser-tests/snippets/should-parse/type-alias-function-type-args new file mode 100644 index 00000000..1ab584d5 --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-function-type-args @@ -0,0 +1 @@ +type alias Function = List A -> List B C D -> List D E F diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 35cc6c2b..eec39a40 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -1238,11 +1238,7 @@ exprAppend ({ parents, nesting } as currentLeaf) token = Result.map2 (\newOutput newParents -> { parents = newParents - , nesting = - NestingLeafType_TypeWithArgs - { name = token - , args = empty - } + , nesting = newOutput } ) (case output of diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 8c10724b..5163566c 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -2382,6 +2382,225 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Newlines [] 0) ] } + , { name = "type-alias-function-type-args" + , source = """type alias Function = List A -> List B C D -> List D E F +""" + , pretty = """ + ( ( Ok + , ( TypeAlias + , ( ty, Function ) + , ( genericArgs, () ) + , ( expr + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, A ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + , ( to + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, B ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, C ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, D ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + , ( to + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, D ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, E ) + , ( args, () ) + ) + ) + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, F ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) + ) ) +""" + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + Function + { from = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "A" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , to = + Function + { from = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "B" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "C" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + , to = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "D" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "E" + , qualifiedness = PossiblyQualified Nothing + } + , UserDefinedType + { args = [] + , name = "F" + , qualifiedness = PossiblyQualified Nothing + } + ] + , name = "List" + , qualifiedness = PossiblyQualified Nothing + } + } + } + , genericArgs = [] + , ty = "Function" + } + ) + ] + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 37, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 46, row = 1 }, start = { col = 44, row = 1 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 51, row = 1 }, start = { col = 47, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 52, row = 1 }, start = { col = 51, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 53, row = 1 }, start = { col = 52, row = 1 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 54, row = 1 }, start = { col = 53, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 55, row = 1 }, start = { col = 54, row = 1 } } (Token (Identifier { name = "E", qualifiers = [] })) + , Located { end = { col = 56, row = 1 }, start = { col = 55, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 57, row = 1 }, start = { col = 56, row = 1 } } (Token (Identifier { name = "F", qualifiers = [] })) + , Located { end = { col = 1, row = 2 }, start = { col = 57, row = 1 } } (Newlines [] 0) + ] + } , { name = "type-alias-funky-indentation" , source = """type alias Model = List Int From 9d470403f93e7a309061bf249ee6e922bbd7afd3 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 21:27:51 +0100 Subject: [PATCH 085/103] remove "Partial" from TypeExpression --- src/Stage/Parse/Contextualize.elm | 58 +++++++++++++++---------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index eec39a40..68770495 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -148,19 +148,19 @@ type BlockValueDeclaration though :(). -} -type PartialTypeExpression +type TypeExpression = TypeExpression_NamedType { name : String - , args : Stack PartialTypeExpression + , args : Stack TypeExpression } | TypeExpression_Unit - | TypeExpression_Bracketed PartialTypeExpression - | TypeExpression_Tuple PartialTypeExpression PartialTypeExpression (List PartialTypeExpression) - | TypeExpression_Record (List ( String, PartialTypeExpression )) + | TypeExpression_Bracketed TypeExpression + | TypeExpression_Tuple TypeExpression TypeExpression (List TypeExpression) + | TypeExpression_Record (List ( String, TypeExpression )) | TypeExpression_Function - { firstInput : PartialTypeExpression - , otherInputs : List PartialTypeExpression - , output : PartialTypeExpression + { firstInput : TypeExpression + , otherInputs : List TypeExpression + , output : TypeExpression } @@ -168,44 +168,44 @@ type LastEntryOfRecord = LastEntryOfRecord_Empty | LastEntryOfRecord_Key String | LastEntryOfRecord_KeyColon String - | LastEntryOfRecord_KeyValue String PartialTypeExpression + | LastEntryOfRecord_KeyValue String TypeExpression type alias PartialRecord = - { firstEntries : Stack ( String, PartialTypeExpression ) + { firstEntries : Stack ( String, TypeExpression ) , lastEntry : LastEntryOfRecord } type NestingParentType - = NestingParentType_Bracket (Stack PartialTypeExpression) + = NestingParentType_Bracket (Stack TypeExpression) | NestingParentType_PartialRecord - { firstEntries : Stack ( String, PartialTypeExpression ) + { firstEntries : Stack ( String, TypeExpression ) , lastEntryName : String } | NestingParentType_TypeWithArgs { name : String - , args : Stack PartialTypeExpression + , args : Stack TypeExpression } | NestingParentType_Function - { firstInput : PartialTypeExpression - , otherInputs : Stack PartialTypeExpression + { firstInput : TypeExpression + , otherInputs : Stack TypeExpression } type NestingLeafType - = NestingLeafType_Bracket (Stack PartialTypeExpression) (Maybe PartialTypeExpression) + = NestingLeafType_Bracket (Stack TypeExpression) (Maybe TypeExpression) | NestingLeafType_PartialRecord PartialRecord | NestingLeafType_TypeWithArgs { name : String - , args : Stack PartialTypeExpression + , args : Stack TypeExpression } | NestingLeafType_Function - { firstInput : PartialTypeExpression - , otherInputs : Stack PartialTypeExpression - , output : Maybe PartialTypeExpression + { firstInput : TypeExpression + , otherInputs : Stack TypeExpression + , output : Maybe TypeExpression } - | NestingLeafType_Expr PartialTypeExpression + | NestingLeafType_Expr TypeExpression type alias PartialTypeExpressionLeaf = @@ -220,7 +220,7 @@ type PartialResult progress done type alias TypeExpressionResult = - PartialResult PartialTypeExpressionLeaf PartialTypeExpression + PartialResult PartialTypeExpressionLeaf TypeExpression @@ -267,10 +267,10 @@ type Error | Error_MissingFunctionReturnType | Error_ExpectedColonWhilstParsingRecord | Error_ExpectedKeyWhilstParsingRecord - | Error_TypeDoesNotTakeArgs PartialTypeExpression PartialTypeExpression - | Error_TypeDoesNotTakeArgs2 PartialTypeExpression + | Error_TypeDoesNotTakeArgs TypeExpression TypeExpression + | Error_TypeDoesNotTakeArgs2 TypeExpression | Error_ValueDoesNotTakeArgs Frontend.LocatedExpr - | Error_ExtraItemAfterBlock PartialTypeExpression Lexer.LexItem + | Error_ExtraItemAfterBlock TypeExpression Lexer.LexItem | Error_TooManyTupleArgs -- (ConcreteType PossiblyQualified) @@ -1124,7 +1124,7 @@ leafToParents { parents, nesting } = (\n -> n :: parents) -parentsToLeafWith : PartialTypeExpression -> List NestingParentType -> PartialTypeExpressionLeaf +parentsToLeafWith : TypeExpression -> List NestingParentType -> PartialTypeExpressionLeaf parentsToLeafWith expr parents = case parents of nesting :: grandparents -> @@ -1316,8 +1316,8 @@ appendColonTo prevExpr = closeBracket : - Stack PartialTypeExpression - -> Maybe PartialTypeExpression + Stack TypeExpression + -> Maybe TypeExpression -> List NestingParentType -> Result Error PartialTypeExpressionLeaf closeBracket argStack mLastExpression parents = @@ -1705,7 +1705,7 @@ type ToConcreteTypeError {-| TODO(harry): custom error message here -} -partialTypeExpressionToConcreteType : PartialTypeExpression -> Result ToConcreteTypeError (ConcreteType PossiblyQualified) +partialTypeExpressionToConcreteType : TypeExpression -> Result ToConcreteTypeError (ConcreteType PossiblyQualified) partialTypeExpressionToConcreteType pte = case pte of TypeExpression_NamedType { name, args } -> From ad3d8a008eff38f498e1481116a62aec826c05eb Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 19 Oct 2020 23:06:38 +0100 Subject: [PATCH 086/103] use parent struct from TypeExpressions I found this to be nice for value expressions. So using it for type expressions too. --- parser-tests/Live.elm | 39 ++- src/Stage/Parse/Contextualize.elm | 545 +++++++++++++++--------------- src/Stage/Parse/Pretty.elm | 71 +++- tests/ParserLexerTestCases.elm | 180 +++++----- 4 files changed, 459 insertions(+), 376 deletions(-) diff --git a/parser-tests/Live.elm b/parser-tests/Live.elm index 37db6bf2..32aca6be 100644 --- a/parser-tests/Live.elm +++ b/parser-tests/Live.elm @@ -8,6 +8,7 @@ import Html.Events as Events import Parser.Advanced as P import Stage.Parse.Contextualize as Contextualize import Stage.Parse.Lexer as Lexer +import Stage.Parse.Pretty as Pretty {-| We're essentially a Node.JS app (until we get self-hosting :P ). @@ -41,7 +42,7 @@ subscriptions _ = init : () -> ( Model, Cmd never ) init () = - ( """type alias Model =""", Cmd.none ) + ( """type alias Model = { h: (""", Cmd.none ) view : Model -> Html Msg @@ -106,10 +107,42 @@ view model = -- [ Attributes.style "w" ] (case lexed of Ok lexItems -> + let + contextualized = + Contextualize.run lexItems + in [ Html.div [ Attributes.style "white-space" "pre-wrap" ] - [ Html.text - (Debug.toString (Contextualize.run lexItems)) + [ Html.div + [] + [ Html.text + (Debug.toString (Debug.log "parsed" <| contextualized)) + ] + , Html.div + [] + [ Html.text + (Pretty.printWithIndentationOf 0 + (Pretty.listWith + (\rBlock -> + case rBlock of + Ok block -> + Pretty.Many + [ Pretty.Atom "Ok" + , Pretty.block block + ] + + Err e -> + Pretty.Many + [ Pretty.Atom "Err" + , Pretty.Many + [ Pretty.pair "state" (Pretty.state e.state) + ] + ] + ) + contextualized + ) + ) + ] ] ] diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 68770495..54d7a572 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -113,7 +113,7 @@ type BlockTypeAlias = BlockTypeAlias_Keywords | BlockTypeAlias_Named String (Stack String) | BlockTypeAlias_NamedAssigns String (List String) - | BlockTypeAlias_Completish String (List String) PartialTypeExpressionLeaf + | BlockTypeAlias_Completish String (List String) TypeExpressionNestingLeaf type BlockCustomType @@ -174,44 +174,51 @@ type LastEntryOfRecord type alias PartialRecord = { firstEntries : Stack ( String, TypeExpression ) , lastEntry : LastEntryOfRecord + , parent : Maybe TypeExpressionNestingParent } -type NestingParentType - = NestingParentType_Bracket (Stack TypeExpression) +type TypeExpressionNestingParent + = NestingParentType_Bracket + { expressions : Stack TypeExpression + , parent : Maybe TypeExpressionNestingParent + } | NestingParentType_PartialRecord { firstEntries : Stack ( String, TypeExpression ) , lastEntryName : String + , parent : Maybe TypeExpressionNestingParent } | NestingParentType_TypeWithArgs { name : String , args : Stack TypeExpression + , parent : Maybe TypeExpressionNestingParent } | NestingParentType_Function { firstInput : TypeExpression , otherInputs : Stack TypeExpression + , parent : Maybe TypeExpressionNestingParent } -type NestingLeafType - = NestingLeafType_Bracket (Stack TypeExpression) (Maybe TypeExpression) - | NestingLeafType_PartialRecord PartialRecord - | NestingLeafType_TypeWithArgs +type TypeExpressionNestingLeaf + = TypeExpressionNestingLeaf_Bracket + { firstExpressions : Stack TypeExpression + , trailingExpression : Maybe TypeExpression + , parent : Maybe TypeExpressionNestingParent + } + | TypeExpressionNestingLeaf_PartialRecord PartialRecord + | TypeExpressionNestingLeaf_TypeWithArgs { name : String , args : Stack TypeExpression + , parent : Maybe TypeExpressionNestingParent } - | NestingLeafType_Function + | TypeExpressionNestingLeaf_Function { firstInput : TypeExpression , otherInputs : Stack TypeExpression , output : Maybe TypeExpression + , parent : Maybe TypeExpressionNestingParent } - | NestingLeafType_Expr TypeExpression - - -type alias PartialTypeExpressionLeaf = - { parents : List NestingParentType - , nesting : NestingLeafType - } + | TypeExpressionNestingLeaf_Expr TypeExpression type PartialResult progress done @@ -220,7 +227,7 @@ type PartialResult progress done type alias TypeExpressionResult = - PartialResult PartialTypeExpressionLeaf TypeExpression + PartialResult TypeExpressionNestingLeaf TypeExpression @@ -242,7 +249,7 @@ type ExpressionNestingLeaf , rhs : Maybe Frontend.LocatedExpr , parent : Maybe ExpressionNestingParent } - | ExpressionNestingLeafType_Expr Frontend.LocatedExpr + | ExpressionTypeExpressionNestingLeaf_Expr Frontend.LocatedExpr type alias ExpressionResult = @@ -489,7 +496,7 @@ parseAnything state item = Error_PartwayThroughBlock |> ParseResult_Err - ExpressionNestingLeafType_Expr expr -> + ExpressionTypeExpressionNestingLeaf_Expr expr -> expr |> PartialResult_Done |> newExpressionState name args @@ -507,8 +514,8 @@ parseAnything state item = |> ParseResult_Err State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> - case (autoCollapseNesting CollapseLevel_Function exprSoFar).nesting of - NestingLeafType_Expr expr -> + case autoCollapseNesting CollapseLevel_Function exprSoFar of + TypeExpressionNestingLeaf_Expr expr -> PartialResult_Done expr |> newTypeAliasState name typeArgs @@ -751,20 +758,20 @@ parserTypeExprFromEmpty newState item = Debug.todo "" else - { parents = [] - , nesting = - NestingLeafType_TypeWithArgs - { name = name - , args = empty - } - } + TypeExpressionNestingLeaf_TypeWithArgs + { name = name + , args = empty + , parent = Nothing + } |> PartialResult_Progress |> newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> - { parents = [] - , nesting = NestingLeafType_Bracket empty Nothing - } + TypeExpressionNestingLeaf_Bracket + { firstExpressions = empty + , trailingExpression = Nothing + , parent = Nothing + } |> PartialResult_Progress |> newState @@ -773,13 +780,11 @@ parserTypeExprFromEmpty newState item = |> ParseResult_Err Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> - { nesting = - NestingLeafType_PartialRecord - { firstEntries = empty - , lastEntry = LastEntryOfRecord_Empty - } - , parents = [] - } + TypeExpressionNestingLeaf_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty + , parent = Nothing + } |> PartialResult_Progress |> newState @@ -802,7 +807,7 @@ parserTypeExprFromEmpty newState item = parserTypeExpr : (TypeExpressionResult -> ParseResult) - -> PartialTypeExpressionLeaf + -> TypeExpressionNestingLeaf -> Located Lexer.LexToken -> ParseResult parserTypeExpr newState prevExpr item = @@ -816,12 +821,14 @@ parserTypeExpr newState prevExpr item = |> partialExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> - leafToParents prevExpr + leafToParent prevExpr |> Result.map - (\parents -> - { parents = parents - , nesting = NestingLeafType_Bracket empty Nothing - } + (\parent -> + TypeExpressionNestingLeaf_Bracket + { firstExpressions = empty + , trailingExpression = Nothing + , parent = Just parent + } ) |> partialExpressionToParseResult newState @@ -830,26 +837,26 @@ parserTypeExpr newState prevExpr item = collapsedLeaf = autoCollapseNesting CollapseLevel_Function prevExpr in - case collapsedLeaf.nesting of - NestingLeafType_Expr _ -> + case collapsedLeaf of + TypeExpressionNestingLeaf_Expr _ -> Error_UnmatchedBracket Lexer.Round Lexer.Close |> ParseResult_Err - NestingLeafType_TypeWithArgs { name, args } -> + TypeExpressionNestingLeaf_TypeWithArgs { name, args } -> Debug.todo "Make this state impossible" - NestingLeafType_Bracket argStack mLastExpression -> - closeBracket argStack mLastExpression collapsedLeaf.parents + TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> + closeBracket firstExpressions trailingExpression parent |> partialExpressionToParseResult newState - NestingLeafType_PartialRecord _ -> + TypeExpressionNestingLeaf_PartialRecord _ -> Error_WrongClosingBracket { expecting = Lexer.Curly , found = Lexer.Round } |> ParseResult_Err - NestingLeafType_Function { output } -> + TypeExpressionNestingLeaf_Function { output } -> case output of Nothing -> Error_MissingFunctionReturnType @@ -859,16 +866,14 @@ parserTypeExpr newState prevExpr item = Debug.todo "Make this state impossible" Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> - leafToParents prevExpr + leafToParent prevExpr |> Result.map - (\newParents -> - { nesting = - NestingLeafType_PartialRecord - { firstEntries = empty - , lastEntry = LastEntryOfRecord_Empty - } - , parents = newParents - } + (\newParent -> + TypeExpressionNestingLeaf_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty + , parent = Just newParent + } ) |> partialExpressionToParseResult newState @@ -885,26 +890,26 @@ parserTypeExpr newState prevExpr item = collapsedLeaf = autoCollapseNesting CollapseLevel_Function prevExpr in - case collapsedLeaf.nesting of - NestingLeafType_Expr _ -> + case collapsedLeaf of + TypeExpressionNestingLeaf_Expr _ -> Error_UnmatchedBracket Lexer.Curly Lexer.Close |> ParseResult_Err - NestingLeafType_TypeWithArgs { name, args } -> + TypeExpressionNestingLeaf_TypeWithArgs { name, args } -> Debug.todo "Make this state impossible" - NestingLeafType_Bracket _ _ -> + TypeExpressionNestingLeaf_Bracket _ -> Error_WrongClosingBracket { expecting = Lexer.Round , found = Lexer.Curly } |> ParseResult_Err - NestingLeafType_PartialRecord pr -> - closeRecord pr collapsedLeaf.parents + TypeExpressionNestingLeaf_PartialRecord pr -> + closeRecord pr |> partialExpressionToParseResult newState - NestingLeafType_Function { output } -> + TypeExpressionNestingLeaf_Function { output } -> case output of Nothing -> Error_MissingFunctionReturnType @@ -918,57 +923,58 @@ parserTypeExpr newState prevExpr item = collapsedLeaf = autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr in - case collapsedLeaf.nesting of - NestingLeafType_Expr expr -> - { nesting = - NestingLeafType_Function - { firstInput = expr - , otherInputs = empty - , output = Nothing - } - , parents = [] - } + case collapsedLeaf of + TypeExpressionNestingLeaf_Expr expr -> + TypeExpressionNestingLeaf_Function + { firstInput = expr + , otherInputs = empty + , output = Nothing + , parent = Nothing + } |> PartialResult_Progress |> newState - NestingLeafType_TypeWithArgs _ -> + TypeExpressionNestingLeaf_TypeWithArgs _ -> Debug.todo "make state impossible" - NestingLeafType_Function { firstInput, otherInputs, output } -> + TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> case output of Nothing -> Error_InvalidToken Expecting_Unknown |> ParseResult_Err Just output_ -> - { nesting = - NestingLeafType_Function - { firstInput = firstInput - , otherInputs = output_ |> pushOnto otherInputs - , output = Nothing - } - , parents = collapsedLeaf.parents - } + TypeExpressionNestingLeaf_Function + { firstInput = firstInput + , otherInputs = output_ |> pushOnto otherInputs + , output = Nothing + , parent = parent + } |> PartialResult_Progress |> newState - NestingLeafType_Bracket argStack (Just expr) -> - { nesting = - NestingLeafType_Function - { firstInput = expr - , otherInputs = empty - , output = Nothing - } - , parents = NestingParentType_Bracket argStack :: collapsedLeaf.parents - } - |> PartialResult_Progress - |> newState + TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> + case trailingExpression of + Just trailingExpression_ -> + TypeExpressionNestingLeaf_Function + { firstInput = trailingExpression_ + , otherInputs = empty + , output = Nothing + , parent = + { expressions = firstExpressions + , parent = parent + } + |> NestingParentType_Bracket + |> Just + } + |> PartialResult_Progress + |> newState - NestingLeafType_Bracket _ Nothing -> - Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + Nothing -> + Error_InvalidToken Expecting_Unknown + |> ParseResult_Err - NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of LastEntryOfRecord_Empty -> Error_InvalidToken Expecting_Identifier @@ -983,19 +989,18 @@ parserTypeExpr newState prevExpr item = |> ParseResult_Err LastEntryOfRecord_KeyValue key value -> - { nesting = - NestingLeafType_Function - { firstInput = value - , otherInputs = empty - , output = Nothing - } - , parents = - NestingParentType_PartialRecord + TypeExpressionNestingLeaf_Function + { firstInput = value + , otherInputs = empty + , output = Nothing + , parent = { firstEntries = firstEntries , lastEntryName = key + , parent = parent } - :: collapsedLeaf.parents - } + |> NestingParentType_PartialRecord + |> Just + } |> PartialResult_Progress |> newState @@ -1019,7 +1024,7 @@ parserExpressionFromEmpty newState item = Just i -> Frontend.Int i |> withCorrectLocation - |> ExpressionNestingLeafType_Expr + |> ExpressionTypeExpressionNestingLeaf_Expr |> PartialResult_Progress |> newState @@ -1068,24 +1073,29 @@ parserExpression newState prevExpr item = -- HELPERS -leafToParents : PartialTypeExpressionLeaf -> Result Error (List NestingParentType) -leafToParents { parents, nesting } = - (case nesting of - NestingLeafType_Expr expr -> +leafToParent : TypeExpressionNestingLeaf -> Result Error TypeExpressionNestingParent +leafToParent leaf = + case leaf of + TypeExpressionNestingLeaf_Expr expr -> -- Cannot nest unless there is a trailing comma! Error_TypeDoesNotTakeArgs2 expr |> Err - NestingLeafType_Bracket _ (Just lastType) -> - -- Cannot nest unless there is a trailing comma! - Error_TypeDoesNotTakeArgs2 lastType - |> Err + TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> + case trailingExpression of + Just lastType -> + -- Cannot nest unless there is a trailing comma! + Error_TypeDoesNotTakeArgs2 lastType + |> Err - NestingLeafType_Bracket els Nothing -> - NestingParentType_Bracket els - |> Ok + Nothing -> + { expressions = firstExpressions + , parent = parent + } + |> NestingParentType_Bracket + |> Ok - NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of LastEntryOfRecord_Empty -> Error_ExpectedKeyWhilstParsingRecord @@ -1096,75 +1106,77 @@ leafToParents { parents, nesting } = |> Err LastEntryOfRecord_KeyColon key -> - NestingParentType_PartialRecord { firstEntries = firstEntries, lastEntryName = key } + { firstEntries = firstEntries + , lastEntryName = key + , parent = parent + } + |> NestingParentType_PartialRecord |> Ok LastEntryOfRecord_KeyValue _ lastValueType -> Error_TypeDoesNotTakeArgs2 lastValueType |> Err - NestingLeafType_TypeWithArgs details -> + TypeExpressionNestingLeaf_TypeWithArgs details -> NestingParentType_TypeWithArgs details |> Ok - NestingLeafType_Function { firstInput, otherInputs, output } -> + TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> case output of Nothing -> NestingParentType_Function { firstInput = firstInput , otherInputs = otherInputs + , parent = parent } |> Ok Just te -> Error_TypeDoesNotTakeArgs2 te |> Err - ) - |> Result.map - (\n -> n :: parents) - - -parentsToLeafWith : TypeExpression -> List NestingParentType -> PartialTypeExpressionLeaf -parentsToLeafWith expr parents = - case parents of - nesting :: grandparents -> - { nesting = - case nesting of - NestingParentType_PartialRecord { firstEntries, lastEntryName } -> - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr - } - NestingParentType_Bracket els -> - NestingLeafType_Bracket els (Just expr) - NestingParentType_TypeWithArgs { name, args } -> - NestingLeafType_TypeWithArgs - { name = name - , args = expr |> pushOnto args - } +parentsToLeafWith : TypeExpression -> Maybe TypeExpressionNestingParent -> TypeExpressionNestingLeaf +parentsToLeafWith expr toMakeIntoLeaf = + case toMakeIntoLeaf of + Just (NestingParentType_PartialRecord { firstEntries, lastEntryName, parent }) -> + TypeExpressionNestingLeaf_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyValue lastEntryName expr + , parent = parent + } - NestingParentType_Function { firstInput, otherInputs } -> - NestingLeafType_Function - { firstInput = firstInput - , otherInputs = otherInputs - , output = Just expr - } - , parents = grandparents - } + Just (NestingParentType_Bracket { expressions, parent }) -> + TypeExpressionNestingLeaf_Bracket + { firstExpressions = expressions + , trailingExpression = Just expr + , parent = parent + } - [] -> - { nesting = NestingLeafType_Expr expr - , parents = [] - } + Just (NestingParentType_TypeWithArgs { name, args, parent }) -> + TypeExpressionNestingLeaf_TypeWithArgs + { name = name + , args = expr |> pushOnto args + , parent = parent + } + + Just (NestingParentType_Function { firstInput, otherInputs, parent }) -> + TypeExpressionNestingLeaf_Function + { firstInput = firstInput + , otherInputs = otherInputs + , output = Just expr + , parent = parent + } + + Nothing -> + TypeExpressionNestingLeaf_Expr expr exprAppend : - PartialTypeExpressionLeaf + TypeExpressionNestingLeaf -> String - -> Result Error PartialTypeExpressionLeaf -exprAppend ({ parents, nesting } as currentLeaf) token = + -> Result Error TypeExpressionNestingLeaf +exprAppend currentLeaf token = let newType = TypeExpression_NamedType @@ -1172,138 +1184,130 @@ exprAppend ({ parents, nesting } as currentLeaf) token = , args = empty } in - case nesting of + case currentLeaf of -- We are within a nested bracket. - NestingLeafType_Bracket _ mostNested -> - case mostNested of + TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression } -> + case trailingExpression of Nothing -> - leafToParents currentLeaf + leafToParent currentLeaf |> Result.map - (\newParents -> - { parents = newParents - , nesting = - NestingLeafType_TypeWithArgs - { name = token - , args = empty - } - } + (\newParent -> + TypeExpressionNestingLeaf_TypeWithArgs + { name = token + , args = empty + , parent = Just newParent + } ) Just existingRoot -> Error_TypeDoesNotTakeArgs existingRoot newType |> Err - NestingLeafType_Expr expr -> + TypeExpressionNestingLeaf_Expr expr -> Error_TypeDoesNotTakeArgs expr newType |> Err - NestingLeafType_PartialRecord pr -> + TypeExpressionNestingLeaf_PartialRecord pr -> case pr.lastEntry of LastEntryOfRecord_Empty -> - { parents = parents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = pr.firstEntries - , lastEntry = LastEntryOfRecord_Key token - } - } + TypeExpressionNestingLeaf_PartialRecord + { firstEntries = pr.firstEntries + , lastEntry = LastEntryOfRecord_Key token + , parent = pr.parent + } |> Ok _ -> - leafToParents currentLeaf + leafToParent currentLeaf |> Result.map - (\newParents -> - { parents = newParents - , nesting = - NestingLeafType_TypeWithArgs - { name = token - , args = empty - } - } + (\newParent -> + TypeExpressionNestingLeaf_TypeWithArgs + { name = token + , args = empty + , parent = Just newParent + } ) - NestingLeafType_TypeWithArgs { name, args } -> - { nesting = - NestingLeafType_TypeWithArgs - { name = name - , args = - newType - |> pushOnto args - } - , parents = parents - } + TypeExpressionNestingLeaf_TypeWithArgs { name, args, parent } -> + TypeExpressionNestingLeaf_TypeWithArgs + { name = name + , args = + newType + |> pushOnto args + , parent = parent + } |> Ok - NestingLeafType_Function { firstInput, output } -> - Result.map2 - (\newOutput newParents -> - { parents = newParents - , nesting = newOutput - } - ) - (case output of - Just outputExpr -> - Error_TypeDoesNotTakeArgs outputExpr newType - |> Err + TypeExpressionNestingLeaf_Function { firstInput, output } -> + Result.andThen + (\newParent -> + case output of + Just outputExpr -> + Error_TypeDoesNotTakeArgs outputExpr newType + |> Err - Nothing -> - NestingLeafType_TypeWithArgs - { name = token - , args = empty - } - |> Ok + Nothing -> + TypeExpressionNestingLeaf_TypeWithArgs + { name = token + , args = empty + , parent = Just newParent + } + |> Ok ) - (leafToParents currentLeaf) + (leafToParent currentLeaf) -appendCommaTo : PartialTypeExpressionLeaf -> Result Error PartialTypeExpressionLeaf +appendCommaTo : TypeExpressionNestingLeaf -> Result Error TypeExpressionNestingLeaf appendCommaTo prevExpr = let collapsedLeaf = autoCollapseNesting CollapseLevel_Function prevExpr in - case collapsedLeaf.nesting of - NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + case collapsedLeaf of + TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of LastEntryOfRecord_KeyValue key value -> - { parents = collapsedLeaf.parents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = ( key, value ) |> pushOnto firstEntries - , lastEntry = LastEntryOfRecord_Empty - } - } + TypeExpressionNestingLeaf_PartialRecord + { firstEntries = ( key, value ) |> pushOnto firstEntries + , lastEntry = LastEntryOfRecord_Empty + , parent = parent + } |> Ok _ -> Error_InvalidToken Expecting_Unknown |> Err - NestingLeafType_Bracket argStack (Just expr) -> - { nesting = - NestingLeafType_Bracket (expr |> pushOnto argStack) Nothing - , parents = collapsedLeaf.parents - } - |> Ok + TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> + case trailingExpression of + Just trailingExpression_ -> + TypeExpressionNestingLeaf_Bracket + { firstExpressions = trailingExpression_ |> pushOnto firstExpressions + , trailingExpression = Nothing + , parent = parent + } + |> Ok + + Nothing -> + Error_InvalidToken Expecting_Unknown + |> Err _ -> Error_InvalidToken Expecting_Unknown |> Err -appendColonTo : PartialTypeExpressionLeaf -> Result Error PartialTypeExpressionLeaf +appendColonTo : TypeExpressionNestingLeaf -> Result Error TypeExpressionNestingLeaf appendColonTo prevExpr = - case prevExpr.nesting of - NestingLeafType_PartialRecord { firstEntries, lastEntry } -> + case prevExpr of + TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of LastEntryOfRecord_Key key -> - { parents = prevExpr.parents - , nesting = - NestingLeafType_PartialRecord - { firstEntries = firstEntries - , lastEntry = LastEntryOfRecord_KeyColon key - } - } + TypeExpressionNestingLeaf_PartialRecord + { firstEntries = firstEntries + , lastEntry = LastEntryOfRecord_KeyColon key + , parent = parent + } |> Ok _ -> @@ -1318,9 +1322,9 @@ appendColonTo prevExpr = closeBracket : Stack TypeExpression -> Maybe TypeExpression - -> List NestingParentType - -> Result Error PartialTypeExpressionLeaf -closeBracket argStack mLastExpression parents = + -> Maybe TypeExpressionNestingParent + -> Result Error TypeExpressionNestingLeaf +closeBracket argStack mLastExpression mParent = let rexpr = if argStack /= empty && mLastExpression == Nothing then @@ -1355,7 +1359,7 @@ closeBracket argStack mLastExpression parents = in case rexpr of Ok expr -> - parentsToLeafWith expr parents + parentsToLeafWith expr mParent |> Ok Err e -> @@ -1364,16 +1368,15 @@ closeBracket argStack mLastExpression parents = closeRecord : PartialRecord - -> List NestingParentType - -> Result Error PartialTypeExpressionLeaf -closeRecord { firstEntries, lastEntry } parents = + -> Result Error TypeExpressionNestingLeaf +closeRecord { firstEntries, lastEntry, parent } = let fromRecord recordEntries = let record = TypeExpression_Record recordEntries in - parentsToLeafWith record parents + parentsToLeafWith record parent in case lastEntry of LastEntryOfRecord_KeyValue key value -> @@ -1493,7 +1496,7 @@ appendOperatorTo leaf appendingOp = } |> Ok - ExpressionNestingLeafType_Expr locatedexpr -> + ExpressionTypeExpressionNestingLeaf_Expr locatedexpr -> ExpressionNestingLeaf_Operator { op = appendingOp , lhs = locatedexpr @@ -1521,7 +1524,7 @@ appendValueExprTo leaf appendingExpr = Error_ValueDoesNotTakeArgs parentRhs |> Err - ExpressionNestingLeafType_Expr locatedExpr -> + ExpressionTypeExpressionNestingLeaf_Expr locatedExpr -> Error_ValueDoesNotTakeArgs locatedExpr |> Err @@ -1574,8 +1577,8 @@ blockFromState state = |> Just State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs partialExpr) -> - case (autoCollapseNesting CollapseLevel_Function partialExpr).nesting of - NestingLeafType_Expr expr -> + case autoCollapseNesting CollapseLevel_Function partialExpr of + TypeExpressionNestingLeaf_Expr expr -> partialTypeExpressionToConcreteType expr |> Result.map (\conceteType -> @@ -1613,7 +1616,7 @@ blockFromState state = |> Err |> Just - ExpressionNestingLeafType_Expr expr -> + ExpressionTypeExpressionNestingLeaf_Expr expr -> { name = name , args = args , valueExpr__ = expr @@ -1632,27 +1635,27 @@ type CollapseLevel | CollapseLevel_Function -autoCollapseNesting : CollapseLevel -> PartialTypeExpressionLeaf -> PartialTypeExpressionLeaf +autoCollapseNesting : CollapseLevel -> TypeExpressionNestingLeaf -> TypeExpressionNestingLeaf autoCollapseNesting collapseLevel pte = - case pte.nesting of - NestingLeafType_TypeWithArgs { name, args } -> + case pte of + TypeExpressionNestingLeaf_TypeWithArgs { name, args, parent } -> let newTypeExpr = TypeExpression_NamedType { name = name, args = args } in - parentsToLeafWith newTypeExpr pte.parents + parentsToLeafWith newTypeExpr parent |> autoCollapseNesting collapseLevel - NestingLeafType_Expr _ -> + TypeExpressionNestingLeaf_Expr _ -> pte - NestingLeafType_Bracket _ _ -> + TypeExpressionNestingLeaf_Bracket _ -> pte - NestingLeafType_PartialRecord _ -> + TypeExpressionNestingLeaf_PartialRecord _ -> pte - NestingLeafType_Function { firstInput, otherInputs, output } -> + TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> case ( collapseLevel, output ) of ( CollapseLevel_TypeWithArgs, _ ) -> pte @@ -1669,7 +1672,7 @@ autoCollapseNesting collapseLevel pte = , output = outputExpr } in - parentsToLeafWith newTypeExpr pte.parents + parentsToLeafWith newTypeExpr parent |> autoCollapseNesting collapseLevel diff --git a/src/Stage/Parse/Pretty.elm b/src/Stage/Parse/Pretty.elm index 53677c5c..c8f1b47d 100644 --- a/src/Stage/Parse/Pretty.elm +++ b/src/Stage/Parse/Pretty.elm @@ -7,7 +7,7 @@ import Elm.Data.Module as ModuleType exposing (ModuleType) import Elm.Data.Operator as Operator import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete as Concrete exposing (ConcreteType) -import Stage.Parse.Contextualize exposing (Block(..)) +import Stage.Parse.Contextualize as Contextualize exposing (Block(..), BlockTypeAlias(..), State(..), TypeExpressionNestingLeaf(..)) import Stage.Parse.Token as Token @@ -145,6 +145,56 @@ block b = Debug.todo "" +state : State -> Sexpr String +state s = + case s of + State_BlockStart -> + Atom "State_BlockStart" + + State_Error_Recovery -> + Atom "State_Error_Recovery" + + State_BlockFirstItem _ -> + pair "State_BlockFirstItem" (Atom "TODO") + + State_BlockTypeAlias BlockTypeAlias_Keywords -> + pair "State_BlockTypeAlias" (Atom "BlockTypeAlias_Keywords") + + State_BlockTypeAlias (BlockTypeAlias_Named name genericArgs) -> + pair "State_BlockTypeAlias" + (Many + [ Atom "BlockTypeAlias_Named" + , Atom name + , listWith Atom (Contextualize.toList (\x -> x) genericArgs) + ] + ) + + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name genericArgs) -> + pair "State_BlockTypeAlias" + (Many + [ Atom "BlockTypeAlias_NamedAssigns" + , Atom name + , listWith Atom genericArgs + ] + ) + + State_BlockTypeAlias (BlockTypeAlias_Completish name genericArgs typeExpr_) -> + pair "State_BlockTypeAlias" + (Many + [ Atom "BlockTypeAlias_Completish" + , Atom name + , listWith Atom genericArgs + , typeExpressionNestingLeaf typeExpr_ + ] + ) + + State_BlockCustomType _ -> + pair "State_BlockCustomType" (Atom "TODO") + + State_BlockValueDeclaration _ -> + pair "State_BlockValueDeclaration" (Atom "TODO") + + expr : Frontend.LocatedExpr -> Sexpr String expr expr_ = case Located.unwrap expr_ of @@ -297,6 +347,25 @@ typeExpr expr_ = ) +typeExpressionNestingLeaf : TypeExpressionNestingLeaf -> Sexpr String +typeExpressionNestingLeaf leaf = + case leaf of + TypeExpressionNestingLeaf_Bracket record -> + pair "TypeExpressionNestingLeaf_Bracket" (Atom "TODO") + + TypeExpressionNestingLeaf_PartialRecord partialRecord -> + pair "TypeExpressionNestingLeaf_PartialRecord" (Atom "TODO") + + TypeExpressionNestingLeaf_TypeWithArgs record -> + pair "TypeExpressionNestingLeaf_TypeWithArgs" (Atom "TODO") + + TypeExpressionNestingLeaf_Function record -> + pair "TypeExpressionNestingLeaf_Function" (Atom "TODO") + + TypeExpressionNestingLeaf_Expr typeExpression -> + pair "TypeExpressionNestingLeaf_Expr" (Atom "TODO") + + moduleType : ModuleType -> Sexpr String moduleType m = case m of diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 5163566c..b69a9a8f 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -4206,16 +4206,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_MissingFunctionReturnType , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil (Bracket Round Close)))) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish "Function" - [] - { nesting = NestingLeafType_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing } - , parents = - [ NestingParentType_Bracket (Stack []) - ] - } - ) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Function" [] (TypeExpressionNestingLeaf_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing, parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }) })) } ] , lexed = @@ -4326,7 +4317,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })), parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })))) } ] , lexed = @@ -4359,7 +4350,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) } ] , lexed = @@ -4391,7 +4382,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Expr TypeExpression_Unit, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) } ] , lexed = @@ -4543,7 +4534,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] { nesting = NestingLeafType_Bracket (Stack []) Nothing, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing })) } ] , lexed = @@ -4572,16 +4563,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0)) - , state = - State_BlockTypeAlias - (BlockTypeAlias_Completish "Hi" - [] - { nesting = NestingLeafType_TypeWithArgs { args = Stack [], name = "Int" } - , parents = - [ NestingParentType_Bracket (Stack []) - ] - } - ) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = "Int", parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }) })) } ] , lexed = @@ -4611,7 +4593,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty }, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] (TypeExpressionNestingLeaf_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty, parent = Nothing })) } ] , lexed = @@ -4639,7 +4621,7 @@ List Int [ Err { error = Error_ExpectedColonWhilstParsingRecord , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = "j7", qualifiers = [] }))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] { nesting = NestingLeafType_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi" }, parents = [] }) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] (TypeExpressionNestingLeaf_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi", parent = Nothing })) } ] , lexed = @@ -4711,17 +4693,15 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] - { nesting = - NestingLeafType_Expr - (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) - (TypeExpression_NamedType { args = Stack [], name = "A" }) - [ TypeExpression_NamedType { args = Stack [], name = "B" } - , TypeExpression_NamedType { args = Stack [], name = "C" } - , TypeExpression_NamedType { args = Stack [], name = "D" } - ] - ) - , parents = [] - } + (TypeExpressionNestingLeaf_Expr + (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) + (TypeExpression_NamedType { args = Stack [], name = "A" }) + [ TypeExpression_NamedType { args = Stack [], name = "B" } + , TypeExpression_NamedType { args = Stack [], name = "C" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + ) + ) ) } , Err @@ -4813,57 +4793,55 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] - { nesting = - NestingLeafType_Expr - (TypeExpression_Tuple - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } - ] - , name = "A" - } - ) - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "F" } - , TypeExpression_NamedType { args = Stack [], name = "E" } - , TypeExpression_NamedType { args = Stack [], name = "D" } - ] - , name = "C" - } - ) - [ TypeExpression_NamedType - { args = - Stack - [ TypeExpression_Bracketed - (TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "K" } - ] - , name = "J" - } - ) - , TypeExpression_NamedType { args = Stack [], name = "I" } - ] - , name = "H" - } - , TypeExpression_NamedType - { args = - Stack - [ TypeExpression_NamedType { args = Stack [], name = "P" } - , TypeExpression_NamedType { args = Stack [], name = "O" } - , TypeExpression_Unit - , TypeExpression_NamedType { args = Stack [], name = "M" } - ] - , name = "L" - } - ] + (TypeExpressionNestingLeaf_Expr + (TypeExpression_Tuple + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "Int" } + ] + , name = "A" + } ) - , parents = [] - } + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "F" } + , TypeExpression_NamedType { args = Stack [], name = "E" } + , TypeExpression_NamedType { args = Stack [], name = "D" } + ] + , name = "C" + } + ) + [ TypeExpression_NamedType + { args = + Stack + [ TypeExpression_Bracketed + (TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "K" } + ] + , name = "J" + } + ) + , TypeExpression_NamedType { args = Stack [], name = "I" } + ] + , name = "H" + } + , TypeExpression_NamedType + { args = + Stack + [ TypeExpression_NamedType { args = Stack [], name = "P" } + , TypeExpression_NamedType { args = Stack [], name = "O" } + , TypeExpression_Unit + , TypeExpression_NamedType { args = Stack [], name = "M" } + ] + , name = "L" + } + ] + ) + ) ) } ] @@ -4956,15 +4934,15 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] - { nesting = - NestingLeafType_Bracket - (Stack + (TypeExpressionNestingLeaf_Bracket + { firstExpressions = + Stack [ TypeExpression_NamedType { args = Stack [], name = "Int" } ] - ) - Nothing - , parents = [] - } + , parent = Nothing + , trailingExpression = Nothing + } + ) ) } ] @@ -5017,15 +4995,15 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] - { nesting = - NestingLeafType_Bracket - (Stack + (TypeExpressionNestingLeaf_Bracket + { firstExpressions = + Stack [ TypeExpression_NamedType { args = Stack [], name = "Int" } ] - ) - Nothing - , parents = [] - } + , parent = Nothing + , trailingExpression = Nothing + } + ) ) } ] From 790b3c5f9e8f5c7122e2cdca5481705d8a247ee4 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 22 Oct 2020 21:57:48 +0100 Subject: [PATCH 087/103] wip: case sensitive lexing --- parser-tests/Update.elm | 1 + .../type-alias-lower-case-types | 8 + .../should-parse/type-alias-function-generic | 2 + src/Stage/Parse/Contextualize.elm | 457 ++++++--- src/Stage/Parse/Lexer.elm | 70 +- src/Stage/Parse/Pretty.elm | 22 +- src/Stage/Parse/Token.elm | 67 +- tests/ParserLexerTestCases.elm | 916 +++++++++++------- 8 files changed, 980 insertions(+), 563 deletions(-) create mode 100644 parser-tests/snippets/should-not-parse/type-alias-lower-case-types diff --git a/parser-tests/Update.elm b/parser-tests/Update.elm index 4cc7ad43..91979491 100644 --- a/parser-tests/Update.elm +++ b/parser-tests/Update.elm @@ -1,6 +1,7 @@ port module Update exposing (main) import Elm.Data.Located as Located exposing (Located) +import Live import Parser.Advanced as P import Platform import Stage.Parse.Contextualize as Contextualize diff --git a/parser-tests/snippets/should-not-parse/type-alias-lower-case-types b/parser-tests/snippets/should-not-parse/type-alias-lower-case-types new file mode 100644 index 00000000..a1c71a32 --- /dev/null +++ b/parser-tests/snippets/should-not-parse/type-alias-lower-case-types @@ -0,0 +1,8 @@ +type alias A = B.C.d + +type alias B = List A.d + +type alias C = list A + +type alias D a = a -> B.c +type alias E a = B.c -> a \ No newline at end of file diff --git a/parser-tests/snippets/should-parse/type-alias-function-generic b/parser-tests/snippets/should-parse/type-alias-function-generic index b52b9d14..cb780075 100644 --- a/parser-tests/snippets/should-parse/type-alias-function-generic +++ b/parser-tests/snippets/should-parse/type-alias-function-generic @@ -1 +1,3 @@ type alias Function a = List Int -> List (List a) + +type alias Function b c = b -> c \ No newline at end of file diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 54d7a572..6b38d46c 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -62,17 +62,17 @@ type Block , exposingList : Elm.Data.Exposing.Exposing } | ValueDeclaration - { name : Located String + { name : Located Token.LowerCase -- TODO(harry): these could be patterns! - , args : List (Located String) + , args : List (Located Token.LowerCase) -- This key's name is hard coded into parser-tests/Update.elm , valueExpr__ : Frontend.LocatedExpr } | TypeAlias - { ty : String - , genericArgs : List String + { ty : Token.UpperCase + , genericArgs : List Token.LowerCase , expr : ConcreteType PossiblyQualified } | CustomType @@ -111,28 +111,28 @@ type BlockFirstItem type BlockTypeAlias = BlockTypeAlias_Keywords - | BlockTypeAlias_Named String (Stack String) - | BlockTypeAlias_NamedAssigns String (List String) - | BlockTypeAlias_Completish String (List String) TypeExpressionNestingLeaf + | BlockTypeAlias_Named Token.UpperCase (Stack Token.LowerCase) + | BlockTypeAlias_NamedAssigns Token.UpperCase (List Token.LowerCase) + | BlockTypeAlias_Completish Token.UpperCase (List Token.LowerCase) TypeExpressionNestingLeaf type BlockCustomType - = BlockCustomType_Named String (Stack String) - | BlockCustomType_NamedAssigns String (List String) + = BlockCustomType_Named Token.UpperCase (Stack Token.LowerCase) + | BlockCustomType_NamedAssigns Token.UpperCase (List Token.LowerCase) type BlockValueDeclaration = BlockValueDeclaration_Named - { name : Located String - , args : Stack (Located String) + { name : Located Token.LowerCase + , args : Stack (Located Token.LowerCase) } | BlockValueDeclaration_NamedAssigns - { name : Located String - , args : List (Located String) + { name : Located Token.LowerCase + , args : List (Located Token.LowerCase) } | BlockValueDeclaration_Completish - { name : Located String - , args : List (Located String) + { name : Located Token.LowerCase + , args : List (Located Token.LowerCase) , partialExpr : ExpressionNestingLeaf } @@ -150,13 +150,15 @@ type BlockValueDeclaration -} type TypeExpression = TypeExpression_NamedType - { name : String + { qualifiers : List Token.UpperCase + , name : Token.UpperCase , args : Stack TypeExpression } + | TypeExpression_GenericType Token.LowerCase | TypeExpression_Unit | TypeExpression_Bracketed TypeExpression | TypeExpression_Tuple TypeExpression TypeExpression (List TypeExpression) - | TypeExpression_Record (List ( String, TypeExpression )) + | TypeExpression_Record (List ( Token.LowerCase, TypeExpression )) | TypeExpression_Function { firstInput : TypeExpression , otherInputs : List TypeExpression @@ -166,13 +168,13 @@ type TypeExpression type LastEntryOfRecord = LastEntryOfRecord_Empty - | LastEntryOfRecord_Key String - | LastEntryOfRecord_KeyColon String - | LastEntryOfRecord_KeyValue String TypeExpression + | LastEntryOfRecord_Key Token.LowerCase + | LastEntryOfRecord_KeyColon Token.LowerCase + | LastEntryOfRecord_KeyValue Token.LowerCase TypeExpression type alias PartialRecord = - { firstEntries : Stack ( String, TypeExpression ) + { firstEntries : Stack ( Token.LowerCase, TypeExpression ) , lastEntry : LastEntryOfRecord , parent : Maybe TypeExpressionNestingParent } @@ -184,12 +186,13 @@ type TypeExpressionNestingParent , parent : Maybe TypeExpressionNestingParent } | NestingParentType_PartialRecord - { firstEntries : Stack ( String, TypeExpression ) - , lastEntryName : String + { firstEntries : Stack ( Token.LowerCase, TypeExpression ) + , lastEntryName : Token.LowerCase , parent : Maybe TypeExpressionNestingParent } | NestingParentType_TypeWithArgs - { name : String + { qualifiers : List Token.UpperCase + , name : Token.UpperCase , args : Stack TypeExpression , parent : Maybe TypeExpressionNestingParent } @@ -208,7 +211,8 @@ type TypeExpressionNestingLeaf } | TypeExpressionNestingLeaf_PartialRecord PartialRecord | TypeExpressionNestingLeaf_TypeWithArgs - { name : String + { qualifiers : List Token.UpperCase + , name : Token.UpperCase , args : Stack TypeExpression , parent : Maybe TypeExpressionNestingParent } @@ -259,10 +263,27 @@ type alias ExpressionResult = type Error = Error_InvalidToken Expecting | Error_MisplacedKeyword Keyword - | Error_BlockStartsWithTypeOrConstructor Token.TypeOrConstructor + | Error_BlockStartsWithUpperCase Token.UpperCase | Error_BlockStartsWithQualifiedName - { qualifiers : List String - , name : String + { qualifiers : List Token.UpperCase + , name : Token.Token + } + | Error_QualifiedArgName + { qualifiers : List Token.UpperCase + , name : Token.Token + } + | Error_UpperCaseArgName + { qualifiers : List Token.UpperCase + , name : Token.UpperCase + } + | Error_UpperCaseRecordKey Token.UpperCase + | Error_QualifiedRecordKey + { qualifiers : List Token.UpperCase + , name : Token.Token + } + | Error_LowerCasedTypename + { qualifiers : List Token.UpperCase + , name : Token.LowerCase } -- Type Expressions -- | Error_TypeNameStartsWithLowerCase String @@ -411,6 +432,7 @@ runHelp items state = parseAnything : State -> Located Lexer.LexItem -> ParseResult parseAnything state item = let + newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> PartialResult TypeExpressionNestingLeaf TypeExpression -> ParseResult newTypeAliasState aliasName typeArgs res = case res of PartialResult_Progress expr -> @@ -431,6 +453,7 @@ parseAnything state item = Error_TooManyTupleArgs a b c d e |> ParseResult_Err + newExpressionState : Located Token.LowerCase -> List (Located Token.LowerCase) -> PartialResult ExpressionNestingLeaf LocatedExpr -> ParseResult newExpressionState name args res = case res of PartialResult_Progress expr -> @@ -660,14 +683,20 @@ parseBlockStart region item = ParseResult_Err (Error_BlockStartsWithQualifiedName identitfier) else - ParseResult_Ok - (State_BlockValueDeclaration - (BlockValueDeclaration_Named - { name = withCorrectLocation name - , args = empty - } - ) - ) + case name of + Token.TokenLowerCase lower -> + ParseResult_Ok + (State_BlockValueDeclaration + (BlockValueDeclaration_Named + { name = withCorrectLocation lower + , args = empty + } + ) + ) + + Token.TokenUpperCase upperCase -> + Error_BlockStartsWithUpperCase upperCase + |> ParseResult_Err _ -> ParseResult_Err (Error_InvalidToken Expecting_Block) @@ -689,8 +718,17 @@ parseTypeBlock item = ParseResult_Err (Error_BlockStartsWithQualifiedName identifier) else - State_BlockCustomType (BlockCustomType_Named name empty) - |> ParseResult_Ok + case name of + Token.TokenLowerCase lower -> + Error_LowerCasedTypename + { qualifiers = qualifiers + , name = lower + } + |> ParseResult_Err + + Token.TokenUpperCase upper -> + State_BlockCustomType (BlockCustomType_Named upper empty) + |> ParseResult_Ok _ -> -- TODO(harry) indicate that we could also be expecting the `alias` @@ -711,15 +749,24 @@ parseTypeAliasName item = ParseResult_Err (Error_BlockStartsWithQualifiedName identifier) else - State_BlockTypeAlias (BlockTypeAlias_Named name empty) - |> ParseResult_Ok + case name of + Token.TokenLowerCase lower -> + Error_LowerCasedTypename + { qualifiers = qualifiers + , name = lower + } + |> ParseResult_Err + + Token.TokenUpperCase upper -> + State_BlockTypeAlias (BlockTypeAlias_Named upper empty) + |> ParseResult_Ok _ -> Error_InvalidToken Expecting_TypeName |> ParseResult_Err -parseLowercaseArgsOrAssignment : (Located String -> State) -> State -> Located Lexer.LexToken -> ParseResult +parseLowercaseArgsOrAssignment : (Located Token.LowerCase -> State) -> State -> Located Lexer.LexToken -> ParseResult parseLowercaseArgsOrAssignment onTypeArg onAssignment item = let withCorrectLocation x = @@ -732,11 +779,17 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = Lexer.Identifier ({ qualifiers, name } as identifier) -> if qualifiers /= [] then - ParseResult_Err (Error_BlockStartsWithQualifiedName identifier) + ParseResult_Err (Error_QualifiedArgName identifier) else - onTypeArg (withCorrectLocation name) - |> ParseResult_Ok + case name of + Token.TokenLowerCase lower -> + onTypeArg (withCorrectLocation lower) + |> ParseResult_Ok + + Token.TokenUpperCase upper -> + Error_UpperCaseArgName { qualifiers = qualifiers, name = upper } + |> ParseResult_Err Lexer.Sigil Lexer.Assign -> onAssignment @@ -754,17 +807,34 @@ parserTypeExprFromEmpty : parserTypeExprFromEmpty newState item = case Located.unwrap item of Lexer.Identifier { qualifiers, name } -> - if qualifiers /= [] then - Debug.todo "" + case name of + Token.TokenLowerCase lower -> + if qualifiers == [] then + TypeExpression_GenericType lower + |> TypeExpressionNestingLeaf_Expr + |> PartialResult_Progress + |> newState + + else + Error_LowerCasedTypename + { qualifiers = qualifiers + , name = lower + } + |> ParseResult_Err - else - TypeExpressionNestingLeaf_TypeWithArgs - { name = name - , args = empty - , parent = Nothing - } - |> PartialResult_Progress - |> newState + Token.TokenUpperCase upper -> + if qualifiers /= [] then + Debug.todo "" + + else + TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = qualifiers + , name = upper + , args = empty + , parent = Nothing + } + |> PartialResult_Progress + |> newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> TypeExpressionNestingLeaf_Bracket @@ -812,13 +882,9 @@ parserTypeExpr : -> ParseResult parserTypeExpr newState prevExpr item = case Located.unwrap item of - Lexer.Identifier { qualifiers, name } -> - if qualifiers /= [] then - Debug.todo "" - - else - exprAppend prevExpr name - |> partialExpressionToParseResult newState + Lexer.Identifier ident -> + exprAppend prevExpr ident + |> partialExpressionToParseResult newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> leafToParent prevExpr @@ -1153,9 +1219,10 @@ parentsToLeafWith expr toMakeIntoLeaf = , parent = parent } - Just (NestingParentType_TypeWithArgs { name, args, parent }) -> + Just (NestingParentType_TypeWithArgs { qualifiers, name, args, parent }) -> TypeExpressionNestingLeaf_TypeWithArgs - { name = name + { qualifiers = qualifiers + , name = name , args = expr |> pushOnto args , parent = parent } @@ -1174,87 +1241,175 @@ parentsToLeafWith expr toMakeIntoLeaf = exprAppend : TypeExpressionNestingLeaf - -> String + -> + { qualifiers : List Token.UpperCase + , name : Token.Token + } -> Result Error TypeExpressionNestingLeaf exprAppend currentLeaf token = - let - newType = - TypeExpression_NamedType - { name = token - , args = empty - } - in - case currentLeaf of - -- We are within a nested bracket. - TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression } -> - case trailingExpression of - Nothing -> - leafToParent currentLeaf - |> Result.map - (\newParent -> - TypeExpressionNestingLeaf_TypeWithArgs - { name = token - , args = empty - , parent = Just newParent + case token.name of + Token.TokenLowerCase lower -> + let + lowerCaseTypeError = + Error_LowerCasedTypename + { qualifiers = token.qualifiers + , name = lower + } + |> Err + + doesNotTakeArgsError expr = + if token.qualifiers == [] then + Error_TypeDoesNotTakeArgs expr + (TypeExpression_GenericType lower) + |> Err + + else + lowerCaseTypeError + in + case currentLeaf of + -- We are within a nested bracket. + TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> + case trailingExpression of + Nothing -> + if token.qualifiers == [] then + TypeExpressionNestingLeaf_Bracket + { firstExpressions = firstExpressions + , trailingExpression = Just (TypeExpression_GenericType lower) + , parent = parent } - ) + |> Ok - Just existingRoot -> - Error_TypeDoesNotTakeArgs existingRoot newType - |> Err + else + lowerCaseTypeError - TypeExpressionNestingLeaf_Expr expr -> - Error_TypeDoesNotTakeArgs expr newType - |> Err + Just existingRoot -> + doesNotTakeArgsError existingRoot - TypeExpressionNestingLeaf_PartialRecord pr -> - case pr.lastEntry of - LastEntryOfRecord_Empty -> - TypeExpressionNestingLeaf_PartialRecord - { firstEntries = pr.firstEntries - , lastEntry = LastEntryOfRecord_Key token - , parent = pr.parent - } - |> Ok + TypeExpressionNestingLeaf_Expr expr -> + doesNotTakeArgsError expr - _ -> - leafToParent currentLeaf - |> Result.map - (\newParent -> - TypeExpressionNestingLeaf_TypeWithArgs - { name = token - , args = empty - , parent = Just newParent + TypeExpressionNestingLeaf_PartialRecord pr -> + case pr.lastEntry of + LastEntryOfRecord_Empty -> + if token.qualifiers == [] then + TypeExpressionNestingLeaf_PartialRecord + { firstEntries = pr.firstEntries + , lastEntry = LastEntryOfRecord_Key lower + , parent = pr.parent } - ) + |> Ok - TypeExpressionNestingLeaf_TypeWithArgs { name, args, parent } -> - TypeExpressionNestingLeaf_TypeWithArgs - { name = name - , args = - newType - |> pushOnto args - , parent = parent - } - |> Ok + else + Error_QualifiedRecordKey + { qualifiers = token.qualifiers + , name = token.name + } + |> Err - TypeExpressionNestingLeaf_Function { firstInput, output } -> - Result.andThen - (\newParent -> - case output of - Just outputExpr -> - Error_TypeDoesNotTakeArgs outputExpr newType - |> Err + _ -> + leafToParent currentLeaf + |> Result.map (Just >> parentsToLeafWith (TypeExpression_GenericType lower)) + TypeExpressionNestingLeaf_TypeWithArgs _ -> + leafToParent currentLeaf + |> Result.map (Just >> parentsToLeafWith (TypeExpression_GenericType lower)) + + TypeExpressionNestingLeaf_Function _ -> + leafToParent currentLeaf + |> Result.map (Just >> parentsToLeafWith (TypeExpression_GenericType lower)) + + Token.TokenUpperCase upper -> + let + doesNotTakeArgsError expr = + Error_TypeDoesNotTakeArgs expr + (TypeExpression_NamedType + { qualifiers = token.qualifiers + , name = upper + , args = empty + } + ) + |> Err + in + case currentLeaf of + -- We are within a nested bracket. + TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression } -> + case trailingExpression of Nothing -> - TypeExpressionNestingLeaf_TypeWithArgs - { name = token - , args = empty - , parent = Just newParent - } - |> Ok - ) - (leafToParent currentLeaf) + leafToParent currentLeaf + |> Result.map + (\newParent -> + TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = token.qualifiers + , name = upper + , args = empty + , parent = Just newParent + } + ) + + Just existingRoot -> + doesNotTakeArgsError existingRoot + + TypeExpressionNestingLeaf_Expr expr -> + doesNotTakeArgsError expr + + TypeExpressionNestingLeaf_PartialRecord pr -> + case pr.lastEntry of + LastEntryOfRecord_Empty -> + if token.qualifiers /= [] then + Error_QualifiedRecordKey + { qualifiers = token.qualifiers + , name = token.name + } + |> Err + + else + Error_UpperCaseRecordKey upper + |> Err + + _ -> + leafToParent currentLeaf + |> Result.map + (\newParent -> + TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = token.qualifiers + , name = upper + , args = empty + , parent = Just newParent + } + ) + + TypeExpressionNestingLeaf_TypeWithArgs { name, args, parent } -> + TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = token.qualifiers + , name = name + , args = + { qualifiers = token.qualifiers + , name = upper + , args = empty + } + |> TypeExpression_NamedType + |> pushOnto args + , parent = parent + } + |> Ok + + TypeExpressionNestingLeaf_Function { firstInput, output } -> + Result.andThen + (\newParent -> + case output of + Just outputExpr -> + doesNotTakeArgsError outputExpr + + Nothing -> + TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = token.qualifiers + , name = upper + , args = empty + , parent = Just newParent + } + |> Ok + ) + (leafToParent currentLeaf) appendCommaTo : TypeExpressionNestingLeaf -> Result Error TypeExpressionNestingLeaf @@ -1638,10 +1793,10 @@ type CollapseLevel autoCollapseNesting : CollapseLevel -> TypeExpressionNestingLeaf -> TypeExpressionNestingLeaf autoCollapseNesting collapseLevel pte = case pte of - TypeExpressionNestingLeaf_TypeWithArgs { name, args, parent } -> + TypeExpressionNestingLeaf_TypeWithArgs { qualifiers, name, args, parent } -> let newTypeExpr = - TypeExpression_NamedType { name = name, args = args } + TypeExpression_NamedType { qualifiers = qualifiers, name = name, args = args } in parentsToLeafWith newTypeExpr parent |> autoCollapseNesting collapseLevel @@ -1711,19 +1866,45 @@ type ToConcreteTypeError partialTypeExpressionToConcreteType : TypeExpression -> Result ToConcreteTypeError (ConcreteType PossiblyQualified) partialTypeExpressionToConcreteType pte = case pte of - TypeExpression_NamedType { name, args } -> + TypeExpression_NamedType { qualifiers, name, args } -> + let + (Token.UpperCase sName) = + name + + mModuleName = + if qualifiers == [] then + Nothing + + else + qualifiers + |> List.map (\(Token.UpperCase s) -> s) + |> String.join "." + |> Just + in args |> toList partialTypeExpressionToConcreteType |> collectList (\x -> x) |> Result.map (\goodArgs -> - { qualifiedness = Qualifiedness.PossiblyQualified Nothing - , name = name + { qualifiedness = Qualifiedness.PossiblyQualified mModuleName + , name = sName , args = goodArgs } |> ConcreteType.UserDefinedType ) + TypeExpression_GenericType name -> + let + (Token.LowerCase sName) = + name + in + { qualifiedness = Qualifiedness.PossiblyQualified Nothing + , name = sName + , args = [] + } + |> ConcreteType.UserDefinedType + |> Ok + TypeExpression_Unit -> ConcreteType.Unit |> Ok @@ -1759,7 +1940,7 @@ partialTypeExpressionToConcreteType pte = TypeExpression_Record keyValues -> keyValues |> collectList - (\( key, value ) -> + (\( Token.LowerCase key, value ) -> partialTypeExpressionToConcreteType value |> Result.map (\concreteValue -> ( key, concreteValue )) ) diff --git a/src/Stage/Parse/Lexer.elm b/src/Stage/Parse/Lexer.elm index 31896b79..e71d194b 100644 --- a/src/Stage/Parse/Lexer.elm +++ b/src/Stage/Parse/Lexer.elm @@ -17,11 +17,11 @@ type LexItem type LexToken = Sigil LexSigil | Identifier - { qualifiers : List String - , name : String + { qualifiers : List Token.UpperCase + , name : Token.Token } - | RecordAccessorLiteral String - | RecordAccessorFunction String + | RecordAccessorLiteral Token.LowerCase + | RecordAccessorFunction Token.LowerCase | Keyword Token.Keyword | NumericLiteral String | TextLiteral LexLiteralType String @@ -34,8 +34,8 @@ type LexIgnorable type LexInvalid = IdentifierWithTrailingDot - { qualifiers : List String - , name : String + { qualifiers : List Token.UpperCase + , name : Token.UpperCase } | IllegalCharacter Char | OtherInvalid String @@ -150,13 +150,13 @@ toString item = Operator.toString op Token (Identifier { qualifiers, name }) -> - (qualifiers ++ [ name ]) + (List.map (\(Token.UpperCase s) -> s) qualifiers ++ [ Token.tokenToString name ]) |> String.join "." - Token (RecordAccessorLiteral name) -> + Token (RecordAccessorLiteral (Token.LowerCase name)) -> "." ++ name - Token (RecordAccessorFunction name) -> + Token (RecordAccessorFunction (Token.LowerCase name)) -> "." ++ name Token (Keyword k) -> @@ -189,8 +189,11 @@ toString item = "{-|" ++ s ++ "-}" Invalid (IdentifierWithTrailingDot { qualifiers, name }) -> - (qualifiers ++ [ name, "" ]) + ((qualifiers ++ [ name ]) + |> List.map (\(Token.UpperCase s) -> s) |> String.join "." + ) + ++ "." Invalid (IllegalCharacter c) -> String.fromChar c @@ -268,14 +271,26 @@ parser = ) -word : Parser_ String -word = +upperCaseWord : Parser_ Token.UpperCase +upperCaseWord = + P.variable + { start = Char.isUpper + , inner = \c -> Char.isAlphaNum c || c == '_' + , reserved = Set.empty + , expecting = ExpectingToken + } + |> P.map Token.UpperCase + + +lowerCaseWord : Parser_ Token.LowerCase +lowerCaseWord = P.variable - { start = Char.isAlpha + { start = Char.isLower , inner = \c -> Char.isAlphaNum c || c == '_' , reserved = Set.empty , expecting = ExpectingToken } + |> P.map Token.LowerCase identifierParser : Parser_ LexItem @@ -286,7 +301,7 @@ identifierParser = [ P.succeed (\x -> x) |. P.symbol (P.Token "." ExpectingSigil) |= P.oneOf - [ word + [ upperCaseWord |> P.map (\new -> P.Loop @@ -294,6 +309,16 @@ identifierParser = , name = new } ) + , lowerCaseWord + |> P.map + (\new -> + { qualifiers = List.reverse (name :: reversedQualifiers) + , name = Token.TokenLowerCase new + } + |> Identifier + |> Token + |> P.Done + ) , { qualifiers = List.reverse reversedQualifiers , name = name } @@ -303,7 +328,7 @@ identifierParser = |> P.succeed ] , { qualifiers = List.reverse reversedQualifiers - , name = name + , name = Token.TokenUpperCase name } |> Identifier |> Token @@ -375,8 +400,17 @@ identifierParser = |> Keyword |> Token ) - , word + , upperCaseWord |> P.andThen (\first -> P.loop { reversedQualifiers = [], name = first } loopHelp) + , lowerCaseWord + |> P.map + (\name -> + { name = Token.TokenLowerCase name + , qualifiers = [] + } + |> Identifier + |> Token + ) ] @@ -385,7 +419,7 @@ recordAccessorParser previous = P.succeed (\x -> x) |. P.symbol (P.Token "." ExpectingSigil) |= P.oneOf - [ word + [ lowerCaseWord |> P.map (case previous of Just (Token (Sigil (Bracket Round Close))) -> @@ -395,7 +429,7 @@ recordAccessorParser previous = RecordAccessorLiteral >> Token Just (Token (Identifier _)) -> - \_ -> Debug.todo "impossible state: add ICE here" + RecordAccessorLiteral >> Token _ -> RecordAccessorFunction >> Token diff --git a/src/Stage/Parse/Pretty.elm b/src/Stage/Parse/Pretty.elm index c8f1b47d..817c42f8 100644 --- a/src/Stage/Parse/Pretty.elm +++ b/src/Stage/Parse/Pretty.elm @@ -105,14 +105,12 @@ block b = [ Atom "ValueDeclaration" , Many [ Atom "name" - , Atom (Located.unwrap record.name) + , record.name |> Located.unwrap |> Token.TokenLowerCase |> Token.tokenToString |> Atom ] , Many [ Atom "args" , listWith - (\locatedArg -> - Atom (Located.unwrap locatedArg) - ) + (Located.unwrap >> Token.TokenLowerCase >> Token.tokenToString >> Atom) record.args ] , Many @@ -126,13 +124,13 @@ block b = [ Atom "TypeAlias" , Many [ Atom "ty" - , Atom record.ty + , record.ty |> Token.TokenUpperCase |> Token.tokenToString |> Atom ] , Many [ Atom "genericArgs" , Many (record.genericArgs - |> List.map Atom + |> List.map (Token.TokenLowerCase >> Token.tokenToString >> Atom) ) ] , Many @@ -164,8 +162,8 @@ state s = pair "State_BlockTypeAlias" (Many [ Atom "BlockTypeAlias_Named" - , Atom name - , listWith Atom (Contextualize.toList (\x -> x) genericArgs) + , name |> Token.TokenUpperCase |> Token.tokenToString |> Atom + , listWith Atom (Contextualize.toList (Token.TokenLowerCase >> Token.tokenToString) genericArgs) ] ) @@ -173,8 +171,8 @@ state s = pair "State_BlockTypeAlias" (Many [ Atom "BlockTypeAlias_NamedAssigns" - , Atom name - , listWith Atom genericArgs + , name |> Token.TokenUpperCase |> Token.tokenToString |> Atom + , listWith (Token.TokenLowerCase >> Token.tokenToString >> Atom) genericArgs ] ) @@ -182,8 +180,8 @@ state s = pair "State_BlockTypeAlias" (Many [ Atom "BlockTypeAlias_Completish" - , Atom name - , listWith Atom genericArgs + , name |> Token.TokenUpperCase |> Token.tokenToString |> Atom + , listWith (Token.TokenLowerCase >> Token.tokenToString >> Atom) genericArgs , typeExpressionNestingLeaf typeExpr_ ] ) diff --git a/src/Stage/Parse/Token.elm b/src/Stage/Parse/Token.elm index 51d55e17..2ebc72c4 100644 --- a/src/Stage/Parse/Token.elm +++ b/src/Stage/Parse/Token.elm @@ -13,18 +13,26 @@ type Keyword | Else -type TypeOrConstructor - = TypeOrConstructor String +type UpperCase + = UpperCase String -type ValueOrFunctionOrGenericType - = ValueOrFunctionOrGenericType String +type LowerCase + = LowerCase String type Token - = TokenTypeOrConstructor TypeOrConstructor - | TokenValueOrFunction ValueOrFunctionOrGenericType - | TokenKeyword Keyword + = TokenUpperCase UpperCase + | TokenLowerCase LowerCase + + +tokenToString t = + case t of + TokenUpperCase (UpperCase s) -> + s + + TokenLowerCase (LowerCase s) -> + s keywordToString : Keyword -> String @@ -56,48 +64,3 @@ keywordToString keyword = Else -> "else" - - -{-| Note: empty strings become `ValueOrFunction`s --} -classifyToken : String -> Token -classifyToken token = - case token of - "module" -> - TokenKeyword Module - - "type" -> - TokenKeyword Type - - "alias" -> - TokenKeyword Alias - - "exposing" -> - TokenKeyword Exposing - - "case" -> - TokenKeyword Case - - "of" -> - TokenKeyword Of - - "if" -> - TokenKeyword If - - "then" -> - TokenKeyword Then - - "else" -> - TokenKeyword Else - - _ -> - case String.uncons token of - Just ( first, _ ) -> - if Char.isUpper first then - TokenTypeOrConstructor (TypeOrConstructor token) - - else - TokenValueOrFunction (ValueOrFunctionOrGenericType token) - - Nothing -> - TokenValueOrFunction (ValueOrFunctionOrGenericType token) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index b69a9a8f..73c35226 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -8,7 +8,7 @@ import Elm.Data.Qualifiedness exposing (PossiblyQualified(..)) import Elm.Data.Type.Concrete exposing (ConcreteType(..)) import Stage.Parse.Contextualize as Contextualize exposing (..) import Stage.Parse.Lexer exposing (..) -import Stage.Parse.Token exposing (Keyword(..), TypeOrConstructor(..), ValueOrFunctionOrGenericType(..)) +import Stage.Parse.Token exposing (Keyword(..), LowerCase(..), Token(..), UpperCase(..)) @@ -55,12 +55,12 @@ b = 78 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } "b", valueExpr__ = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (LowerCase "a"), valueExpr__ = Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (LowerCase "b"), valueExpr__ = Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) @@ -71,7 +71,7 @@ b = 78 ] 0 ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) @@ -143,12 +143,12 @@ b = 78 + 5 + 2+ 4 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Add) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } "b", valueExpr__ = Located { end = { col = 18, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } Add) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Frontend.Int 4))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (LowerCase "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Add) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (LowerCase "b"), valueExpr__ = Located { end = { col = 18, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } Add) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 18, row = 3 }, start = { col = 17, row = 3 } } (Frontend.Int 4))) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) @@ -163,7 +163,7 @@ b = 78 + 5 + 2+ 4 ] 0 ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) @@ -255,12 +255,12 @@ b = 78 * 5 * 2 / 4 * 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } "b", valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Multiply) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Divide) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Multiply) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Multiply) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (LowerCase "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (LowerCase "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Multiply) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Divide) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Multiply) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Multiply) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) @@ -275,7 +275,7 @@ b = 78 * 5 * 2 / 4 * 5 ] 0 ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) @@ -697,20 +697,20 @@ b4 = 78 / 5 / 2 / 4 + 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 14, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } Add) (Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5)))) (Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Frontend.Int 6))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } "a1", valueExpr__ = Located { end = { col = 16, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Operator (Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } Add) (Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Int 7)) (Located { end = { col = 16, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Operator (Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } Multiply) (Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Int 5)) (Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } "a11", valueExpr__ = Located { end = { col = 21, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Operator (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } Add) (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Int 7)) (Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } Add) (Located { end = { col = 17, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } Multiply) (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Int 5)) (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Frontend.Int 6))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } "a2", valueExpr__ = Located { end = { col = 18, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Operator (Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } Add) (Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Int 100)) (Located { end = { col = 18, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Operator (Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } Multiply) (Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Int 5)) (Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } "a3", valueExpr__ = Located { end = { col = 30, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 18, row = 5 }, start = { col = 17, row = 5 } } Add) (Located { end = { col = 16, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 11, row = 5 }, start = { col = 10, row = 5 } } Multiply) (Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Int 345)) (Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (Frontend.Int 2234)))) (Located { end = { col = 30, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Operator (Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } Multiply) (Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Int 2342)) (Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Frontend.Int 1010))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } "b", valueExpr__ = Located { end = { col = 23, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Operator (Located { end = { col = 9, row = 8 }, start = { col = 8, row = 8 } } Add) (Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Int 78)) (Located { end = { col = 23, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } Multiply) (Located { end = { col = 19, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } Divide) (Located { end = { col = 15, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } Multiply) (Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Int 5)) (Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } "b1", valueExpr__ = Located { end = { col = 24, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } Subtract) (Located { end = { col = 20, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 18, row = 9 }, start = { col = 17, row = 9 } } Divide) (Located { end = { col = 16, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 14, row = 9 }, start = { col = 13, row = 9 } } Multiply) (Located { end = { col = 12, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 10, row = 9 }, start = { col = 9, row = 9 } } Multiply) (Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } "b2", valueExpr__ = Located { end = { col = 24, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 14, row = 10 }, start = { col = 13, row = 10 } } Subtract) (Located { end = { col = 12, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 10, row = 10 }, start = { col = 9, row = 10 } } Multiply) (Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } Multiply) (Located { end = { col = 20, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 18, row = 10 }, start = { col = 17, row = 10 } } Divide) (Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } "b3", valueExpr__ = Located { end = { col = 24, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 14, row = 11 }, start = { col = 13, row = 11 } } Add) (Located { end = { col = 12, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 10, row = 11 }, start = { col = 9, row = 11 } } Subtract) (Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } Multiply) (Located { end = { col = 20, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 18, row = 11 }, start = { col = 17, row = 11 } } Divide) (Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Frontend.Int 5))))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } "b4", valueExpr__ = Located { end = { col = 24, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 22, row = 12 }, start = { col = 21, row = 12 } } Add) (Located { end = { col = 20, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 18, row = 12 }, start = { col = 17, row = 12 } } Divide) (Located { end = { col = 16, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 14, row = 12 }, start = { col = 13, row = 12 } } Divide) (Located { end = { col = 12, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 10, row = 12 }, start = { col = 9, row = 12 } } Divide) (Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (LowerCase "a"), valueExpr__ = Located { end = { col = 14, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } Add) (Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Multiply) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5)))) (Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Frontend.Int 6))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (LowerCase "a1"), valueExpr__ = Located { end = { col = 16, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Operator (Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } Add) (Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Frontend.Int 7)) (Located { end = { col = 16, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Operator (Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } Multiply) (Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Frontend.Int 5)) (Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (LowerCase "a11"), valueExpr__ = Located { end = { col = 21, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Operator (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } Add) (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Frontend.Int 7)) (Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } Add) (Located { end = { col = 17, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Operator (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } Multiply) (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Frontend.Int 5)) (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Frontend.Int 6))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (LowerCase "a2"), valueExpr__ = Located { end = { col = 18, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Operator (Located { end = { col = 12, row = 4 }, start = { col = 11, row = 4 } } Add) (Located { end = { col = 9, row = 4 }, start = { col = 6, row = 4 } } (Frontend.Int 100)) (Located { end = { col = 18, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Operator (Located { end = { col = 16, row = 4 }, start = { col = 15, row = 4 } } Multiply) (Located { end = { col = 14, row = 4 }, start = { col = 13, row = 4 } } (Frontend.Int 5)) (Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (LowerCase "a3"), valueExpr__ = Located { end = { col = 30, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 18, row = 5 }, start = { col = 17, row = 5 } } Add) (Located { end = { col = 16, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Operator (Located { end = { col = 11, row = 5 }, start = { col = 10, row = 5 } } Multiply) (Located { end = { col = 9, row = 5 }, start = { col = 6, row = 5 } } (Frontend.Int 345)) (Located { end = { col = 16, row = 5 }, start = { col = 12, row = 5 } } (Frontend.Int 2234)))) (Located { end = { col = 30, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Operator (Located { end = { col = 25, row = 5 }, start = { col = 24, row = 5 } } Multiply) (Located { end = { col = 23, row = 5 }, start = { col = 19, row = 5 } } (Frontend.Int 2342)) (Located { end = { col = 30, row = 5 }, start = { col = 26, row = 5 } } (Frontend.Int 1010))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (LowerCase "b"), valueExpr__ = Located { end = { col = 23, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Operator (Located { end = { col = 9, row = 8 }, start = { col = 8, row = 8 } } Add) (Located { end = { col = 7, row = 8 }, start = { col = 5, row = 8 } } (Frontend.Int 78)) (Located { end = { col = 23, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 21, row = 8 }, start = { col = 20, row = 8 } } Multiply) (Located { end = { col = 19, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } Divide) (Located { end = { col = 15, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Operator (Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } Multiply) (Located { end = { col = 11, row = 8 }, start = { col = 10, row = 8 } } (Frontend.Int 5)) (Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 8 }, start = { col = 18, row = 8 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (LowerCase "b1"), valueExpr__ = Located { end = { col = 24, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 22, row = 9 }, start = { col = 21, row = 9 } } Subtract) (Located { end = { col = 20, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 18, row = 9 }, start = { col = 17, row = 9 } } Divide) (Located { end = { col = 16, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 14, row = 9 }, start = { col = 13, row = 9 } } Multiply) (Located { end = { col = 12, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Operator (Located { end = { col = 10, row = 9 }, start = { col = 9, row = 9 } } Multiply) (Located { end = { col = 8, row = 9 }, start = { col = 6, row = 9 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 9 }, start = { col = 11, row = 9 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 9 }, start = { col = 15, row = 9 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 9 }, start = { col = 19, row = 9 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (LowerCase "b2"), valueExpr__ = Located { end = { col = 24, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 14, row = 10 }, start = { col = 13, row = 10 } } Subtract) (Located { end = { col = 12, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Operator (Located { end = { col = 10, row = 10 }, start = { col = 9, row = 10 } } Multiply) (Located { end = { col = 8, row = 10 }, start = { col = 6, row = 10 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 10 }, start = { col = 11, row = 10 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 22, row = 10 }, start = { col = 21, row = 10 } } Multiply) (Located { end = { col = 20, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Operator (Located { end = { col = 18, row = 10 }, start = { col = 17, row = 10 } } Divide) (Located { end = { col = 16, row = 10 }, start = { col = 15, row = 10 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 10 }, start = { col = 19, row = 10 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (LowerCase "b3"), valueExpr__ = Located { end = { col = 24, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 14, row = 11 }, start = { col = 13, row = 11 } } Add) (Located { end = { col = 12, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Operator (Located { end = { col = 10, row = 11 }, start = { col = 9, row = 11 } } Subtract) (Located { end = { col = 8, row = 11 }, start = { col = 6, row = 11 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 11 }, start = { col = 11, row = 11 } } (Frontend.Int 5)))) (Located { end = { col = 24, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 22, row = 11 }, start = { col = 21, row = 11 } } Multiply) (Located { end = { col = 20, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Operator (Located { end = { col = 18, row = 11 }, start = { col = 17, row = 11 } } Divide) (Located { end = { col = 16, row = 11 }, start = { col = 15, row = 11 } } (Frontend.Int 2)) (Located { end = { col = 20, row = 11 }, start = { col = 19, row = 11 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Frontend.Int 5))))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (LowerCase "b4"), valueExpr__ = Located { end = { col = 24, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 22, row = 12 }, start = { col = 21, row = 12 } } Add) (Located { end = { col = 20, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 18, row = 12 }, start = { col = 17, row = 12 } } Divide) (Located { end = { col = 16, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 14, row = 12 }, start = { col = 13, row = 12 } } Divide) (Located { end = { col = 12, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Operator (Located { end = { col = 10, row = 12 }, start = { col = 9, row = 12 } } Divide) (Located { end = { col = 8, row = 12 }, start = { col = 6, row = 12 } } (Frontend.Int 78)) (Located { end = { col = 12, row = 12 }, start = { col = 11, row = 12 } } (Frontend.Int 5)))) (Located { end = { col = 16, row = 12 }, start = { col = 15, row = 12 } } (Frontend.Int 2)))) (Located { end = { col = 20, row = 12 }, start = { col = 19, row = 12 } } (Frontend.Int 4)))) (Located { end = { col = 24, row = 12 }, start = { col = 23, row = 12 } } (Frontend.Int 5))) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) @@ -724,7 +724,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 13, row = 1 }, start = { col = 12, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Token (NumericLiteral "6")) , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) - , Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = "a1", qualifiers = [] })) + , Located { end = { col = 3, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a1"), qualifiers = [] })) , Located { end = { col = 4, row = 2 }, start = { col = 3, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 2 }, start = { col = 4, row = 2 } } (Token (Sigil Assign)) , Located { end = { col = 7, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 2)) @@ -738,7 +738,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 3 }, start = { col = 16, row = 2 } } (Newlines [] 0) - , Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "a11", qualifiers = [] })) + , Located { end = { col = 4, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a11"), qualifiers = [] })) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 2)) @@ -756,7 +756,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 20, row = 3 }, start = { col = 19, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Token (NumericLiteral "6")) , Located { end = { col = 1, row = 4 }, start = { col = 21, row = 3 } } (Newlines [] 0) - , Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (Token (Identifier { name = "a2", qualifiers = [] })) + , Located { end = { col = 3, row = 4 }, start = { col = 1, row = 4 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a2"), qualifiers = [] })) , Located { end = { col = 4, row = 4 }, start = { col = 3, row = 4 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 4 }, start = { col = 4, row = 4 } } (Token (Sigil Assign)) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Ignorable (Whitespace 1)) @@ -770,7 +770,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 17, row = 4 }, start = { col = 16, row = 4 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 4 }, start = { col = 17, row = 4 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 5 }, start = { col = 18, row = 4 } } (Newlines [] 0) - , Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (Token (Identifier { name = "a3", qualifiers = [] })) + , Located { end = { col = 3, row = 5 }, start = { col = 1, row = 5 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a3"), qualifiers = [] })) , Located { end = { col = 4, row = 5 }, start = { col = 3, row = 5 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 5 }, start = { col = 4, row = 5 } } (Token (Sigil Assign)) , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) @@ -794,7 +794,7 @@ b4 = 78 / 5 / 2 / 4 + 5 ] 0 ) - , Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 2, row = 8 }, start = { col = 1, row = 8 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 3, row = 8 }, start = { col = 2, row = 8 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 8 }, start = { col = 3, row = 8 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 8 }, start = { col = 4, row = 8 } } (Ignorable (Whitespace 1)) @@ -816,7 +816,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 22, row = 8 }, start = { col = 21, row = 8 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 8 }, start = { col = 22, row = 8 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 9 }, start = { col = 23, row = 8 } } (Newlines [] 0) - , Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (Token (Identifier { name = "b1", qualifiers = [] })) + , Located { end = { col = 3, row = 9 }, start = { col = 1, row = 9 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b1"), qualifiers = [] })) , Located { end = { col = 4, row = 9 }, start = { col = 3, row = 9 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 9 }, start = { col = 4, row = 9 } } (Token (Sigil Assign)) , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Ignorable (Whitespace 1)) @@ -838,7 +838,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 23, row = 9 }, start = { col = 22, row = 9 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 9 }, start = { col = 23, row = 9 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 10 }, start = { col = 24, row = 9 } } (Newlines [] 0) - , Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (Token (Identifier { name = "b2", qualifiers = [] })) + , Located { end = { col = 3, row = 10 }, start = { col = 1, row = 10 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b2"), qualifiers = [] })) , Located { end = { col = 4, row = 10 }, start = { col = 3, row = 10 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 10 }, start = { col = 4, row = 10 } } (Token (Sigil Assign)) , Located { end = { col = 6, row = 10 }, start = { col = 5, row = 10 } } (Ignorable (Whitespace 1)) @@ -860,7 +860,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 23, row = 10 }, start = { col = 22, row = 10 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 10 }, start = { col = 23, row = 10 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 11 }, start = { col = 24, row = 10 } } (Newlines [] 0) - , Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (Token (Identifier { name = "b3", qualifiers = [] })) + , Located { end = { col = 3, row = 11 }, start = { col = 1, row = 11 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b3"), qualifiers = [] })) , Located { end = { col = 4, row = 11 }, start = { col = 3, row = 11 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 11 }, start = { col = 4, row = 11 } } (Token (Sigil Assign)) , Located { end = { col = 6, row = 11 }, start = { col = 5, row = 11 } } (Ignorable (Whitespace 1)) @@ -882,7 +882,7 @@ b4 = 78 / 5 / 2 / 4 + 5 , Located { end = { col = 23, row = 11 }, start = { col = 22, row = 11 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 11 }, start = { col = 23, row = 11 } } (Token (NumericLiteral "5")) , Located { end = { col = 1, row = 12 }, start = { col = 24, row = 11 } } (Newlines [] 0) - , Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (Token (Identifier { name = "b4", qualifiers = [] })) + , Located { end = { col = 3, row = 12 }, start = { col = 1, row = 12 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b4"), qualifiers = [] })) , Located { end = { col = 4, row = 12 }, start = { col = 3, row = 12 } } (Ignorable (Whitespace 1)) , Located { end = { col = 5, row = 12 }, start = { col = 4, row = 12 } } (Token (Sigil Assign)) , Located { end = { col = 6, row = 12 }, start = { col = 5, row = 12 } } (Ignorable (Whitespace 1)) @@ -984,12 +984,12 @@ b = 78 + 5 + 2 - 4 + 5 """ , contextualized = Just - [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } "a", valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Subtract) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) - , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } "b", valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Add) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Subtract) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) + [ Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (LowerCase "a"), valueExpr__ = Located { end = { col = 10, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Operator (Located { end = { col = 8, row = 1 }, start = { col = 7, row = 1 } } Subtract) (Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Frontend.Int 5)) (Located { end = { col = 10, row = 1 }, start = { col = 9, row = 1 } } (Frontend.Int 5))) }) + , Ok (ValueDeclaration { args = [], name = Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (LowerCase "b"), valueExpr__ = Located { end = { col = 23, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } Add) (Located { end = { col = 19, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 17, row = 3 }, start = { col = 16, row = 3 } } Subtract) (Located { end = { col = 15, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } Add) (Located { end = { col = 11, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Operator (Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } Add) (Located { end = { col = 7, row = 3 }, start = { col = 5, row = 3 } } (Frontend.Int 78)) (Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Frontend.Int 5)))) (Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Frontend.Int 2)))) (Located { end = { col = 19, row = 3 }, start = { col = 18, row = 3 } } (Frontend.Int 4)))) (Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Frontend.Int 5))) }) ] , lexed = Ok - [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + [ Located { end = { col = 2, row = 1 }, start = { col = 1, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 3, row = 1 }, start = { col = 2, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 1 }, start = { col = 3, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 1 }, start = { col = 4, row = 1 } } (Ignorable (Whitespace 1)) @@ -1004,7 +1004,7 @@ b = 78 + 5 + 2 - 4 + 5 ] 0 ) - , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 2, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 3, row = 3 }, start = { col = 2, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 4, row = 3 }, start = { col = 3, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 3 }, start = { col = 4, row = 3 } } (Ignorable (Whitespace 1)) @@ -1075,7 +1075,7 @@ b = 78 + 5 + 2 - 4 + 5 , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = "Model" + , ty = UpperCase "Model" } ) ] @@ -1085,13 +1085,13 @@ b = 78 + 5 + 2 - 4 + 5 , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Model"), qualifiers = [] })) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) ] } @@ -1156,15 +1156,15 @@ expr hi = 77 , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = "Model" + , ty = UpperCase "Model" } ) , Ok (ValueDeclaration { args = - [ Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } "hi" + [ Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (LowerCase "hi") ] - , name = Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } "expr" + , name = Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (LowerCase "expr") , valueExpr__ = Located { end = { col = 13, row = 3 }, start = { col = 11, row = 3 } } (Frontend.Int 77) } ) @@ -1175,22 +1175,22 @@ expr hi = 77 , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Model"), qualifiers = [] })) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 24, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 28, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 28, row = 1 } } (Newlines [ 0 ] 0 ) - , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = "expr", qualifiers = [] })) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "expr"), qualifiers = [] })) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 8, row = 3 }, start = { col = 6, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "hi"), qualifiers = [] })) , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Ignorable (Whitespace 1)) @@ -1240,7 +1240,7 @@ expr hi = 77 ] ) , genericArgs = [] - , ty = "Ty" + , ty = UpperCase "Ty" } ) ] @@ -1250,17 +1250,17 @@ expr hi = 77 , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "hi"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil (Bracket Curly Close))) @@ -1368,7 +1368,7 @@ expr hi = 77 } } , genericArgs = [] - , ty = "Function" + , ty = UpperCase "Function" } ) ] @@ -1378,22 +1378,22 @@ expr hi = 77 , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 31, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 34, row = 1 }, start = { col = 32, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 39, row = 1 }, start = { col = 35, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 45, row = 1 }, start = { col = 41, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 46, row = 1 }, start = { col = 45, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 49, row = 1 }, start = { col = 46, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) ] @@ -1541,7 +1541,7 @@ type alias Function = A -> B -> C -> D } } , genericArgs = [] - , ty = "Function" + , ty = UpperCase "Function" } ) , Ok @@ -1580,7 +1580,7 @@ type alias Function = A -> B -> C -> D } } , genericArgs = [] - , ty = "Function" + , ty = UpperCase "Function" } ) ] @@ -1590,47 +1590,48 @@ type alias Function = A -> B -> C -> D , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 27, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "B"), qualifiers = [] })) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Token (Sigil Assign)) , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 27, row = 2 }, start = { col = 25, row = 2 } } (Token (Sigil ThinArrow)) , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "B"), qualifiers = [] })) , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 32, row = 2 }, start = { col = 30, row = 2 } } (Token (Sigil ThinArrow)) , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 37, row = 2 }, start = { col = 35, row = 2 } } (Token (Sigil ThinArrow)) , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "D"), qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 39, row = 2 } } (Newlines [] 0) ] } , { name = "type-alias-function-generic" , source = """type alias Function a = List Int -> List (List a) -""" + +type alias Function b c = b -> c""" , pretty = """ ( ( Ok , ( TypeAlias @@ -1691,7 +1692,41 @@ type alias Function = A -> B -> C -> D ) ) ) - ) ) + ) + , ( Ok + , ( TypeAlias + , ( ty, Function ) + , ( genericArgs + , ( b, c ) + ) + , ( expr + , ( Function + , ( ( from + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, b ) + , ( args, () ) + ) + ) + ) + , ( to + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified, Nothing ) + ) + , ( name, c ) + , ( args, () ) + ) + ) + ) + ) + ) + ) + ) + ) + ) """ , contextualized = Just @@ -1731,9 +1766,33 @@ type alias Function = A -> B -> C -> D } } , genericArgs = - [ "a" + [ LowerCase "a" + ] + , ty = UpperCase "Function" + } + ) + , Ok + (TypeAlias + { expr = + Function + { from = + UserDefinedType + { args = [] + , name = "b" + , qualifiedness = PossiblyQualified Nothing + } + , to = + UserDefinedType + { args = [] + , name = "c" + , qualifiedness = PossiblyQualified Nothing + } + } + , genericArgs = + [ LowerCase "b" + , LowerCase "c" ] - , ty = "Function" + , ty = UpperCase "Function" } ) ] @@ -1743,26 +1802,48 @@ type alias Function = A -> B -> C -> D , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 29, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 36, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 41, row = 1 }, start = { col = 37, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 47, row = 1 }, start = { col = 43, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 48, row = 1 }, start = { col = 47, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 49, row = 1 }, start = { col = 48, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 50, row = 1 }, start = { col = 49, row = 1 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 1, row = 2 }, start = { col = 50, row = 1 } } (Newlines [] 0) + , Located { end = { col = 1, row = 3 }, start = { col = 50, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "c"), qualifiers = [] })) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) + , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 31, row = 3 }, start = { col = 29, row = 3 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "c"), qualifiers = [] })) ] } , { name = "type-alias-function-nested" @@ -1952,7 +2033,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) } , genericArgs = [] - , ty = "Function" + , ty = UpperCase "Function" } ) , Ok @@ -1982,7 +2063,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = "Function2" + , ty = UpperCase "Function2" } ) , Ok @@ -2009,7 +2090,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) Unit , genericArgs = [] - , ty = "Function3" + , ty = UpperCase "Function3" } ) , Ok @@ -2042,7 +2123,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) Unit , genericArgs = [] - , ty = "Function3" + , ty = UpperCase "Function3" } ) ] @@ -2052,7 +2133,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) @@ -2063,10 +2144,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 29, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 34, row = 1 }, start = { col = 31, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 42, row = 1 }, start = { col = 36, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "String"), qualifiers = [] })) , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 3 }, start = { col = 44, row = 1 } } @@ -2079,13 +2160,13 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = "Function2", qualifiers = [] })) + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function2"), qualifiers = [] })) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Token (Sigil Colon)) , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token (Sigil (Bracket Round Open))) @@ -2094,10 +2175,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 34, row = 3 }, start = { col = 32, row = 3 } } (Token (Sigil ThinArrow)) , Located { end = { col = 35, row = 3 }, start = { col = 34, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 36, row = 3 }, start = { col = 35, row = 3 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 39, row = 3 }, start = { col = 36, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 40, row = 3 }, start = { col = 39, row = 3 } } (Token (Sigil Comma)) , Located { end = { col = 41, row = 3 }, start = { col = 40, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 47, row = 3 }, start = { col = 41, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "String"), qualifiers = [] })) , Located { end = { col = 48, row = 3 }, start = { col = 47, row = 3 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 49, row = 3 }, start = { col = 48, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 50, row = 3 }, start = { col = 49, row = 3 } } (Token (Sigil (Bracket Curly Close))) @@ -2111,7 +2192,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token (Identifier { name = "Function3", qualifiers = [] })) + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function3"), qualifiers = [] })) , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Token (Sigil Assign)) , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Ignorable (Whitespace 1)) @@ -2122,10 +2203,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 30, row = 5 }, start = { col = 28, row = 5 } } (Token (Sigil ThinArrow)) , Located { end = { col = 31, row = 5 }, start = { col = 30, row = 5 } } (Ignorable (Whitespace 1)) , Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 35, row = 5 }, start = { col = 32, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 36, row = 5 }, start = { col = 35, row = 5 } } (Token (Sigil Comma)) , Located { end = { col = 37, row = 5 }, start = { col = 36, row = 5 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 43, row = 5 }, start = { col = 37, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "String"), qualifiers = [] })) , Located { end = { col = 44, row = 5 }, start = { col = 43, row = 5 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 45, row = 5 }, start = { col = 44, row = 5 } } (Token (Sigil Comma)) , Located { end = { col = 46, row = 5 }, start = { col = 45, row = 5 } } (Ignorable (Whitespace 1)) @@ -2142,12 +2223,12 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token (Identifier { name = "Function3", qualifiers = [] })) + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function3"), qualifiers = [] })) , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Token (Sigil Assign)) , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Token (Sigil Comma)) , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Token (Sigil (Bracket Round Open))) @@ -2156,10 +2237,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 35, row = 7 }, start = { col = 33, row = 7 } } (Token (Sigil ThinArrow)) , Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 37, row = 7 }, start = { col = 36, row = 7 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 40, row = 7 }, start = { col = 37, row = 7 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 41, row = 7 }, start = { col = 40, row = 7 } } (Token (Sigil Comma)) , Located { end = { col = 42, row = 7 }, start = { col = 41, row = 7 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 48, row = 7 }, start = { col = 42, row = 7 } } (Token (Identifier { name = TokenUpperCase (UpperCase "String"), qualifiers = [] })) , Located { end = { col = 49, row = 7 }, start = { col = 48, row = 7 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 50, row = 7 }, start = { col = 49, row = 7 } } (Token (Sigil Comma)) , Located { end = { col = 51, row = 7 }, start = { col = 50, row = 7 } } (Ignorable (Whitespace 1)) @@ -2251,7 +2332,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , to = Record (Dict.fromList []) } , genericArgs = [] - , ty = "Function" + , ty = UpperCase "Function" } ) ] @@ -2261,28 +2342,28 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Token (Identifier { name = "d", qualifiers = [] })) + , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "d"), qualifiers = [] })) , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token (Identifier { name = "E", qualifiers = [] })) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "E"), qualifiers = [] })) , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Ignorable (Whitespace 1)) @@ -2354,7 +2435,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ) } , genericArgs = [] - , ty = "Function" + , ty = UpperCase "Function" } ) ] @@ -2364,7 +2445,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) @@ -2374,10 +2455,10 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 28, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 33, row = 1 }, start = { col = 30, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 41, row = 1 }, start = { col = 35, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "String"), qualifiers = [] })) , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 42, row = 1 } } (Newlines [] 0) ] @@ -2561,7 +2642,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) } } , genericArgs = [] - , ty = "Function" + , ty = UpperCase "Function" } ) ] @@ -2571,33 +2652,33 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 32, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 37, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 37, row = 1 }, start = { col = 33, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 38, row = 1 }, start = { col = 37, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "B"), qualifiers = [] })) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 41, row = 1 }, start = { col = 40, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) , Located { end = { col = 42, row = 1 }, start = { col = 41, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 43, row = 1 }, start = { col = 42, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "D"), qualifiers = [] })) , Located { end = { col = 44, row = 1 }, start = { col = 43, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 46, row = 1 }, start = { col = 44, row = 1 } } (Token (Sigil ThinArrow)) , Located { end = { col = 47, row = 1 }, start = { col = 46, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 51, row = 1 }, start = { col = 47, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 51, row = 1 }, start = { col = 47, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 52, row = 1 }, start = { col = 51, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 53, row = 1 }, start = { col = 52, row = 1 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 53, row = 1 }, start = { col = 52, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "D"), qualifiers = [] })) , Located { end = { col = 54, row = 1 }, start = { col = 53, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 55, row = 1 }, start = { col = 54, row = 1 } } (Token (Identifier { name = "E", qualifiers = [] })) + , Located { end = { col = 55, row = 1 }, start = { col = 54, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "E"), qualifiers = [] })) , Located { end = { col = 56, row = 1 }, start = { col = 55, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 57, row = 1 }, start = { col = 56, row = 1 } } (Token (Identifier { name = "F", qualifiers = [] })) + , Located { end = { col = 57, row = 1 }, start = { col = 56, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "F"), qualifiers = [] })) , Located { end = { col = 1, row = 2 }, start = { col = 57, row = 1 } } (Newlines [] 0) ] } @@ -2649,7 +2730,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = "Model" + , ty = UpperCase "Model" } ) ] @@ -2659,13 +2740,13 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) - , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Model"), qualifiers = [] })) , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Token (Sigil Assign)) , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 17, row = 2 }, start = { col = 13, row = 2 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 17, row = 2 }, start = { col = 13, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 2 } } (Newlines [] 0) ] } @@ -2718,7 +2799,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = "Model" + , ty = UpperCase "Model" } ) ] @@ -2728,13 +2809,13 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 5, row = 2 }, start = { col = 11, row = 1 } } (Newlines [] 4) - , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 10, row = 2 }, start = { col = 5, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Model"), qualifiers = [] })) , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Token (Sigil Assign)) , Located { end = { col = 2, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 1) - , Located { end = { col = 6, row = 3 }, start = { col = 2, row = 3 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 6, row = 3 }, start = { col = 2, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 10, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Newlines [] 0) ] } @@ -2815,7 +2896,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = "Ty" + , ty = UpperCase "Ty" } ) ] @@ -2825,28 +2906,28 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "B"), qualifiers = [] })) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token (Identifier { name = "c", qualifiers = [] })) + , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "c"), qualifiers = [] })) , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) , Located { end = { col = 36, row = 1 }, start = { col = 35, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 37, row = 1 }, start = { col = 36, row = 1 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 1, row = 2 }, start = { col = 37, row = 1 } } (Newlines [] 0) @@ -2868,7 +2949,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , contextualized = Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = "Ty" }) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = UpperCase "Ty" }) ] , lexed = Ok @@ -2876,7 +2957,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) @@ -2904,7 +2985,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , contextualized = Just - [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = "Ty" }) + [ Ok (TypeAlias { expr = Record (Dict.fromList []), genericArgs = [], ty = UpperCase "Ty" }) ] , lexed = Ok @@ -2912,7 +2993,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) @@ -2970,7 +3051,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = "Ty" + , ty = UpperCase "Ty" } ) ] @@ -2980,17 +3061,17 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 20, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "hi"), qualifiers = [] })) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 24, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Sigil (Bracket Round Close))) @@ -3173,7 +3254,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = "Ty" + , ty = UpperCase "Ty" } ) ] @@ -3183,49 +3264,49 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 9, row = 2 }, start = { col = 7, row = 2 } } (Token (Identifier { name = TokenLowerCase (LowerCase "hi"), qualifiers = [] })) , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Token (Sigil Colon)) , Located { end = { col = 12, row = 2 }, start = { col = 10, row = 2 } } (Ignorable (Whitespace 2)) , Located { end = { col = 13, row = 2 }, start = { col = 12, row = 2 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 14, row = 2 }, start = { col = 13, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (Sigil Colon)) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 2 }, start = { col = 17, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 20, row = 2 }, start = { col = 17, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Token (Sigil Comma)) , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 23, row = 2 }, start = { col = 22, row = 2 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token (Sigil Colon)) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 29, row = 2 }, start = { col = 25, row = 2 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 29, row = 2 }, start = { col = 25, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 36, row = 2 }, start = { col = 30, row = 2 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 36, row = 2 }, start = { col = 30, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "String"), qualifiers = [] })) , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 5, row = 3 }, start = { col = 38, row = 2 } } (Newlines [] 4) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Comma)) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "ih", qualifiers = [] })) + , Located { end = { col = 9, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "ih"), qualifiers = [] })) , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Token (Sigil Colon)) , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Token (Identifier { name = "CustomType", qualifiers = [] })) + , Located { end = { col = 21, row = 3 }, start = { col = 11, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "CustomType"), qualifiers = [] })) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "B"), qualifiers = [] })) , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "D"), qualifiers = [] })) , Located { end = { col = 31, row = 3 }, start = { col = 30, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Token (Identifier { name = "E", qualifiers = [] })) + , Located { end = { col = 32, row = 3 }, start = { col = 31, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "E"), qualifiers = [] })) , Located { end = { col = 33, row = 3 }, start = { col = 32, row = 3 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 5, row = 4 }, start = { col = 33, row = 3 } } (Newlines [] 4) , Located { end = { col = 6, row = 4 }, start = { col = 5, row = 4 } } (Token (Sigil (Bracket Curly Close))) @@ -3274,7 +3355,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = "Ty" + , ty = UpperCase "Ty" } ) ] @@ -3284,16 +3365,16 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "hi"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 1, row = 2 }, start = { col = 28, row = 1 } } (Newlines [] 0) @@ -3344,7 +3425,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) ] ) , genericArgs = [] - , ty = "Ty" + , ty = UpperCase "Ty" } ) ] @@ -3354,23 +3435,23 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "hi"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 30, row = 1 }, start = { col = 27, row = 1 } } (Token (Identifier { name = "buy", qualifiers = [] })) + , Located { end = { col = 30, row = 1 }, start = { col = 27, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "buy"), qualifiers = [] })) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil Colon)) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 38, row = 1 }, start = { col = 32, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 38, row = 1 }, start = { col = 32, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "String"), qualifiers = [] })) , Located { end = { col = 39, row = 1 }, start = { col = 38, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 40, row = 1 }, start = { col = 39, row = 1 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 1, row = 2 }, start = { col = 40, row = 1 } } (Newlines [] 0) @@ -3390,7 +3471,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) """ , contextualized = Just - [ Ok (TypeAlias { expr = Unit, genericArgs = [], ty = "Hi" }) + [ Ok (TypeAlias { expr = Unit, genericArgs = [], ty = UpperCase "Hi" }) ] , lexed = Ok @@ -3398,7 +3479,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) @@ -3439,7 +3520,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = "Hi" + , ty = UpperCase "Hi" } ) ] @@ -3449,12 +3530,12 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 22, row = 1 } } (Newlines [] 0) ] @@ -3506,7 +3587,7 @@ type alias Function3 = (Int, () -> (Int, String), ()) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = "Hi" + , ty = UpperCase "Hi" } ) ] @@ -3516,14 +3597,14 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 22, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) ] @@ -3612,7 +3693,7 @@ type alias Hi = (Int) } ) , genericArgs = [] - , ty = "Hi" + , ty = UpperCase "Hi" } ) , Ok @@ -3624,7 +3705,7 @@ type alias Hi = (Int) , qualifiedness = PossiblyQualified Nothing } , genericArgs = [] - , ty = "Hi" + , ty = UpperCase "Hi" } ) ] @@ -3634,29 +3715,29 @@ type alias Hi = (Int) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "String", qualifiers = [] })) + , Located { end = { col = 34, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "String"), qualifiers = [] })) , Located { end = { col = 35, row = 1 }, start = { col = 34, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 35, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 22, row = 2 }, start = { col = 21, row = 2 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 3 }, start = { col = 22, row = 2 } } (Newlines [] 0) ] @@ -3742,10 +3823,10 @@ type alias Hi = ((), (), ()) } ) , genericArgs = [] - , ty = "Hi" + , ty = UpperCase "Hi" } ) - , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, genericArgs = [], ty = "Hi" }) + , Ok (TypeAlias { expr = Tuple3 Unit Unit Unit, genericArgs = [], ty = UpperCase "Hi" }) ] , lexed = Ok @@ -3753,25 +3834,25 @@ type alias Hi = ((), (), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "Two", qualifiers = [] })) + , Located { end = { col = 26, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Two"), qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = "Three", qualifiers = [] })) + , Located { end = { col = 33, row = 1 }, start = { col = 28, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Three"), qualifiers = [] })) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Ignorable (Whitespace 1)) @@ -3881,7 +3962,7 @@ type alias Hi = ((), (), ()) ] ) , genericArgs = [] - , ty = "Hi" + , ty = UpperCase "Hi" } ) ] @@ -3891,34 +3972,34 @@ type alias Hi = ((), (), ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 5, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 4) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 7, row = 2 }, start = { col = 6, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 8, row = 2 }, start = { col = 7, row = 2 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 9, row = 2 }, start = { col = 8, row = 2 } } (Token (Sigil Colon)) , Located { end = { col = 10, row = 2 }, start = { col = 9, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 10, row = 2 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 14, row = 2 }, start = { col = 11, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Token (Sigil Comma)) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 19, row = 2 }, start = { col = 16, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Token (Sigil Comma)) , Located { end = { col = 21, row = 2 }, start = { col = 20, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 24, row = 2 }, start = { col = 21, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 5, row = 3 }, start = { col = 25, row = 2 } } (Newlines [] 4) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Token (Sigil Comma)) , Located { end = { col = 7, row = 3 }, start = { col = 6, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = "b", qualifiers = [] })) + , Located { end = { col = 8, row = 3 }, start = { col = 7, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "b"), qualifiers = [] })) , Located { end = { col = 9, row = 3 }, start = { col = 8, row = 3 } } (Token (Sigil Colon)) , Located { end = { col = 10, row = 3 }, start = { col = 9, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 3 }, start = { col = 10, row = 3 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Token (Identifier { name = "good_bye", qualifiers = [] })) + , Located { end = { col = 21, row = 3 }, start = { col = 13, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "good_bye"), qualifiers = [] })) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Token (Sigil Colon)) , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Token (Sigil (Bracket Round Open))) @@ -3985,7 +4066,7 @@ Hi. case""" Just [ Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] }))) + , item = Just (Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Foo", qualifiers = [] }))) , state = State_BlockStart } , Err @@ -3995,9 +4076,9 @@ Hi. case""" (Located { end = { col = 11, row = 7 }, start = { col = 1, row = 7 } } (Invalid (IdentifierWithTrailingDot - { name = "Bing" + { name = UpperCase "Bing" , qualifiers = - [ "Boor" + [ UpperCase "Boor" ] } ) @@ -4007,23 +4088,23 @@ Hi. case""" } , Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] }))) + , item = Just (Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Bor", qualifiers = [] }))) , state = State_Error_Recovery } , Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Big", qualifiers = [] }))) + , item = Just (Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Big", qualifiers = [] }))) , state = State_Error_Recovery } , Err { error = Error_InvalidToken Expecting_Unknown - , item = Just (Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] }))) + , item = Just (Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Hi", qualifiers = [] }))) , state = State_Error_Recovery } ] , lexed = Ok - [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = "Foo", qualifiers = [] })) + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Foo", qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 5, row = 1 } } (Newlines [ 0 @@ -4033,9 +4114,9 @@ Hi. case""" , Located { end = { col = 8, row = 3 }, start = { col = 1, row = 3 } } (Token (Identifier - { name = "Bar" + { name = TokenUpperCase (UpperCase "Bar") , qualifiers = - [ "Foo" + [ UpperCase "Foo" ] } ) @@ -4049,10 +4130,10 @@ Hi. case""" , Located { end = { col = 12, row = 5 }, start = { col = 1, row = 5 } } (Token (Identifier - { name = "baz" + { name = TokenLowerCase (LowerCase "baz") , qualifiers = - [ "Foo" - , "Bar" + [ UpperCase "Foo" + , UpperCase "Bar" ] } ) @@ -4066,9 +4147,9 @@ Hi. case""" , Located { end = { col = 11, row = 7 }, start = { col = 1, row = 7 } } (Invalid (IdentifierWithTrailingDot - { name = "Bing" + { name = UpperCase "Bing" , qualifiers = - [ "Boor" + [ UpperCase "Boor" ] } ) @@ -4079,41 +4160,33 @@ Hi. case""" ] 0 ) - , Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Bor", qualifiers = [] })) + , Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Bor", qualifiers = [] })) , Located { end = { col = 6, row = 9 }, start = { col = 5, row = 9 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = "Big", qualifiers = [] })) + , Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Big", qualifiers = [] })) , Located { end = { col = 1, row = 11 }, start = { col = 10, row = 9 } } (Newlines [ 0 ] 0 ) - , Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (Token (RecordAccessorFunction "sf")) + , Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (Token (RecordAccessorFunction (LowerCase "sf"))) , Located { end = { col = 1, row = 13 }, start = { col = 4, row = 11 } } (Newlines [ 0 ] 0 ) - , Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } (Token (Identifier { name = "sfsdf", qualifiers = [] })) + , Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } (Token (Identifier { name = TokenLowerCase (LowerCase "sfsdf"), qualifiers = [] })) , Located { end = { col = 7, row = 13 }, start = { col = 6, row = 13 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (Token (RecordAccessorFunction "sdfsd")) + , Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (Token (RecordAccessorFunction (LowerCase "sdfsd"))) , Located { end = { col = 1, row = 15 }, start = { col = 13, row = 13 } } (Newlines [ 0 ] 0 ) - , Located { end = { col = 15, row = 15 }, start = { col = 1, row = 15 } } - (Token - (Identifier - { name = "sdgsghj" - , qualifiers = - [ "asfasf" - ] - } - ) - ) + , Located { end = { col = 7, row = 15 }, start = { col = 1, row = 15 } } (Token (Identifier { name = TokenLowerCase (LowerCase "asfasf"), qualifiers = [] })) + , Located { end = { col = 15, row = 15 }, start = { col = 7, row = 15 } } (Token (RecordAccessorLiteral (LowerCase "sdgsghj"))) , Located { end = { col = 1, row = 17 }, start = { col = 15, row = 15 } } (Newlines [ 0 @@ -4121,9 +4194,9 @@ Hi. case""" 0 ) , Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 6, row = 17 }, start = { col = 2, row = 17 } } (Token (Identifier { name = "shdf", qualifiers = [] })) + , Located { end = { col = 6, row = 17 }, start = { col = 2, row = 17 } } (Token (Identifier { name = TokenLowerCase (LowerCase "shdf"), qualifiers = [] })) , Located { end = { col = 7, row = 17 }, start = { col = 6, row = 17 } } (Token (Sigil (Bracket Round Close))) - , Located { end = { col = 20, row = 17 }, start = { col = 7, row = 17 } } (Token (RecordAccessorLiteral "helloLiteral")) + , Located { end = { col = 20, row = 17 }, start = { col = 7, row = 17 } } (Token (RecordAccessorLiteral (LowerCase "helloLiteral"))) , Located { end = { col = 1, row = 19 }, start = { col = 20, row = 17 } } (Newlines [ 0 @@ -4131,19 +4204,19 @@ Hi. case""" 0 ) , Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 7, row = 19 }, start = { col = 2, row = 19 } } (Token (Identifier { name = "sjhsf", qualifiers = [] })) + , Located { end = { col = 7, row = 19 }, start = { col = 2, row = 19 } } (Token (Identifier { name = TokenLowerCase (LowerCase "sjhsf"), qualifiers = [] })) , Located { end = { col = 8, row = 19 }, start = { col = 7, row = 19 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 9, row = 19 }, start = { col = 8, row = 19 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 23, row = 19 }, start = { col = 9, row = 19 } } (Token (RecordAccessorFunction "helloFunction")) + , Located { end = { col = 23, row = 19 }, start = { col = 9, row = 19 } } (Token (RecordAccessorFunction (LowerCase "helloFunction"))) , Located { end = { col = 1, row = 21 }, start = { col = 23, row = 19 } } (Newlines [ 0 ] 0 ) - , Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } (Token (Identifier { name = "sfhsdf", qualifiers = [] })) + , Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } (Token (Identifier { name = TokenLowerCase (LowerCase "sfhsdf"), qualifiers = [] })) , Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 22, row = 21 }, start = { col = 8, row = 21 } } (Token (RecordAccessorFunction "helloFunction")) + , Located { end = { col = 22, row = 21 }, start = { col = 8, row = 21 } } (Token (RecordAccessorFunction (LowerCase "helloFunction"))) , Located { end = { col = 23, row = 21 }, start = { col = 22, row = 21 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 23 }, start = { col = 23, row = 21 } } (Newlines @@ -4152,7 +4225,7 @@ Hi. case""" 0 ) , Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Token (Keyword Case)) - , Located { end = { col = 8, row = 23 }, start = { col = 5, row = 23 } } (Token (RecordAccessorFunction "hi")) + , Located { end = { col = 8, row = 23 }, start = { col = 5, row = 23 } } (Token (RecordAccessorFunction (LowerCase "hi"))) , Located { end = { col = 1, row = 25 }, start = { col = 8, row = 23 } } (Newlines [ 0 @@ -4162,9 +4235,9 @@ Hi. case""" , Located { end = { col = 8, row = 25 }, start = { col = 1, row = 25 } } (Token (Identifier - { name = "case" + { name = TokenLowerCase (LowerCase "case") , qualifiers = - [ "Hi" + [ UpperCase "Hi" ] } ) @@ -4177,14 +4250,14 @@ Hi. case""" ) , Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Token (Keyword Case)) , Located { end = { col = 6, row = 27 }, start = { col = 5, row = 27 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 9, row = 27 }, start = { col = 6, row = 27 } } (Token (RecordAccessorFunction "hi")) + , Located { end = { col = 9, row = 27 }, start = { col = 6, row = 27 } } (Token (RecordAccessorFunction (LowerCase "hi"))) , Located { end = { col = 1, row = 29 }, start = { col = 9, row = 27 } } (Newlines [ 0 ] 0 ) - , Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = "Hi", qualifiers = [] })) + , Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Hi", qualifiers = [] })) , Located { end = { col = 5, row = 29 }, start = { col = 4, row = 29 } } (Ignorable (Whitespace 1)) , Located { end = { col = 9, row = 29 }, start = { col = 5, row = 29 } } (Token (Keyword Case)) ] @@ -4206,7 +4279,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_MissingFunctionReturnType , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil (Bracket Round Close)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Function" [] (TypeExpressionNestingLeaf_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing, parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }) })) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Function") [] (TypeExpressionNestingLeaf_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing, parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }) })) } ] , lexed = @@ -4215,7 +4288,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Function", qualifiers = [] })) + , Located { end = { col = 20, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function"), qualifiers = [] })) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) @@ -4236,13 +4309,13 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = "Function2", qualifiers = [] })) + , Located { end = { col = 21, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function2"), qualifiers = [] })) , Located { end = { col = 22, row = 3 }, start = { col = 21, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 3 }, start = { col = 22, row = 3 } } (Token (Sigil Assign)) , Located { end = { col = 24, row = 3 }, start = { col = 23, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 25, row = 3 }, start = { col = 24, row = 3 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 26, row = 3 }, start = { col = 25, row = 3 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = "a", qualifiers = [] })) + , Located { end = { col = 27, row = 3 }, start = { col = 26, row = 3 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) , Located { end = { col = 28, row = 3 }, start = { col = 27, row = 3 } } (Token (Sigil Colon)) , Located { end = { col = 29, row = 3 }, start = { col = 28, row = 3 } } (Ignorable (Whitespace 1)) , Located { end = { col = 30, row = 3 }, start = { col = 29, row = 3 } } (Token (Sigil (Bracket Round Open))) @@ -4261,7 +4334,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token (Identifier { name = "Function3", qualifiers = [] })) + , Located { end = { col = 21, row = 5 }, start = { col = 12, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function3"), qualifiers = [] })) , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 5 }, start = { col = 22, row = 5 } } (Token (Sigil Assign)) , Located { end = { col = 24, row = 5 }, start = { col = 23, row = 5 } } (Ignorable (Whitespace 1)) @@ -4286,12 +4359,12 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token (Identifier { name = "Function3", qualifiers = [] })) + , Located { end = { col = 21, row = 7 }, start = { col = 12, row = 7 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Function3"), qualifiers = [] })) , Located { end = { col = 22, row = 7 }, start = { col = 21, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Token (Sigil Assign)) , Located { end = { col = 24, row = 7 }, start = { col = 23, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 25, row = 7 }, start = { col = 24, row = 7 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 28, row = 7 }, start = { col = 25, row = 7 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 29, row = 7 }, start = { col = 28, row = 7 } } (Token (Sigil Comma)) , Located { end = { col = 30, row = 7 }, start = { col = 29, row = 7 } } (Ignorable (Whitespace 1)) , Located { end = { col = 31, row = 7 }, start = { col = 30, row = 7 } } (Token (Sigil (Bracket Round Open))) @@ -4315,9 +4388,9 @@ type alias Function3 = (Int, () ->, ()) , contextualized = Just [ Err - { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })) + { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] })) , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = "Int" })))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] })))) } ] , lexed = @@ -4326,12 +4399,12 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open))) @@ -4350,7 +4423,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) } ] , lexed = @@ -4359,7 +4432,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) @@ -4382,7 +4455,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) } ] , lexed = @@ -4391,7 +4464,7 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) @@ -4399,11 +4472,172 @@ type alias Function3 = (Int, () ->, ()) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 20, row = 1 }, start = { col = 19, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 24, row = 1 }, start = { col = 21, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 25, row = 1 } } (Newlines [] 0) ] } + , { name = "type-alias-lower-case-types" + , source = """type alias A = B.C.d + +type alias B = List A.d + +type alias C = list A + +type alias D a = a -> B.c +type alias E a = B.c -> a""" + , pretty = """ + ( ( Err, todo ) ) +""" + , contextualized = + Just + [ Err + { error = + Error_LowerCasedTypename + { name = LowerCase "d" + , qualifiers = + [ UpperCase "B" + , UpperCase "C" + ] + } + , item = + Just + (Located { end = { col = 21, row = 1 }, start = { col = 16, row = 1 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "d") + , qualifiers = + [ UpperCase "B" + , UpperCase "C" + ] + } + ) + ) + ) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (UpperCase "A") []) + } + ] + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 1 }, start = { col = 16, row = 1 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "d") + , qualifiers = + [ UpperCase "B" + , UpperCase "C" + ] + } + ) + ) + , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "B"), qualifiers = [] })) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 3 }, start = { col = 16, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 3 }, start = { col = 21, row = 3 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "d") + , qualifiers = + [ UpperCase "A" + ] + } + ) + ) + , Located { end = { col = 1, row = 5 }, start = { col = 24, row = 3 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 5 }, start = { col = 1, row = 5 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 5 }, start = { col = 5, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 5 }, start = { col = 6, row = 5 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 5 }, start = { col = 11, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 5 }, start = { col = 12, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) + , Located { end = { col = 14, row = 5 }, start = { col = 13, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 5 }, start = { col = 14, row = 5 } } (Token (Sigil Assign)) + , Located { end = { col = 16, row = 5 }, start = { col = 15, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 5 }, start = { col = 16, row = 5 } } (Token (Identifier { name = TokenLowerCase (LowerCase "list"), qualifiers = [] })) + , Located { end = { col = 21, row = 5 }, start = { col = 20, row = 5 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) + , Located { end = { col = 1, row = 7 }, start = { col = 22, row = 5 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 7 }, start = { col = 1, row = 7 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 7 }, start = { col = 5, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 7 }, start = { col = 6, row = 7 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 7 }, start = { col = 11, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 7 }, start = { col = 12, row = 7 } } (Token (Identifier { name = TokenUpperCase (UpperCase "D"), qualifiers = [] })) + , Located { end = { col = 14, row = 7 }, start = { col = 13, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 7 }, start = { col = 14, row = 7 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) + , Located { end = { col = 16, row = 7 }, start = { col = 15, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 7 }, start = { col = 16, row = 7 } } (Token (Sigil Assign)) + , Located { end = { col = 18, row = 7 }, start = { col = 17, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 19, row = 7 }, start = { col = 18, row = 7 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) + , Located { end = { col = 20, row = 7 }, start = { col = 19, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 22, row = 7 }, start = { col = 20, row = 7 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 23, row = 7 }, start = { col = 22, row = 7 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 7 }, start = { col = 23, row = 7 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "c") + , qualifiers = + [ UpperCase "B" + ] + } + ) + ) + , Located { end = { col = 1, row = 8 }, start = { col = 26, row = 7 } } (Newlines [] 0) + , Located { end = { col = 5, row = 8 }, start = { col = 1, row = 8 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 8 }, start = { col = 5, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 8 }, start = { col = 6, row = 8 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 8 }, start = { col = 11, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 8 }, start = { col = 12, row = 8 } } (Token (Identifier { name = TokenUpperCase (UpperCase "E"), qualifiers = [] })) + , Located { end = { col = 14, row = 8 }, start = { col = 13, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 8 }, start = { col = 14, row = 8 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) + , Located { end = { col = 16, row = 8 }, start = { col = 15, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 17, row = 8 }, start = { col = 16, row = 8 } } (Token (Sigil Assign)) + , Located { end = { col = 18, row = 8 }, start = { col = 17, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 8 }, start = { col = 18, row = 8 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "c") + , qualifiers = + [ UpperCase "B" + ] + } + ) + ) + , Located { end = { col = 22, row = 8 }, start = { col = 21, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 24, row = 8 }, start = { col = 22, row = 8 } } (Token (Sigil ThinArrow)) + , Located { end = { col = 25, row = 8 }, start = { col = 24, row = 8 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 8 }, start = { col = 25, row = 8 } } (Token (Identifier { name = TokenLowerCase (LowerCase "a"), qualifiers = [] })) + ] + } , { name = "type-alias-multiline-missing-indentation" , source = """type alias Model = List Int @@ -4418,21 +4652,12 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns "Model" []) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (UpperCase "Model") []) } , Err - { error = Error_PartwayThroughBlock - , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0)) - , state = - State_BlockValueDeclaration - (BlockValueDeclaration_Named - { args = - Stack - [ Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } "Int" - ] - , name = Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } "List" - } - ) + { error = Error_BlockStartsWithUpperCase (UpperCase "List") + , item = Just (Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] }))) + , state = State_BlockStart } ] , lexed = @@ -4441,13 +4666,13 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Model", qualifiers = [] })) + , Located { end = { col = 17, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Model"), qualifiers = [] })) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 1, row = 2 }, start = { col = 19, row = 1 } } (Newlines [] 0) - , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = "List", qualifiers = [] })) + , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 9, row = 2 }, start = { col = 6, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 9, row = 2 } } (Newlines [] 0) ] } @@ -4484,7 +4709,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Named "Hi" (Stack [])) + , state = State_BlockTypeAlias (BlockTypeAlias_Named (UpperCase "Hi") (Stack [])) } ] , lexed = @@ -4493,7 +4718,7 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 1, row = 2 }, start = { col = 14, row = 1 } } (Newlines [] 0) ] } @@ -4508,7 +4733,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns "Hi" []) + , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (UpperCase "Hi") []) } ] , lexed = @@ -4517,7 +4742,7 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 1, row = 2 }, start = { col = 16, row = 1 } } (Newlines [] 0) @@ -4534,7 +4759,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing })) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing })) } ] , lexed = @@ -4543,7 +4768,7 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) @@ -4563,7 +4788,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Hi" [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = "Int", parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }) })) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "Int", parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }), qualifiers = [] })) } ] , lexed = @@ -4572,13 +4797,13 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 9, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 8) - , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 12, row = 2 }, start = { col = 9, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0) ] } @@ -4593,7 +4818,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 18, row = 1 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] (TypeExpressionNestingLeaf_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty, parent = Nothing })) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Ty") [] (TypeExpressionNestingLeaf_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Empty, parent = Nothing })) } ] , lexed = @@ -4602,7 +4827,7 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) @@ -4620,8 +4845,8 @@ List Int Just [ Err { error = Error_ExpectedColonWhilstParsingRecord - , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = "j7", qualifiers = [] }))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish "Ty" [] (TypeExpressionNestingLeaf_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key "hi", parent = Nothing })) + , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "j7"), qualifiers = [] }))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Ty") [] (TypeExpressionNestingLeaf_PartialRecord { firstEntries = Stack [], lastEntry = LastEntryOfRecord_Key (LowerCase "hi"), parent = Nothing })) } ] , lexed = @@ -4630,15 +4855,15 @@ List Int , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Ty", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Ty"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Curly Open))) , Located { end = { col = 19, row = 1 }, start = { col = 18, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = "hi", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 19, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "hi"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = "j7", qualifiers = [] })) + , Located { end = { col = 24, row = 1 }, start = { col = 22, row = 1 } } (Token (Identifier { name = TokenLowerCase (LowerCase "j7"), qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Sigil (Bracket Curly Close))) , Located { end = { col = 1, row = 2 }, start = { col = 26, row = 1 } } (Newlines [] 0) @@ -4691,14 +4916,14 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0)) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish "Hi" + (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr - (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = "Int" }) - (TypeExpression_NamedType { args = Stack [], name = "A" }) - [ TypeExpression_NamedType { args = Stack [], name = "B" } - , TypeExpression_NamedType { args = Stack [], name = "C" } - , TypeExpression_NamedType { args = Stack [], name = "D" } + (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] }) + (TypeExpression_NamedType { args = Stack [], name = UpperCase "A", qualifiers = [] }) + [ TypeExpression_NamedType { args = Stack [], name = UpperCase "B", qualifiers = [] } + , TypeExpression_NamedType { args = Stack [], name = UpperCase "C", qualifiers = [] } + , TypeExpression_NamedType { args = Stack [], name = UpperCase "D", qualifiers = [] } ] ) ) @@ -4791,26 +5016,28 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0)) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish "Hi" + (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } + [ TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] } ] - , name = "A" + , name = UpperCase "A" + , qualifiers = [] } ) (TypeExpression_NamedType { args = Stack - [ TypeExpression_NamedType { args = Stack [], name = "F" } - , TypeExpression_NamedType { args = Stack [], name = "E" } - , TypeExpression_NamedType { args = Stack [], name = "D" } + [ TypeExpression_NamedType { args = Stack [], name = UpperCase "F", qualifiers = [] } + , TypeExpression_NamedType { args = Stack [], name = UpperCase "E", qualifiers = [] } + , TypeExpression_NamedType { args = Stack [], name = UpperCase "D", qualifiers = [] } ] - , name = "C" + , name = UpperCase "C" + , qualifiers = [] } ) [ TypeExpression_NamedType @@ -4820,24 +5047,27 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) (TypeExpression_NamedType { args = Stack - [ TypeExpression_NamedType { args = Stack [], name = "K" } + [ TypeExpression_NamedType { args = Stack [], name = UpperCase "K", qualifiers = [] } ] - , name = "J" + , name = UpperCase "J" + , qualifiers = [] } ) - , TypeExpression_NamedType { args = Stack [], name = "I" } + , TypeExpression_NamedType { args = Stack [], name = UpperCase "I", qualifiers = [] } ] - , name = "H" + , name = UpperCase "H" + , qualifiers = [] } , TypeExpression_NamedType { args = Stack - [ TypeExpression_NamedType { args = Stack [], name = "P" } - , TypeExpression_NamedType { args = Stack [], name = "O" } + [ TypeExpression_NamedType { args = Stack [], name = UpperCase "P", qualifiers = [] } + , TypeExpression_NamedType { args = Stack [], name = UpperCase "O", qualifiers = [] } , TypeExpression_Unit - , TypeExpression_NamedType { args = Stack [], name = "M" } + , TypeExpression_NamedType { args = Stack [], name = UpperCase "M", qualifiers = [] } ] - , name = "L" + , name = UpperCase "L" + , qualifiers = [] } ] ) @@ -4851,70 +5081,70 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Identifier { name = "B", qualifiers = [] })) + , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "B"), qualifiers = [] })) , Located { end = { col = 28, row = 1 }, start = { col = 27, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 29, row = 1 }, start = { col = 28, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 30, row = 1 }, start = { col = 29, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) , Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 32, row = 1 }, start = { col = 31, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 33, row = 1 }, start = { col = 32, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "D"), qualifiers = [] })) , Located { end = { col = 34, row = 1 }, start = { col = 33, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 34, row = 1 } } (Newlines [] 0) , Located { end = { col = 5, row = 2 }, start = { col = 1, row = 2 } } (Token (Keyword Type)) , Located { end = { col = 6, row = 2 }, start = { col = 5, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 2 }, start = { col = 6, row = 2 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 2 }, start = { col = 11, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 2 }, start = { col = 12, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 2 }, start = { col = 14, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 2 }, start = { col = 15, row = 2 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 2 }, start = { col = 16, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 2 }, start = { col = 17, row = 2 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 19, row = 2 }, start = { col = 18, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) , Located { end = { col = 20, row = 2 }, start = { col = 19, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 23, row = 2 }, start = { col = 20, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 24, row = 2 }, start = { col = 23, row = 2 } } (Token (Sigil Comma)) , Located { end = { col = 25, row = 2 }, start = { col = 24, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Token (Identifier { name = "C", qualifiers = [] })) + , Located { end = { col = 26, row = 2 }, start = { col = 25, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "C"), qualifiers = [] })) , Located { end = { col = 27, row = 2 }, start = { col = 26, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token (Identifier { name = "D", qualifiers = [] })) + , Located { end = { col = 28, row = 2 }, start = { col = 27, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "D"), qualifiers = [] })) , Located { end = { col = 29, row = 2 }, start = { col = 28, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Token (Identifier { name = "E", qualifiers = [] })) + , Located { end = { col = 30, row = 2 }, start = { col = 29, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "E"), qualifiers = [] })) , Located { end = { col = 31, row = 2 }, start = { col = 30, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Token (Identifier { name = "F", qualifiers = [] })) + , Located { end = { col = 32, row = 2 }, start = { col = 31, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "F"), qualifiers = [] })) , Located { end = { col = 33, row = 2 }, start = { col = 32, row = 2 } } (Token (Sigil Comma)) , Located { end = { col = 34, row = 2 }, start = { col = 33, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Token (Identifier { name = "H", qualifiers = [] })) + , Located { end = { col = 35, row = 2 }, start = { col = 34, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "H"), qualifiers = [] })) , Located { end = { col = 36, row = 2 }, start = { col = 35, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Token (Identifier { name = "I", qualifiers = [] })) + , Located { end = { col = 37, row = 2 }, start = { col = 36, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "I"), qualifiers = [] })) , Located { end = { col = 38, row = 2 }, start = { col = 37, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 39, row = 2 }, start = { col = 38, row = 2 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Token (Identifier { name = "J", qualifiers = [] })) + , Located { end = { col = 40, row = 2 }, start = { col = 39, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "J"), qualifiers = [] })) , Located { end = { col = 41, row = 2 }, start = { col = 40, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Token (Identifier { name = "K", qualifiers = [] })) + , Located { end = { col = 42, row = 2 }, start = { col = 41, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "K"), qualifiers = [] })) , Located { end = { col = 43, row = 2 }, start = { col = 42, row = 2 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 44, row = 2 }, start = { col = 43, row = 2 } } (Token (Sigil Comma)) , Located { end = { col = 45, row = 2 }, start = { col = 44, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Token (Identifier { name = "L", qualifiers = [] })) + , Located { end = { col = 46, row = 2 }, start = { col = 45, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "L"), qualifiers = [] })) , Located { end = { col = 47, row = 2 }, start = { col = 46, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Token (Identifier { name = "M", qualifiers = [] })) + , Located { end = { col = 48, row = 2 }, start = { col = 47, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "M"), qualifiers = [] })) , Located { end = { col = 49, row = 2 }, start = { col = 48, row = 2 } } (Ignorable (Whitespace 1)) , Located { end = { col = 50, row = 2 }, start = { col = 49, row = 2 } } (Token (Sigil (Bracket Round Open))) , Located { end = { col = 51, row = 2 }, start = { col = 50, row = 2 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 52, row = 2 }, start = { col = 51, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Token (Identifier { name = "O", qualifiers = [] })) + , Located { end = { col = 53, row = 2 }, start = { col = 52, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "O"), qualifiers = [] })) , Located { end = { col = 54, row = 2 }, start = { col = 53, row = 2 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Token (Identifier { name = "P", qualifiers = [] })) + , Located { end = { col = 55, row = 2 }, start = { col = 54, row = 2 } } (Token (Identifier { name = TokenUpperCase (UpperCase "P"), qualifiers = [] })) , Located { end = { col = 56, row = 2 }, start = { col = 55, row = 2 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 3 }, start = { col = 56, row = 2 } } (Newlines [] 0) ] @@ -4932,12 +5162,12 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil Comma))) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish "Hi" + (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } + [ TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] } ] , parent = Nothing , trailingExpression = Nothing @@ -4952,17 +5182,17 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 23, row = 1 }, start = { col = 22, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 25, row = 1 }, start = { col = 24, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = "A", qualifiers = [] })) + , Located { end = { col = 26, row = 1 }, start = { col = 25, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) , Located { end = { col = 27, row = 1 }, start = { col = 26, row = 1 } } (Token (Sigil (Bracket Round Close))) , Located { end = { col = 1, row = 2 }, start = { col = 27, row = 1 } } (Newlines [] 0) ] @@ -4993,12 +5223,12 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) ) , state = State_BlockTypeAlias - (BlockTypeAlias_Completish "Hi" + (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack - [ TypeExpression_NamedType { args = Stack [], name = "Int" } + [ TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] } ] , parent = Nothing , trailingExpression = Nothing @@ -5013,12 +5243,12 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) - , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = "Hi", qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Hi"), qualifiers = [] })) , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Token (Sigil Assign)) , Located { end = { col = 17, row = 1 }, start = { col = 16, row = 1 } } (Ignorable (Whitespace 1)) , Located { end = { col = 18, row = 1 }, start = { col = 17, row = 1 } } (Token (Sigil (Bracket Round Open))) - , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = "Int", qualifiers = [] })) + , Located { end = { col = 21, row = 1 }, start = { col = 18, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "Int"), qualifiers = [] })) , Located { end = { col = 22, row = 1 }, start = { col = 21, row = 1 } } (Token (Sigil Comma)) , Located { end = { col = 1, row = 5 }, start = { col = 22, row = 1 } } (Newlines From f02c872af0347be91a7312b2c34d751284afd4e4 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 22 Oct 2020 22:08:45 +0100 Subject: [PATCH 088/103] do not stop parsing on first error Oops! We should leave "error recovery mode" when we see a non-indented line. We were not doing so. --- src/Stage/Parse/Contextualize.elm | 49 +++--- tests/ParserLexerTestCases.elm | 261 +++++++++++++++++++++++++++++- 2 files changed, 284 insertions(+), 26 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 6b38d46c..34d9afbc 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -484,7 +484,7 @@ parseAnything state item = Lexer.Newlines _ 0 -> case state of State_Error_Recovery -> - State_Error_Recovery + State_BlockStart |> ParseResult_Ok State_BlockStart -> @@ -1257,30 +1257,31 @@ exprAppend currentLeaf token = } |> Err - doesNotTakeArgsError expr = + genericType = if token.qualifiers == [] then - Error_TypeDoesNotTakeArgs expr - (TypeExpression_GenericType lower) - |> Err + TypeExpression_GenericType lower + |> Ok else lowerCaseTypeError + + doesNotTakeArgsError expr = + Result.andThen (Error_TypeDoesNotTakeArgs expr >> Err) genericType in case currentLeaf of -- We are within a nested bracket. TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> case trailingExpression of Nothing -> - if token.qualifiers == [] then - TypeExpressionNestingLeaf_Bracket - { firstExpressions = firstExpressions - , trailingExpression = Just (TypeExpression_GenericType lower) - , parent = parent - } - |> Ok - - else - lowerCaseTypeError + genericType + |> Result.map + (\ty -> + TypeExpressionNestingLeaf_Bracket + { firstExpressions = firstExpressions + , trailingExpression = Just ty + , parent = parent + } + ) Just existingRoot -> doesNotTakeArgsError existingRoot @@ -1307,16 +1308,22 @@ exprAppend currentLeaf token = |> Err _ -> - leafToParent currentLeaf - |> Result.map (Just >> parentsToLeafWith (TypeExpression_GenericType lower)) + Result.map2 + (\newParent gt -> parentsToLeafWith gt (Just newParent)) + (leafToParent currentLeaf) + genericType TypeExpressionNestingLeaf_TypeWithArgs _ -> - leafToParent currentLeaf - |> Result.map (Just >> parentsToLeafWith (TypeExpression_GenericType lower)) + Result.map2 + (\newParent gt -> parentsToLeafWith gt (Just newParent)) + (leafToParent currentLeaf) + genericType TypeExpressionNestingLeaf_Function _ -> - leafToParent currentLeaf - |> Result.map (Just >> parentsToLeafWith (TypeExpression_GenericType lower)) + Result.map2 + (\newParent gt -> parentsToLeafWith gt (Just newParent)) + (leafToParent currentLeaf) + genericType Token.TokenUpperCase upper -> let diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 73c35226..3085e1c3 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -4060,6 +4060,17 @@ Hi. case""" , ( Err, todo ) , ( Err, todo ) , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) ) """ , contextualized = @@ -4069,6 +4080,54 @@ Hi. case""" , item = Just (Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Foo", qualifiers = [] }))) , state = State_BlockStart } + , Err + { error = + Error_BlockStartsWithQualifiedName + { name = TokenUpperCase (UpperCase "Bar") + , qualifiers = + [ UpperCase "Foo" + ] + } + , item = + Just + (Located { end = { col = 8, row = 3 }, start = { col = 1, row = 3 } } + (Token + (Identifier + { name = TokenUpperCase (UpperCase "Bar") + , qualifiers = + [ UpperCase "Foo" + ] + } + ) + ) + ) + , state = State_BlockStart + } + , Err + { error = + Error_BlockStartsWithQualifiedName + { name = TokenLowerCase (LowerCase "baz") + , qualifiers = + [ UpperCase "Foo" + , UpperCase "Bar" + ] + } + , item = + Just + (Located { end = { col = 12, row = 5 }, start = { col = 1, row = 5 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "baz") + , qualifiers = + [ UpperCase "Foo" + , UpperCase "Bar" + ] + } + ) + ) + ) + , state = State_BlockStart + } , Err { error = Error_InvalidToken Expecting_Unknown , item = @@ -4084,22 +4143,85 @@ Hi. case""" ) ) ) - , state = State_Error_Recovery + , state = State_BlockStart } , Err { error = Error_InvalidToken Expecting_Unknown , item = Just (Located { end = { col = 5, row = 9 }, start = { col = 1, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Bor", qualifiers = [] }))) - , state = State_Error_Recovery + , state = State_BlockStart } , Err { error = Error_InvalidToken Expecting_Unknown , item = Just (Located { end = { col = 10, row = 9 }, start = { col = 6, row = 9 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Big", qualifiers = [] }))) , state = State_Error_Recovery } + , Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 4, row = 11 }, start = { col = 1, row = 11 } } (Token (RecordAccessorFunction (LowerCase "sf")))) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken (Expecting_Sigil Assign) + , item = Just (Located { end = { col = 13, row = 13 }, start = { col = 7, row = 13 } } (Token (RecordAccessorFunction (LowerCase "sdfsd")))) + , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 6, row = 13 }, start = { col = 1, row = 13 } } (LowerCase "sfsdf") }) + } + , Err + { error = Error_InvalidToken (Expecting_Sigil Assign) + , item = Just (Located { end = { col = 15, row = 15 }, start = { col = 7, row = 15 } } (Token (RecordAccessorLiteral (LowerCase "sdgsghj")))) + , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 7, row = 15 }, start = { col = 1, row = 15 } } (LowerCase "asfasf") }) + } + , Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 2, row = 17 }, start = { col = 1, row = 17 } } (Token (Sigil (Bracket Round Open)))) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken Expecting_Block + , item = Just (Located { end = { col = 2, row = 19 }, start = { col = 1, row = 19 } } (Token (Sigil (Bracket Round Open)))) + , state = State_BlockStart + } + , Err + { error = Error_InvalidToken (Expecting_Sigil Assign) + , item = Just (Located { end = { col = 8, row = 21 }, start = { col = 7, row = 21 } } (Token (Sigil (Bracket Round Open)))) + , state = State_BlockValueDeclaration (BlockValueDeclaration_Named { args = Stack [], name = Located { end = { col = 7, row = 21 }, start = { col = 1, row = 21 } } (LowerCase "sfhsdf") }) + } + , Err + { error = Error_MisplacedKeyword Case + , item = Just (Located { end = { col = 5, row = 23 }, start = { col = 1, row = 23 } } (Token (Keyword Case))) + , state = State_BlockStart + } + , Err + { error = + Error_BlockStartsWithQualifiedName + { name = TokenLowerCase (LowerCase "case") + , qualifiers = + [ UpperCase "Hi" + ] + } + , item = + Just + (Located { end = { col = 8, row = 25 }, start = { col = 1, row = 25 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "case") + , qualifiers = + [ UpperCase "Hi" + ] + } + ) + ) + ) + , state = State_BlockStart + } + , Err + { error = Error_MisplacedKeyword Case + , item = Just (Located { end = { col = 5, row = 27 }, start = { col = 1, row = 27 } } (Token (Keyword Case))) + , state = State_BlockStart + } , Err { error = Error_InvalidToken Expecting_Unknown , item = Just (Located { end = { col = 4, row = 29 }, start = { col = 1, row = 29 } } (Invalid (IdentifierWithTrailingDot { name = UpperCase "Hi", qualifiers = [] }))) - , state = State_Error_Recovery + , state = State_BlockStart } ] , lexed = @@ -4272,7 +4394,11 @@ type alias Function3 = (() -> , ()) type alias Function3 = (Int, () ->, ()) """ , pretty = """ - ( ( Err, todo ) ) + ( ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + ) """ , contextualized = Just @@ -4281,6 +4407,41 @@ type alias Function3 = (Int, () ->, ()) , item = Just (Located { end = { col = 31, row = 1 }, start = { col = 30, row = 1 } } (Token (Sigil (Bracket Round Close)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Function") [] (TypeExpressionNestingLeaf_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing, parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }) })) } + , Err + { error = Error_MissingFunctionReturnType + , item = Just (Located { end = { col = 37, row = 3 }, start = { col = 36, row = 3 } } (Token (Sigil (Bracket Curly Close)))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Function2") [] (TypeExpressionNestingLeaf_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing, parent = Just (NestingParentType_PartialRecord { firstEntries = Stack [], lastEntryName = LowerCase "a", parent = Nothing }) })) + } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 32, row = 5 }, start = { col = 31, row = 5 } } (Token (Sigil Comma))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Function3") [] (TypeExpressionNestingLeaf_Function { firstInput = TypeExpression_Unit, otherInputs = Stack [], output = Nothing, parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }) })) + } + , Err + { error = Error_InvalidToken Expecting_Unknown + , item = Just (Located { end = { col = 36, row = 7 }, start = { col = 35, row = 7 } } (Token (Sigil Comma))) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (UpperCase "Function3") + [] + (TypeExpressionNestingLeaf_Function + { firstInput = TypeExpression_Unit + , otherInputs = Stack [] + , output = Nothing + , parent = + Just + (NestingParentType_Bracket + { expressions = + Stack + [ TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] } + ] + , parent = Nothing + } + ) + } + ) + ) + } ] , lexed = Ok @@ -4487,7 +4648,12 @@ type alias C = list A type alias D a = a -> B.c type alias E a = B.c -> a""" , pretty = """ - ( ( Err, todo ) ) + ( ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + , ( Err, todo ) + ) """ , contextualized = Just @@ -4516,6 +4682,91 @@ type alias E a = B.c -> a""" ) , state = State_BlockTypeAlias (BlockTypeAlias_NamedAssigns (UpperCase "A") []) } + , Err + { error = + Error_LowerCasedTypename + { name = LowerCase "d" + , qualifiers = + [ UpperCase "A" + ] + } + , item = + Just + (Located { end = { col = 24, row = 3 }, start = { col = 21, row = 3 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "d") + , qualifiers = + [ UpperCase "A" + ] + } + ) + ) + ) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "B") [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "List", parent = Nothing, qualifiers = [] })) + } + , Err + { error = Error_TypeDoesNotTakeArgs (TypeExpression_GenericType (LowerCase "list")) (TypeExpression_NamedType { args = Stack [], name = UpperCase "A", qualifiers = [] }) + , item = Just (Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] }))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "C") [] (TypeExpressionNestingLeaf_Expr (TypeExpression_GenericType (LowerCase "list")))) + } + , Err + { error = + Error_LowerCasedTypename + { name = LowerCase "c" + , qualifiers = + [ UpperCase "B" + ] + } + , item = + Just + (Located { end = { col = 26, row = 7 }, start = { col = 23, row = 7 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "c") + , qualifiers = + [ UpperCase "B" + ] + } + ) + ) + ) + , state = + State_BlockTypeAlias + (BlockTypeAlias_Completish (UpperCase "D") + [ LowerCase "a" + ] + (TypeExpressionNestingLeaf_Function { firstInput = TypeExpression_GenericType (LowerCase "a"), otherInputs = Stack [], output = Nothing, parent = Nothing }) + ) + } + , Err + { error = + Error_LowerCasedTypename + { name = LowerCase "c" + , qualifiers = + [ UpperCase "B" + ] + } + , item = + Just + (Located { end = { col = 21, row = 8 }, start = { col = 18, row = 8 } } + (Token + (Identifier + { name = TokenLowerCase (LowerCase "c") + , qualifiers = + [ UpperCase "B" + ] + } + ) + ) + ) + , state = + State_BlockTypeAlias + (BlockTypeAlias_NamedAssigns (UpperCase "E") + [ LowerCase "a" + ] + ) + } ] , lexed = Ok From f16d3c30aa4ce024de39fd6f625695e1f1cdfcd3 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Thu, 22 Oct 2020 22:26:35 +0100 Subject: [PATCH 089/103] we do not need partial results This was an extra layer we do not need. Expressions are never done until they have to be done due to a newline. Therefore, we only ever used the progress variant unless we are parsing the newline token. Because we now parse newline tokens at a nice an high level of the parser we can deal with them nicely. --- src/Stage/Parse/Contextualize.elm | 113 +++++++++++------------------- 1 file changed, 42 insertions(+), 71 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 34d9afbc..46f978db 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -225,15 +225,6 @@ type TypeExpressionNestingLeaf | TypeExpressionNestingLeaf_Expr TypeExpression -type PartialResult progress done - = PartialResult_Progress progress - | PartialResult_Done done - - -type alias TypeExpressionResult = - PartialResult TypeExpressionNestingLeaf TypeExpression - - -- EXPRESSIONS -- @@ -256,10 +247,6 @@ type ExpressionNestingLeaf | ExpressionTypeExpressionNestingLeaf_Expr Frontend.LocatedExpr -type alias ExpressionResult = - PartialResult ExpressionNestingLeaf Frontend.LocatedExpr - - type Error = Error_InvalidToken Expecting | Error_MisplacedKeyword Keyword @@ -432,47 +419,45 @@ runHelp items state = parseAnything : State -> Located Lexer.LexItem -> ParseResult parseAnything state item = let - newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> PartialResult TypeExpressionNestingLeaf TypeExpression -> ParseResult - newTypeAliasState aliasName typeArgs res = - case res of - PartialResult_Progress expr -> - State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs expr) - |> ParseResult_Ok - - PartialResult_Done expr -> - case partialTypeExpressionToConcreteType expr of - Ok concreteType -> - { ty = aliasName - , genericArgs = typeArgs - , expr = concreteType - } - |> TypeAlias - |> ParseResult_Complete + newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> TypeExpressionNestingLeaf -> ParseResult + newTypeAliasState aliasName typeArgs expr = + State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs expr) + |> ParseResult_Ok - Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> - Error_TooManyTupleArgs a b c d e - |> ParseResult_Err + doneParsingTypeAlias : Token.UpperCase -> List Token.LowerCase -> TypeExpression -> ParseResult + doneParsingTypeAlias aliasName typeArgs expr = + case partialTypeExpressionToConcreteType expr of + Ok concreteType -> + { ty = aliasName + , genericArgs = typeArgs + , expr = concreteType + } + |> TypeAlias + |> ParseResult_Complete - newExpressionState : Located Token.LowerCase -> List (Located Token.LowerCase) -> PartialResult ExpressionNestingLeaf LocatedExpr -> ParseResult - newExpressionState name args res = - case res of - PartialResult_Progress expr -> - State_BlockValueDeclaration - (BlockValueDeclaration_Completish - { name = name - , args = args - , partialExpr = expr - } - ) - |> ParseResult_Ok + Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> + Error_TooManyTupleArgs a b c d e + |> ParseResult_Err - PartialResult_Done expr -> + newExpressionState : Located Token.LowerCase -> List (Located Token.LowerCase) -> ExpressionNestingLeaf -> ParseResult + newExpressionState name args expr = + State_BlockValueDeclaration + (BlockValueDeclaration_Completish { name = name , args = args - , valueExpr__ = expr + , partialExpr = expr } - |> ValueDeclaration - |> ParseResult_Complete + ) + |> ParseResult_Ok + + doneParsingExpr : Located Token.LowerCase -> List (Located Token.LowerCase) -> LocatedExpr -> ParseResult + doneParsingExpr name args expr = + { name = name + , args = args + , valueExpr__ = expr + } + |> ValueDeclaration + |> ParseResult_Complete region = Located.getRegion item @@ -512,17 +497,14 @@ parseAnything state item = case rhs of Just rhs_ -> collapseOperators { op = op, lhs = lhs, parent = parent } rhs_ - |> PartialResult_Done - |> newExpressionState name args + |> doneParsingExpr name args Nothing -> Error_PartwayThroughBlock |> ParseResult_Err ExpressionTypeExpressionNestingLeaf_Expr expr -> - expr - |> PartialResult_Done - |> newExpressionState name args + doneParsingExpr name args expr State_BlockTypeAlias BlockTypeAlias_Keywords -> Error_PartwayThroughBlock @@ -539,8 +521,7 @@ parseAnything state item = State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> case autoCollapseNesting CollapseLevel_Function exprSoFar of TypeExpressionNestingLeaf_Expr expr -> - PartialResult_Done expr - |> newTypeAliasState name typeArgs + doneParsingTypeAlias name typeArgs expr _ -> Error_PartwayThroughBlock @@ -801,7 +782,7 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = parserTypeExprFromEmpty : - (TypeExpressionResult -> ParseResult) + (TypeExpressionNestingLeaf -> ParseResult) -> Located Lexer.LexToken -> ParseResult parserTypeExprFromEmpty newState item = @@ -812,7 +793,6 @@ parserTypeExprFromEmpty newState item = if qualifiers == [] then TypeExpression_GenericType lower |> TypeExpressionNestingLeaf_Expr - |> PartialResult_Progress |> newState else @@ -833,7 +813,6 @@ parserTypeExprFromEmpty newState item = , args = empty , parent = Nothing } - |> PartialResult_Progress |> newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> @@ -842,7 +821,6 @@ parserTypeExprFromEmpty newState item = , trailingExpression = Nothing , parent = Nothing } - |> PartialResult_Progress |> newState Lexer.Sigil (Lexer.Bracket role Lexer.Close) -> @@ -855,7 +833,6 @@ parserTypeExprFromEmpty newState item = , lastEntry = LastEntryOfRecord_Empty , parent = Nothing } - |> PartialResult_Progress |> newState Lexer.Sigil Lexer.Colon -> @@ -876,7 +853,7 @@ parserTypeExprFromEmpty newState item = parserTypeExpr : - (TypeExpressionResult -> ParseResult) + (TypeExpressionNestingLeaf -> ParseResult) -> TypeExpressionNestingLeaf -> Located Lexer.LexToken -> ParseResult @@ -997,7 +974,6 @@ parserTypeExpr newState prevExpr item = , output = Nothing , parent = Nothing } - |> PartialResult_Progress |> newState TypeExpressionNestingLeaf_TypeWithArgs _ -> @@ -1016,7 +992,6 @@ parserTypeExpr newState prevExpr item = , output = Nothing , parent = parent } - |> PartialResult_Progress |> newState TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> @@ -1033,7 +1008,6 @@ parserTypeExpr newState prevExpr item = |> NestingParentType_Bracket |> Just } - |> PartialResult_Progress |> newState Nothing -> @@ -1067,7 +1041,6 @@ parserTypeExpr newState prevExpr item = |> NestingParentType_PartialRecord |> Just } - |> PartialResult_Progress |> newState _ -> @@ -1076,7 +1049,7 @@ parserTypeExpr newState prevExpr item = parserExpressionFromEmpty : - (ExpressionResult -> ParseResult) + (ExpressionNestingLeaf -> ParseResult) -> Located Lexer.LexToken -> ParseResult parserExpressionFromEmpty newState item = @@ -1091,7 +1064,6 @@ parserExpressionFromEmpty newState item = Frontend.Int i |> withCorrectLocation |> ExpressionTypeExpressionNestingLeaf_Expr - |> PartialResult_Progress |> newState Nothing -> @@ -1104,7 +1076,7 @@ parserExpressionFromEmpty newState item = parserExpression : - (ExpressionResult -> ParseResult) + (ExpressionNestingLeaf -> ParseResult) -> ExpressionNestingLeaf -> Located Lexer.LexToken -> ParseResult @@ -1845,14 +1817,13 @@ TODO(harry): We can inline this function. -} partialExpressionToParseResult : - (PartialResult progress neverDone -> ParseResult) + (progress -> ParseResult) -> Result Error progress -> ParseResult partialExpressionToParseResult newState rnewPartialType = case rnewPartialType of Ok newPartialType -> - PartialResult_Progress newPartialType - |> newState + newState newPartialType Err e -> ParseResult_Err e From 776ebcf965c76fe89ac959d65cb52beafb595961 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 23 Oct 2020 18:19:59 +0100 Subject: [PATCH 090/103] use normal results in more places needs tidy up next commit --- src/Stage/Parse/Contextualize.elm | 309 +++++++++++++++--------------- 1 file changed, 159 insertions(+), 150 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 46f978db..f6170374 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -3,7 +3,7 @@ module Stage.Parse.Contextualize exposing (..) {-| Here we define parsers. A parser is function type alias Parser = - Lexer.LexItem -> ParseResult + Lexer.LexItem -> Result Error State that takes one lexed item and produces either an error or some state (it can also choose to skip the lexed item). @@ -419,10 +419,10 @@ runHelp items state = parseAnything : State -> Located Lexer.LexItem -> ParseResult parseAnything state item = let - newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> TypeExpressionNestingLeaf -> ParseResult + newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> TypeExpressionNestingLeaf -> Result Error State newTypeAliasState aliasName typeArgs expr = State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs expr) - |> ParseResult_Ok + |> Ok doneParsingTypeAlias : Token.UpperCase -> List Token.LowerCase -> TypeExpression -> ParseResult doneParsingTypeAlias aliasName typeArgs expr = @@ -439,7 +439,7 @@ parseAnything state item = Error_TooManyTupleArgs a b c d e |> ParseResult_Err - newExpressionState : Located Token.LowerCase -> List (Located Token.LowerCase) -> ExpressionNestingLeaf -> ParseResult + newExpressionState : Located Token.LowerCase -> List (Located Token.LowerCase) -> ExpressionNestingLeaf -> Result Error State newExpressionState name args expr = State_BlockValueDeclaration (BlockValueDeclaration_Completish @@ -448,7 +448,7 @@ parseAnything state item = , partialExpr = expr } ) - |> ParseResult_Ok + |> Ok doneParsingExpr : Located Token.LowerCase -> List (Located Token.LowerCase) -> LocatedExpr -> ParseResult doneParsingExpr name args expr = @@ -541,98 +541,107 @@ parseAnything state item = ParseResult_Skip Lexer.Token token -> - case state of - State_Error_Recovery -> - State_Error_Recovery - |> ParseResult_Ok + let + res = + case state of + State_Error_Recovery -> + State_Error_Recovery + |> Ok - State_BlockStart -> - parseBlockStart region token + State_BlockStart -> + parseBlockStart region token - State_BlockFirstItem BlockFirstItem_Type -> - parseTypeBlock token + State_BlockFirstItem BlockFirstItem_Type -> + parseTypeBlock token - State_BlockFirstItem BlockFirstItem_Module -> - Debug.todo "BlockFirstItem_Module" + State_BlockFirstItem BlockFirstItem_Module -> + Debug.todo "BlockFirstItem_Module" - State_BlockValueDeclaration (BlockValueDeclaration_Named { name, args }) -> - parseLowercaseArgsOrAssignment - (\newArg -> - State_BlockValueDeclaration - (BlockValueDeclaration_Named - { name = name - , args = newArg |> pushOnto args - } + State_BlockValueDeclaration (BlockValueDeclaration_Named { name, args }) -> + parseLowercaseArgsOrAssignment + (\newArg -> + State_BlockValueDeclaration + (BlockValueDeclaration_Named + { name = name + , args = newArg |> pushOnto args + } + ) ) - ) - (State_BlockValueDeclaration - (BlockValueDeclaration_NamedAssigns - { name = name - , args = args |> toList (\x -> x) - } - ) - ) - (Located.located region token) - - State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> - parserExpressionFromEmpty (newExpressionState name args) (Located.located region token) - - State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> - parserExpression - (newExpressionState name args) - partialExpr - (Located.located region token) - - State_BlockTypeAlias BlockTypeAlias_Keywords -> - parseTypeAliasName token - - State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> - parseLowercaseArgsOrAssignment - (\newTypeArg -> - State_BlockTypeAlias - (BlockTypeAlias_Named - name - (Located.unwrap newTypeArg |> pushOnto typeArgs) + (State_BlockValueDeclaration + (BlockValueDeclaration_NamedAssigns + { name = name + , args = args |> toList (\x -> x) + } + ) ) - ) - (State_BlockTypeAlias - (BlockTypeAlias_NamedAssigns - name - (typeArgs |> toList (\x -> x)) - ) - ) - (Located.located region token) - - State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> - parserTypeExprFromEmpty - (newTypeAliasState name typeArgs) - (Located.located region token) - - State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> - parserTypeExpr - (newTypeAliasState name typeArgs) - exprSoFar - (Located.located region token) - - State_BlockCustomType (BlockCustomType_Named name typeArgs) -> - parseLowercaseArgsOrAssignment - (\newTypeArg -> - State_BlockCustomType - (BlockCustomType_Named - name - (Located.unwrap newTypeArg |> pushOnto typeArgs) + (Located.located region token) + + State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> + parserExpressionFromEmpty (newExpressionState name args) (Located.located region token) + + State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> + parserExpression + (newExpressionState name args) + partialExpr + (Located.located region token) + + State_BlockTypeAlias BlockTypeAlias_Keywords -> + parseTypeAliasName token + + State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> + parseLowercaseArgsOrAssignment + (\newTypeArg -> + State_BlockTypeAlias + (BlockTypeAlias_Named + name + (Located.unwrap newTypeArg |> pushOnto typeArgs) + ) ) - ) - (State_BlockCustomType - (BlockCustomType_NamedAssigns - name - (typeArgs |> toList (\x -> x)) - ) - ) - (Located.located region token) + (State_BlockTypeAlias + (BlockTypeAlias_NamedAssigns + name + (typeArgs |> toList (\x -> x)) + ) + ) + (Located.located region token) + + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> + parserTypeExprFromEmpty + (newTypeAliasState name typeArgs) + (Located.located region token) + + State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> + parserTypeExpr + (newTypeAliasState name typeArgs) + exprSoFar + (Located.located region token) + + State_BlockCustomType (BlockCustomType_Named name typeArgs) -> + parseLowercaseArgsOrAssignment + (\newTypeArg -> + State_BlockCustomType + (BlockCustomType_Named + name + (Located.unwrap newTypeArg |> pushOnto typeArgs) + ) + ) + (State_BlockCustomType + (BlockCustomType_NamedAssigns + name + (typeArgs |> toList (\x -> x)) + ) + ) + (Located.located region token) - State_BlockCustomType (BlockCustomType_NamedAssigns _ _) -> - Debug.todo "BlockCustomType_NamedAssigns" + State_BlockCustomType (BlockCustomType_NamedAssigns _ _) -> + Debug.todo "BlockCustomType_NamedAssigns" + in + case res of + Ok s -> + ParseResult_Ok s + + Err e -> + ParseResult_Err e {-| @@ -643,7 +652,7 @@ parseAnything state item = If the LexItem is a `Newlines` with indentation or is `Whitespace`. -} -parseBlockStart : Located.Region -> Lexer.LexToken -> ParseResult +parseBlockStart : Located.Region -> Lexer.LexToken -> Result Error State parseBlockStart region item = let withCorrectLocation = @@ -651,22 +660,22 @@ parseBlockStart region item = in case item of Lexer.Keyword Token.Type -> - ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Type) + Ok (State_BlockFirstItem BlockFirstItem_Type) Lexer.Keyword Token.Module -> - ParseResult_Ok (State_BlockFirstItem BlockFirstItem_Module) + Ok (State_BlockFirstItem BlockFirstItem_Module) Lexer.Keyword other -> - ParseResult_Err (Error_MisplacedKeyword other) + Err (Error_MisplacedKeyword other) Lexer.Identifier ({ qualifiers, name } as identitfier) -> if qualifiers /= [] then - ParseResult_Err (Error_BlockStartsWithQualifiedName identitfier) + Err (Error_BlockStartsWithQualifiedName identitfier) else case name of Token.TokenLowerCase lower -> - ParseResult_Ok + Ok (State_BlockValueDeclaration (BlockValueDeclaration_Named { name = withCorrectLocation lower @@ -677,26 +686,26 @@ parseBlockStart region item = Token.TokenUpperCase upperCase -> Error_BlockStartsWithUpperCase upperCase - |> ParseResult_Err + |> Err _ -> - ParseResult_Err (Error_InvalidToken Expecting_Block) + Err (Error_InvalidToken Expecting_Block) -parseTypeBlock : Lexer.LexToken -> ParseResult +parseTypeBlock : Lexer.LexToken -> Result Error State parseTypeBlock item = case item of Lexer.Keyword Token.Alias -> State_BlockTypeAlias BlockTypeAlias_Keywords - |> ParseResult_Ok + |> Ok Lexer.Keyword other -> Error_MisplacedKeyword other - |> ParseResult_Err + |> Err Lexer.Identifier ({ qualifiers, name } as identifier) -> if qualifiers /= [] then - ParseResult_Err (Error_BlockStartsWithQualifiedName identifier) + Err (Error_BlockStartsWithQualifiedName identifier) else case name of @@ -705,29 +714,29 @@ parseTypeBlock item = { qualifiers = qualifiers , name = lower } - |> ParseResult_Err + |> Err Token.TokenUpperCase upper -> State_BlockCustomType (BlockCustomType_Named upper empty) - |> ParseResult_Ok + |> Ok _ -> -- TODO(harry) indicate that we could also be expecting the `alias` -- keyword. Error_InvalidToken Expecting_TypeName - |> ParseResult_Err + |> Err -parseTypeAliasName : Lexer.LexToken -> ParseResult +parseTypeAliasName : Lexer.LexToken -> Result Error State parseTypeAliasName item = case item of Lexer.Keyword other -> Error_MisplacedKeyword other - |> ParseResult_Err + |> Err Lexer.Identifier ({ qualifiers, name } as identifier) -> if qualifiers /= [] then - ParseResult_Err (Error_BlockStartsWithQualifiedName identifier) + Err (Error_BlockStartsWithQualifiedName identifier) else case name of @@ -736,18 +745,18 @@ parseTypeAliasName item = { qualifiers = qualifiers , name = lower } - |> ParseResult_Err + |> Err Token.TokenUpperCase upper -> State_BlockTypeAlias (BlockTypeAlias_Named upper empty) - |> ParseResult_Ok + |> Ok _ -> Error_InvalidToken Expecting_TypeName - |> ParseResult_Err + |> Err -parseLowercaseArgsOrAssignment : (Located Token.LowerCase -> State) -> State -> Located Lexer.LexToken -> ParseResult +parseLowercaseArgsOrAssignment : (Located Token.LowerCase -> State) -> State -> Located Lexer.LexToken -> Result Error State parseLowercaseArgsOrAssignment onTypeArg onAssignment item = let withCorrectLocation x = @@ -756,35 +765,35 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = case Located.unwrap item of Lexer.Keyword kw -> Error_MisplacedKeyword kw - |> ParseResult_Err + |> Err Lexer.Identifier ({ qualifiers, name } as identifier) -> if qualifiers /= [] then - ParseResult_Err (Error_QualifiedArgName identifier) + Err (Error_QualifiedArgName identifier) else case name of Token.TokenLowerCase lower -> onTypeArg (withCorrectLocation lower) - |> ParseResult_Ok + |> Ok Token.TokenUpperCase upper -> Error_UpperCaseArgName { qualifiers = qualifiers, name = upper } - |> ParseResult_Err + |> Err Lexer.Sigil Lexer.Assign -> onAssignment - |> ParseResult_Ok + |> Ok _ -> Error_InvalidToken (Expecting_Sigil Lexer.Assign) - |> ParseResult_Err + |> Err parserTypeExprFromEmpty : - (TypeExpressionNestingLeaf -> ParseResult) + (TypeExpressionNestingLeaf -> Result Error State) -> Located Lexer.LexToken - -> ParseResult + -> Result Error State parserTypeExprFromEmpty newState item = case Located.unwrap item of Lexer.Identifier { qualifiers, name } -> @@ -800,7 +809,7 @@ parserTypeExprFromEmpty newState item = { qualifiers = qualifiers , name = lower } - |> ParseResult_Err + |> Err Token.TokenUpperCase upper -> if qualifiers /= [] then @@ -825,7 +834,7 @@ parserTypeExprFromEmpty newState item = Lexer.Sigil (Lexer.Bracket role Lexer.Close) -> Error_UnmatchedBracket role Lexer.Close - |> ParseResult_Err + |> Err Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> TypeExpressionNestingLeaf_PartialRecord @@ -837,26 +846,26 @@ parserTypeExprFromEmpty newState item = Lexer.Sigil Lexer.Colon -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err Lexer.Sigil Lexer.Comma -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err Lexer.Sigil Lexer.ThinArrow -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err _ -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err parserTypeExpr : - (TypeExpressionNestingLeaf -> ParseResult) + (TypeExpressionNestingLeaf -> Result Error State) -> TypeExpressionNestingLeaf -> Located Lexer.LexToken - -> ParseResult + -> Result Error State parserTypeExpr newState prevExpr item = case Located.unwrap item of Lexer.Identifier ident -> @@ -883,7 +892,7 @@ parserTypeExpr newState prevExpr item = case collapsedLeaf of TypeExpressionNestingLeaf_Expr _ -> Error_UnmatchedBracket Lexer.Round Lexer.Close - |> ParseResult_Err + |> Err TypeExpressionNestingLeaf_TypeWithArgs { name, args } -> Debug.todo "Make this state impossible" @@ -897,13 +906,13 @@ parserTypeExpr newState prevExpr item = { expecting = Lexer.Curly , found = Lexer.Round } - |> ParseResult_Err + |> Err TypeExpressionNestingLeaf_Function { output } -> case output of Nothing -> Error_MissingFunctionReturnType - |> ParseResult_Err + |> Err Just _ -> Debug.todo "Make this state impossible" @@ -936,7 +945,7 @@ parserTypeExpr newState prevExpr item = case collapsedLeaf of TypeExpressionNestingLeaf_Expr _ -> Error_UnmatchedBracket Lexer.Curly Lexer.Close - |> ParseResult_Err + |> Err TypeExpressionNestingLeaf_TypeWithArgs { name, args } -> Debug.todo "Make this state impossible" @@ -946,7 +955,7 @@ parserTypeExpr newState prevExpr item = { expecting = Lexer.Round , found = Lexer.Curly } - |> ParseResult_Err + |> Err TypeExpressionNestingLeaf_PartialRecord pr -> closeRecord pr @@ -956,7 +965,7 @@ parserTypeExpr newState prevExpr item = case output of Nothing -> Error_MissingFunctionReturnType - |> ParseResult_Err + |> Err Just _ -> Debug.todo "Make this state impossible" @@ -983,7 +992,7 @@ parserTypeExpr newState prevExpr item = case output of Nothing -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err Just output_ -> TypeExpressionNestingLeaf_Function @@ -1012,21 +1021,21 @@ parserTypeExpr newState prevExpr item = Nothing -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of LastEntryOfRecord_Empty -> Error_InvalidToken Expecting_Identifier - |> ParseResult_Err + |> Err LastEntryOfRecord_Key _ -> Error_InvalidToken (Expecting_Sigil Lexer.Colon) - |> ParseResult_Err + |> Err LastEntryOfRecord_KeyColon _ -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err LastEntryOfRecord_KeyValue key value -> TypeExpressionNestingLeaf_Function @@ -1045,13 +1054,13 @@ parserTypeExpr newState prevExpr item = _ -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err parserExpressionFromEmpty : - (ExpressionNestingLeaf -> ParseResult) + (ExpressionNestingLeaf -> Result Error State) -> Located Lexer.LexToken - -> ParseResult + -> Result Error State parserExpressionFromEmpty newState item = let withCorrectLocation x = @@ -1068,18 +1077,18 @@ parserExpressionFromEmpty newState item = Nothing -> Error_InvalidNumericLiteral str - |> ParseResult_Err + |> Err _ -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err parserExpression : - (ExpressionNestingLeaf -> ParseResult) + (ExpressionNestingLeaf -> Result Error State) -> ExpressionNestingLeaf -> Located Lexer.LexToken - -> ParseResult + -> Result Error State parserExpression newState prevExpr item = let withCorrectLocation x = @@ -1100,11 +1109,11 @@ parserExpression newState prevExpr item = Nothing -> Error_InvalidNumericLiteral str - |> ParseResult_Err + |> Err _ -> Error_InvalidToken Expecting_Unknown - |> ParseResult_Err + |> Err @@ -1817,16 +1826,16 @@ TODO(harry): We can inline this function. -} partialExpressionToParseResult : - (progress -> ParseResult) + (progress -> Result Error State) -> Result Error progress - -> ParseResult + -> Result Error State partialExpressionToParseResult newState rnewPartialType = case rnewPartialType of Ok newPartialType -> newState newPartialType Err e -> - ParseResult_Err e + Err e type ToConcreteTypeError From 33a7a7e4f3416076cb45fffe21bc5a869d71bc35 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 23 Oct 2020 18:32:33 +0100 Subject: [PATCH 091/103] more sane results in return types --- src/Stage/Parse/Contextualize.elm | 297 ++++++++++++++---------------- 1 file changed, 134 insertions(+), 163 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index f6170374..e6cd9dd7 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -90,12 +90,10 @@ type State | State_BlockValueDeclaration BlockValueDeclaration -type ParseResult - = ParseResult_Ok State - | ParseResult_Complete Block - | ParseResult_Err Error - | ParseResult_Skip - | ParseResult_Panic String +type ParseSuccess + = ParseSuccess_NewState State + | ParseSuccess_Complete Block + | ParseSuccess_Skip type alias State_ = @@ -340,23 +338,34 @@ runHelp items state = case items of item :: rest -> case parseAnything state.state item of - ParseResult_Ok newState_ -> + Ok (ParseSuccess_NewState newState_) -> runHelp rest { previousBlocks = state.previousBlocks , state = newState_ } - ParseResult_Complete block -> + Ok (ParseSuccess_Complete block) -> runHelp rest { previousBlocks = Ok block :: state.previousBlocks , state = State_BlockStart } - ParseResult_Err error -> + Ok ParseSuccess_Skip -> runHelp rest + state + + Err error -> + runHelp + (case error of + Error_Panic _ -> + [{- An empty list to abort parsing. -}] + + _ -> + rest + ) { previousBlocks = Err { state = state.state @@ -373,25 +382,6 @@ runHelp items state = State_Error_Recovery } - ParseResult_Panic error -> - -- TODO(harry): more violent error here - runHelp - [{- An empty list to abort parsing. -}] - { previousBlocks = - Err - { state = state.state - , item = Just item - , error = Error_Panic error - } - :: state.previousBlocks - , state = State_Error_Recovery - } - - ParseResult_Skip -> - runHelp - rest - state - [] -> List.reverse (case blockFromState state.state of @@ -416,7 +406,7 @@ runHelp items state = -- parsers -parseAnything : State -> Located Lexer.LexItem -> ParseResult +parseAnything : State -> Located Lexer.LexItem -> Result Error ParseSuccess parseAnything state item = let newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> TypeExpressionNestingLeaf -> Result Error State @@ -424,7 +414,7 @@ parseAnything state item = State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs expr) |> Ok - doneParsingTypeAlias : Token.UpperCase -> List Token.LowerCase -> TypeExpression -> ParseResult + doneParsingTypeAlias : Token.UpperCase -> List Token.LowerCase -> TypeExpression -> Result Error ParseSuccess doneParsingTypeAlias aliasName typeArgs expr = case partialTypeExpressionToConcreteType expr of Ok concreteType -> @@ -433,11 +423,12 @@ parseAnything state item = , expr = concreteType } |> TypeAlias - |> ParseResult_Complete + |> ParseSuccess_Complete + |> Ok Err (ToConcreteTypeError_TooManyTupleArgs a b c d e) -> Error_TooManyTupleArgs a b c d e - |> ParseResult_Err + |> Err newExpressionState : Located Token.LowerCase -> List (Located Token.LowerCase) -> ExpressionNestingLeaf -> Result Error State newExpressionState name args expr = @@ -450,46 +441,49 @@ parseAnything state item = ) |> Ok - doneParsingExpr : Located Token.LowerCase -> List (Located Token.LowerCase) -> LocatedExpr -> ParseResult + doneParsingExpr : Located Token.LowerCase -> List (Located Token.LowerCase) -> LocatedExpr -> ParseSuccess doneParsingExpr name args expr = { name = name , args = args , valueExpr__ = expr } |> ValueDeclaration - |> ParseResult_Complete + |> ParseSuccess_Complete region = Located.getRegion item in case Located.unwrap item of Lexer.Invalid _ -> - ParseResult_Err (Error_InvalidToken Expecting_Unknown) + Err (Error_InvalidToken Expecting_Unknown) Lexer.Newlines _ 0 -> case state of State_Error_Recovery -> State_BlockStart - |> ParseResult_Ok + |> ParseSuccess_NewState + |> Ok State_BlockStart -> - ParseResult_Ok State_BlockStart + State_BlockStart + |> ParseSuccess_NewState + |> Ok State_BlockFirstItem BlockFirstItem_Type -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockFirstItem BlockFirstItem_Module -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockValueDeclaration (BlockValueDeclaration_Named _) -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns _) -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> case partialExpr of @@ -498,25 +492,27 @@ parseAnything state item = Just rhs_ -> collapseOperators { op = op, lhs = lhs, parent = parent } rhs_ |> doneParsingExpr name args + |> Ok Nothing -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err ExpressionTypeExpressionNestingLeaf_Expr expr -> doneParsingExpr name args expr + |> Ok State_BlockTypeAlias BlockTypeAlias_Keywords -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockTypeAlias (BlockTypeAlias_Named _ _) -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockTypeAlias (BlockTypeAlias_NamedAssigns _ _) -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> case autoCollapseNesting CollapseLevel_Function exprSoFar of @@ -525,123 +521,117 @@ parseAnything state item = _ -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockCustomType (BlockCustomType_Named _ _) -> Error_PartwayThroughBlock - |> ParseResult_Err + |> Err State_BlockCustomType (BlockCustomType_NamedAssigns _ _) -> Debug.todo "BlockCustomType_NamedAssigns" Lexer.Newlines _ _ -> - ParseResult_Skip + Ok ParseSuccess_Skip Lexer.Ignorable _ -> - ParseResult_Skip + Ok ParseSuccess_Skip Lexer.Token token -> - let - res = - case state of - State_Error_Recovery -> - State_Error_Recovery - |> Ok + Result.map + ParseSuccess_NewState + (case state of + State_Error_Recovery -> + State_Error_Recovery + |> Ok - State_BlockStart -> - parseBlockStart region token + State_BlockStart -> + parseBlockStart region token - State_BlockFirstItem BlockFirstItem_Type -> - parseTypeBlock token + State_BlockFirstItem BlockFirstItem_Type -> + parseTypeBlock token - State_BlockFirstItem BlockFirstItem_Module -> - Debug.todo "BlockFirstItem_Module" + State_BlockFirstItem BlockFirstItem_Module -> + Debug.todo "BlockFirstItem_Module" - State_BlockValueDeclaration (BlockValueDeclaration_Named { name, args }) -> - parseLowercaseArgsOrAssignment - (\newArg -> - State_BlockValueDeclaration - (BlockValueDeclaration_Named - { name = name - , args = newArg |> pushOnto args - } - ) - ) - (State_BlockValueDeclaration - (BlockValueDeclaration_NamedAssigns + State_BlockValueDeclaration (BlockValueDeclaration_Named { name, args }) -> + parseLowercaseArgsOrAssignment + (\newArg -> + State_BlockValueDeclaration + (BlockValueDeclaration_Named { name = name - , args = args |> toList (\x -> x) + , args = newArg |> pushOnto args } ) + ) + (State_BlockValueDeclaration + (BlockValueDeclaration_NamedAssigns + { name = name + , args = args |> toList (\x -> x) + } ) - (Located.located region token) - - State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> - parserExpressionFromEmpty (newExpressionState name args) (Located.located region token) - - State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> - parserExpression - (newExpressionState name args) - partialExpr - (Located.located region token) - - State_BlockTypeAlias BlockTypeAlias_Keywords -> - parseTypeAliasName token - - State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> - parseLowercaseArgsOrAssignment - (\newTypeArg -> - State_BlockTypeAlias - (BlockTypeAlias_Named - name - (Located.unwrap newTypeArg |> pushOnto typeArgs) - ) - ) - (State_BlockTypeAlias - (BlockTypeAlias_NamedAssigns + ) + (Located.located region token) + + State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> + parserExpressionFromEmpty (newExpressionState name args) (Located.located region token) + + State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> + parserExpression + (newExpressionState name args) + partialExpr + (Located.located region token) + + State_BlockTypeAlias BlockTypeAlias_Keywords -> + parseTypeAliasName token + + State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> + parseLowercaseArgsOrAssignment + (\newTypeArg -> + State_BlockTypeAlias + (BlockTypeAlias_Named name - (typeArgs |> toList (\x -> x)) + (Located.unwrap newTypeArg |> pushOnto typeArgs) ) + ) + (State_BlockTypeAlias + (BlockTypeAlias_NamedAssigns + name + (typeArgs |> toList (\x -> x)) ) - (Located.located region token) - - State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> - parserTypeExprFromEmpty - (newTypeAliasState name typeArgs) - (Located.located region token) - - State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> - parserTypeExpr - (newTypeAliasState name typeArgs) - exprSoFar - (Located.located region token) - - State_BlockCustomType (BlockCustomType_Named name typeArgs) -> - parseLowercaseArgsOrAssignment - (\newTypeArg -> - State_BlockCustomType - (BlockCustomType_Named - name - (Located.unwrap newTypeArg |> pushOnto typeArgs) - ) - ) - (State_BlockCustomType - (BlockCustomType_NamedAssigns + ) + (Located.located region token) + + State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> + parserTypeExprFromEmpty + (newTypeAliasState name typeArgs) + (Located.located region token) + + State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> + parserTypeExpr + (newTypeAliasState name typeArgs) + exprSoFar + (Located.located region token) + + State_BlockCustomType (BlockCustomType_Named name typeArgs) -> + parseLowercaseArgsOrAssignment + (\newTypeArg -> + State_BlockCustomType + (BlockCustomType_Named name - (typeArgs |> toList (\x -> x)) + (Located.unwrap newTypeArg |> pushOnto typeArgs) ) + ) + (State_BlockCustomType + (BlockCustomType_NamedAssigns + name + (typeArgs |> toList (\x -> x)) ) - (Located.located region token) - - State_BlockCustomType (BlockCustomType_NamedAssigns _ _) -> - Debug.todo "BlockCustomType_NamedAssigns" - in - case res of - Ok s -> - ParseResult_Ok s + ) + (Located.located region token) - Err e -> - ParseResult_Err e + State_BlockCustomType (BlockCustomType_NamedAssigns _ _) -> + Debug.todo "BlockCustomType_NamedAssigns" + ) {-| @@ -870,7 +860,7 @@ parserTypeExpr newState prevExpr item = case Located.unwrap item of Lexer.Identifier ident -> exprAppend prevExpr ident - |> partialExpressionToParseResult newState + |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> leafToParent prevExpr @@ -882,7 +872,7 @@ parserTypeExpr newState prevExpr item = , parent = Just parent } ) - |> partialExpressionToParseResult newState + |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> let @@ -899,7 +889,7 @@ parserTypeExpr newState prevExpr item = TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> closeBracket firstExpressions trailingExpression parent - |> partialExpressionToParseResult newState + |> Result.andThen newState TypeExpressionNestingLeaf_PartialRecord _ -> Error_WrongClosingBracket @@ -927,15 +917,15 @@ parserTypeExpr newState prevExpr item = , parent = Just newParent } ) - |> partialExpressionToParseResult newState + |> Result.andThen newState Lexer.Sigil Lexer.Colon -> appendColonTo prevExpr - |> partialExpressionToParseResult newState + |> Result.andThen newState Lexer.Sigil Lexer.Comma -> appendCommaTo prevExpr - |> partialExpressionToParseResult newState + |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> let @@ -959,7 +949,7 @@ parserTypeExpr newState prevExpr item = TypeExpressionNestingLeaf_PartialRecord pr -> closeRecord pr - |> partialExpressionToParseResult newState + |> Result.andThen newState TypeExpressionNestingLeaf_Function { output } -> case output of @@ -1097,7 +1087,7 @@ parserExpression newState prevExpr item = case Located.unwrap item of Lexer.Sigil (Lexer.Operator op) -> appendOperatorTo prevExpr (withCorrectLocation op) - |> partialExpressionToParseResult newState + |> Result.andThen newState Lexer.NumericLiteral str -> case String.toInt str of @@ -1105,7 +1095,7 @@ parserExpression newState prevExpr item = Frontend.Int i |> withCorrectLocation |> appendValueExprTo prevExpr - |> partialExpressionToParseResult newState + |> Result.andThen newState Nothing -> Error_InvalidNumericLiteral str @@ -1819,25 +1809,6 @@ autoCollapseNesting collapseLevel pte = |> autoCollapseNesting collapseLevel -{-| TODO(harry): We can add things to a tuple too! Rename this function -appropriately. - -TODO(harry): We can inline this function. - --} -partialExpressionToParseResult : - (progress -> Result Error State) - -> Result Error progress - -> Result Error State -partialExpressionToParseResult newState rnewPartialType = - case rnewPartialType of - Ok newPartialType -> - newState newPartialType - - Err e -> - Err e - - type ToConcreteTypeError = ToConcreteTypeError_TooManyTupleArgs -- From a572cae51b413d6ba46cbf829805b14c13de7cb0 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 23 Oct 2020 18:34:59 +0100 Subject: [PATCH 092/103] undo elm format for block --- src/Stage/Parse/Contextualize.elm | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index e6cd9dd7..8db94d81 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -30,27 +30,17 @@ unindented line. In the following Program - module Main exposing (..) +```text +module Main exposing (..) -- 0 - -- 0 - import Dict +import Dict -- 1 +type A = A -- 2 - -- 1 - type - A - -- 2 - = A -- 2 - - a : A - - -- 3 - a = - -- 4 - A - - -- 4 +a : A -- 3 +a = A -- 4 +``` There are five blocks. From 05428f0820eaeb90f148c4f0c671188dd5e903bc Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 23 Oct 2020 18:39:36 +0100 Subject: [PATCH 093/103] inline collapseNesting calls --- src/Stage/Parse/Contextualize.elm | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 8db94d81..81536c3e 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -865,11 +865,7 @@ parserTypeExpr newState prevExpr item = |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> - let - collapsedLeaf = - autoCollapseNesting CollapseLevel_Function prevExpr - in - case collapsedLeaf of + case autoCollapseNesting CollapseLevel_Function prevExpr of TypeExpressionNestingLeaf_Expr _ -> Error_UnmatchedBracket Lexer.Round Lexer.Close |> Err @@ -918,11 +914,7 @@ parserTypeExpr newState prevExpr item = |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> - let - collapsedLeaf = - autoCollapseNesting CollapseLevel_Function prevExpr - in - case collapsedLeaf of + case autoCollapseNesting CollapseLevel_Function prevExpr of TypeExpressionNestingLeaf_Expr _ -> Error_UnmatchedBracket Lexer.Curly Lexer.Close |> Err @@ -951,11 +943,7 @@ parserTypeExpr newState prevExpr item = Debug.todo "Make this state impossible" Lexer.Sigil Lexer.ThinArrow -> - let - collapsedLeaf = - autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr - in - case collapsedLeaf of + case autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr of TypeExpressionNestingLeaf_Expr expr -> TypeExpressionNestingLeaf_Function { firstInput = expr @@ -1382,11 +1370,7 @@ exprAppend currentLeaf token = appendCommaTo : TypeExpressionNestingLeaf -> Result Error TypeExpressionNestingLeaf appendCommaTo prevExpr = - let - collapsedLeaf = - autoCollapseNesting CollapseLevel_Function prevExpr - in - case collapsedLeaf of + case autoCollapseNesting CollapseLevel_Function prevExpr of TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of LastEntryOfRecord_KeyValue key value -> @@ -1809,8 +1793,6 @@ type ToConcreteTypeError (List (ConcreteType PossiblyQualified)) -{-| TODO(harry): custom error message here --} partialTypeExpressionToConcreteType : TypeExpression -> Result ToConcreteTypeError (ConcreteType PossiblyQualified) partialTypeExpressionToConcreteType pte = case pte of From d2489a5a7c6b682382f30d188ba0fd78065a5478 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 23 Oct 2020 18:42:14 +0100 Subject: [PATCH 094/103] do not call a type partial when it is not --- src/Stage/Parse/Contextualize.elm | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 81536c3e..a6b43421 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -406,7 +406,7 @@ parseAnything state item = doneParsingTypeAlias : Token.UpperCase -> List Token.LowerCase -> TypeExpression -> Result Error ParseSuccess doneParsingTypeAlias aliasName typeArgs expr = - case partialTypeExpressionToConcreteType expr of + case typeExpressionToConcreteType expr of Ok concreteType -> { ty = aliasName , genericArgs = typeArgs @@ -1686,7 +1686,7 @@ blockFromState state = State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs partialExpr) -> case autoCollapseNesting CollapseLevel_Function partialExpr of TypeExpressionNestingLeaf_Expr expr -> - partialTypeExpressionToConcreteType expr + typeExpressionToConcreteType expr |> Result.map (\conceteType -> { ty = aliasName @@ -1793,8 +1793,8 @@ type ToConcreteTypeError (List (ConcreteType PossiblyQualified)) -partialTypeExpressionToConcreteType : TypeExpression -> Result ToConcreteTypeError (ConcreteType PossiblyQualified) -partialTypeExpressionToConcreteType pte = +typeExpressionToConcreteType : TypeExpression -> Result ToConcreteTypeError (ConcreteType PossiblyQualified) +typeExpressionToConcreteType pte = case pte of TypeExpression_NamedType { qualifiers, name, args } -> let @@ -1812,7 +1812,7 @@ partialTypeExpressionToConcreteType pte = |> Just in args - |> toList partialTypeExpressionToConcreteType + |> toList typeExpressionToConcreteType |> collectList (\x -> x) |> Result.map (\goodArgs -> @@ -1840,30 +1840,30 @@ partialTypeExpressionToConcreteType pte = |> Ok TypeExpression_Bracketed ty -> - partialTypeExpressionToConcreteType ty + typeExpressionToConcreteType ty TypeExpression_Tuple first second [] -> Result.map2 ConcreteType.Tuple - (partialTypeExpressionToConcreteType first) - (partialTypeExpressionToConcreteType second) + (typeExpressionToConcreteType first) + (typeExpressionToConcreteType second) TypeExpression_Tuple first second (third :: []) -> Result.map3 ConcreteType.Tuple3 - (partialTypeExpressionToConcreteType first) - (partialTypeExpressionToConcreteType second) - (partialTypeExpressionToConcreteType third) + (typeExpressionToConcreteType first) + (typeExpressionToConcreteType second) + (typeExpressionToConcreteType third) TypeExpression_Tuple first second (third :: fouth :: rest) -> Result.map5 ToConcreteTypeError_TooManyTupleArgs - (partialTypeExpressionToConcreteType first) - (partialTypeExpressionToConcreteType second) - (partialTypeExpressionToConcreteType third) - (partialTypeExpressionToConcreteType fouth) + (typeExpressionToConcreteType first) + (typeExpressionToConcreteType second) + (typeExpressionToConcreteType third) + (typeExpressionToConcreteType fouth) (rest - |> collectList partialTypeExpressionToConcreteType + |> collectList typeExpressionToConcreteType ) |> Result.andThen Err @@ -1871,7 +1871,7 @@ partialTypeExpressionToConcreteType pte = keyValues |> collectList (\( Token.LowerCase key, value ) -> - partialTypeExpressionToConcreteType value + typeExpressionToConcreteType value |> Result.map (\concreteValue -> ( key, concreteValue )) ) |> Result.map @@ -1897,12 +1897,12 @@ partialTypeExpressionToConcreteType pte = concreteOtherInputs } ) - (partialTypeExpressionToConcreteType functionTypeExpr.firstInput) + (typeExpressionToConcreteType functionTypeExpr.firstInput) (functionTypeExpr.otherInputs |> List.reverse - |> collectList partialTypeExpressionToConcreteType + |> collectList typeExpressionToConcreteType ) - (partialTypeExpressionToConcreteType functionTypeExpr.output) + (typeExpressionToConcreteType functionTypeExpr.output) collectList : (a -> Result e o) -> List a -> Result e (List o) From 0564e9c5dedb3e6c5e4dc95502612fe1a64cc71c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 23 Oct 2020 19:10:26 +0100 Subject: [PATCH 095/103] make impossible states impossible Lovely! --- src/Stage/Parse/Contextualize.elm | 107 ++++++++++++++++++------------ src/Stage/Parse/Pretty.elm | 2 +- tests/ParserLexerTestCases.elm | 4 +- 3 files changed, 67 insertions(+), 46 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index a6b43421..88004ba2 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -101,7 +101,7 @@ type BlockTypeAlias = BlockTypeAlias_Keywords | BlockTypeAlias_Named Token.UpperCase (Stack Token.LowerCase) | BlockTypeAlias_NamedAssigns Token.UpperCase (List Token.LowerCase) - | BlockTypeAlias_Completish Token.UpperCase (List Token.LowerCase) TypeExpressionNestingLeaf + | BlockTypeAlias_Completish Token.UpperCase (List Token.LowerCase) (TypeExpressionNestingLeaf () ()) type BlockCustomType @@ -183,6 +183,7 @@ type TypeExpressionNestingParent , name : Token.UpperCase , args : Stack TypeExpression , parent : Maybe TypeExpressionNestingParent + , phantom : () } | NestingParentType_Function { firstInput : TypeExpression @@ -191,7 +192,10 @@ type TypeExpressionNestingParent } -type TypeExpressionNestingLeaf +{-| Sometimes we need to limit which types of `TypeExpressionNestingLeaf` are valid. We do that using the phantom type +parameters. For example `TypeExpressionNestingLeaf () Never` cannot be a `TypeExpressionNestingLeaf_TypeWithArgs`. +-} +type TypeExpressionNestingLeaf phantomFunctionWithOutput phantomTypeWithArgs = TypeExpressionNestingLeaf_Bracket { firstExpressions : Stack TypeExpression , trailingExpression : Maybe TypeExpression @@ -203,11 +207,12 @@ type TypeExpressionNestingLeaf , name : Token.UpperCase , args : Stack TypeExpression , parent : Maybe TypeExpressionNestingParent + , phantom : phantomTypeWithArgs } | TypeExpressionNestingLeaf_Function { firstInput : TypeExpression , otherInputs : Stack TypeExpression - , output : Maybe TypeExpression + , output : Maybe ( TypeExpression, phantomFunctionWithOutput ) , parent : Maybe TypeExpressionNestingParent } | TypeExpressionNestingLeaf_Expr TypeExpression @@ -399,7 +404,7 @@ runHelp items state = parseAnything : State -> Located Lexer.LexItem -> Result Error ParseSuccess parseAnything state item = let - newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> TypeExpressionNestingLeaf -> Result Error State + newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> TypeExpressionNestingLeaf () () -> Result Error State newTypeAliasState aliasName typeArgs expr = State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs expr) |> Ok @@ -771,7 +776,7 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = parserTypeExprFromEmpty : - (TypeExpressionNestingLeaf -> Result Error State) + (TypeExpressionNestingLeaf () () -> Result Error State) -> Located Lexer.LexToken -> Result Error State parserTypeExprFromEmpty newState item = @@ -801,6 +806,7 @@ parserTypeExprFromEmpty newState item = , name = upper , args = empty , parent = Nothing + , phantom = () } |> newState @@ -842,8 +848,8 @@ parserTypeExprFromEmpty newState item = parserTypeExpr : - (TypeExpressionNestingLeaf -> Result Error State) - -> TypeExpressionNestingLeaf + (TypeExpressionNestingLeaf () () -> Result Error State) + -> TypeExpressionNestingLeaf () () -> Located Lexer.LexToken -> Result Error State parserTypeExpr newState prevExpr item = @@ -870,8 +876,8 @@ parserTypeExpr newState prevExpr item = Error_UnmatchedBracket Lexer.Round Lexer.Close |> Err - TypeExpressionNestingLeaf_TypeWithArgs { name, args } -> - Debug.todo "Make this state impossible" + TypeExpressionNestingLeaf_TypeWithArgs { name, args, phantom } -> + never phantom TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> closeBracket firstExpressions trailingExpression parent @@ -890,8 +896,8 @@ parserTypeExpr newState prevExpr item = Error_MissingFunctionReturnType |> Err - Just _ -> - Debug.todo "Make this state impossible" + Just ( _, phantom ) -> + never phantom Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> leafToParent prevExpr @@ -919,8 +925,8 @@ parserTypeExpr newState prevExpr item = Error_UnmatchedBracket Lexer.Curly Lexer.Close |> Err - TypeExpressionNestingLeaf_TypeWithArgs { name, args } -> - Debug.todo "Make this state impossible" + TypeExpressionNestingLeaf_TypeWithArgs { name, args, phantom } -> + never phantom TypeExpressionNestingLeaf_Bracket _ -> Error_WrongClosingBracket @@ -939,11 +945,11 @@ parserTypeExpr newState prevExpr item = Error_MissingFunctionReturnType |> Err - Just _ -> - Debug.todo "Make this state impossible" + Just ( _, phantom ) -> + never phantom Lexer.Sigil Lexer.ThinArrow -> - case autoCollapseNesting CollapseLevel_TypeWithArgs prevExpr of + case autoCollapseNesting (CollapseLevel_TypeWithArgs ()) prevExpr of TypeExpressionNestingLeaf_Expr expr -> TypeExpressionNestingLeaf_Function { firstInput = expr @@ -953,8 +959,8 @@ parserTypeExpr newState prevExpr item = } |> newState - TypeExpressionNestingLeaf_TypeWithArgs _ -> - Debug.todo "make state impossible" + TypeExpressionNestingLeaf_TypeWithArgs { phantom } -> + never phantom TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> case output of @@ -965,7 +971,7 @@ parserTypeExpr newState prevExpr item = Just output_ -> TypeExpressionNestingLeaf_Function { firstInput = firstInput - , otherInputs = output_ |> pushOnto otherInputs + , otherInputs = output_ |> Tuple.first |> pushOnto otherInputs , output = Nothing , parent = parent } @@ -1088,7 +1094,7 @@ parserExpression newState prevExpr item = -- HELPERS -leafToParent : TypeExpressionNestingLeaf -> Result Error TypeExpressionNestingParent +leafToParent : TypeExpressionNestingLeaf () () -> Result Error TypeExpressionNestingParent leafToParent leaf = case leaf of TypeExpressionNestingLeaf_Expr expr -> @@ -1146,12 +1152,12 @@ leafToParent leaf = } |> Ok - Just te -> + Just ( te, () ) -> Error_TypeDoesNotTakeArgs2 te |> Err -parentsToLeafWith : TypeExpression -> Maybe TypeExpressionNestingParent -> TypeExpressionNestingLeaf +parentsToLeafWith : TypeExpression -> Maybe TypeExpressionNestingParent -> TypeExpressionNestingLeaf () () parentsToLeafWith expr toMakeIntoLeaf = case toMakeIntoLeaf of Just (NestingParentType_PartialRecord { firstEntries, lastEntryName, parent }) -> @@ -1174,13 +1180,14 @@ parentsToLeafWith expr toMakeIntoLeaf = , name = name , args = expr |> pushOnto args , parent = parent + , phantom = () } Just (NestingParentType_Function { firstInput, otherInputs, parent }) -> TypeExpressionNestingLeaf_Function { firstInput = firstInput , otherInputs = otherInputs - , output = Just expr + , output = Just ( expr, () ) , parent = parent } @@ -1189,12 +1196,12 @@ parentsToLeafWith expr toMakeIntoLeaf = exprAppend : - TypeExpressionNestingLeaf + TypeExpressionNestingLeaf () () -> { qualifiers : List Token.UpperCase , name : Token.Token } - -> Result Error TypeExpressionNestingLeaf + -> Result Error (TypeExpressionNestingLeaf () ()) exprAppend currentLeaf token = case token.name of Token.TokenLowerCase lower -> @@ -1299,6 +1306,7 @@ exprAppend currentLeaf token = , name = upper , args = empty , parent = Just newParent + , phantom = () } ) @@ -1331,6 +1339,7 @@ exprAppend currentLeaf token = , name = upper , args = empty , parent = Just newParent + , phantom = () } ) @@ -1346,6 +1355,7 @@ exprAppend currentLeaf token = |> TypeExpression_NamedType |> pushOnto args , parent = parent + , phantom = () } |> Ok @@ -1353,7 +1363,7 @@ exprAppend currentLeaf token = Result.andThen (\newParent -> case output of - Just outputExpr -> + Just ( outputExpr, () ) -> doesNotTakeArgsError outputExpr Nothing -> @@ -1362,13 +1372,14 @@ exprAppend currentLeaf token = , name = upper , args = empty , parent = Just newParent + , phantom = () } |> Ok ) (leafToParent currentLeaf) -appendCommaTo : TypeExpressionNestingLeaf -> Result Error TypeExpressionNestingLeaf +appendCommaTo : TypeExpressionNestingLeaf () () -> Result Error (TypeExpressionNestingLeaf () ()) appendCommaTo prevExpr = case autoCollapseNesting CollapseLevel_Function prevExpr of TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> @@ -1404,7 +1415,7 @@ appendCommaTo prevExpr = |> Err -appendColonTo : TypeExpressionNestingLeaf -> Result Error TypeExpressionNestingLeaf +appendColonTo : TypeExpressionNestingLeaf () () -> Result Error (TypeExpressionNestingLeaf () ()) appendColonTo prevExpr = case prevExpr of TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> @@ -1430,7 +1441,7 @@ closeBracket : Stack TypeExpression -> Maybe TypeExpression -> Maybe TypeExpressionNestingParent - -> Result Error TypeExpressionNestingLeaf + -> Result Error (TypeExpressionNestingLeaf () ()) closeBracket argStack mLastExpression mParent = let rexpr = @@ -1475,7 +1486,7 @@ closeBracket argStack mLastExpression mParent = closeRecord : PartialRecord - -> Result Error TypeExpressionNestingLeaf + -> Result Error (TypeExpressionNestingLeaf () ()) closeRecord { firstEntries, lastEntry, parent } = let fromRecord recordEntries = @@ -1737,12 +1748,12 @@ blockFromState state = -- helper functions -type CollapseLevel - = CollapseLevel_TypeWithArgs +type CollapseLevel phantomFunctionWithOutput + = CollapseLevel_TypeWithArgs phantomFunctionWithOutput | CollapseLevel_Function -autoCollapseNesting : CollapseLevel -> TypeExpressionNestingLeaf -> TypeExpressionNestingLeaf +autoCollapseNesting : CollapseLevel phantomFunctionWithOutput -> TypeExpressionNestingLeaf () () -> TypeExpressionNestingLeaf phantomFunctionWithOutput Never autoCollapseNesting collapseLevel pte = case pte of TypeExpressionNestingLeaf_TypeWithArgs { qualifiers, name, args, parent } -> @@ -1753,24 +1764,34 @@ autoCollapseNesting collapseLevel pte = parentsToLeafWith newTypeExpr parent |> autoCollapseNesting collapseLevel - TypeExpressionNestingLeaf_Expr _ -> - pte + TypeExpressionNestingLeaf_Expr expr -> + TypeExpressionNestingLeaf_Expr expr - TypeExpressionNestingLeaf_Bracket _ -> - pte + TypeExpressionNestingLeaf_Bracket b -> + TypeExpressionNestingLeaf_Bracket b - TypeExpressionNestingLeaf_PartialRecord _ -> - pte + TypeExpressionNestingLeaf_PartialRecord pr -> + TypeExpressionNestingLeaf_PartialRecord pr TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> case ( collapseLevel, output ) of - ( CollapseLevel_TypeWithArgs, _ ) -> - pte + ( CollapseLevel_TypeWithArgs phantom, _ ) -> + TypeExpressionNestingLeaf_Function + { firstInput = firstInput + , otherInputs = otherInputs + , output = output |> Maybe.map (\( o, _ ) -> ( o, phantom )) + , parent = parent + } ( CollapseLevel_Function, Nothing ) -> - pte + TypeExpressionNestingLeaf_Function + { firstInput = firstInput + , otherInputs = otherInputs + , output = Nothing + , parent = parent + } - ( CollapseLevel_Function, Just outputExpr ) -> + ( CollapseLevel_Function, Just ( outputExpr, () ) ) -> let newTypeExpr = TypeExpression_Function diff --git a/src/Stage/Parse/Pretty.elm b/src/Stage/Parse/Pretty.elm index 817c42f8..9fa7f819 100644 --- a/src/Stage/Parse/Pretty.elm +++ b/src/Stage/Parse/Pretty.elm @@ -345,7 +345,7 @@ typeExpr expr_ = ) -typeExpressionNestingLeaf : TypeExpressionNestingLeaf -> Sexpr String +typeExpressionNestingLeaf : TypeExpressionNestingLeaf () () -> Sexpr String typeExpressionNestingLeaf leaf = case leaf of TypeExpressionNestingLeaf_Bracket record -> diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 3085e1c3..b9814ca5 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -4703,7 +4703,7 @@ type alias E a = B.c -> a""" ) ) ) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "B") [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "List", parent = Nothing, qualifiers = [] })) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "B") [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "List", parent = Nothing, phantom = (), qualifiers = [] })) } , Err { error = Error_TypeDoesNotTakeArgs (TypeExpression_GenericType (LowerCase "list")) (TypeExpression_NamedType { args = Stack [], name = UpperCase "A", qualifiers = [] }) @@ -5039,7 +5039,7 @@ List Int [ Err { error = Error_PartwayThroughBlock , item = Just (Located { end = { col = 1, row = 3 }, start = { col = 12, row = 2 } } (Newlines [] 0)) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "Int", parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }), qualifiers = [] })) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "Int", parent = Just (NestingParentType_Bracket { expressions = Stack [], parent = Nothing }), phantom = (), qualifiers = [] })) } ] , lexed = From 49f6497321839bde3f7686cf0a5ff6b792401d0c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Fri, 23 Oct 2020 19:23:15 +0100 Subject: [PATCH 096/103] separate collapsing functions the logic is clearer when we have two separate functions --- src/Stage/Parse/Contextualize.elm | 66 ++++++++++++++++++------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 88004ba2..730febf3 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -266,7 +266,6 @@ type Error , name : Token.LowerCase } -- Type Expressions -- - | Error_TypeNameStartsWithLowerCase String | Error_UnmatchedBracket Lexer.BracketType Lexer.BracketRole | Error_WrongClosingBracket { expecting : Lexer.BracketType @@ -510,7 +509,7 @@ parseAnything state item = |> Err State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> - case autoCollapseNesting CollapseLevel_Function exprSoFar of + case collapseFunction exprSoFar of TypeExpressionNestingLeaf_Expr expr -> doneParsingTypeAlias name typeArgs expr @@ -653,9 +652,9 @@ parseBlockStart region item = Lexer.Keyword other -> Err (Error_MisplacedKeyword other) - Lexer.Identifier ({ qualifiers, name } as identitfier) -> + Lexer.Identifier ({ qualifiers, name } as identifier) -> if qualifiers /= [] then - Err (Error_BlockStartsWithQualifiedName identitfier) + Err (Error_BlockStartsWithQualifiedName identifier) else case name of @@ -871,7 +870,7 @@ parserTypeExpr newState prevExpr item = |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> - case autoCollapseNesting CollapseLevel_Function prevExpr of + case collapseFunction prevExpr of TypeExpressionNestingLeaf_Expr _ -> Error_UnmatchedBracket Lexer.Round Lexer.Close |> Err @@ -920,7 +919,7 @@ parserTypeExpr newState prevExpr item = |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> - case autoCollapseNesting CollapseLevel_Function prevExpr of + case collapseFunction prevExpr of TypeExpressionNestingLeaf_Expr _ -> Error_UnmatchedBracket Lexer.Curly Lexer.Close |> Err @@ -949,7 +948,7 @@ parserTypeExpr newState prevExpr item = never phantom Lexer.Sigil Lexer.ThinArrow -> - case autoCollapseNesting (CollapseLevel_TypeWithArgs ()) prevExpr of + case collapseTypeWithArgs prevExpr of TypeExpressionNestingLeaf_Expr expr -> TypeExpressionNestingLeaf_Function { firstInput = expr @@ -1381,7 +1380,7 @@ exprAppend currentLeaf token = appendCommaTo : TypeExpressionNestingLeaf () () -> Result Error (TypeExpressionNestingLeaf () ()) appendCommaTo prevExpr = - case autoCollapseNesting CollapseLevel_Function prevExpr of + case collapseFunction prevExpr of TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of LastEntryOfRecord_KeyValue key value -> @@ -1695,7 +1694,7 @@ blockFromState state = |> Just State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs partialExpr) -> - case autoCollapseNesting CollapseLevel_Function partialExpr of + case collapseFunction partialExpr of TypeExpressionNestingLeaf_Expr expr -> typeExpressionToConcreteType expr |> Result.map @@ -1748,13 +1747,8 @@ blockFromState state = -- helper functions -type CollapseLevel phantomFunctionWithOutput - = CollapseLevel_TypeWithArgs phantomFunctionWithOutput - | CollapseLevel_Function - - -autoCollapseNesting : CollapseLevel phantomFunctionWithOutput -> TypeExpressionNestingLeaf () () -> TypeExpressionNestingLeaf phantomFunctionWithOutput Never -autoCollapseNesting collapseLevel pte = +collapseTypeWithArgs : TypeExpressionNestingLeaf () () -> TypeExpressionNestingLeaf () Never +collapseTypeWithArgs pte = case pte of TypeExpressionNestingLeaf_TypeWithArgs { qualifiers, name, args, parent } -> let @@ -1762,7 +1756,7 @@ autoCollapseNesting collapseLevel pte = TypeExpression_NamedType { qualifiers = qualifiers, name = name, args = args } in parentsToLeafWith newTypeExpr parent - |> autoCollapseNesting collapseLevel + |> collapseTypeWithArgs TypeExpressionNestingLeaf_Expr expr -> TypeExpressionNestingLeaf_Expr expr @@ -1774,16 +1768,32 @@ autoCollapseNesting collapseLevel pte = TypeExpressionNestingLeaf_PartialRecord pr TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> - case ( collapseLevel, output ) of - ( CollapseLevel_TypeWithArgs phantom, _ ) -> - TypeExpressionNestingLeaf_Function - { firstInput = firstInput - , otherInputs = otherInputs - , output = output |> Maybe.map (\( o, _ ) -> ( o, phantom )) - , parent = parent - } + TypeExpressionNestingLeaf_Function + { firstInput = firstInput + , otherInputs = otherInputs + , output = output |> Maybe.map (\( o, _ ) -> ( o, () )) + , parent = parent + } - ( CollapseLevel_Function, Nothing ) -> + +collapseFunction : TypeExpressionNestingLeaf () () -> TypeExpressionNestingLeaf Never Never +collapseFunction pte = + case collapseTypeWithArgs pte of + TypeExpressionNestingLeaf_TypeWithArgs { phantom } -> + never phantom + + TypeExpressionNestingLeaf_Expr expr -> + TypeExpressionNestingLeaf_Expr expr + + TypeExpressionNestingLeaf_Bracket b -> + TypeExpressionNestingLeaf_Bracket b + + TypeExpressionNestingLeaf_PartialRecord pr -> + TypeExpressionNestingLeaf_PartialRecord pr + + TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> + case output of + Nothing -> TypeExpressionNestingLeaf_Function { firstInput = firstInput , otherInputs = otherInputs @@ -1791,7 +1801,7 @@ autoCollapseNesting collapseLevel pte = , parent = parent } - ( CollapseLevel_Function, Just ( outputExpr, () ) ) -> + Just ( outputExpr, () ) -> let newTypeExpr = TypeExpression_Function @@ -1801,7 +1811,7 @@ autoCollapseNesting collapseLevel pte = } in parentsToLeafWith newTypeExpr parent - |> autoCollapseNesting collapseLevel + |> collapseFunction type ToConcreteTypeError From 4b91f1d83d66cef0b28a5cdea31bc53a5c555994 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sun, 25 Oct 2020 09:02:02 +0000 Subject: [PATCH 097/103] allow qualified type names at top level --- .../should-parse/type-alias-qualified-type | 3 + src/Stage/Parse/Contextualize.elm | 20 +-- tests/ParserLexerTestCases.elm | 137 ++++++++++++++++++ 3 files changed, 148 insertions(+), 12 deletions(-) create mode 100644 parser-tests/snippets/should-parse/type-alias-qualified-type diff --git a/parser-tests/snippets/should-parse/type-alias-qualified-type b/parser-tests/snippets/should-parse/type-alias-qualified-type new file mode 100644 index 00000000..d7854fbc --- /dev/null +++ b/parser-tests/snippets/should-parse/type-alias-qualified-type @@ -0,0 +1,3 @@ +type alias A = B.C.D + +type alias A = List B.C.D \ No newline at end of file diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 730febf3..8c1a96fe 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -796,18 +796,14 @@ parserTypeExprFromEmpty newState item = |> Err Token.TokenUpperCase upper -> - if qualifiers /= [] then - Debug.todo "" - - else - TypeExpressionNestingLeaf_TypeWithArgs - { qualifiers = qualifiers - , name = upper - , args = empty - , parent = Nothing - , phantom = () - } - |> newState + TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = qualifiers + , name = upper + , args = empty + , parent = Nothing + , phantom = () + } + |> newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> TypeExpressionNestingLeaf_Bracket diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index b9814ca5..e53e0da5 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -2819,6 +2819,143 @@ type alias Function3 = (Int, () -> (Int, String), ()) , Located { end = { col = 1, row = 4 }, start = { col = 10, row = 3 } } (Newlines [] 0) ] } + , { name = "type-alias-qualified-type" + , source = """type alias A = B.C.D + +type alias A = List B.C.D""" + , pretty = """ + ( ( Ok + , ( TypeAlias + , ( ty, A ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified + , ( Just, B.C ) + ) + ) + , ( name, D ) + , ( args, () ) + ) + ) + ) + ) + ) + , ( Ok + , ( TypeAlias + , ( ty, A ) + , ( genericArgs, () ) + , ( expr + , ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified + , ( Just, B.C ) + ) + ) + , ( name, List ) + , ( args + , ( ( UserDefinedType + , ( ( qualifiedness + , ( PossiblyQualified + , ( Just, B.C ) + ) + ) + , ( name, D ) + , ( args, () ) + ) + ) ) + ) + ) + ) + ) + ) + ) + ) +""" + , contextualized = + Just + [ Ok + (TypeAlias + { expr = + UserDefinedType + { args = [] + , name = "D" + , qualifiedness = PossiblyQualified (Just "B.C") + } + , genericArgs = [] + , ty = UpperCase "A" + } + ) + , Ok + (TypeAlias + { expr = + UserDefinedType + { args = + [ UserDefinedType + { args = [] + , name = "D" + , qualifiedness = PossiblyQualified (Just "B.C") + } + ] + , name = "List" + , qualifiedness = PossiblyQualified (Just "B.C") + } + , genericArgs = [] + , ty = UpperCase "A" + } + ) + ] + , lexed = + Ok + [ Located { end = { col = 5, row = 1 }, start = { col = 1, row = 1 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 1 }, start = { col = 5, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 1 }, start = { col = 6, row = 1 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 1 }, start = { col = 11, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 1 }, start = { col = 12, row = 1 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) + , Located { end = { col = 14, row = 1 }, start = { col = 13, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 1 }, start = { col = 14, row = 1 } } (Token (Sigil Assign)) + , Located { end = { col = 16, row = 1 }, start = { col = 15, row = 1 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 21, row = 1 }, start = { col = 16, row = 1 } } + (Token + (Identifier + { name = TokenUpperCase (UpperCase "D") + , qualifiers = + [ UpperCase "B" + , UpperCase "C" + ] + } + ) + ) + , Located { end = { col = 1, row = 3 }, start = { col = 21, row = 1 } } + (Newlines + [ 0 + ] + 0 + ) + , Located { end = { col = 5, row = 3 }, start = { col = 1, row = 3 } } (Token (Keyword Type)) + , Located { end = { col = 6, row = 3 }, start = { col = 5, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 11, row = 3 }, start = { col = 6, row = 3 } } (Token (Keyword Alias)) + , Located { end = { col = 12, row = 3 }, start = { col = 11, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 13, row = 3 }, start = { col = 12, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] })) + , Located { end = { col = 14, row = 3 }, start = { col = 13, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 15, row = 3 }, start = { col = 14, row = 3 } } (Token (Sigil Assign)) + , Located { end = { col = 16, row = 3 }, start = { col = 15, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 20, row = 3 }, start = { col = 16, row = 3 } } (Token (Identifier { name = TokenUpperCase (UpperCase "List"), qualifiers = [] })) + , Located { end = { col = 21, row = 3 }, start = { col = 20, row = 3 } } (Ignorable (Whitespace 1)) + , Located { end = { col = 26, row = 3 }, start = { col = 21, row = 3 } } + (Token + (Identifier + { name = TokenUpperCase (UpperCase "D") + , qualifiers = + [ UpperCase "B" + , UpperCase "C" + ] + } + ) + ) + ] + } , { name = "type-alias-record-3-entries" , source = """type alias Ty = { a: A, b: B, c: C } """ From 5e48cd323b5de6467139fedfde02e3b956d4ae0c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sun, 25 Oct 2020 09:07:44 +0000 Subject: [PATCH 098/103] move post processing out of fn We had this when I wanted uniform return types. Much better now though. --- src/Stage/Parse/Contextualize.elm | 75 ++++++++++++------------------- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 8c1a96fe..713e70b3 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -567,13 +567,12 @@ parseAnything state item = (Located.located region token) State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> - parserExpressionFromEmpty (newExpressionState name args) (Located.located region token) + parserExpressionFromEmpty (Located.located region token) + |> Result.andThen (newExpressionState name args) State_BlockValueDeclaration (BlockValueDeclaration_Completish { name, args, partialExpr }) -> - parserExpression - (newExpressionState name args) - partialExpr - (Located.located region token) + parserExpression partialExpr (Located.located region token) + |> Result.andThen (newExpressionState name args) State_BlockTypeAlias BlockTypeAlias_Keywords -> parseTypeAliasName token @@ -596,15 +595,12 @@ parseAnything state item = (Located.located region token) State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> - parserTypeExprFromEmpty - (newTypeAliasState name typeArgs) - (Located.located region token) + parserTypeExprFromEmpty (Located.located region token) + |> Result.andThen (newTypeAliasState name typeArgs) State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> - parserTypeExpr - (newTypeAliasState name typeArgs) - exprSoFar - (Located.located region token) + parserTypeExpr exprSoFar (Located.located region token) + |> Result.andThen (newTypeAliasState name typeArgs) State_BlockCustomType (BlockCustomType_Named name typeArgs) -> parseLowercaseArgsOrAssignment @@ -775,10 +771,9 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = parserTypeExprFromEmpty : - (TypeExpressionNestingLeaf () () -> Result Error State) - -> Located Lexer.LexToken - -> Result Error State -parserTypeExprFromEmpty newState item = + Located Lexer.LexToken + -> Result Error (TypeExpressionNestingLeaf () ()) +parserTypeExprFromEmpty item = case Located.unwrap item of Lexer.Identifier { qualifiers, name } -> case name of @@ -786,7 +781,7 @@ parserTypeExprFromEmpty newState item = if qualifiers == [] then TypeExpression_GenericType lower |> TypeExpressionNestingLeaf_Expr - |> newState + |> Ok else Error_LowerCasedTypename @@ -803,7 +798,7 @@ parserTypeExprFromEmpty newState item = , parent = Nothing , phantom = () } - |> newState + |> Ok Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> TypeExpressionNestingLeaf_Bracket @@ -811,7 +806,7 @@ parserTypeExprFromEmpty newState item = , trailingExpression = Nothing , parent = Nothing } - |> newState + |> Ok Lexer.Sigil (Lexer.Bracket role Lexer.Close) -> Error_UnmatchedBracket role Lexer.Close @@ -823,7 +818,7 @@ parserTypeExprFromEmpty newState item = , lastEntry = LastEntryOfRecord_Empty , parent = Nothing } - |> newState + |> Ok Lexer.Sigil Lexer.Colon -> Error_InvalidToken Expecting_Unknown @@ -843,15 +838,13 @@ parserTypeExprFromEmpty newState item = parserTypeExpr : - (TypeExpressionNestingLeaf () () -> Result Error State) - -> TypeExpressionNestingLeaf () () + TypeExpressionNestingLeaf () () -> Located Lexer.LexToken - -> Result Error State -parserTypeExpr newState prevExpr item = + -> Result Error (TypeExpressionNestingLeaf () ()) +parserTypeExpr prevExpr item = case Located.unwrap item of Lexer.Identifier ident -> exprAppend prevExpr ident - |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> leafToParent prevExpr @@ -863,7 +856,6 @@ parserTypeExpr newState prevExpr item = , parent = Just parent } ) - |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> case collapseFunction prevExpr of @@ -876,7 +868,6 @@ parserTypeExpr newState prevExpr item = TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> closeBracket firstExpressions trailingExpression parent - |> Result.andThen newState TypeExpressionNestingLeaf_PartialRecord _ -> Error_WrongClosingBracket @@ -904,15 +895,12 @@ parserTypeExpr newState prevExpr item = , parent = Just newParent } ) - |> Result.andThen newState Lexer.Sigil Lexer.Colon -> appendColonTo prevExpr - |> Result.andThen newState Lexer.Sigil Lexer.Comma -> appendCommaTo prevExpr - |> Result.andThen newState Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> case collapseFunction prevExpr of @@ -932,7 +920,6 @@ parserTypeExpr newState prevExpr item = TypeExpressionNestingLeaf_PartialRecord pr -> closeRecord pr - |> Result.andThen newState TypeExpressionNestingLeaf_Function { output } -> case output of @@ -952,7 +939,7 @@ parserTypeExpr newState prevExpr item = , output = Nothing , parent = Nothing } - |> newState + |> Ok TypeExpressionNestingLeaf_TypeWithArgs { phantom } -> never phantom @@ -970,7 +957,7 @@ parserTypeExpr newState prevExpr item = , output = Nothing , parent = parent } - |> newState + |> Ok TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> case trailingExpression of @@ -986,7 +973,7 @@ parserTypeExpr newState prevExpr item = |> NestingParentType_Bracket |> Just } - |> newState + |> Ok Nothing -> Error_InvalidToken Expecting_Unknown @@ -1019,7 +1006,7 @@ parserTypeExpr newState prevExpr item = |> NestingParentType_PartialRecord |> Just } - |> newState + |> Ok _ -> Error_InvalidToken Expecting_Unknown @@ -1027,10 +1014,9 @@ parserTypeExpr newState prevExpr item = parserExpressionFromEmpty : - (ExpressionNestingLeaf -> Result Error State) - -> Located Lexer.LexToken - -> Result Error State -parserExpressionFromEmpty newState item = + Located Lexer.LexToken + -> Result Error ExpressionNestingLeaf +parserExpressionFromEmpty item = let withCorrectLocation x = Located.map (\_ -> x) item @@ -1042,7 +1028,7 @@ parserExpressionFromEmpty newState item = Frontend.Int i |> withCorrectLocation |> ExpressionTypeExpressionNestingLeaf_Expr - |> newState + |> Ok Nothing -> Error_InvalidNumericLiteral str @@ -1054,11 +1040,10 @@ parserExpressionFromEmpty newState item = parserExpression : - (ExpressionNestingLeaf -> Result Error State) - -> ExpressionNestingLeaf + ExpressionNestingLeaf -> Located Lexer.LexToken - -> Result Error State -parserExpression newState prevExpr item = + -> Result Error ExpressionNestingLeaf +parserExpression prevExpr item = let withCorrectLocation x = Located.map (\_ -> x) item @@ -1066,7 +1051,6 @@ parserExpression newState prevExpr item = case Located.unwrap item of Lexer.Sigil (Lexer.Operator op) -> appendOperatorTo prevExpr (withCorrectLocation op) - |> Result.andThen newState Lexer.NumericLiteral str -> case String.toInt str of @@ -1074,7 +1058,6 @@ parserExpression newState prevExpr item = Frontend.Int i |> withCorrectLocation |> appendValueExprTo prevExpr - |> Result.andThen newState Nothing -> Error_InvalidNumericLiteral str From 14537f3f6e1a98cde9f751747c61d6570cf7735c Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sun, 25 Oct 2020 09:20:22 +0000 Subject: [PATCH 099/103] tidy parseLowercaseArgsOrAssignment removes another case of passing a callback to a function. This time we use a new custom type. Much more elmish! --- src/Stage/Parse/Contextualize.elm | 117 ++++++++++++++++-------------- 1 file changed, 64 insertions(+), 53 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 713e70b3..00d9ec89 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -548,23 +548,26 @@ parseAnything state item = Debug.todo "BlockFirstItem_Module" State_BlockValueDeclaration (BlockValueDeclaration_Named { name, args }) -> - parseLowercaseArgsOrAssignment - (\newArg -> - State_BlockValueDeclaration - (BlockValueDeclaration_Named - { name = name - , args = newArg |> pushOnto args - } - ) - ) - (State_BlockValueDeclaration - (BlockValueDeclaration_NamedAssigns - { name = name - , args = args |> toList (\x -> x) - } + parseLowercaseArgsOrAssignment token + |> Result.map + (\res -> + case res of + ArgOrAssign_Arg newArg -> + State_BlockValueDeclaration + (BlockValueDeclaration_Named + { name = name + , args = Located.located region newArg |> pushOnto args + } + ) + + ArgOrAssign_Assign -> + State_BlockValueDeclaration + (BlockValueDeclaration_NamedAssigns + { name = name + , args = args |> toList (\x -> x) + } + ) ) - ) - (Located.located region token) State_BlockValueDeclaration (BlockValueDeclaration_NamedAssigns { name, args }) -> parserExpressionFromEmpty (Located.located region token) @@ -578,21 +581,24 @@ parseAnything state item = parseTypeAliasName token State_BlockTypeAlias (BlockTypeAlias_Named name typeArgs) -> - parseLowercaseArgsOrAssignment - (\newTypeArg -> - State_BlockTypeAlias - (BlockTypeAlias_Named - name - (Located.unwrap newTypeArg |> pushOnto typeArgs) - ) - ) - (State_BlockTypeAlias - (BlockTypeAlias_NamedAssigns - name - (typeArgs |> toList (\x -> x)) + parseLowercaseArgsOrAssignment token + |> Result.map + (\res -> + case res of + ArgOrAssign_Arg newTypeArg -> + State_BlockTypeAlias + (BlockTypeAlias_Named + name + (newTypeArg |> pushOnto typeArgs) + ) + + ArgOrAssign_Assign -> + State_BlockTypeAlias + (BlockTypeAlias_NamedAssigns + name + (typeArgs |> toList (\x -> x)) + ) ) - ) - (Located.located region token) State_BlockTypeAlias (BlockTypeAlias_NamedAssigns name typeArgs) -> parserTypeExprFromEmpty (Located.located region token) @@ -603,21 +609,24 @@ parseAnything state item = |> Result.andThen (newTypeAliasState name typeArgs) State_BlockCustomType (BlockCustomType_Named name typeArgs) -> - parseLowercaseArgsOrAssignment - (\newTypeArg -> - State_BlockCustomType - (BlockCustomType_Named - name - (Located.unwrap newTypeArg |> pushOnto typeArgs) - ) - ) - (State_BlockCustomType - (BlockCustomType_NamedAssigns - name - (typeArgs |> toList (\x -> x)) + parseLowercaseArgsOrAssignment token + |> Result.map + (\res -> + case res of + ArgOrAssign_Arg newTypeArg -> + State_BlockCustomType + (BlockCustomType_Named + name + (newTypeArg |> pushOnto typeArgs) + ) + + ArgOrAssign_Assign -> + State_BlockCustomType + (BlockCustomType_NamedAssigns + name + (typeArgs |> toList (\x -> x)) + ) ) - ) - (Located.located region token) State_BlockCustomType (BlockCustomType_NamedAssigns _ _) -> Debug.todo "BlockCustomType_NamedAssigns" @@ -736,13 +745,14 @@ parseTypeAliasName item = |> Err -parseLowercaseArgsOrAssignment : (Located Token.LowerCase -> State) -> State -> Located Lexer.LexToken -> Result Error State -parseLowercaseArgsOrAssignment onTypeArg onAssignment item = - let - withCorrectLocation x = - Located.map (\_ -> x) item - in - case Located.unwrap item of +type ArgOrAssign + = ArgOrAssign_Arg Token.LowerCase + | ArgOrAssign_Assign + + +parseLowercaseArgsOrAssignment : Lexer.LexToken -> Result Error ArgOrAssign +parseLowercaseArgsOrAssignment item = + case item of Lexer.Keyword kw -> Error_MisplacedKeyword kw |> Err @@ -754,7 +764,8 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = else case name of Token.TokenLowerCase lower -> - onTypeArg (withCorrectLocation lower) + lower + |> ArgOrAssign_Arg |> Ok Token.TokenUpperCase upper -> @@ -762,7 +773,7 @@ parseLowercaseArgsOrAssignment onTypeArg onAssignment item = |> Err Lexer.Sigil Lexer.Assign -> - onAssignment + ArgOrAssign_Assign |> Ok _ -> From 96c3269c1001edb3c50ef315e9039efa2e2095cd Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sun, 25 Oct 2020 16:01:58 +0000 Subject: [PATCH 100/103] Include the (partial) type arg in Error_TypeDoesNotTakeArgs --- src/Stage/Parse/Contextualize.elm | 187 +++++++++++++++--------------- tests/ParserLexerTestCases.elm | 8 +- 2 files changed, 97 insertions(+), 98 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 00d9ec89..99b13be8 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -274,8 +274,7 @@ type Error | Error_MissingFunctionReturnType | Error_ExpectedColonWhilstParsingRecord | Error_ExpectedKeyWhilstParsingRecord - | Error_TypeDoesNotTakeArgs TypeExpression TypeExpression - | Error_TypeDoesNotTakeArgs2 TypeExpression + | Error_TypeDoesNotTakeArgs TypeExpression (TypeExpressionNestingLeaf () ()) | Error_ValueDoesNotTakeArgs Frontend.LocatedExpr | Error_ExtraItemAfterBlock TypeExpression Lexer.LexItem | Error_TooManyTupleArgs @@ -781,9 +780,7 @@ parseLowercaseArgsOrAssignment item = |> Err -parserTypeExprFromEmpty : - Located Lexer.LexToken - -> Result Error (TypeExpressionNestingLeaf () ()) +parserTypeExprFromEmpty : Located Lexer.LexToken -> Result Error (TypeExpressionNestingLeaf () ()) parserTypeExprFromEmpty item = case Located.unwrap item of Lexer.Identifier { qualifiers, name } -> @@ -859,14 +856,14 @@ parserTypeExpr prevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> leafToParent prevExpr - |> Result.map - (\parent -> - TypeExpressionNestingLeaf_Bracket - { firstExpressions = empty - , trailingExpression = Nothing - , parent = Just parent - } - ) + (\mParent -> + TypeExpressionNestingLeaf_Bracket + { firstExpressions = empty + , trailingExpression = Nothing + , parent = mParent + } + |> Ok + ) Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> case collapseFunction prevExpr of @@ -898,14 +895,14 @@ parserTypeExpr prevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> leafToParent prevExpr - |> Result.map - (\newParent -> - TypeExpressionNestingLeaf_PartialRecord - { firstEntries = empty - , lastEntry = LastEntryOfRecord_Empty - , parent = Just newParent - } - ) + (\mNewParent -> + TypeExpressionNestingLeaf_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty + , parent = mNewParent + } + |> Ok + ) Lexer.Sigil Lexer.Colon -> appendColonTo prevExpr @@ -1024,9 +1021,7 @@ parserTypeExpr prevExpr item = |> Err -parserExpressionFromEmpty : - Located Lexer.LexToken - -> Result Error ExpressionNestingLeaf +parserExpressionFromEmpty : Located Lexer.LexToken -> Result Error ExpressionNestingLeaf parserExpressionFromEmpty item = let withCorrectLocation x = @@ -1083,27 +1078,28 @@ parserExpression prevExpr item = -- HELPERS -leafToParent : TypeExpressionNestingLeaf () () -> Result Error TypeExpressionNestingParent -leafToParent leaf = +leafToParent : TypeExpressionNestingLeaf () () -> (Maybe TypeExpressionNestingParent -> Result Error (TypeExpressionNestingLeaf () ())) -> Result Error (TypeExpressionNestingLeaf () ()) +leafToParent leaf processParent = case leaf of TypeExpressionNestingLeaf_Expr expr -> -- Cannot nest unless there is a trailing comma! - Error_TypeDoesNotTakeArgs2 expr - |> Err + processParent Nothing + |> Result.andThen (Error_TypeDoesNotTakeArgs expr >> Err) TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> case trailingExpression of Just lastType -> -- Cannot nest unless there is a trailing comma! - Error_TypeDoesNotTakeArgs2 lastType - |> Err + processParent Nothing + |> Result.andThen (Error_TypeDoesNotTakeArgs lastType >> Err) Nothing -> { expressions = firstExpressions , parent = parent } |> NestingParentType_Bracket - |> Ok + |> Just + |> processParent TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of @@ -1121,15 +1117,17 @@ leafToParent leaf = , parent = parent } |> NestingParentType_PartialRecord - |> Ok + |> Just + |> processParent LastEntryOfRecord_KeyValue _ lastValueType -> - Error_TypeDoesNotTakeArgs2 lastValueType - |> Err + processParent Nothing + |> Result.andThen (Error_TypeDoesNotTakeArgs lastValueType >> Err) TypeExpressionNestingLeaf_TypeWithArgs details -> NestingParentType_TypeWithArgs details - |> Ok + |> Just + |> processParent TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> case output of @@ -1139,11 +1137,12 @@ leafToParent leaf = , otherInputs = otherInputs , parent = parent } - |> Ok + |> Just + |> processParent Just ( te, () ) -> - Error_TypeDoesNotTakeArgs2 te - |> Err + processParent Nothing + |> Result.andThen (Error_TypeDoesNotTakeArgs te >> Err) parentsToLeafWith : TypeExpression -> Maybe TypeExpressionNestingParent -> TypeExpressionNestingLeaf () () @@ -1209,12 +1208,8 @@ exprAppend currentLeaf token = else lowerCaseTypeError - - doesNotTakeArgsError expr = - Result.andThen (Error_TypeDoesNotTakeArgs expr >> Err) genericType in case currentLeaf of - -- We are within a nested bracket. TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> case trailingExpression of Nothing -> @@ -1229,10 +1224,14 @@ exprAppend currentLeaf token = ) Just existingRoot -> - doesNotTakeArgsError existingRoot + genericType + |> Result.andThen + (TypeExpressionNestingLeaf_Expr >> Error_TypeDoesNotTakeArgs existingRoot >> Err) TypeExpressionNestingLeaf_Expr expr -> - doesNotTakeArgsError expr + genericType + |> Result.andThen + (TypeExpressionNestingLeaf_Expr >> Error_TypeDoesNotTakeArgs expr >> Err) TypeExpressionNestingLeaf_PartialRecord pr -> case pr.lastEntry of @@ -1253,57 +1252,55 @@ exprAppend currentLeaf token = |> Err _ -> - Result.map2 - (\newParent gt -> parentsToLeafWith gt (Just newParent)) - (leafToParent currentLeaf) - genericType + -- TODO(harry): dedup + leafToParent + currentLeaf + (\mNewParent -> + genericType + |> Result.map (\gt -> parentsToLeafWith gt mNewParent) + ) TypeExpressionNestingLeaf_TypeWithArgs _ -> - Result.map2 - (\newParent gt -> parentsToLeafWith gt (Just newParent)) - (leafToParent currentLeaf) - genericType + leafToParent + currentLeaf + (\mNewParent -> + genericType + |> Result.map (\gt -> parentsToLeafWith gt mNewParent) + ) TypeExpressionNestingLeaf_Function _ -> - Result.map2 - (\newParent gt -> parentsToLeafWith gt (Just newParent)) - (leafToParent currentLeaf) - genericType + leafToParent + currentLeaf + (\mNewParent -> + genericType + |> Result.map (\gt -> parentsToLeafWith gt mNewParent) + ) Token.TokenUpperCase upper -> let - doesNotTakeArgsError expr = - Error_TypeDoesNotTakeArgs expr - (TypeExpression_NamedType - { qualifiers = token.qualifiers - , name = upper - , args = empty - } - ) - |> Err + ty parent = + TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = token.qualifiers + , name = upper + , args = empty + , parent = parent + , phantom = () + } in case currentLeaf of -- We are within a nested bracket. TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression } -> case trailingExpression of Nothing -> - leafToParent currentLeaf - |> Result.map - (\newParent -> - TypeExpressionNestingLeaf_TypeWithArgs - { qualifiers = token.qualifiers - , name = upper - , args = empty - , parent = Just newParent - , phantom = () - } - ) + leafToParent currentLeaf (ty >> Ok) Just existingRoot -> - doesNotTakeArgsError existingRoot + Error_TypeDoesNotTakeArgs existingRoot (ty Nothing) + |> Err TypeExpressionNestingLeaf_Expr expr -> - doesNotTakeArgsError expr + Error_TypeDoesNotTakeArgs expr (ty Nothing) + |> Err TypeExpressionNestingLeaf_PartialRecord pr -> case pr.lastEntry of @@ -1320,17 +1317,18 @@ exprAppend currentLeaf token = |> Err _ -> - leafToParent currentLeaf - |> Result.map - (\newParent -> - TypeExpressionNestingLeaf_TypeWithArgs - { qualifiers = token.qualifiers - , name = upper - , args = empty - , parent = Just newParent - , phantom = () - } - ) + leafToParent + currentLeaf + (\mNewParent -> + TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = token.qualifiers + , name = upper + , args = empty + , parent = mNewParent + , phantom = () + } + |> Ok + ) TypeExpressionNestingLeaf_TypeWithArgs { name, args, parent } -> TypeExpressionNestingLeaf_TypeWithArgs @@ -1349,23 +1347,24 @@ exprAppend currentLeaf token = |> Ok TypeExpressionNestingLeaf_Function { firstInput, output } -> - Result.andThen - (\newParent -> + leafToParent currentLeaf + (\mNewParent -> case output of Just ( outputExpr, () ) -> - doesNotTakeArgsError outputExpr + Error_TypeDoesNotTakeArgs outputExpr (ty Nothing) + |> Err Nothing -> + -- TODO(harry) dedup TypeExpressionNestingLeaf_TypeWithArgs { qualifiers = token.qualifiers , name = upper , args = empty - , parent = Just newParent + , parent = mNewParent , phantom = () } |> Ok ) - (leafToParent currentLeaf) appendCommaTo : TypeExpressionNestingLeaf () () -> Result Error (TypeExpressionNestingLeaf () ()) diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index e53e0da5..9835c1f4 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -4686,7 +4686,7 @@ type alias Function3 = (Int, () ->, ()) , contextualized = Just [ Err - { error = Error_TypeDoesNotTakeArgs2 (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] })) + { error = Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] })) (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing }) , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] })))) } @@ -4719,7 +4719,7 @@ type alias Function3 = (Int, () ->, ()) , contextualized = Just [ Err - { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit + { error = Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing }) , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) } @@ -4751,7 +4751,7 @@ type alias Function3 = (Int, () ->, ()) , contextualized = Just [ Err - { error = Error_TypeDoesNotTakeArgs2 TypeExpression_Unit + { error = Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing }) , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) } @@ -4843,7 +4843,7 @@ type alias E a = B.c -> a""" , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "B") [] (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "List", parent = Nothing, phantom = (), qualifiers = [] })) } , Err - { error = Error_TypeDoesNotTakeArgs (TypeExpression_GenericType (LowerCase "list")) (TypeExpression_NamedType { args = Stack [], name = UpperCase "A", qualifiers = [] }) + { error = Error_TypeDoesNotTakeArgs (TypeExpression_GenericType (LowerCase "list")) (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "A", parent = Nothing, phantom = (), qualifiers = [] }) , item = Just (Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] }))) , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "C") [] (TypeExpressionNestingLeaf_Expr (TypeExpression_GenericType (LowerCase "list")))) } From 626b543c00072a8a758b12f8194c1a976c71925d Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sun, 25 Oct 2020 19:27:35 +0000 Subject: [PATCH 101/103] tidy leaf to parent (slightly) still a messy function, needs more love. --- src/Stage/Parse/Contextualize.elm | 128 +++++++++++++++++------------- 1 file changed, 74 insertions(+), 54 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 99b13be8..d1dd132d 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -862,7 +862,6 @@ parserTypeExpr prevExpr item = , trailingExpression = Nothing , parent = mParent } - |> Ok ) Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> @@ -901,7 +900,6 @@ parserTypeExpr prevExpr item = , lastEntry = LastEntryOfRecord_Empty , parent = mNewParent } - |> Ok ) Lexer.Sigil Lexer.Colon -> @@ -1078,20 +1076,18 @@ parserExpression prevExpr item = -- HELPERS -leafToParent : TypeExpressionNestingLeaf () () -> (Maybe TypeExpressionNestingParent -> Result Error (TypeExpressionNestingLeaf () ())) -> Result Error (TypeExpressionNestingLeaf () ()) +leafToParent : TypeExpressionNestingLeaf () () -> (Maybe TypeExpressionNestingParent -> TypeExpressionNestingLeaf () ()) -> Result Error (TypeExpressionNestingLeaf () ()) leafToParent leaf processParent = case leaf of TypeExpressionNestingLeaf_Expr expr -> -- Cannot nest unless there is a trailing comma! - processParent Nothing - |> Result.andThen (Error_TypeDoesNotTakeArgs expr >> Err) + Error_TypeDoesNotTakeArgs expr (processParent Nothing) |> Err TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression, parent } -> case trailingExpression of Just lastType -> -- Cannot nest unless there is a trailing comma! - processParent Nothing - |> Result.andThen (Error_TypeDoesNotTakeArgs lastType >> Err) + Error_TypeDoesNotTakeArgs lastType (processParent Nothing) |> Err Nothing -> { expressions = firstExpressions @@ -1100,6 +1096,7 @@ leafToParent leaf processParent = |> NestingParentType_Bracket |> Just |> processParent + |> Ok TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> case lastEntry of @@ -1119,15 +1116,16 @@ leafToParent leaf processParent = |> NestingParentType_PartialRecord |> Just |> processParent + |> Ok LastEntryOfRecord_KeyValue _ lastValueType -> - processParent Nothing - |> Result.andThen (Error_TypeDoesNotTakeArgs lastValueType >> Err) + Error_TypeDoesNotTakeArgs lastValueType (processParent Nothing) |> Err TypeExpressionNestingLeaf_TypeWithArgs details -> NestingParentType_TypeWithArgs details |> Just |> processParent + |> Ok TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> case output of @@ -1139,10 +1137,10 @@ leafToParent leaf processParent = } |> Just |> processParent + |> Ok Just ( te, () ) -> - processParent Nothing - |> Result.andThen (Error_TypeDoesNotTakeArgs te >> Err) + Error_TypeDoesNotTakeArgs te (processParent Nothing) |> Err parentsToLeafWith : TypeExpression -> Maybe TypeExpressionNestingParent -> TypeExpressionNestingLeaf () () @@ -1251,30 +1249,59 @@ exprAppend currentLeaf token = } |> Err - _ -> - -- TODO(harry): dedup - leafToParent - currentLeaf - (\mNewParent -> - genericType - |> Result.map (\gt -> parentsToLeafWith gt mNewParent) - ) + LastEntryOfRecord_Key _ -> + Error_ExpectedColonWhilstParsingRecord + |> Err - TypeExpressionNestingLeaf_TypeWithArgs _ -> - leafToParent - currentLeaf - (\mNewParent -> + LastEntryOfRecord_KeyColon key -> genericType - |> Result.map (\gt -> parentsToLeafWith gt mNewParent) - ) + |> Result.map + (\gt -> + { firstEntries = pr.firstEntries + , lastEntryName = key + , parent = pr.parent + } + |> NestingParentType_PartialRecord + |> Just + |> parentsToLeafWith gt + ) - TypeExpressionNestingLeaf_Function _ -> - leafToParent - currentLeaf - (\mNewParent -> + LastEntryOfRecord_KeyValue _ lastValueType -> genericType - |> Result.map (\gt -> parentsToLeafWith gt mNewParent) - ) + |> Result.andThen + (\gt -> + Error_TypeDoesNotTakeArgs lastValueType (TypeExpressionNestingLeaf_Expr gt) + |> Err + ) + + TypeExpressionNestingLeaf_TypeWithArgs details -> + genericType + |> Result.map + (\gt -> + parentsToLeafWith gt (Just (NestingParentType_TypeWithArgs details)) + ) + + TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> + genericType + |> Result.andThen + (\gt -> + case output of + Nothing -> + parentsToLeafWith + gt + ({ firstInput = firstInput + , otherInputs = otherInputs + , parent = parent + } + |> NestingParentType_Function + |> Just + ) + |> Ok + + Just ( te, () ) -> + Error_TypeDoesNotTakeArgs te (parentsToLeafWith gt Nothing) + |> Err + ) Token.TokenUpperCase upper -> let @@ -1292,7 +1319,7 @@ exprAppend currentLeaf token = TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression } -> case trailingExpression of Nothing -> - leafToParent currentLeaf (ty >> Ok) + leafToParent currentLeaf ty Just existingRoot -> Error_TypeDoesNotTakeArgs existingRoot (ty Nothing) @@ -1327,7 +1354,6 @@ exprAppend currentLeaf token = , parent = mNewParent , phantom = () } - |> Ok ) TypeExpressionNestingLeaf_TypeWithArgs { name, args, parent } -> @@ -1346,25 +1372,21 @@ exprAppend currentLeaf token = } |> Ok - TypeExpressionNestingLeaf_Function { firstInput, output } -> - leafToParent currentLeaf - (\mNewParent -> - case output of - Just ( outputExpr, () ) -> - Error_TypeDoesNotTakeArgs outputExpr (ty Nothing) - |> Err + TypeExpressionNestingLeaf_Function { firstInput, otherInputs, parent, output } -> + case output of + Nothing -> + NestingParentType_Function + { firstInput = firstInput + , otherInputs = otherInputs + , parent = parent + } + |> Just + |> ty + |> Ok - Nothing -> - -- TODO(harry) dedup - TypeExpressionNestingLeaf_TypeWithArgs - { qualifiers = token.qualifiers - , name = upper - , args = empty - , parent = mNewParent - , phantom = () - } - |> Ok - ) + Just ( te, () ) -> + Error_TypeDoesNotTakeArgs te (ty Nothing) + |> Err appendCommaTo : TypeExpressionNestingLeaf () () -> Result Error (TypeExpressionNestingLeaf () ()) @@ -1472,9 +1494,7 @@ closeBracket argStack mLastExpression mParent = Err e -closeRecord : - PartialRecord - -> Result Error (TypeExpressionNestingLeaf () ()) +closeRecord : PartialRecord -> Result Error (TypeExpressionNestingLeaf () ()) closeRecord { firstEntries, lastEntry, parent } = let fromRecord recordEntries = From df9e3cf062a67f1f09178d171f922fe88ff61082 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Sun, 25 Oct 2020 19:45:48 +0000 Subject: [PATCH 102/103] rename functions `exprAppend` becomes `appendPossiblyQualifiedTokenTo` and `parentsToLeafWith` becomes `appendTypeExprTo`. These names do a much better job at explaining what these functions do. --- src/Stage/Parse/Contextualize.elm | 75 ++++++++++++++----------------- 1 file changed, 33 insertions(+), 42 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index d1dd132d..0b4d0361 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -852,7 +852,7 @@ parserTypeExpr : parserTypeExpr prevExpr item = case Located.unwrap item of Lexer.Identifier ident -> - exprAppend prevExpr ident + appendPossiblyQualifiedTokenTo prevExpr ident Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> leafToParent prevExpr @@ -1143,8 +1143,8 @@ leafToParent leaf processParent = Error_TypeDoesNotTakeArgs te (processParent Nothing) |> Err -parentsToLeafWith : TypeExpression -> Maybe TypeExpressionNestingParent -> TypeExpressionNestingLeaf () () -parentsToLeafWith expr toMakeIntoLeaf = +appendTypeExprTo : Maybe TypeExpressionNestingParent -> TypeExpression -> TypeExpressionNestingLeaf () () +appendTypeExprTo toMakeIntoLeaf expr = case toMakeIntoLeaf of Just (NestingParentType_PartialRecord { firstEntries, lastEntryName, parent }) -> TypeExpressionNestingLeaf_PartialRecord @@ -1181,14 +1181,14 @@ parentsToLeafWith expr toMakeIntoLeaf = TypeExpressionNestingLeaf_Expr expr -exprAppend : +appendPossiblyQualifiedTokenTo : TypeExpressionNestingLeaf () () -> { qualifiers : List Token.UpperCase , name : Token.Token } -> Result Error (TypeExpressionNestingLeaf () ()) -exprAppend currentLeaf token = +appendPossiblyQualifiedTokenTo currentLeaf token = case token.name of Token.TokenLowerCase lower -> let @@ -1256,14 +1256,14 @@ exprAppend currentLeaf token = LastEntryOfRecord_KeyColon key -> genericType |> Result.map - (\gt -> - { firstEntries = pr.firstEntries - , lastEntryName = key - , parent = pr.parent - } + (appendTypeExprTo + ({ firstEntries = pr.firstEntries + , lastEntryName = key + , parent = pr.parent + } |> NestingParentType_PartialRecord |> Just - |> parentsToLeafWith gt + ) ) LastEntryOfRecord_KeyValue _ lastValueType -> @@ -1276,10 +1276,7 @@ exprAppend currentLeaf token = TypeExpressionNestingLeaf_TypeWithArgs details -> genericType - |> Result.map - (\gt -> - parentsToLeafWith gt (Just (NestingParentType_TypeWithArgs details)) - ) + |> Result.map (appendTypeExprTo (Just (NestingParentType_TypeWithArgs details))) TypeExpressionNestingLeaf_Function { firstInput, otherInputs, output, parent } -> genericType @@ -1287,19 +1284,21 @@ exprAppend currentLeaf token = (\gt -> case output of Nothing -> - parentsToLeafWith - gt - ({ firstInput = firstInput - , otherInputs = otherInputs - , parent = parent - } - |> NestingParentType_Function - |> Just - ) + gt + |> appendTypeExprTo + ({ firstInput = firstInput + , otherInputs = otherInputs + , parent = parent + } + |> NestingParentType_Function + |> Just + ) |> Ok Just ( te, () ) -> - Error_TypeDoesNotTakeArgs te (parentsToLeafWith gt Nothing) + gt + |> appendTypeExprTo Nothing + |> Error_TypeDoesNotTakeArgs te |> Err ) @@ -1485,37 +1484,28 @@ closeBracket argStack mLastExpression mParent = TypeExpression_Tuple first second rest |> Ok in - case rexpr of - Ok expr -> - parentsToLeafWith expr mParent - |> Ok - - Err e -> - Err e + rexpr + |> Result.map (appendTypeExprTo mParent) closeRecord : PartialRecord -> Result Error (TypeExpressionNestingLeaf () ()) closeRecord { firstEntries, lastEntry, parent } = let - fromRecord recordEntries = - let - record = - TypeExpression_Record recordEntries - in - parentsToLeafWith record parent + fromRecordEntries recordEntries = + appendTypeExprTo parent (TypeExpression_Record recordEntries) in case lastEntry of LastEntryOfRecord_KeyValue key value -> ( key, value ) |> pushOnto firstEntries |> toList (\x -> x) - |> fromRecord + |> fromRecordEntries |> Ok LastEntryOfRecord_Empty -> if firstEntries == empty then [] - |> fromRecord + |> fromRecordEntries |> Ok else @@ -1764,7 +1754,8 @@ collapseTypeWithArgs pte = newTypeExpr = TypeExpression_NamedType { qualifiers = qualifiers, name = name, args = args } in - parentsToLeafWith newTypeExpr parent + newTypeExpr + |> appendTypeExprTo parent |> collapseTypeWithArgs TypeExpressionNestingLeaf_Expr expr -> @@ -1819,7 +1810,7 @@ collapseFunction pte = , output = outputExpr } in - parentsToLeafWith newTypeExpr parent + appendTypeExprTo parent newTypeExpr |> collapseFunction From 4eaf664a6cc503e602b50a434723faacf78ea0a4 Mon Sep 17 00:00:00 2001 From: Harry Sarson Date: Mon, 26 Oct 2020 19:25:56 +0000 Subject: [PATCH 103/103] more type trickery to avoid callbacks --- src/Stage/Parse/Contextualize.elm | 183 +++++++++++++++++------------- src/Stage/Parse/Pretty.elm | 4 +- tests/ParserLexerTestCases.elm | 12 +- 3 files changed, 112 insertions(+), 87 deletions(-) diff --git a/src/Stage/Parse/Contextualize.elm b/src/Stage/Parse/Contextualize.elm index 0b4d0361..4db3d09f 100644 --- a/src/Stage/Parse/Contextualize.elm +++ b/src/Stage/Parse/Contextualize.elm @@ -101,7 +101,7 @@ type BlockTypeAlias = BlockTypeAlias_Keywords | BlockTypeAlias_Named Token.UpperCase (Stack Token.LowerCase) | BlockTypeAlias_NamedAssigns Token.UpperCase (List Token.LowerCase) - | BlockTypeAlias_Completish Token.UpperCase (List Token.LowerCase) (TypeExpressionNestingLeaf () ()) + | BlockTypeAlias_Completish Token.UpperCase (List Token.LowerCase) (TypeExpressionNestingLeaf () () ()) type BlockCustomType @@ -195,7 +195,7 @@ type TypeExpressionNestingParent {-| Sometimes we need to limit which types of `TypeExpressionNestingLeaf` are valid. We do that using the phantom type parameters. For example `TypeExpressionNestingLeaf () Never` cannot be a `TypeExpressionNestingLeaf_TypeWithArgs`. -} -type TypeExpressionNestingLeaf phantomFunctionWithOutput phantomTypeWithArgs +type TypeExpressionNestingLeaf phantomFunctionWithOutput phantomTypeWithArgs phantomHasParent = TypeExpressionNestingLeaf_Bracket { firstExpressions : Stack TypeExpression , trailingExpression : Maybe TypeExpression @@ -215,7 +215,7 @@ type TypeExpressionNestingLeaf phantomFunctionWithOutput phantomTypeWithArgs , output : Maybe ( TypeExpression, phantomFunctionWithOutput ) , parent : Maybe TypeExpressionNestingParent } - | TypeExpressionNestingLeaf_Expr TypeExpression + | TypeExpressionNestingLeaf_Expr phantomHasParent TypeExpression @@ -274,7 +274,7 @@ type Error | Error_MissingFunctionReturnType | Error_ExpectedColonWhilstParsingRecord | Error_ExpectedKeyWhilstParsingRecord - | Error_TypeDoesNotTakeArgs TypeExpression (TypeExpressionNestingLeaf () ()) + | Error_TypeDoesNotTakeArgs TypeExpression (TypeExpressionNestingLeaf () () ()) | Error_ValueDoesNotTakeArgs Frontend.LocatedExpr | Error_ExtraItemAfterBlock TypeExpression Lexer.LexItem | Error_TooManyTupleArgs @@ -402,7 +402,7 @@ runHelp items state = parseAnything : State -> Located Lexer.LexItem -> Result Error ParseSuccess parseAnything state item = let - newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> TypeExpressionNestingLeaf () () -> Result Error State + newTypeAliasState : Token.UpperCase -> List Token.LowerCase -> TypeExpressionNestingLeaf () () () -> Result Error State newTypeAliasState aliasName typeArgs expr = State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs expr) |> Ok @@ -509,7 +509,7 @@ parseAnything state item = State_BlockTypeAlias (BlockTypeAlias_Completish name typeArgs exprSoFar) -> case collapseFunction exprSoFar of - TypeExpressionNestingLeaf_Expr expr -> + TypeExpressionNestingLeaf_Expr () expr -> doneParsingTypeAlias name typeArgs expr _ -> @@ -780,7 +780,7 @@ parseLowercaseArgsOrAssignment item = |> Err -parserTypeExprFromEmpty : Located Lexer.LexToken -> Result Error (TypeExpressionNestingLeaf () ()) +parserTypeExprFromEmpty : Located Lexer.LexToken -> Result Error (TypeExpressionNestingLeaf () () ()) parserTypeExprFromEmpty item = case Located.unwrap item of Lexer.Identifier { qualifiers, name } -> @@ -788,7 +788,7 @@ parserTypeExprFromEmpty item = Token.TokenLowerCase lower -> if qualifiers == [] then TypeExpression_GenericType lower - |> TypeExpressionNestingLeaf_Expr + |> TypeExpressionNestingLeaf_Expr () |> Ok else @@ -846,27 +846,26 @@ parserTypeExprFromEmpty item = parserTypeExpr : - TypeExpressionNestingLeaf () () + TypeExpressionNestingLeaf () () () -> Located Lexer.LexToken - -> Result Error (TypeExpressionNestingLeaf () ()) + -> Result Error (TypeExpressionNestingLeaf () () ()) parserTypeExpr prevExpr item = case Located.unwrap item of Lexer.Identifier ident -> appendPossiblyQualifiedTokenTo prevExpr ident Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Open) -> - leafToParent prevExpr - (\mParent -> - TypeExpressionNestingLeaf_Bracket - { firstExpressions = empty - , trailingExpression = Nothing - , parent = mParent - } + addNewNestingContextTo prevExpr + (TypeExpressionNestingLeaf_Bracket + { firstExpressions = empty + , trailingExpression = Nothing + , parent = Nothing + } ) Lexer.Sigil (Lexer.Bracket Lexer.Round Lexer.Close) -> case collapseFunction prevExpr of - TypeExpressionNestingLeaf_Expr _ -> + TypeExpressionNestingLeaf_Expr () _ -> Error_UnmatchedBracket Lexer.Round Lexer.Close |> Err @@ -893,13 +892,12 @@ parserTypeExpr prevExpr item = never phantom Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Open) -> - leafToParent prevExpr - (\mNewParent -> - TypeExpressionNestingLeaf_PartialRecord - { firstEntries = empty - , lastEntry = LastEntryOfRecord_Empty - , parent = mNewParent - } + addNewNestingContextTo prevExpr + (TypeExpressionNestingLeaf_PartialRecord + { firstEntries = empty + , lastEntry = LastEntryOfRecord_Empty + , parent = Nothing + } ) Lexer.Sigil Lexer.Colon -> @@ -910,7 +908,7 @@ parserTypeExpr prevExpr item = Lexer.Sigil (Lexer.Bracket Lexer.Curly Lexer.Close) -> case collapseFunction prevExpr of - TypeExpressionNestingLeaf_Expr _ -> + TypeExpressionNestingLeaf_Expr () _ -> Error_UnmatchedBracket Lexer.Curly Lexer.Close |> Err @@ -938,7 +936,7 @@ parserTypeExpr prevExpr item = Lexer.Sigil Lexer.ThinArrow -> case collapseTypeWithArgs prevExpr of - TypeExpressionNestingLeaf_Expr expr -> + TypeExpressionNestingLeaf_Expr () expr -> TypeExpressionNestingLeaf_Function { firstInput = expr , otherInputs = empty @@ -1076,10 +1074,32 @@ parserExpression prevExpr item = -- HELPERS -leafToParent : TypeExpressionNestingLeaf () () -> (Maybe TypeExpressionNestingParent -> TypeExpressionNestingLeaf () ()) -> Result Error (TypeExpressionNestingLeaf () ()) -leafToParent leaf processParent = - case leaf of - TypeExpressionNestingLeaf_Expr expr -> +{-| Takes the first `TypeExpressionNestingLeaf () () ()`, converts it into a `TypeExpressionNestingParent` and +overwrites the `parent` field of the second `TypeExpressionNestingLeaf () () Never` with the newly created +`TypeExpressionNestingParent`. +-} +addNewNestingContextTo : TypeExpressionNestingLeaf () () () -> TypeExpressionNestingLeaf () () Never -> Result Error (TypeExpressionNestingLeaf () () ()) +addNewNestingContextTo oldLeaf newLeaf = + let + processParent mParent = + case newLeaf of + TypeExpressionNestingLeaf_Bracket record -> + TypeExpressionNestingLeaf_Bracket { record | parent = mParent } + + TypeExpressionNestingLeaf_PartialRecord partialRecord -> + TypeExpressionNestingLeaf_PartialRecord { partialRecord | parent = mParent } + + TypeExpressionNestingLeaf_TypeWithArgs record -> + TypeExpressionNestingLeaf_TypeWithArgs { record | parent = mParent } + + TypeExpressionNestingLeaf_Function record -> + TypeExpressionNestingLeaf_Function { record | parent = mParent } + + TypeExpressionNestingLeaf_Expr notAnExpression _ -> + never notAnExpression + in + case oldLeaf of + TypeExpressionNestingLeaf_Expr () expr -> -- Cannot nest unless there is a trailing comma! Error_TypeDoesNotTakeArgs expr (processParent Nothing) |> Err @@ -1143,7 +1163,7 @@ leafToParent leaf processParent = Error_TypeDoesNotTakeArgs te (processParent Nothing) |> Err -appendTypeExprTo : Maybe TypeExpressionNestingParent -> TypeExpression -> TypeExpressionNestingLeaf () () +appendTypeExprTo : Maybe TypeExpressionNestingParent -> TypeExpression -> TypeExpressionNestingLeaf () () () appendTypeExprTo toMakeIntoLeaf expr = case toMakeIntoLeaf of Just (NestingParentType_PartialRecord { firstEntries, lastEntryName, parent }) -> @@ -1178,16 +1198,16 @@ appendTypeExprTo toMakeIntoLeaf expr = } Nothing -> - TypeExpressionNestingLeaf_Expr expr + TypeExpressionNestingLeaf_Expr () expr appendPossiblyQualifiedTokenTo : - TypeExpressionNestingLeaf () () + TypeExpressionNestingLeaf () () () -> { qualifiers : List Token.UpperCase , name : Token.Token } - -> Result Error (TypeExpressionNestingLeaf () ()) + -> Result Error (TypeExpressionNestingLeaf () () ()) appendPossiblyQualifiedTokenTo currentLeaf token = case token.name of Token.TokenLowerCase lower -> @@ -1224,12 +1244,12 @@ appendPossiblyQualifiedTokenTo currentLeaf token = Just existingRoot -> genericType |> Result.andThen - (TypeExpressionNestingLeaf_Expr >> Error_TypeDoesNotTakeArgs existingRoot >> Err) + (TypeExpressionNestingLeaf_Expr () >> Error_TypeDoesNotTakeArgs existingRoot >> Err) - TypeExpressionNestingLeaf_Expr expr -> + TypeExpressionNestingLeaf_Expr () expr -> genericType |> Result.andThen - (TypeExpressionNestingLeaf_Expr >> Error_TypeDoesNotTakeArgs expr >> Err) + (TypeExpressionNestingLeaf_Expr () >> Error_TypeDoesNotTakeArgs expr >> Err) TypeExpressionNestingLeaf_PartialRecord pr -> case pr.lastEntry of @@ -1270,7 +1290,7 @@ appendPossiblyQualifiedTokenTo currentLeaf token = genericType |> Result.andThen (\gt -> - Error_TypeDoesNotTakeArgs lastValueType (TypeExpressionNestingLeaf_Expr gt) + Error_TypeDoesNotTakeArgs lastValueType (TypeExpressionNestingLeaf_Expr () gt) |> Err ) @@ -1304,28 +1324,30 @@ appendPossiblyQualifiedTokenTo currentLeaf token = Token.TokenUpperCase upper -> let - ty parent = - TypeExpressionNestingLeaf_TypeWithArgs - { qualifiers = token.qualifiers - , name = upper - , args = empty - , parent = parent - , phantom = () - } + record = + { qualifiers = token.qualifiers + , name = upper + , args = empty + , parent = Nothing + , phantom = () + } + + ty = + TypeExpressionNestingLeaf_TypeWithArgs record in case currentLeaf of -- We are within a nested bracket. TypeExpressionNestingLeaf_Bracket { firstExpressions, trailingExpression } -> case trailingExpression of Nothing -> - leafToParent currentLeaf ty + addNewNestingContextTo currentLeaf ty Just existingRoot -> - Error_TypeDoesNotTakeArgs existingRoot (ty Nothing) + Error_TypeDoesNotTakeArgs existingRoot ty |> Err - TypeExpressionNestingLeaf_Expr expr -> - Error_TypeDoesNotTakeArgs expr (ty Nothing) + TypeExpressionNestingLeaf_Expr () expr -> + Error_TypeDoesNotTakeArgs expr ty |> Err TypeExpressionNestingLeaf_PartialRecord pr -> @@ -1343,16 +1365,15 @@ appendPossiblyQualifiedTokenTo currentLeaf token = |> Err _ -> - leafToParent + addNewNestingContextTo currentLeaf - (\mNewParent -> - TypeExpressionNestingLeaf_TypeWithArgs - { qualifiers = token.qualifiers - , name = upper - , args = empty - , parent = mNewParent - , phantom = () - } + (TypeExpressionNestingLeaf_TypeWithArgs + { qualifiers = token.qualifiers + , name = upper + , args = empty + , parent = Nothing + , phantom = () + } ) TypeExpressionNestingLeaf_TypeWithArgs { name, args, parent } -> @@ -1374,21 +1395,25 @@ appendPossiblyQualifiedTokenTo currentLeaf token = TypeExpressionNestingLeaf_Function { firstInput, otherInputs, parent, output } -> case output of Nothing -> - NestingParentType_Function - { firstInput = firstInput - , otherInputs = otherInputs - , parent = parent - } - |> Just - |> ty + { record + | parent = + Just + (NestingParentType_Function + { firstInput = firstInput + , otherInputs = otherInputs + , parent = parent + } + ) + } + |> TypeExpressionNestingLeaf_TypeWithArgs |> Ok Just ( te, () ) -> - Error_TypeDoesNotTakeArgs te (ty Nothing) + Error_TypeDoesNotTakeArgs te ty |> Err -appendCommaTo : TypeExpressionNestingLeaf () () -> Result Error (TypeExpressionNestingLeaf () ()) +appendCommaTo : TypeExpressionNestingLeaf () () () -> Result Error (TypeExpressionNestingLeaf () () ()) appendCommaTo prevExpr = case collapseFunction prevExpr of TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> @@ -1424,7 +1449,7 @@ appendCommaTo prevExpr = |> Err -appendColonTo : TypeExpressionNestingLeaf () () -> Result Error (TypeExpressionNestingLeaf () ()) +appendColonTo : TypeExpressionNestingLeaf () () () -> Result Error (TypeExpressionNestingLeaf () () ()) appendColonTo prevExpr = case prevExpr of TypeExpressionNestingLeaf_PartialRecord { firstEntries, lastEntry, parent } -> @@ -1450,7 +1475,7 @@ closeBracket : Stack TypeExpression -> Maybe TypeExpression -> Maybe TypeExpressionNestingParent - -> Result Error (TypeExpressionNestingLeaf () ()) + -> Result Error (TypeExpressionNestingLeaf () () ()) closeBracket argStack mLastExpression mParent = let rexpr = @@ -1488,7 +1513,7 @@ closeBracket argStack mLastExpression mParent = |> Result.map (appendTypeExprTo mParent) -closeRecord : PartialRecord -> Result Error (TypeExpressionNestingLeaf () ()) +closeRecord : PartialRecord -> Result Error (TypeExpressionNestingLeaf () () ()) closeRecord { firstEntries, lastEntry, parent } = let fromRecordEntries recordEntries = @@ -1694,7 +1719,7 @@ blockFromState state = State_BlockTypeAlias (BlockTypeAlias_Completish aliasName typeArgs partialExpr) -> case collapseFunction partialExpr of - TypeExpressionNestingLeaf_Expr expr -> + TypeExpressionNestingLeaf_Expr () expr -> typeExpressionToConcreteType expr |> Result.map (\conceteType -> @@ -1746,7 +1771,7 @@ blockFromState state = -- helper functions -collapseTypeWithArgs : TypeExpressionNestingLeaf () () -> TypeExpressionNestingLeaf () Never +collapseTypeWithArgs : TypeExpressionNestingLeaf () () () -> TypeExpressionNestingLeaf () Never () collapseTypeWithArgs pte = case pte of TypeExpressionNestingLeaf_TypeWithArgs { qualifiers, name, args, parent } -> @@ -1758,8 +1783,8 @@ collapseTypeWithArgs pte = |> appendTypeExprTo parent |> collapseTypeWithArgs - TypeExpressionNestingLeaf_Expr expr -> - TypeExpressionNestingLeaf_Expr expr + TypeExpressionNestingLeaf_Expr () expr -> + TypeExpressionNestingLeaf_Expr () expr TypeExpressionNestingLeaf_Bracket b -> TypeExpressionNestingLeaf_Bracket b @@ -1776,14 +1801,14 @@ collapseTypeWithArgs pte = } -collapseFunction : TypeExpressionNestingLeaf () () -> TypeExpressionNestingLeaf Never Never +collapseFunction : TypeExpressionNestingLeaf () () () -> TypeExpressionNestingLeaf Never Never () collapseFunction pte = case collapseTypeWithArgs pte of TypeExpressionNestingLeaf_TypeWithArgs { phantom } -> never phantom - TypeExpressionNestingLeaf_Expr expr -> - TypeExpressionNestingLeaf_Expr expr + TypeExpressionNestingLeaf_Expr () expr -> + TypeExpressionNestingLeaf_Expr () expr TypeExpressionNestingLeaf_Bracket b -> TypeExpressionNestingLeaf_Bracket b diff --git a/src/Stage/Parse/Pretty.elm b/src/Stage/Parse/Pretty.elm index 9fa7f819..c294d06f 100644 --- a/src/Stage/Parse/Pretty.elm +++ b/src/Stage/Parse/Pretty.elm @@ -345,7 +345,7 @@ typeExpr expr_ = ) -typeExpressionNestingLeaf : TypeExpressionNestingLeaf () () -> Sexpr String +typeExpressionNestingLeaf : TypeExpressionNestingLeaf () () () -> Sexpr String typeExpressionNestingLeaf leaf = case leaf of TypeExpressionNestingLeaf_Bracket record -> @@ -360,7 +360,7 @@ typeExpressionNestingLeaf leaf = TypeExpressionNestingLeaf_Function record -> pair "TypeExpressionNestingLeaf_Function" (Atom "TODO") - TypeExpressionNestingLeaf_Expr typeExpression -> + TypeExpressionNestingLeaf_Expr () typeExpression -> pair "TypeExpressionNestingLeaf_Expr" (Atom "TODO") diff --git a/tests/ParserLexerTestCases.elm b/tests/ParserLexerTestCases.elm index 9835c1f4..8a89e910 100644 --- a/tests/ParserLexerTestCases.elm +++ b/tests/ParserLexerTestCases.elm @@ -4688,7 +4688,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] })) (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing }) , item = Just (Located { end = { col = 24, row = 1 }, start = { col = 23, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] })))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr () (TypeExpression_Bracketed (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] })))) } ] , lexed = @@ -4721,7 +4721,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing }) , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr () TypeExpression_Unit)) } ] , lexed = @@ -4753,7 +4753,7 @@ type alias Function3 = (Int, () ->, ()) [ Err { error = Error_TypeDoesNotTakeArgs TypeExpression_Unit (TypeExpressionNestingLeaf_Bracket { firstExpressions = Stack [], parent = Nothing, trailingExpression = Nothing }) , item = Just (Located { end = { col = 21, row = 1 }, start = { col = 20, row = 1 } } (Token (Sigil (Bracket Round Open)))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr TypeExpression_Unit)) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] (TypeExpressionNestingLeaf_Expr () TypeExpression_Unit)) } ] , lexed = @@ -4845,7 +4845,7 @@ type alias E a = B.c -> a""" , Err { error = Error_TypeDoesNotTakeArgs (TypeExpression_GenericType (LowerCase "list")) (TypeExpressionNestingLeaf_TypeWithArgs { args = Stack [], name = UpperCase "A", parent = Nothing, phantom = (), qualifiers = [] }) , item = Just (Located { end = { col = 22, row = 5 }, start = { col = 21, row = 5 } } (Token (Identifier { name = TokenUpperCase (UpperCase "A"), qualifiers = [] }))) - , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "C") [] (TypeExpressionNestingLeaf_Expr (TypeExpression_GenericType (LowerCase "list")))) + , state = State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "C") [] (TypeExpressionNestingLeaf_Expr () (TypeExpression_GenericType (LowerCase "list")))) } , Err { error = @@ -5306,7 +5306,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] - (TypeExpressionNestingLeaf_Expr + (TypeExpressionNestingLeaf_Expr () (TypeExpression_Tuple (TypeExpression_NamedType { args = Stack [], name = UpperCase "Int", qualifiers = [] }) (TypeExpression_NamedType { args = Stack [], name = UpperCase "A", qualifiers = [] }) [ TypeExpression_NamedType { args = Stack [], name = UpperCase "B", qualifiers = [] } @@ -5406,7 +5406,7 @@ type alias Hi = (A Int, C D E F, H I (J K), L M () O P) State_BlockTypeAlias (BlockTypeAlias_Completish (UpperCase "Hi") [] - (TypeExpressionNestingLeaf_Expr + (TypeExpressionNestingLeaf_Expr () (TypeExpression_Tuple (TypeExpression_NamedType { args =