From 87049fa7b2f7a74b77d336077ff16bc46c92eb95 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 19 Jul 2024 00:17:50 +0200 Subject: [PATCH 01/44] Remove Elm.Parser.parse and rename parseToFile to parse --- CHANGELOG.md | 2 + review/suppressed/NoDeprecated.json | 8 ---- src/Elm/Internal/RawFile.elm | 7 +--- src/Elm/Parser.elm | 28 ++------------ src/Elm/Processing.elm | 2 +- tests/Elm/Parser/FileTests.elm | 16 ++++---- tests/Elm/ProcessingTests.elm | 60 ++--------------------------- 7 files changed, 18 insertions(+), 105 deletions(-) delete mode 100644 review/suppressed/NoDeprecated.json diff --git a/CHANGELOG.md b/CHANGELOG.md index bebe9535d..de367be2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## [Unreleased] +- Removed the deprecated `Elm.Parser.parse` function, and renamed `Elm.Parser.parseToFile` to `Elm.Parser.parse` (in other words, `Elm.Parser.parse`'s type changed to be the same as `parseToFile`) + ## [7.3.4] - 2024-07-26 Parsing is faster by ~90%. A big thank you to [@lue-bird](https://github.com/lue-bird) for finding and introducing a huge amount of performance improvements. diff --git a/review/suppressed/NoDeprecated.json b/review/suppressed/NoDeprecated.json deleted file mode 100644 index 10c022460..000000000 --- a/review/suppressed/NoDeprecated.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 1, - "automatically created by": "elm-review suppress", - "learn more": "elm-review suppress --help", - "suppressions": [ - { "count": 2, "filePath": "tests/Elm/ProcessingTests.elm" } - ] -} diff --git a/src/Elm/Internal/RawFile.elm b/src/Elm/Internal/RawFile.elm index 24cd95be9..83914f9e6 100644 --- a/src/Elm/Internal/RawFile.elm +++ b/src/Elm/Internal/RawFile.elm @@ -1,12 +1,7 @@ -module Elm.Internal.RawFile exposing (RawFile(..), fromFile) +module Elm.Internal.RawFile exposing (RawFile(..)) import Elm.Syntax.File exposing (File) type RawFile = Raw File - - -fromFile : File -> RawFile -fromFile = - Raw diff --git a/src/Elm/Parser.elm b/src/Elm/Parser.elm index 639c353b4..d503e7535 100644 --- a/src/Elm/Parser.elm +++ b/src/Elm/Parser.elm @@ -1,42 +1,20 @@ -module Elm.Parser exposing - ( parseToFile - , parse - ) +module Elm.Parser exposing (parse) {-| -@docs parseToFile @docs parse -} -import Elm.Internal.RawFile as InternalRawFile import Elm.Parser.File exposing (file) -import Elm.RawFile exposing (RawFile) import Elm.Syntax.File exposing (File) import Parser import ParserFast -{-| **@deprecated** Use [`parseToFile`](#parseToFile) instead, which is simpler and doesn't require post-processing. -Since v7.3.3, post-processing is unnecessary. - -Parse some text as if it is an Elm source file. -When parsing fails, the result will contain a list of errors indicating what went wrong (and/or where). -If it succeeds, you will get a `RawFile`. -This `RawFile` will require some post-processing to properly setup documentation and ensure that operator precedence is applied correctly (based on dependencies). -To process a `RawFile`, check out the `Processing` module. - --} -parse : String -> Result (List Parser.DeadEnd) RawFile -parse input = - parseToFile input - |> Result.map InternalRawFile.fromFile - - {-| Parse some text as if it is an Elm source file. When parsing fails, the result will contain a list of errors indicating what went wrong (and/or where). -} -parseToFile : String -> Result (List Parser.DeadEnd) File -parseToFile input = +parse : String -> Result (List Parser.DeadEnd) File +parse input = ParserFast.run file input diff --git a/src/Elm/Processing.elm b/src/Elm/Processing.elm index 10e64f6ff..3536c3a9a 100644 --- a/src/Elm/Processing.elm +++ b/src/Elm/Processing.elm @@ -6,7 +6,7 @@ module Elm.Processing exposing {-| Processing raw files with the context of other files and dependencies. Since v7.3.3, post-processing is unnecessary. -Use [`Elm.Parser.parseToFile`](Elm-Parser#parseToFile) instead. +Use [`Elm.Parser.parseToFile`](Elm-Parser#parse) instead. ## Types diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index ad92b15c2..a45dcfba0 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -100,7 +100,7 @@ f = {- 6 -} """ in - Elm.Parser.parseToFile input + Elm.Parser.parse input |> Result.map .comments |> Expect.equal (Ok @@ -133,7 +133,7 @@ b = 1 """ - |> Elm.Parser.parseToFile + |> Elm.Parser.parse |> Result.map .comments |> Expect.equal (Ok @@ -159,7 +159,7 @@ caseWhitespace f = case f of """ - |> Elm.Parser.parseToFile + |> Elm.Parser.parse |> Expect.equal (Ok { moduleDefinition = @@ -217,7 +217,7 @@ lambdaWhitespace = \\ a b -> a --some comment """ - |> Elm.Parser.parseToFile + |> Elm.Parser.parse |> Expect.equal (Ok { moduleDefinition = @@ -277,7 +277,7 @@ letWhitespace = let --some comment """ - |> Elm.Parser.parseToFile + |> Elm.Parser.parse |> Expect.equal (Ok { moduleDefinition = @@ -338,7 +338,7 @@ import Dict type Configuration = Configuration """ - |> Elm.Parser.parseToFile + |> Elm.Parser.parse |> Expect.equal (Ok { moduleDefinition = @@ -385,7 +385,7 @@ module Foo exposing (..) type Configuration = Configuration """ - |> Elm.Parser.parseToFile + |> Elm.Parser.parse |> Expect.equal (Ok { moduleDefinition = @@ -427,7 +427,7 @@ import String -} port sendResponse : String -> Cmd msg """ - |> Elm.Parser.parseToFile + |> Elm.Parser.parse |> Expect.equal (Ok { moduleDefinition = diff --git a/tests/Elm/ProcessingTests.elm b/tests/Elm/ProcessingTests.elm index 4577a68c4..3971c1e29 100644 --- a/tests/Elm/ProcessingTests.elm +++ b/tests/Elm/ProcessingTests.elm @@ -1,7 +1,6 @@ -module Elm.ProcessingTests exposing (suite, suiteDeprecated) +module Elm.ProcessingTests exposing (suite) import Elm.Parser as Parser -import Elm.Processing as Processing import Elm.Syntax.Declaration exposing (..) import Elm.Syntax.Exposing exposing (..) import Elm.Syntax.Expression exposing (..) @@ -12,7 +11,6 @@ import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (Pattern(..)) import Elm.Syntax.TypeAnnotation exposing (..) import Expect -import Parser import Test exposing (..) @@ -22,35 +20,13 @@ import Test exposing (..) suite : Test suite = - describe "Elm.Processing" - (List.map - (\( name, input, output ) -> - test name <| - \() -> - Parser.parseToFile (String.trim input) - |> Expect.equal (Ok output) - ) - testCases - ) - - -{-| Using the deprecated `Elm.Parser.parse`. --} -suiteDeprecated : Test -suiteDeprecated = describe "Elm.Processing.parse" (List.map (\( name, input, output ) -> test name <| \() -> - case context of - Ok context_ -> - Parser.parse (String.trim input) - |> Result.map (Processing.process context_) - |> Expect.equal (Ok output) - - Err _ -> - Expect.fail "Failed to generate context." + Parser.parse (String.trim input) + |> Expect.equal (Ok output) ) testCases ) @@ -76,36 +52,6 @@ testCases = ] -context : Result (List Parser.DeadEnd) Processing.ProcessContext -context = - """ -module Basics exposing ((+), (-), (*), (/), (//), (^), (==), (/=), (<), (>), (<=), (>=), (&&), (||), (++), (<|), (|>), (<<), (>>)) - - -infix right 0 (<|) = apL -infix left 0 (|>) = apR -infix right 2 (||) = or -infix right 3 (&&) = and -infix non 4 (==) = eq -infix non 4 (/=) = neq -infix non 4 (<) = lt -infix non 4 (>) = gt -infix non 4 (<=) = le -infix non 4 (>=) = ge -infix right 5 (++) = append -infix left 6 (+) = add -infix left 6 (-) = sub -infix left 7 (*) = mul -infix left 7 (/) = fdiv -infix left 7 (//) = idiv -infix right 8 (^) = pow -infix left 9 (<<) = composeL -infix right 9 (>>) = composeR""" - |> String.trim - |> Parser.parse - |> Result.map (\a -> Processing.addFile a Processing.init) - - functionWithDocs : ( String, String, File ) functionWithDocs = ( "functionWithDocs" From df98908be71e0a1b8280bb1c24cf5a911aa272f8 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 19 Jul 2024 00:29:58 +0200 Subject: [PATCH 02/44] Remove Elm.Writer module --- CHANGELOG.md | 3 + elm.json | 4 +- review/suppressed/NoImportingEverything.json | 8 - src/Elm/Writer.elm | 685 ------------------- src/List/Extra.elm | 31 +- tests/Elm/WriterTests.elm | 468 ------------- 6 files changed, 5 insertions(+), 1194 deletions(-) delete mode 100644 review/suppressed/NoImportingEverything.json delete mode 100644 src/Elm/Writer.elm delete mode 100644 tests/Elm/WriterTests.elm diff --git a/CHANGELOG.md b/CHANGELOG.md index de367be2e..e0254ba59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ - Removed the deprecated `Elm.Parser.parse` function, and renamed `Elm.Parser.parseToFile` to `Elm.Parser.parse` (in other words, `Elm.Parser.parse`'s type changed to be the same as `parseToFile`) +- Removed APIs: + - `Elm.Writer` module + ## [7.3.4] - 2024-07-26 Parsing is faster by ~90%. A big thank you to [@lue-bird](https://github.com/lue-bird) for finding and introducing a huge amount of performance improvements. diff --git a/elm.json b/elm.json index 0b83ce37f..a182f2169 100644 --- a/elm.json +++ b/elm.json @@ -10,7 +10,6 @@ "Elm.Parser", "Elm.Processing", "Elm.RawFile", - "Elm.Writer", "Elm.Syntax.Comments", "Elm.Syntax.Declaration", "Elm.Syntax.Documentation", @@ -35,8 +34,7 @@ "elm/json": "1.0.0 <= v < 2.0.0", "elm/parser": "1.0.0 <= v < 2.0.0", "miniBill/elm-unicode": "1.0.2 <= v < 2.0.0", - "rtfeldman/elm-hex": "1.0.0 <= v < 2.0.0", - "stil4m/structured-writer": "1.0.1 <= v < 2.0.0" + "rtfeldman/elm-hex": "1.0.0 <= v < 2.0.0" }, "test-dependencies": { "elm-explorations/test": "2.0.0 <= v < 3.0.0" diff --git a/review/suppressed/NoImportingEverything.json b/review/suppressed/NoImportingEverything.json deleted file mode 100644 index dc62dffc5..000000000 --- a/review/suppressed/NoImportingEverything.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "version": 1, - "automatically created by": "elm-review suppress", - "learn more": "elm-review suppress --help", - "suppressions": [ - { "count": 13, "filePath": "src/Elm/Writer.elm" } - ] -} diff --git a/src/Elm/Writer.elm b/src/Elm/Writer.elm deleted file mode 100644 index 417ae9762..000000000 --- a/src/Elm/Writer.elm +++ /dev/null @@ -1,685 +0,0 @@ -module Elm.Writer exposing (write, writeFile, writePattern, writeExpression, writeTypeAnnotation, writeDeclaration) - -{-| Write a file to a string. - -**DEPRECATED:** In practice the writer is not very good, and this functionality will very likely be removed in the next major version. -We highly recommend using [the-sett/elm-syntax-dsl](https://package.elm-lang.org/packages/the-sett/elm-syntax-dsl/latest/) instead. - -@docs write, writeFile, writePattern, writeExpression, writeTypeAnnotation, writeDeclaration - --} - -import Elm.Syntax.Declaration exposing (..) -import Elm.Syntax.Documentation exposing (..) -import Elm.Syntax.Exposing exposing (..) -import Elm.Syntax.Expression exposing (..) -import Elm.Syntax.File exposing (..) -import Elm.Syntax.Import exposing (Import) -import Elm.Syntax.Infix exposing (..) -import Elm.Syntax.Module exposing (..) -import Elm.Syntax.ModuleName exposing (..) -import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (..) -import Elm.Syntax.Range exposing (Range) -import Elm.Syntax.Signature exposing (Signature) -import Elm.Syntax.Type exposing (..) -import Elm.Syntax.TypeAlias exposing (..) -import Elm.Syntax.TypeAnnotation exposing (..) -import Hex -import List.Extra -import StructuredWriter as Writer exposing (..) - - -{-| Transform a writer to a string --} -write : Writer -> String -write = - Writer.write - - -{-| Write a file --} -writeFile : File -> Writer -writeFile file = - breaked - [ writeModule <| Node.value file.moduleDefinition - , breaked (List.map (Node.value >> writeImport) file.imports) - , breaked (List.map writeDeclaration file.declarations) - ] - - -writeModule : Module -> Writer -writeModule m = - case m of - NormalModule defaultModuleData -> - writeDefaultModuleData defaultModuleData - - PortModule defaultModuleData -> - spaced - [ string "port" - , writeDefaultModuleData defaultModuleData - ] - - EffectModule effectModuleData -> - writeEffectModuleData effectModuleData - - -writeDefaultModuleData : DefaultModuleData -> Writer -writeDefaultModuleData { moduleName, exposingList } = - spaced - [ string "module" - , writeModuleName <| Node.value moduleName - , writeExposureExpose <| Node.value exposingList - ] - - -writeEffectModuleData : EffectModuleData -> Writer -writeEffectModuleData { moduleName, exposingList, command, subscription } = - spaced - [ string "effect" - , string "module" - , writeModuleName <| Node.value moduleName - , writeWhere ( command, subscription ) - , writeExposureExpose <| Node.value exposingList - ] - - -writeWhere : ( Maybe (Node String), Maybe (Node String) ) -> Writer -writeWhere input = - case input of - ( Nothing, Nothing ) -> - epsilon - - ( Just x, Nothing ) -> - spaced - [ string "where { command =" - , string <| Node.value x - , string "}" - ] - - ( Nothing, Just x ) -> - spaced - [ string "where { subscription =" - , string <| Node.value x - , string "}" - ] - - ( Just x, Just y ) -> - spaced - [ string "where { command =" - , string <| Node.value x - , string ", subscription =" - , string <| Node.value y - , string "}" - ] - - -writeModuleName : ModuleName -> Writer -writeModuleName moduleName = - string (String.join "." moduleName) - - -writeExposureExpose : Exposing -> Writer -writeExposureExpose x = - case x of - All _ -> - string "exposing (..)" - - Explicit exposeList -> - let - diffLines : Bool - diffLines = - List.map Node.range exposeList - |> startOnDifferentLines - in - spaced - [ string "exposing" - , parensComma diffLines (List.map writeExpose exposeList) - ] - - -writeExpose : Node TopLevelExpose -> Writer -writeExpose (Node _ exp) = - case exp of - InfixExpose x -> - string ("(" ++ x ++ ")") - - FunctionExpose f -> - string f - - TypeOrAliasExpose t -> - string t - - TypeExpose { name, open } -> - case open of - Just _ -> - spaced - [ string name - , string "(..)" - ] - - Nothing -> - string name - - -startOnDifferentLines : List Range -> Bool -startOnDifferentLines xs = - List.length (List.Extra.unique (List.map (.start >> .row) xs)) > 1 - - -writeImport : Import -> Writer -writeImport { moduleName, moduleAlias, exposingList } = - spaced - [ string "import" - , writeModuleName <| Node.value moduleName - , maybe (Maybe.map (Node.value >> writeModuleName >> (\x -> spaced [ string "as", x ])) moduleAlias) - , maybe (Maybe.map (Node.value >> writeExposureExpose) exposingList) - ] - - -writeLetDeclaration : Node LetDeclaration -> Writer -writeLetDeclaration (Node _ letDeclaration) = - case letDeclaration of - LetFunction function -> - writeFunction function - - LetDestructuring pattern expression -> - writeDestructuring pattern expression - - -{-| Write a declaration --} -writeDeclaration : Node Declaration -> Writer -writeDeclaration (Node _ decl) = - case decl of - FunctionDeclaration function -> - writeFunction function - - AliasDeclaration typeAlias -> - writeTypeAlias typeAlias - - CustomTypeDeclaration type_ -> - writeType type_ - - PortDeclaration p -> - writePortDeclaration p - - InfixDeclaration i -> - writeInfix i - - Destructuring pattern expression -> - writeDestructuring pattern expression - - -writeFunction : Function -> Writer -writeFunction { documentation, signature, declaration } = - breaked - [ maybe (Maybe.map writeDocumentation documentation) - , maybe (Maybe.map (Node.value >> writeSignature) signature) - , writeFunctionImplementation <| Node.value declaration - ] - - -writeFunctionImplementation : FunctionImplementation -> Writer -writeFunctionImplementation declaration = - breaked - [ spaced - [ string <| Node.value declaration.name - , spaced (List.map writePattern declaration.arguments) - , string "=" - ] - , indent 4 (writeExpression declaration.expression) - ] - - -writeSignature : Signature -> Writer -writeSignature signature = - spaced - [ string <| Node.value signature.name - , string ":" - , writeTypeAnnotation signature.typeAnnotation - ] - - -writeDocumentation : Node Documentation -> Writer -writeDocumentation = - Node.value >> string - - -writeTypeAlias : TypeAlias -> Writer -writeTypeAlias typeAlias = - breaked - [ spaced - [ string "type alias" - , string <| Node.value typeAlias.name - , spaced (List.map (Node.value >> string) typeAlias.generics) - , string "=" - ] - , indent 4 (writeTypeAnnotation typeAlias.typeAnnotation) - ] - - -writeType : Type -> Writer -writeType type_ = - breaked - [ spaced - [ string "type" - , string <| Node.value type_.name - , spaced (List.map (Node.value >> string) type_.generics) - ] - , let - diffLines : Bool - diffLines = - List.map Node.range type_.constructors - |> startOnDifferentLines - in - indent 4 - (sepBy ( "= ", " | ", "" ) - diffLines - (List.map (Node.value >> writeValueConstructor) type_.constructors) - ) - ] - - -writeValueConstructor : ValueConstructor -> Writer -writeValueConstructor { name, arguments } = - spaced - ((string <| Node.value name) - :: List.map (wrapInSurroundingParentheses >> writeTypeAnnotation) arguments - ) - - -writePortDeclaration : Signature -> Writer -writePortDeclaration signature = - spaced [ string "port", writeSignature signature ] - - -writeInfix : Infix -> Writer -writeInfix { direction, precedence, operator, function } = - spaced - [ string "infix" - , case Node.value direction of - Left -> - string "left" - - Right -> - string "right" - - Non -> - string "non" - , string (String.fromInt (Node.value precedence)) - , string (Node.value operator) - , string "=" - , string (Node.value function) - ] - - -writeDestructuring : Node Pattern -> Node Expression -> Writer -writeDestructuring pattern expression = - breaked - [ spaced [ writePattern pattern, string "=" ] - , indent 4 (writeExpression expression) - ] - - -{-| Write a type annotation --} -writeTypeAnnotation : Node TypeAnnotation -> Writer -writeTypeAnnotation (Node _ typeAnnotation) = - case typeAnnotation of - GenericType s -> - string s - - Typed (Node _ ( moduleName, name )) args -> - spaced - ((string <| String.join "." (moduleName ++ [ name ])) - :: List.map (writeTypeAnnotation >> parensIfContainsSpaces) args - ) - - Unit -> - string "()" - - Tupled xs -> - parensComma False (List.map writeTypeAnnotation xs) - - Record xs -> - bracesComma False (List.map writeRecordField xs) - - GenericRecord name fields -> - spaced - [ string "{" - , string <| Node.value name - , string "|" - , sepByComma False (List.map writeRecordField <| Node.value fields) - , string "}" - ] - - FunctionTypeAnnotation left right -> - let - addParensForSubTypeAnnotation : Node TypeAnnotation -> Writer - addParensForSubTypeAnnotation type_ = - case type_ of - Node _ (FunctionTypeAnnotation _ _) -> - join [ string "(", writeTypeAnnotation type_, string ")" ] - - _ -> - writeTypeAnnotation type_ - in - spaced - [ addParensForSubTypeAnnotation left - , string "->" - , addParensForSubTypeAnnotation right - ] - - -writeRecordField : Node RecordField -> Writer -writeRecordField (Node _ ( name, ref )) = - spaced - [ string <| Node.value name - , string ":" - , writeTypeAnnotation ref - ] - - -{-| Writer an expression --} -writeExpression : Node Expression -> Writer -writeExpression (Node range inner) = - let - recurRangeHelper : Node Expression -> ( Range, Writer ) - recurRangeHelper (Node x y) = - ( x, writeExpression (Node x y) ) - - writeRecordSetter : RecordSetter -> ( Range, Writer ) - writeRecordSetter ( name, expr ) = - ( Node.range expr - , spaced [ string <| Node.value name, string "=", writeExpression expr ] - ) - - sepHelper : (Bool -> List Writer -> Writer) -> List ( Range, Writer ) -> Writer - sepHelper f l = - let - diffLines : Bool - diffLines = - List.map Tuple.first l - |> startOnDifferentLines - in - f diffLines (List.map Tuple.second l) - in - case inner of - UnitExpr -> - string "()" - - Application xs -> - case xs of - [] -> - epsilon - - [ x ] -> - writeExpression x - - x :: rest -> - spaced - [ writeExpression x - , sepHelper sepBySpace (List.map recurRangeHelper rest) - ] - - OperatorApplication x dir left right -> - case dir of - Left -> - sepHelper sepBySpace - [ ( Node.range left, writeExpression left ) - , ( range, spaced [ string x, writeExpression right ] ) - ] - - Right -> - sepHelper sepBySpace - [ ( Node.range left, spaced [ writeExpression left, string x ] ) - , ( Node.range right, writeExpression right ) - ] - - Non -> - sepHelper sepBySpace - [ ( Node.range left, spaced [ writeExpression left, string x ] ) - , ( Node.range right, writeExpression right ) - ] - - FunctionOrValue moduleName name -> - case moduleName of - [] -> - string name - - _ -> - join - [ writeModuleName <| moduleName - , string "." - , string <| name - ] - - IfBlock condition thenCase elseCase -> - breaked - [ spaced [ string "if", writeExpression condition, string "then" ] - , indent 2 (writeExpression thenCase) - , string "else" - , indent 2 (writeExpression elseCase) - ] - - PrefixOperator x -> - string ("(" ++ x ++ ")") - - Operator x -> - string x - - Hex h -> - join [ string "0x", string (Hex.toString h) ] - - Integer i -> - string (String.fromInt i) - - Floatable f -> - string (String.fromFloat f) - - Negation x -> - append (string "-") (writeExpression x) - - Literal s -> - string ("\"" ++ s ++ "\"") - - CharLiteral c -> - writeChar c - - TupledExpression t -> - join [ string "(", sepHelper sepByComma (List.map recurRangeHelper t), string ")" ] - - ParenthesizedExpression x -> - join [ string "(", writeExpression x, string ")" ] - - LetExpression letBlock -> - breaked - [ string "let" - , indent 2 (breaked (List.map writeLetDeclaration letBlock.declarations)) - , string "in" - , indent 2 (writeExpression letBlock.expression) - ] - - CaseExpression caseBlock -> - let - writeCaseBranch : ( Node Pattern, Node Expression ) -> Writer - writeCaseBranch ( pattern, expression ) = - indent 2 <| - breaked - [ spaced [ writePattern pattern, string "->" ] - , indent 2 (writeExpression expression) - ] - in - breaked - [ string "" - , spaced [ string "case", writeExpression caseBlock.expression, string "of" ] - , breaked (List.map writeCaseBranch caseBlock.cases) - , string "" - ] - - LambdaExpression lambda -> - spaced - [ join - [ string "\\" - , spaced (List.map writePattern lambda.args) - ] - , string "->" - , writeExpression lambda.expression - ] - - RecordExpr setters -> - sepHelper bracesComma (List.map (Node.value >> writeRecordSetter) setters) - - ListExpr xs -> - sepHelper bracketsComma (List.map recurRangeHelper xs) - - RecordAccess expression accessor -> - join [ writeExpression expression, string ".", string <| Node.value accessor ] - - RecordAccessFunction s -> - if String.startsWith "." s then - string s - - else - join [ string ".", string s ] - - RecordUpdateExpression name updates -> - spaced - [ string "{" - , string <| Node.value name - , string "|" - , sepHelper sepByComma (List.map (Node.value >> writeRecordSetter) updates) - , string "}" - ] - - GLSLExpression s -> - join - [ string "[glsl|" - , string s - , string "|]" - ] - - -escapeString : String -> String -escapeString = - String.replace "\"" "\\\"" - - -writeChar : Char -> Writer -writeChar c = - let - escape : String - escape = - if c == '\t' || c == '\'' || c == '\\' then - "\\" - - else - "" - in - string ("'" ++ escape ++ String.fromChar c ++ "'") - - -{-| Write a pattern --} -writePattern : Node Pattern -> Writer -writePattern (Node _ p) = - case p of - AllPattern -> - string "_" - - UnitPattern -> - string "()" - - CharPattern c -> - writeChar c - - StringPattern s -> - string ("\"" ++ escapeString s ++ "\"") - - HexPattern h -> - join [ string "0x", string (Hex.toString h) ] - - IntPattern i -> - string (String.fromInt i) - - FloatPattern f -> - string (String.fromFloat f) - - TuplePattern inner -> - parensComma False (List.map writePattern inner) - - RecordPattern inner -> - bracesComma False (List.map (Node.value >> string) inner) - - UnConsPattern left right -> - spaced [ writePattern left, string "::", writePattern right ] - - ListPattern inner -> - bracketsComma False (List.map writePattern inner) - - VarPattern var -> - string var - - NamedPattern qnr others -> - spaced - [ writeQualifiedNameRef qnr - , spaced (List.map writePattern others) - ] - - AsPattern innerPattern asName -> - spaced [ writePattern innerPattern, string "as", string <| Node.value asName ] - - ParenthesizedPattern innerPattern -> - spaced [ string "(", writePattern innerPattern, string ")" ] - - -writeQualifiedNameRef : QualifiedNameRef -> Writer -writeQualifiedNameRef { moduleName, name } = - case moduleName of - [] -> - string name - - _ -> - join - [ writeModuleName moduleName - , string "." - , string name - ] - - - --- Helpers - - -parensIfContainsSpaces : Writer -> Writer -parensIfContainsSpaces w = - if Writer.write w |> String.contains " " then - join [ string "(", w, string ")" ] - - else - w - - -wrapInSurroundingParentheses : Node TypeAnnotation -> Node TypeAnnotation -wrapInSurroundingParentheses node = - let - withParens : Node TypeAnnotation -> Node TypeAnnotation - withParens n = - Node.empty (Tupled [ n ]) - in - case Node.value node of - FunctionTypeAnnotation _ _ -> - withParens node - - Typed _ typeParameters -> - case typeParameters of - [] -> - node - - _ -> - withParens node - - _ -> - node diff --git a/src/List/Extra.elm b/src/List/Extra.elm index 54f7620bb..f18e57343 100644 --- a/src/List/Extra.elm +++ b/src/List/Extra.elm @@ -1,41 +1,12 @@ -module List.Extra exposing - ( find - , unique - ) +module List.Extra exposing (find) {-| Helper for List functions. find and unique taken from elm-community/list-extra. @docs find -@docs unique -} -{-| Remove duplicate values, keeping the first instance of each element which appears more than once. - - unique [ 0, 1, 1, 0, 1 ] - --> [ 0, 1 ] - --} -unique : List a -> List a -unique list = - uniqueHelp [] list [] - - -uniqueHelp : List a -> List a -> List a -> List a -uniqueHelp existing remaining accumulator = - case remaining of - [] -> - accumulator - - first :: rest -> - if List.member first existing then - uniqueHelp existing rest accumulator - - else - uniqueHelp (first :: existing) rest (first :: accumulator) - - find : (a -> Bool) -> List a -> Maybe a find predicate list = case list of diff --git a/tests/Elm/WriterTests.elm b/tests/Elm/WriterTests.elm deleted file mode 100644 index 6259b9deb..000000000 --- a/tests/Elm/WriterTests.elm +++ /dev/null @@ -1,468 +0,0 @@ -module Elm.WriterTests exposing (suite) - -import Elm.Parser.Expression exposing (expression) -import Elm.Parser.ParserWithCommentsTestUtil exposing (parse) -import Elm.Syntax.Declaration exposing (..) -import Elm.Syntax.Exposing exposing (..) -import Elm.Syntax.Expression exposing (..) -import Elm.Syntax.Module exposing (..) -import Elm.Syntax.Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (..) -import Elm.Syntax.Range exposing (empty) -import Elm.Syntax.Type exposing (..) -import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation(..)) -import Elm.Writer as Writer -import Expect -import Test exposing (..) - - -suite : Test -suite = - describe "Writer" - [ test "write file exposing all" <| - \() -> - { moduleDefinition = - Node empty <| - NormalModule - { moduleName = Node empty <| [ "A" ] - , exposingList = Node empty <| All empty - } - , imports = - [ Node empty - { moduleName = Node empty <| [ "B" ] - , moduleAlias = Nothing - , exposingList = Nothing - } - , Node empty - { moduleName = Node empty <| [ "C" ] - , moduleAlias = Just (Node empty [ "D" ]) - , exposingList = Just (Node empty <| All empty) - } - ] - , declarations = [] - , comments = [] - } - |> Writer.writeFile - |> Writer.write - |> Expect.equal - ("module A exposing (..)\n" - ++ "import B " - ++ "\n" - ++ "import C as D exposing (..)\n" - ) - , describe "Expression" - [ test "write simple expression" <| - \() -> - (Node empty <| - Application - [ Node empty <| FunctionOrValue [] "abc" - , Node empty <| UnitExpr - ] - ) - |> Writer.writeExpression - |> Writer.write - |> Expect.equal "abc ()" - , test "write qualified expression" <| - \() -> - (Node empty <| FunctionOrValue [ "Foo", "Bar" ] "baz") - |> Writer.writeExpression - |> Writer.write - |> Expect.equal "Foo.Bar.baz" - , test "Expression.RecordAccessFunction should be parsed then written idempotently" <| - \() -> - let - input : String - input = - "(.spaceEvenly Internal.Style.classes)" - in - parse input expression - |> Maybe.map Writer.writeExpression - |> Maybe.map Writer.write - |> Expect.equal - (Just input) - , test "regression test for Expression.RecordAccessFunction being written without leading period" <| - \() -> - (Node empty <| - Application - [ Node empty <| FunctionOrValue [ "List" ] "map" - , Node empty <| RecordAccessFunction "name" - , Node empty <| FunctionOrValue [] "people" - ] - ) - |> Writer.writeExpression - |> Writer.write - |> Expect.equal "List.map .name people" - ] - , describe "Pattern" - [ test "write string pattern" <| - \() -> - StringPattern "test" - |> Node empty - |> Writer.writePattern - |> Writer.write - |> Expect.equal "\"test\"" - , test "write string pattern containing \"" <| - \() -> - StringPattern "test\"" - |> Node empty - |> Writer.writePattern - |> Writer.write - |> Expect.equal "\"test\\\"\"" - ] - , describe "TypeAnnotation" - [ test "write simple type" <| - \() -> - Typed (Node empty <| ( [], "String" )) [] - |> Node empty - |> Writer.writeTypeAnnotation - |> Writer.write - |> Expect.equal "String" - , test "write qualified type" <| - \() -> - (Node empty <| - Typed - (Node empty <| ( [ "Json", "Decode" ], "Decoder" )) - [ Node empty <| GenericType "a" ] - ) - |> Writer.writeTypeAnnotation - |> Writer.write - |> Expect.equal "Json.Decode.Decoder a" - , test "write type arguments that require parentheses" <| - \() -> - (Node empty <| - Typed (Node empty ( [], "List" )) - [ Node empty <| - Typed (Node empty ( [], "Dict" )) - [ Node empty <| Typed (Node empty ( [], "String" )) [] - , Node empty <| Typed (Node empty ( [], "Int" )) [] - ] - ] - ) - |> Writer.writeTypeAnnotation - |> Writer.write - |> Expect.equal "List (Dict String Int)" - , test "write type arguments that are functions" <| - \() -> - (Node empty <| - FunctionTypeAnnotation - (Node empty <| - FunctionTypeAnnotation - (Node empty <| GenericType "a") - (Node empty <| GenericType "b") - ) - (Node empty <| Typed (Node empty ( [], "Int" )) []) - ) - |> Writer.writeTypeAnnotation - |> Writer.write - |> Expect.equal "(a -> b) -> Int" - ] - , describe "Declaration" - [ test "write type declaration > simple constructors" <| - \() -> - (Node empty <| - CustomTypeDeclaration - (Type - Nothing - (Node empty "Sample") - [] - [ Node empty <| ValueConstructor (Node empty "Foo") [] - , Node empty <| ValueConstructor (Node empty "Bar") [] - ] - ) - ) - |> Writer.writeDeclaration - |> Writer.write - |> Expect.equal - ("type Sample \n" - ++ " = Foo | Bar" - ) - , test "write type declaration > constructors with arguments" <| - \() -> - let - listT : TypeAnnotation - listT = - Typed (Node empty ( [], "List" )) - [ Node empty <| - Typed (Node empty ( [], "String" )) [] - ] - - stringT : TypeAnnotation - stringT = - Typed (Node empty ( [], "String" )) [] - in - (Node empty <| - CustomTypeDeclaration - (Type - Nothing - (Node empty "Sample") - [] - [ Node empty <| ValueConstructor (Node empty "Foo") [ Node empty listT, Node empty stringT ] - , Node empty <| ValueConstructor (Node empty "Bar") [] - ] - ) - ) - |> Writer.writeDeclaration - |> Writer.write - |> Expect.equal - ("type Sample \n" - ++ " = Foo (List String) String | Bar" - ) - , test "write type declaration > constructors with functions as arguments" <| - \() -> - let - funcT : TypeAnnotation - funcT = - FunctionTypeAnnotation - (Node empty <| Typed (Node empty ( [], "String" )) []) - (Node empty <| Typed (Node empty ( [], "Int" )) []) - - stringT : TypeAnnotation - stringT = - Typed (Node empty ( [], "String" )) [] - in - (Node empty <| - CustomTypeDeclaration - (Type - Nothing - (Node empty "Sample") - [] - [ Node empty <| - ValueConstructor (Node empty "Foo") - [ Node empty funcT - , Node empty stringT - ] - , Node empty <| ValueConstructor (Node empty "Bar") [] - ] - ) - ) - |> Writer.writeDeclaration - |> Writer.write - |> Expect.equal - ("type Sample \n" - ++ " = Foo (String -> Int) String | Bar" - ) - , test "write function with case expression using the right indentations" <| - \() -> - let - body : Expression - body = - CaseExpression - (CaseBlock (Node empty <| FunctionOrValue [] "someCase") - [ ( Node empty <| IntPattern 1, Node empty <| FunctionOrValue [] "doSomething" ) - , ( Node empty <| IntPattern 2, Node empty <| FunctionOrValue [] "doSomethingElse" ) - ] - ) - - function : Declaration - function = - FunctionDeclaration - (Function Nothing - Nothing - (Node empty <| - FunctionImplementation - (Node empty <| "functionName") - [] - (Node empty body) - ) - ) - in - Node empty function - |> Writer.writeDeclaration - |> Writer.write - |> Expect.equal - ("\n\nfunctionName =\n" - ++ " \n" - ++ " case someCase of\n" - ++ " 1 ->\n" - ++ " doSomething\n" - ++ " 2 ->\n" - ++ " doSomethingElse\n" - ++ " " - ) - , test "regression test for incorrect indentation in case expression" <| - \() -> - let - body : Expression - body = - LambdaExpression - { args = [ Node empty (VarPattern "myArgument") ] - , expression = - Node empty <| - CaseExpression - (CaseBlock (Node empty <| FunctionOrValue [] "someCase") - [ ( Node empty <| IntPattern 1, Node empty <| FunctionOrValue [] "doSomething" ) - , ( Node empty <| IntPattern 2, Node empty <| FunctionOrValue [] "doSomethingElse" ) - ] - ) - } - - function : Declaration - function = - FunctionDeclaration - (Function Nothing - Nothing - (Node empty <| - FunctionImplementation - (Node empty <| "functionName") - [] - (Node empty body) - ) - ) - in - Node empty function - |> Writer.writeDeclaration - |> Writer.write - |> Expect.equal - ("\n\nfunctionName =\n" - ++ " \\myArgument -> \n" - ++ " case someCase of\n" - ++ " 1 ->\n" - ++ " doSomething\n" - ++ " 2 ->\n" - ++ " doSomethingElse\n" - ++ " " - ) - , test "regression test for incorrect parenthesis placement in case expression" <| - \() -> - let - body : Expression - body = - ParenthesizedExpression - (Node empty <| - LambdaExpression - { args = [ Node empty (VarPattern "myArgument") ] - , expression = - Node empty <| - CaseExpression - (CaseBlock (Node empty <| FunctionOrValue [] "someCase") - [ ( Node empty <| IntPattern 1, Node empty <| FunctionOrValue [] "doSomething" ) - , ( Node empty <| IntPattern 2, Node empty <| FunctionOrValue [] "doSomethingElse" ) - ] - ) - } - ) - - function : Declaration - function = - FunctionDeclaration - (Function Nothing - Nothing - (Node empty <| - FunctionImplementation - (Node empty <| "functionName") - [] - (Node empty body) - ) - ) - in - Node empty function - |> Writer.writeDeclaration - |> Writer.write - |> Expect.equal - ("\n\nfunctionName =\n" - ++ " (\\myArgument -> \n" - ++ " case someCase of\n" - ++ " 1 ->\n" - ++ " doSomething\n" - ++ " 2 ->\n" - ++ " doSomethingElse\n" - ++ " )" - ) - , test "regression test for char literals not being escaped" <| - \() -> - ListExpr - [ Node empty (CharLiteral '\\') - , Node empty (CharLiteral '"') - , Node empty (CharLiteral '\'') - , Node empty (CharLiteral '\t') - , Node empty (CharLiteral '→') - , Node empty (CharLiteral '\u{00A0}') - ] - |> Node empty - |> Writer.writeExpression - |> Writer.write - |> Expect.equal "['\\\\', '\"', '\\'', '\\\t', '→', '\u{00A0}']" - , test "regression test for char pattern not being escaped" <| - \() -> - ListPattern - [ Node empty (CharPattern '\\') - , Node empty (CharPattern '"') - , Node empty (CharPattern '\'') - , Node empty (CharPattern '\t') - , Node empty (CharPattern '→') - , Node empty (CharPattern '\u{00A0}') - ] - |> Node empty - |> Writer.writePattern - |> Writer.write - |> Expect.equal "['\\\\', '\"', '\\'', '\\\t', '→', '\u{00A0}']" - , test "nested case expressions" <| - \() -> - let - body : Node Expression -> Node Expression - body nested = - Node empty <| - CaseExpression - (CaseBlock (Node empty <| FunctionOrValue [] "someCase") - [ ( Node empty <| IntPattern 1, nested ) - , ( Node empty <| IntPattern 2, Node empty <| FunctionOrValue [] "doSomethingElse" ) - ] - ) - - function : Declaration - function = - FunctionDeclaration - (Function Nothing - Nothing - (Node empty <| - FunctionImplementation - (Node empty <| "functionName") - [] - (Node empty - (ParenthesizedExpression - (Node empty <| - LambdaExpression - { args = [ Node empty (VarPattern "myArgument") ] - , expression = - body (body (Node empty UnitExpr)) - } - ) - ) - ) - ) - ) - in - Node empty function - |> Writer.writeDeclaration - |> Writer.write - |> Expect.equal - ("\n\nfunctionName =\n" - ++ " (\\myArgument -> \n" - ++ " case someCase of\n" - ++ " 1 ->\n" - ++ " \n" - ++ " case someCase of\n" - ++ " 1 ->\n" - ++ " ()\n" - ++ " 2 ->\n" - ++ " doSomethingElse\n" - ++ " \n" - ++ " 2 ->\n" - ++ " doSomethingElse\n" - ++ " )" - ) - ] - , describe "Tuple" - [ test "write tuple" <| - \() -> - (Node empty <| - TupledExpression - [ Node empty <| Integer 1 - , Node empty <| Integer 2 - ] - ) - |> Writer.writeExpression - |> Writer.write - |> Expect.equal "(1, 2)" - ] - ] From 7bcf47dea5122e7f5e08576a0c81c066c021a43c Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 19 Jul 2024 00:37:15 +0200 Subject: [PATCH 03/44] Remove serialization tests --- tests/Elm/Parser/FileTests.elm | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index a45dcfba0..03ba2dcbb 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -1,10 +1,8 @@ module Elm.Parser.FileTests exposing (all) -import Elm.Internal.RawFile as InternalRawFile import Elm.Parser import Elm.Parser.File as Parser import Elm.Parser.Samples as Samples -import Elm.RawFile as RawFile exposing (RawFile) import Elm.Syntax.Declaration exposing (Declaration(..)) import Elm.Syntax.Exposing exposing (Exposing(..)) import Elm.Syntax.Expression exposing (Expression(..), LetDeclaration(..)) @@ -14,8 +12,6 @@ import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (Pattern(..)) import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation(..)) import Expect -import Json.Decode -import Json.Encode import ParserFast import Test exposing (..) @@ -52,27 +48,6 @@ all = -- Parser.parse "module Foo exposing (..) \nx = \n x + _" -- |> Expect.equal (Err [ "Could not continue parsing on location (2,6)" ]) -- ] - , describe "FileTests - serialisation" - (Samples.allSamples - |> List.map - (\( n, s ) -> - test ("sample " ++ String.fromInt n) <| - \() -> - let - parsed : Maybe RawFile - parsed = - ParserFast.run Parser.file s - |> Result.toMaybe - |> Maybe.map InternalRawFile.Raw - - roundTrip : Maybe RawFile - roundTrip = - parsed - |> Maybe.andThen (RawFile.encode >> Json.Encode.encode 0 >> Json.Decode.decodeString RawFile.decoder >> Result.toMaybe) - in - Expect.equal parsed roundTrip - ) - ) , test "Comments ordering" <| \() -> let From 97aadb441ca51369568021b80e410d1a4fcc5b3e Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 19 Jul 2024 00:33:32 +0200 Subject: [PATCH 04/44] Remove Elm.Processing, Elm.RawFile, Elm.Interface and Elm.Dependency --- CHANGELOG.md | 3 + elm.json | 4 - src/Elm/Dependency.elm | 37 -- src/Elm/Interface.elm | 244 ---------- src/Elm/Internal/RawFile.elm | 7 - src/Elm/Processing.elm | 72 --- src/Elm/RawFile.elm | 61 --- tests/Elm/ProcessingTests.elm | 870 ---------------------------------- 8 files changed, 3 insertions(+), 1295 deletions(-) delete mode 100644 src/Elm/Dependency.elm delete mode 100644 src/Elm/Interface.elm delete mode 100644 src/Elm/Internal/RawFile.elm delete mode 100644 src/Elm/Processing.elm delete mode 100644 src/Elm/RawFile.elm delete mode 100644 tests/Elm/ProcessingTests.elm diff --git a/CHANGELOG.md b/CHANGELOG.md index e0254ba59..c669972a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ - Removed APIs: - `Elm.Writer` module + - `Elm.Interface` module + - `Elm.Dependency` module + - `Elm.Processing` and `Elm.RawFile` modules ## [7.3.4] - 2024-07-26 diff --git a/elm.json b/elm.json index a182f2169..39084a5d1 100644 --- a/elm.json +++ b/elm.json @@ -5,11 +5,7 @@ "license": "MIT", "version": "7.3.4", "exposed-modules": [ - "Elm.Dependency", - "Elm.Interface", "Elm.Parser", - "Elm.Processing", - "Elm.RawFile", "Elm.Syntax.Comments", "Elm.Syntax.Declaration", "Elm.Syntax.Documentation", diff --git a/src/Elm/Dependency.elm b/src/Elm/Dependency.elm deleted file mode 100644 index ecef51bfe..000000000 --- a/src/Elm/Dependency.elm +++ /dev/null @@ -1,37 +0,0 @@ -module Elm.Dependency exposing (Dependency, Version) - -{-| This module contains types regarding dependencies of a codebase. -To gain the most information of a codebase, information of the dependencies may be required. -For example, what operators does it define, or what constructors are defined for a custom type. - - -## Types - -@docs Dependency, Version - --} - -import Dict exposing (Dict) -import Elm.Interface exposing (Interface) -import Elm.Syntax.ModuleName exposing (ModuleName) - - -{-| Record that represents a dependency. For example: - - { name = "elm/core" - , version = "1.0.0" - , interfaces = Dict.fromList [ ( "Basics", basicsInterface ), ... ] - } - --} -type alias Dependency = - { name : String - , version : Version - , interfaces : Dict ModuleName Interface - } - - -{-| Alias for a version string. For example "1.2.3". --} -type alias Version = - String diff --git a/src/Elm/Interface.elm b/src/Elm/Interface.elm deleted file mode 100644 index a1858ac9b..000000000 --- a/src/Elm/Interface.elm +++ /dev/null @@ -1,244 +0,0 @@ -module Elm.Interface exposing - ( Interface, Exposed(..) - , build, exposesAlias, exposesFunction, operators - ) - -{-| A type that represents the interface for an Elm module. -You can see this as a trimmed down version of a file that only contains the header (`module X exposing (..)`) and some small set of additional data. - - -## Types - -@docs Interface, Exposed - - -## Functions - -@docs build, exposesAlias, exposesFunction, operators - --} - -import Dict exposing (Dict) -import Elm.Internal.RawFile as InternalRawFile -import Elm.RawFile as RawFile -import Elm.Syntax.Declaration exposing (Declaration(..)) -import Elm.Syntax.Exposing exposing (Exposing(..), TopLevelExpose(..)) -import Elm.Syntax.Expression exposing (FunctionImplementation) -import Elm.Syntax.File exposing (File) -import Elm.Syntax.Infix exposing (Infix, InfixDirection(..)) -import Elm.Syntax.Module as Module -import Elm.Syntax.Node as Node exposing (Node(..)) - - -{-| An interface is just a list of 'things' that are exposed by a module. - - [ Type "Color" [ "Red", "Blue" ], Function "asRgb" ] - --} -type alias Interface = - List Exposed - - -{-| Union type for the things that a module can expose. These are `Function`s, `CustomType`s, and `Alias`es. - -Elm core packages can also define `Operator`s, and thus we take that into account as well. -The `Infix` type alias will contain all the information regarding the operator - --} -type Exposed - = Function String - | CustomType ( String, List String ) - | Alias String - | Operator Infix - - -{-| A function to check whether an `Interface` exposes an certain type alias. --} -exposesAlias : String -> Interface -> Bool -exposesAlias k interface = - List.any - (\x -> - case x of - Alias l -> - k == l - - _ -> - False - ) - interface - - -{-| Check whether an `Interface` exposes an function. - - exposesFunction "A" [ Function "A", CustomType "B", [ "C" ] ] == True - exposesFunction "B" [ Function "A", CustomType "B", [ "C" ] ] == False - exposesFunction "<" [ Infix { operator = "<" , ... } ] == True - exposesFunction "A" [ Alias "A" ] == False - --} -exposesFunction : String -> Interface -> Bool -exposesFunction k interface = - List.any - (\x -> - case x of - Function l -> - k == l - - CustomType ( _, constructors ) -> - List.member k constructors - - Operator inf -> - Node.value inf.operator == k - - Alias _ -> - False - ) - interface - - -{-| Retrieve all operators exposed by the `Interface` --} -operators : Interface -> List Infix -operators = - List.filterMap - (\interface -> - case interface of - Operator operator -> - Just operator - - _ -> - Nothing - ) - - -{-| Build an interface from a file --} -build : RawFile.RawFile -> Interface -build (InternalRawFile.Raw file) = - let - fileDefinitionList : List ( String, Exposed ) - fileDefinitionList = - fileToDefinitions file - in - case Module.exposingList (Node.value file.moduleDefinition) of - Explicit x -> - buildInterfaceFromExplicit x (Dict.fromList fileDefinitionList) - - All _ -> - List.map Tuple.second fileDefinitionList - - -buildInterfaceFromExplicit : List (Node TopLevelExpose) -> Dict String Exposed -> Interface -buildInterfaceFromExplicit x exposedDict = - List.filterMap - (\(Node _ expose) -> - case expose of - InfixExpose k -> - Dict.get k exposedDict - - TypeOrAliasExpose s -> - Dict.get s exposedDict - |> Maybe.map (ifCustomType (\( name, _ ) -> CustomType ( name, [] ))) - - FunctionExpose s -> - Just <| Function s - - TypeExpose exposedType -> - case exposedType.open of - Nothing -> - Just <| CustomType ( exposedType.name, [] ) - - Just _ -> - Dict.get exposedType.name exposedDict - ) - x - - -ifCustomType : (( String, List String ) -> Exposed) -> Exposed -> Exposed -ifCustomType f i = - case i of - CustomType t -> - f t - - _ -> - i - - -fileToDefinitions : File -> List ( String, Exposed ) -fileToDefinitions file = - let - allDeclarations : List ( String, Exposed ) - allDeclarations = - List.filterMap - (\(Node _ decl) -> - case decl of - CustomTypeDeclaration t -> - Just ( Node.value t.name, CustomType ( Node.value t.name, t.constructors |> List.map (Node.value >> .name >> Node.value) ) ) - - AliasDeclaration a -> - Just ( Node.value a.name, Alias <| Node.value a.name ) - - PortDeclaration p -> - Just ( Node.value p.name, Function (Node.value p.name) ) - - FunctionDeclaration f -> - let - declaration : FunctionImplementation - declaration = - Node.value f.declaration - - name : String - name = - Node.value declaration.name - in - Just ( name, Function <| name ) - - InfixDeclaration i -> - Just ( Node.value i.operator, Operator i ) - - Destructuring _ _ -> - Nothing - ) - file.declarations - in - -- I really don't understand what this part of the function does. - allDeclarations - |> List.map - (\( name, _ ) -> - -- AFAIK, it's not possible to have two declarations with the same name - -- in the same file, so this seems pointless. - allDeclarations - |> List.filter (\( otherDeclarationName, _ ) -> otherDeclarationName == name) - ) - |> List.filterMap resolveGroup - - -resolveGroup : List ( String, Exposed ) -> Maybe ( String, Exposed ) -resolveGroup g = - case g of - [] -> - Nothing - - [ x ] -> - Just x - - [ ( n1, t1 ), ( _, t2 ) ] -> - getValidOperatorInterface t1 t2 - |> Maybe.map (\a -> ( n1, a )) - - _ -> - Nothing - - -getValidOperatorInterface : Exposed -> Exposed -> Maybe Exposed -getValidOperatorInterface t1 t2 = - case ( t1, t2 ) of - ( Operator x, Operator y ) -> - if Node.value x.precedence == 5 && Node.value x.direction == Left then - Just <| Operator y - - else - Just <| Operator x - - _ -> - Nothing diff --git a/src/Elm/Internal/RawFile.elm b/src/Elm/Internal/RawFile.elm deleted file mode 100644 index 83914f9e6..000000000 --- a/src/Elm/Internal/RawFile.elm +++ /dev/null @@ -1,7 +0,0 @@ -module Elm.Internal.RawFile exposing (RawFile(..)) - -import Elm.Syntax.File exposing (File) - - -type RawFile - = Raw File diff --git a/src/Elm/Processing.elm b/src/Elm/Processing.elm deleted file mode 100644 index 3536c3a9a..000000000 --- a/src/Elm/Processing.elm +++ /dev/null @@ -1,72 +0,0 @@ -module Elm.Processing exposing - ( ProcessContext - , init, addFile, addDependency, process - ) - -{-| Processing raw files with the context of other files and dependencies. - -Since v7.3.3, post-processing is unnecessary. -Use [`Elm.Parser.parseToFile`](Elm-Parser#parse) instead. - - -## Types - -@docs ProcessContext - - -## Functions - -@docs init, addFile, addDependency, process - --} - -import Dict exposing (Dict) -import Elm.Dependency exposing (Dependency) -import Elm.Interface as Interface exposing (Interface) -import Elm.Internal.RawFile as InternalRawFile -import Elm.RawFile as RawFile -import Elm.Syntax.File exposing (File) -import Elm.Syntax.ModuleName exposing (ModuleName) - - -{-| Opaque type to hold context for the processing --} -type ProcessContext - = ProcessContext ModuleIndexInner - - -type alias ModuleIndexInner = - Dict ModuleName Interface - - -{-| Initialise an empty context --} -init : ProcessContext -init = - ProcessContext Dict.empty - - -{-| Add a file to the context that may be a dependency for the file that will be processed. --} -addFile : RawFile.RawFile -> ProcessContext -> ProcessContext -addFile file (ProcessContext context) = - ProcessContext - (Dict.insert - (RawFile.moduleName file) - (Interface.build file) - context - ) - - -{-| Add a whole dependency with its modules to the context. --} -addDependency : Dependency -> ProcessContext -> ProcessContext -addDependency dep (ProcessContext x) = - ProcessContext (Dict.union dep.interfaces x) - - -{-| Process a rawfile with a context. --} -process : ProcessContext -> RawFile.RawFile -> File -process _ (InternalRawFile.Raw file) = - file diff --git a/src/Elm/RawFile.elm b/src/Elm/RawFile.elm deleted file mode 100644 index 5fb99954b..000000000 --- a/src/Elm/RawFile.elm +++ /dev/null @@ -1,61 +0,0 @@ -module Elm.RawFile exposing - ( RawFile - , moduleName, imports - , encode, decoder - ) - -{-| - -@docs RawFile - -@docs moduleName, imports - - -## Serialization - -@docs encode, decoder - --} - -import Elm.Internal.RawFile as InternalRawFile -import Elm.Syntax.File as File -import Elm.Syntax.Import exposing (Import) -import Elm.Syntax.Module as Module -import Elm.Syntax.ModuleName exposing (ModuleName) -import Elm.Syntax.Node as Node -import Json.Decode as JD exposing (Decoder) -import Json.Encode exposing (Value) - - -{-| A Raw file --} -type alias RawFile = - InternalRawFile.RawFile - - -{-| Retrieve the module name for a raw file --} -moduleName : RawFile -> ModuleName -moduleName (InternalRawFile.Raw file) = - Module.moduleName <| Node.value file.moduleDefinition - - -{-| Encode a `RawFile` syntax element to JSON. --} -imports : RawFile -> List Import -imports (InternalRawFile.Raw file) = - List.map Node.value file.imports - - -{-| Encode a file to a value --} -encode : RawFile -> Value -encode (InternalRawFile.Raw file) = - File.encode file - - -{-| JSON decoder for a `RawFile` syntax element. --} -decoder : Decoder RawFile -decoder = - JD.map InternalRawFile.Raw File.decoder diff --git a/tests/Elm/ProcessingTests.elm b/tests/Elm/ProcessingTests.elm deleted file mode 100644 index 3971c1e29..000000000 --- a/tests/Elm/ProcessingTests.elm +++ /dev/null @@ -1,870 +0,0 @@ -module Elm.ProcessingTests exposing (suite) - -import Elm.Parser as Parser -import Elm.Syntax.Declaration exposing (..) -import Elm.Syntax.Exposing exposing (..) -import Elm.Syntax.Expression exposing (..) -import Elm.Syntax.File exposing (..) -import Elm.Syntax.Infix exposing (..) -import Elm.Syntax.Module exposing (..) -import Elm.Syntax.Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (Pattern(..)) -import Elm.Syntax.TypeAnnotation exposing (..) -import Expect -import Test exposing (..) - - - --- TODO Elm.Processing doesn't exiat anymore, move these tests somewhere else - - -suite : Test -suite = - describe "Elm.Processing.parse" - (List.map - (\( name, input, output ) -> - test name <| - \() -> - Parser.parse (String.trim input) - |> Expect.equal (Ok output) - ) - testCases - ) - - -testCases : List ( String, String, File ) -testCases = - [ functionWithDocs - , functionWithDocsAndSignature - , functionWithSingleLineCommentAsDoc - , fileWithMultipleComments - , functionWithMultiLineCommentAsDoc - , postProcessInfixOperators - , postProcessInfixOperators2 - , postProcessInfixOperators3 - , postProcessInfixOperatorsInNegation - , postProcessInfixOperatorsInRecordAccess - , postProcessInfixOperatorsRegressionTest - , postProcessInfixOperatorsAssociativityTest - , typeAliasWithDocumentation - , typeWithDocumentation - , maxCallStackSizeFailure - ] - - -functionWithDocs : ( String, String, File ) -functionWithDocs = - ( "functionWithDocs" - , """ -module Bar exposing (..) - -import String - -{-| The docs --} -bar = 1 -""" |> String.replace "\u{000D}" "" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = - Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| - All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 14 } } - { moduleName = Node { start = { row = 3, column = 8 }, end = { row = 3, column = 14 } } [ "String" ] - , moduleAlias = Nothing - , exposingList = Nothing - } - ] - , declarations = - [ Node { start = { row = 5, column = 1 }, end = { row = 7, column = 8 } } <| - FunctionDeclaration - { documentation = Just (Node { start = { row = 5, column = 1 }, end = { row = 6, column = 3 } } "{-| The docs\n-}") - , signature = Nothing - , declaration = - Node { start = { row = 7, column = 1 }, end = { row = 7, column = 8 } } - { name = Node { start = { row = 7, column = 1 }, end = { row = 7, column = 4 } } "bar" - , arguments = [] - , expression = Node { start = { row = 7, column = 7 }, end = { row = 7, column = 8 } } <| Integer 1 - } - } - ] - , comments = [] - } - ) - - -functionWithDocsAndSignature : ( String, String, File ) -functionWithDocsAndSignature = - ( "functionWithDocsAndSignature" - , """ -module Bar exposing (..) - -import String - -{-| The docs --} -bar : Int -bar = 1 -""" |> String.replace "\u{000D}" "" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 14 } } - { moduleName = Node { start = { row = 3, column = 8 }, end = { row = 3, column = 14 } } [ "String" ] - , moduleAlias = Nothing - , exposingList = Nothing - } - ] - , declarations = - [ Node { start = { row = 5, column = 1 }, end = { row = 8, column = 8 } } <| - FunctionDeclaration - { documentation = - Just <| Node { start = { row = 5, column = 1 }, end = { row = 6, column = 3 } } "{-| The docs\n-}" - , signature = - Just - (Node { start = { row = 7, column = 1 }, end = { row = 7, column = 10 } } <| - { name = Node { start = { row = 7, column = 1 }, end = { row = 7, column = 4 } } "bar" - , typeAnnotation = - Node { start = { row = 7, column = 7 }, end = { row = 7, column = 10 } } <| - Typed (Node { start = { row = 7, column = 7 }, end = { row = 7, column = 10 } } ( [], "Int" )) [] - } - ) - , declaration = - Node { start = { row = 8, column = 1 }, end = { row = 8, column = 8 } } - { name = Node { start = { row = 8, column = 1 }, end = { row = 8, column = 4 } } "bar" - , arguments = [] - , expression = Node { start = { row = 8, column = 7 }, end = { row = 8, column = 8 } } <| Integer 1 - } - } - ] - , comments = [] - } - ) - - -functionWithSingleLineCommentAsDoc : ( String, String, File ) -functionWithSingleLineCommentAsDoc = - ( "functionWithSingleLineCommentAsDoc" - , """ -module Bar exposing (..) - ---The Doc -bar = 1 -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = [] - , declarations = - [ Node { start = { row = 4, column = 1 }, end = { row = 4, column = 8 } } <| - FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 4, column = 1 }, end = { row = 4, column = 8 } } - { name = Node { start = { row = 4, column = 1 }, end = { row = 4, column = 4 } } "bar" - , arguments = [] - , expression = Node { start = { row = 4, column = 7 }, end = { row = 4, column = 8 } } <| Integer 1 - } - } - ] - , comments = [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 10 } } "--The Doc" ] - } - ) - - -fileWithMultipleComments : ( String, String, File ) -fileWithMultipleComments = - ( "fileWithMultipleComments" - , """ --- comment 1 -module Bar exposing (..) - --- comment 2 -bar = {- comment 3 -} 1 -- comment 4 - -- comment 5 -""" - , { moduleDefinition = - Node { start = { row = 2, column = 1 }, end = { row = 2, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 2, column = 8 }, end = { row = 2, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 2, column = 12 }, end = { row = 2, column = 25 } } <| All { start = { row = 2, column = 22 }, end = { row = 2, column = 24 } } - } - , imports = [] - , declarations = - [ Node { start = { row = 5, column = 1 }, end = { row = 5, column = 24 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 5, column = 1 }, end = { row = 5, column = 24 } } - { name = Node { start = { row = 5, column = 1 }, end = { row = 5, column = 4 } } "bar" - , arguments = [] - , expression = Node { start = { row = 5, column = 23 }, end = { row = 5, column = 24 } } (Integer 1) - } - } - ) - ] - , comments = - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } "-- comment 1" - , Node { start = { row = 4, column = 1 }, end = { row = 4, column = 13 } } "-- comment 2" - , Node { start = { row = 5, column = 7 }, end = { row = 5, column = 22 } } "{- comment 3 -}" - , Node { start = { row = 5, column = 25 }, end = { row = 5, column = 37 } } "-- comment 4" - , Node { start = { row = 6, column = 2 }, end = { row = 6, column = 14 } } "-- comment 5" - ] - } - ) - - -functionWithMultiLineCommentAsDoc : ( String, String, File ) -functionWithMultiLineCommentAsDoc = - ( "functionWithMultiLineCommentAsDoc" - , """ -module Bar exposing (..) - -{- The Doc -} -bar = 1 -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = - Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| - All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = [] - , declarations = - [ Node { start = { row = 4, column = 1 }, end = { row = 4, column = 8 } } <| - FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 4, column = 1 }, end = { row = 4, column = 8 } } - { name = Node { start = { row = 4, column = 1 }, end = { row = 4, column = 4 } } "bar" - , arguments = [] - , expression = Node { start = { row = 4, column = 7 }, end = { row = 4, column = 8 } } <| Integer 1 - } - } - ] - , comments = [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 14 } } "{- The Doc -}" ] - } - ) - - -typeAliasWithDocumentation : ( String, String, File ) -typeAliasWithDocumentation = - ( "typeAliasWithDocumentation" - , """ -module Bar exposing (..) - -import String - -{-| The Doc -} -type alias Foo - = { name : String } -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 14 } } - { moduleName = Node { start = { row = 3, column = 8 }, end = { row = 3, column = 14 } } [ "String" ] - , moduleAlias = Nothing - , exposingList = Nothing - } - ] - , declarations = - [ Node { start = { row = 5, column = 1 }, end = { row = 7, column = 23 } } <| - AliasDeclaration - { documentation = - Just <| - Node { start = { row = 5, column = 1 }, end = { row = 5, column = 15 } } "{-| The Doc -}" - , name = Node { start = { row = 6, column = 12 }, end = { row = 6, column = 15 } } "Foo" - , generics = [] - , typeAnnotation = - Node { start = { row = 7, column = 6 }, end = { row = 7, column = 23 } } <| - Record - [ Node { start = { row = 7, column = 8 }, end = { row = 7, column = 21 } } - ( Node { start = { row = 7, column = 8 }, end = { row = 7, column = 12 } } "name" - , Node { start = { row = 7, column = 15 }, end = { row = 7, column = 21 } } <| - Typed (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 21 } } ( [], "String" )) [] - ) - ] - } - ] - , comments = [] - } - ) - - -maxCallStackSizeFailure : ( String, String, File ) -maxCallStackSizeFailure = - ( "maxCallStackSizeFailure" - , """module Simplify.AstHelpers exposing (log) - - -log : Int -> Int -log a = - Debug.log "ok" a -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 42 } } - (NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 27 } } [ "Simplify", "AstHelpers" ] - , exposingList = - Node { start = { row = 1, column = 28 }, end = { row = 1, column = 42 } } - (Explicit - [ Node { start = { row = 1, column = 38 }, end = { row = 1, column = 41 } } (FunctionExpose "log") - ] - ) - } - ) - , imports = [] - , declarations = - [ Node { start = { row = 4, column = 1 }, end = { row = 6, column = 21 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Just (Node { start = { row = 4, column = 1 }, end = { row = 4, column = 17 } } { name = Node { start = { row = 4, column = 1 }, end = { row = 4, column = 4 } } "log", typeAnnotation = Node { start = { row = 4, column = 7 }, end = { row = 4, column = 17 } } (FunctionTypeAnnotation (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 10 } } (Typed (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 10 } } ( [], "Int" )) [])) (Node { start = { row = 4, column = 14 }, end = { row = 4, column = 17 } } (Typed (Node { start = { row = 4, column = 14 }, end = { row = 4, column = 17 } } ( [], "Int" )) []))) }) - , declaration = - Node { start = { row = 5, column = 1 }, end = { row = 6, column = 21 } } - { name = Node { start = { row = 5, column = 1 }, end = { row = 5, column = 4 } } "log" - , arguments = [ Node { start = { row = 5, column = 5 }, end = { row = 5, column = 6 } } (VarPattern "a") ] - , expression = - Node { start = { row = 6, column = 5 }, end = { row = 6, column = 21 } } - (Application - [ Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } (FunctionOrValue [ "Debug" ] "log") - , Node { start = { row = 6, column = 15 }, end = { row = 6, column = 19 } } (Literal "ok") - , Node { start = { row = 6, column = 20 }, end = { row = 6, column = 21 } } (FunctionOrValue [] "a") - ] - ) - } - } - ) - ] - , comments = [] - } - ) - - -typeWithDocumentation : ( String, String, File ) -typeWithDocumentation = - ( "typeWithDocumentation" - , """ -module Bar exposing (..) - -import String - -{-| The Doc -} -type Foo - = Red - | Blue -""" - , { moduleDefinition = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } (NormalModule { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ], exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } (All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } }) }) - , imports = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 14 } } - { moduleName = Node { start = { row = 3, column = 8 }, end = { row = 3, column = 14 } } [ "String" ] - , moduleAlias = Nothing - , exposingList = Nothing - } - ] - , declarations = - [ Node { start = { row = 5, column = 1 }, end = { row = 8, column = 10 } } - (CustomTypeDeclaration - { documentation = - Just - (Node { start = { row = 5, column = 1 }, end = { row = 5, column = 15 } } - "{-| The Doc -}" - ) - , name = Node { start = { row = 6, column = 6 }, end = { row = 6, column = 9 } } "Foo" - , generics = [] - , constructors = - [ Node { start = { row = 7, column = 6 }, end = { row = 7, column = 9 } } - { name = Node { start = { row = 7, column = 6 }, end = { row = 7, column = 9 } } "Red", arguments = [] } - , Node { start = { row = 8, column = 6 }, end = { row = 8, column = 10 } } - { name = Node { start = { row = 8, column = 6 }, end = { row = 8, column = 10 } } "Blue", arguments = [] } - ] - } - ) - ] - , comments = [] - } - ) - - -postProcessInfixOperators : ( String, String, File ) -postProcessInfixOperators = - ( "postProcessInfixOperators" - , """ -module Bar exposing (..) - -bar = (x + 1) * (2 * y) -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = [] - , declarations = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 24 } } <| - FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 3, column = 1 }, end = { row = 3, column = 24 } } - { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 4 } } "bar" - , arguments = [] - , expression = - Node { start = { row = 3, column = 7 }, end = { row = 3, column = 24 } } <| - OperatorApplication "*" - Left - (Node { start = { row = 3, column = 7 }, end = { row = 3, column = 14 } } <| - ParenthesizedExpression - (Node { start = { row = 3, column = 8 }, end = { row = 3, column = 13 } } <| - OperatorApplication "+" - Left - (Node { start = { row = 3, column = 8 }, end = { row = 3, column = 9 } } <| - FunctionOrValue [] "x" - ) - (Node { start = { row = 3, column = 12 }, end = { row = 3, column = 13 } } <| Integer 1) - ) - ) - (Node { start = { row = 3, column = 17 }, end = { row = 3, column = 24 } } <| - ParenthesizedExpression - (Node { start = { row = 3, column = 18 }, end = { row = 3, column = 23 } } <| - OperatorApplication "*" - Left - (Node { start = { row = 3, column = 18 }, end = { row = 3, column = 19 } } <| Integer 2) - (Node { start = { row = 3, column = 22 }, end = { row = 3, column = 23 } } <| FunctionOrValue [] "y") - ) - ) - } - } - ] - , comments = [] - } - ) - - -postProcessInfixOperators2 : ( String, String, File ) -postProcessInfixOperators2 = - ( "postProcessInfixOperators2" - , """ -module Bar exposing (..) - -bar = x + 1 * 2 -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = [] - , declarations = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 16 } } <| - FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 3, column = 1 }, end = { row = 3, column = 16 } } - { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 4 } } "bar" - , arguments = [] - , expression = - Node { start = { row = 3, column = 7 }, end = { row = 3, column = 16 } } <| - OperatorApplication "+" - Left - (Node { start = { row = 3, column = 7 }, end = { row = 3, column = 8 } } <| - FunctionOrValue [] "x" - ) - (Node { start = { row = 3, column = 11 }, end = { row = 3, column = 16 } } <| - OperatorApplication "*" - Left - (Node { start = { row = 3, column = 11 }, end = { row = 3, column = 12 } } <| Integer 1) - (Node { start = { row = 3, column = 15 }, end = { row = 3, column = 16 } } <| Integer 2) - ) - } - } - ] - , comments = [] - } - ) - - -postProcessInfixOperators3 : ( String, String, File ) -postProcessInfixOperators3 = - ( "postProcessInfixOperators3" - , """ -module Bar exposing (..) - -bar = x * 1 + 2 -""" - , { moduleDefinition = - Node - { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } - <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = [] - , declarations = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 16 } } <| - FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 3, column = 1 }, end = { row = 3, column = 16 } } - { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 4 } } "bar" - , arguments = [] - , expression = - Node { start = { row = 3, column = 7 }, end = { row = 3, column = 16 } } <| - OperatorApplication "+" - Left - (Node { start = { row = 3, column = 7 }, end = { row = 3, column = 12 } } <| - OperatorApplication "*" - Left - (Node { start = { row = 3, column = 7 }, end = { row = 3, column = 8 } } <| FunctionOrValue [] "x") - (Node { start = { row = 3, column = 11 }, end = { row = 3, column = 12 } } <| Integer 1) - ) - (Node { start = { row = 3, column = 15 }, end = { row = 3, column = 16 } } <| Integer 2) - } - } - ] - , comments = [] - } - ) - - -postProcessInfixOperatorsInNegation : ( String, String, File ) -postProcessInfixOperatorsInNegation = - ( "postProcessInfixOperatorsInNegation" - , """ -module Bar exposing (..) - -bar = -(1 * 2) -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = [] - , declarations = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 15 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 3, column = 1 }, end = { row = 3, column = 15 } } - { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 4 } } "bar" - , arguments = [] - , expression = - Node { start = { row = 3, column = 7 }, end = { row = 3, column = 15 } } - (Negation - (Node { start = { row = 3, column = 8 }, end = { row = 3, column = 15 } } - (ParenthesizedExpression - (Node { start = { row = 3, column = 9 }, end = { row = 3, column = 14 } } - (OperatorApplication - "*" - Left - (Node { start = { row = 3, column = 9 }, end = { row = 3, column = 10 } } (Integer 1)) - (Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (Integer 2)) - ) - ) - ) - ) - ) - } - } - ) - ] - , comments = [] - } - ) - - -postProcessInfixOperatorsInRecordAccess : ( String, String, File ) -postProcessInfixOperatorsInRecordAccess = - ( "postProcessInfixOperatorsInRecordAccess" - , """ -module Bar exposing (..) - -bar = (1 * 2).x -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } <| - NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } [ "Bar" ] - , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 25 } } <| All { start = { row = 1, column = 22 }, end = { row = 1, column = 24 } } - } - , imports = [] - , declarations = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 16 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 3, column = 1 }, end = { row = 3, column = 16 } } - { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 4 } } "bar" - , arguments = [] - , expression = - Node { start = { row = 3, column = 7 }, end = { row = 3, column = 16 } } - (RecordAccess - (Node { start = { row = 3, column = 7 }, end = { row = 3, column = 14 } } - (ParenthesizedExpression - (Node { start = { row = 3, column = 8 }, end = { row = 3, column = 13 } } - (OperatorApplication - "*" - Left - (Node { start = { row = 3, column = 8 }, end = { row = 3, column = 9 } } (Integer 1)) - (Node { start = { row = 3, column = 12 }, end = { row = 3, column = 13 } } (Integer 2)) - ) - ) - ) - ) - (Node { start = { row = 3, column = 15 }, end = { row = 3, column = 16 } } "x") - ) - } - } - ) - ] - , comments = [] - } - ) - - -{-| Check to make sure this issue is fixed --} -postProcessInfixOperatorsRegressionTest : ( String, String, File ) -postProcessInfixOperatorsRegressionTest = - ( "postProcessInfixOperatorsRegressionTest" - , """ -module A exposing (..) - -bool1 = True && True || True -bool2 = True || True && True - -numeric1 = 1 ^ 2 * 3 + 4 -numeric2 = 1 + 2 * 3 ^ 4 -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 23 } } - (NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } [ "A" ] - , exposingList = - Node { start = { row = 1, column = 10 }, end = { row = 1, column = 23 } } - (All { start = { row = 1, column = 20 }, end = { row = 1, column = 22 } }) - } - ) - , imports = [] - , declarations = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 29 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 3, column = 1 }, end = { row = 3, column = 29 } } - { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 6 } } "bool1" - , arguments = [] - , expression = - Node { start = { row = 3, column = 9 }, end = { row = 3, column = 29 } } - (OperatorApplication "||" - Right - (Node { start = { row = 3, column = 9 }, end = { row = 3, column = 21 } } - (OperatorApplication "&&" - Right - (Node { start = { row = 3, column = 9 }, end = { row = 3, column = 13 } } (FunctionOrValue [] "True")) - (Node { start = { row = 3, column = 17 }, end = { row = 3, column = 21 } } (FunctionOrValue [] "True")) - ) - ) - (Node { start = { row = 3, column = 25 }, end = { row = 3, column = 29 } } (FunctionOrValue [] "True")) - ) - } - } - ) - , Node { start = { row = 4, column = 1 }, end = { row = 4, column = 29 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 4, column = 1 }, end = { row = 4, column = 29 } } - { name = Node { start = { row = 4, column = 1 }, end = { row = 4, column = 6 } } "bool2" - , arguments = [] - , expression = - Node { start = { row = 4, column = 9 }, end = { row = 4, column = 29 } } - (OperatorApplication "||" - Right - (Node { start = { row = 4, column = 9 }, end = { row = 4, column = 13 } } (FunctionOrValue [] "True")) - (Node { start = { row = 4, column = 17 }, end = { row = 4, column = 29 } } - (OperatorApplication "&&" - Right - (Node { start = { row = 4, column = 17 }, end = { row = 4, column = 21 } } (FunctionOrValue [] "True")) - (Node { start = { row = 4, column = 25 }, end = { row = 4, column = 29 } } (FunctionOrValue [] "True")) - ) - ) - ) - } - } - ) - , Node { start = { row = 6, column = 1 }, end = { row = 6, column = 25 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 6, column = 1 }, end = { row = 6, column = 25 } } - { name = Node { start = { row = 6, column = 1 }, end = { row = 6, column = 9 } } "numeric1" - , arguments = [] - , expression = - Node { start = { row = 6, column = 12 }, end = { row = 6, column = 25 } } - (OperatorApplication "+" - Left - (Node { start = { row = 6, column = 12 }, end = { row = 6, column = 21 } } - (OperatorApplication "*" - Left - (Node { start = { row = 6, column = 12 }, end = { row = 6, column = 17 } } - (OperatorApplication "^" - Right - (Node { start = { row = 6, column = 12 }, end = { row = 6, column = 13 } } (Integer 1)) - (Node { start = { row = 6, column = 16 }, end = { row = 6, column = 17 } } (Integer 2)) - ) - ) - (Node { start = { row = 6, column = 20 }, end = { row = 6, column = 21 } } (Integer 3)) - ) - ) - (Node - { start = { row = 6, column = 24 }, end = { row = 6, column = 25 } } - (Integer 4) - ) - ) - } - } - ) - , Node { start = { row = 7, column = 1 }, end = { row = 7, column = 25 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 7, column = 1 }, end = { row = 7, column = 25 } } - { name = Node { start = { row = 7, column = 1 }, end = { row = 7, column = 9 } } "numeric2" - , arguments = [] - , expression = - Node { start = { row = 7, column = 12 }, end = { row = 7, column = 25 } } - (OperatorApplication "+" - Left - (Node { start = { row = 7, column = 12 }, end = { row = 7, column = 13 } } (Integer 1)) - (Node { start = { row = 7, column = 16 }, end = { row = 7, column = 25 } } - (OperatorApplication "*" - Left - (Node { start = { row = 7, column = 16 }, end = { row = 7, column = 17 } } (Integer 2)) - (Node { start = { row = 7, column = 20 }, end = { row = 7, column = 25 } } - (OperatorApplication "^" - Right - (Node { start = { row = 7, column = 20 }, end = { row = 7, column = 21 } } (Integer 3)) - (Node { start = { row = 7, column = 24 }, end = { row = 7, column = 25 } } (Integer 4)) - ) - ) - ) - ) - ) - } - } - ) - ] - , comments = [] - } - ) - - -{-| Check to make sure this issue is fixed --} -postProcessInfixOperatorsAssociativityTest : ( String, String, File ) -postProcessInfixOperatorsAssociativityTest = - ( "postProcessInfixOperatorsAssociativityTest" - , """ -module A exposing (..) - -numeric1 = 1 + 2 - 3 - -pipeline1 = 1 |> 2 |> 3 -""" - , { moduleDefinition = - Node { start = { row = 1, column = 1 }, end = { row = 1, column = 23 } } - (NormalModule - { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } [ "A" ] - , exposingList = - Node { start = { row = 1, column = 10 }, end = { row = 1, column = 23 } } - (All { start = { row = 1, column = 20 }, end = { row = 1, column = 22 } }) - } - ) - , imports = [] - , declarations = - [ Node { start = { row = 3, column = 1 }, end = { row = 3, column = 21 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 3, column = 1 }, end = { row = 3, column = 21 } } - { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 9 } } "numeric1" - , arguments = [] - , expression = - Node { start = { row = 3, column = 12 }, end = { row = 3, column = 21 } } - (OperatorApplication "-" - Left - (Node { start = { row = 3, column = 12 }, end = { row = 3, column = 17 } } - (OperatorApplication "+" - Left - (Node { start = { row = 3, column = 12 }, end = { row = 3, column = 13 } } (Integer 1)) - (Node { start = { row = 3, column = 16 }, end = { row = 3, column = 17 } } (Integer 2)) - ) - ) - (Node { start = { row = 3, column = 20 }, end = { row = 3, column = 21 } } (Integer 3)) - ) - } - } - ) - , Node { start = { row = 5, column = 1 }, end = { row = 5, column = 24 } } - (FunctionDeclaration - { documentation = Nothing - , signature = Nothing - , declaration = - Node { start = { row = 5, column = 1 }, end = { row = 5, column = 24 } } - { name = Node { start = { row = 5, column = 1 }, end = { row = 5, column = 10 } } "pipeline1" - , arguments = [] - , expression = - Node { start = { row = 5, column = 13 }, end = { row = 5, column = 24 } } - (OperatorApplication "|>" - Left - (Node { start = { row = 5, column = 13 }, end = { row = 5, column = 19 } } - (OperatorApplication "|>" - Left - (Node { start = { row = 5, column = 13 }, end = { row = 5, column = 14 } } (Integer 1)) - (Node { start = { row = 5, column = 18 }, end = { row = 5, column = 19 } } (Integer 2)) - ) - ) - (Node { start = { row = 5, column = 23 }, end = { row = 5, column = 24 } } (Integer 3)) - ) - } - } - ) - ] - , comments = [] - } - ) From 9adfc79ecd2c4b523c8610ed563b8839c1598c3e Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 19 Jul 2024 00:51:07 +0200 Subject: [PATCH 05/44] Remove serialization ability from modules --- CHANGELOG.md | 1 + elm.json | 1 - src/Elm/Json/Util.elm | 29 --- src/Elm/Syntax/Comments.elm | 27 +-- src/Elm/Syntax/Declaration.elm | 76 +----- src/Elm/Syntax/Documentation.elm | 29 +-- src/Elm/Syntax/Exposing.elm | 92 +------- src/Elm/Syntax/Expression.elm | 368 +---------------------------- src/Elm/Syntax/File.elm | 45 +--- src/Elm/Syntax/Import.elm | 47 +--- src/Elm/Syntax/Infix.elm | 74 +----- src/Elm/Syntax/Module.elm | 75 +----- src/Elm/Syntax/ModuleName.elm | 29 +-- src/Elm/Syntax/Node.elm | 27 --- src/Elm/Syntax/Pattern.elm | 171 +------------- src/Elm/Syntax/Range.elm | 42 ---- src/Elm/Syntax/Signature.elm | 35 +-- src/Elm/Syntax/Type.elm | 58 +---- src/Elm/Syntax/TypeAlias.elm | 43 +--- src/Elm/Syntax/TypeAnnotation.elm | 147 +----------- tests/Elm/Syntax/ExposingTests.elm | 32 --- tests/Elm/Syntax/ImportTests.elm | 44 ---- 22 files changed, 57 insertions(+), 1435 deletions(-) delete mode 100644 src/Elm/Json/Util.elm delete mode 100644 tests/Elm/Syntax/ExposingTests.elm delete mode 100644 tests/Elm/Syntax/ImportTests.elm diff --git a/CHANGELOG.md b/CHANGELOG.md index c669972a0..5cd5ff9cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - `Elm.Interface` module - `Elm.Dependency` module - `Elm.Processing` and `Elm.RawFile` modules + - All `encode` and `decode` functions ## [7.3.4] - 2024-07-26 diff --git a/elm.json b/elm.json index 39084a5d1..590fcb2d4 100644 --- a/elm.json +++ b/elm.json @@ -27,7 +27,6 @@ "elm-version": "0.19.0 <= v < 0.20.0", "dependencies": { "elm/core": "1.0.0 <= v < 2.0.0", - "elm/json": "1.0.0 <= v < 2.0.0", "elm/parser": "1.0.0 <= v < 2.0.0", "miniBill/elm-unicode": "1.0.2 <= v < 2.0.0", "rtfeldman/elm-hex": "1.0.0 <= v < 2.0.0" diff --git a/src/Elm/Json/Util.elm b/src/Elm/Json/Util.elm deleted file mode 100644 index 6dc8a4975..000000000 --- a/src/Elm/Json/Util.elm +++ /dev/null @@ -1,29 +0,0 @@ -module Elm.Json.Util exposing (decodeTyped, encodeTyped) - -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) - - -encodeTyped : String -> Value -> Value -encodeTyped x v = - JE.object - [ ( "type", JE.string x ) - , ( x, v ) - ] - - -decodeTyped : List ( String, Decoder a ) -> Decoder a -decodeTyped opts = - JD.lazy - (\() -> - JD.field "type" JD.string - |> JD.andThen - (\t -> - case List.filter (\( opt, _ ) -> opt == t) opts |> List.head of - Just m -> - JD.field (Tuple.first m) <| Tuple.second m - - Nothing -> - JD.fail ("No decoder for type: " ++ t) - ) - ) diff --git a/src/Elm/Syntax/Comments.elm b/src/Elm/Syntax/Comments.elm index 0588e56c5..30578742e 100644 --- a/src/Elm/Syntax/Comments.elm +++ b/src/Elm/Syntax/Comments.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.Comments exposing - ( Comment - , encode, decoder - ) +module Elm.Syntax.Comments exposing (Comment) {-| This syntax represents both single and multi line comments in Elm. For example: @@ -21,32 +18,10 @@ module Elm.Syntax.Comments exposing @docs Comment - -## Serialization - -@docs encode, decoder - -} -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) - {-| Type representing the comment syntax -} type alias Comment = String - - -{-| Encode a `Comment` syntax element to JSON. --} -encode : Comment -> Value -encode = - JE.string - - -{-| JSON decoder for a `Comment` syntax element. --} -decoder : Decoder Comment -decoder = - JD.string diff --git a/src/Elm/Syntax/Declaration.elm b/src/Elm/Syntax/Declaration.elm index a8459c817..d170175bf 100644 --- a/src/Elm/Syntax/Declaration.elm +++ b/src/Elm/Syntax/Declaration.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.Declaration exposing - ( Declaration(..) - , encode, decoder - ) +module Elm.Syntax.Declaration exposing (Declaration(..)) {-| Syntax for the different top-level declarations in Elm. These can be one of the following (all declared in `Declaration`): @@ -18,23 +15,15 @@ These can be one of the following (all declared in `Declaration`): @docs Declaration - -## Serialization - -@docs encode, decoder - -} -import Elm.Json.Util exposing (decodeTyped, encodeTyped) -import Elm.Syntax.Expression as Expression exposing (Expression, Function) -import Elm.Syntax.Infix as Infix exposing (Infix) -import Elm.Syntax.Node as Node exposing (Node) -import Elm.Syntax.Pattern as Pattern exposing (Pattern) -import Elm.Syntax.Signature as Signature exposing (Signature) -import Elm.Syntax.Type as Type exposing (Type) -import Elm.Syntax.TypeAlias as TypeAlias exposing (TypeAlias) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Expression exposing (Expression, Function) +import Elm.Syntax.Infix exposing (Infix) +import Elm.Syntax.Node exposing (Node) +import Elm.Syntax.Pattern exposing (Pattern) +import Elm.Syntax.Signature exposing (Signature) +import Elm.Syntax.Type exposing (Type) +import Elm.Syntax.TypeAlias exposing (TypeAlias) {-| Custom type that represents all different top-level declarations. @@ -49,51 +38,4 @@ type Declaration --- Serialization - - -{-| Encode a `Declaration` syntax element to JSON. --} -encode : Declaration -> Value -encode decl = - case decl of - FunctionDeclaration function -> - encodeTyped "function" (Expression.encodeFunction function) - - AliasDeclaration typeAlias -> - encodeTyped "typeAlias" (TypeAlias.encode typeAlias) - - CustomTypeDeclaration typeDeclaration -> - encodeTyped "typedecl" (Type.encode typeDeclaration) - - PortDeclaration sig -> - encodeTyped "port" (Signature.encode sig) - - InfixDeclaration inf -> - encodeTyped "infix" - (Infix.encode inf) - - Destructuring pattern expression -> - encodeTyped "destructuring" - (JE.object - [ ( "pattern", Node.encode Pattern.encode pattern ) - , ( "expression", Node.encode Expression.encode expression ) - ] - ) - - -{-| JSON decoder for a `Declaration` syntax element. --} -decoder : Decoder Declaration -decoder = - JD.lazy - (\() -> - decodeTyped - [ ( "function", Expression.functionDecoder |> JD.map FunctionDeclaration ) - , ( "typeAlias", TypeAlias.decoder |> JD.map AliasDeclaration ) - , ( "typedecl", Type.decoder |> JD.map CustomTypeDeclaration ) - , ( "port", Signature.decoder |> JD.map PortDeclaration ) - , ( "infix", Infix.decoder |> JD.map InfixDeclaration ) - , ( "destructuring", JD.map2 Destructuring (JD.field "pattern" (Node.decoder Pattern.decoder)) (JD.field "expression" (Node.decoder Expression.decoder)) ) - ] - ) +-- diff --git a/src/Elm/Syntax/Documentation.elm b/src/Elm/Syntax/Documentation.elm index 003f6c3ac..45f5fe6f2 100644 --- a/src/Elm/Syntax/Documentation.elm +++ b/src/Elm/Syntax/Documentation.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.Documentation exposing - ( Documentation - , encode, decoder - ) +module Elm.Syntax.Documentation exposing (Documentation) {-| This syntax represents documentation comments in Elm. @@ -10,16 +7,8 @@ module Elm.Syntax.Documentation exposing @docs Documentation - -## Serialization - -@docs encode, decoder - -} -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) - {-| Type representing the documentation syntax -} @@ -28,18 +17,4 @@ type alias Documentation = --- Serialization - - -{-| Encode a `Documentation` syntax element to JSON. --} -encode : Documentation -> Value -encode = - JE.string - - -{-| JSON decoder for a `Documentation` syntax element. --} -decoder : Decoder Documentation -decoder = - JD.string +-- diff --git a/src/Elm/Syntax/Exposing.elm b/src/Elm/Syntax/Exposing.elm index a9382323e..11dae9985 100644 --- a/src/Elm/Syntax/Exposing.elm +++ b/src/Elm/Syntax/Exposing.elm @@ -1,7 +1,6 @@ module Elm.Syntax.Exposing exposing ( Exposing(..), TopLevelExpose(..), ExposedType , exposesFunction, operators - , encode, decoder ) {-| This syntax represents the exposing declaration for both imports and module headers. @@ -20,18 +19,10 @@ For example: @docs exposesFunction, operators - -## Serialization - -@docs encode, decoder - -} -import Elm.Json.Util exposing (decodeTyped, encodeTyped) -import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Range as Range exposing (Range) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Node exposing (Node(..)) +import Elm.Syntax.Range exposing (Range) {-| Different kind of exposing declarations @@ -108,81 +99,4 @@ operator t = --- Serialization - - -{-| Encode an `Exposing` syntax element to JSON. --} -encode : Exposing -> Value -encode exp = - case exp of - All r -> - encodeTyped "all" <| Range.encode r - - Explicit l -> - encodeTyped "explicit" (JE.list encodeTopLevelExpose l) - - -{-| JSON decoder for an `Exposing` syntax element. --} -decoder : Decoder Exposing -decoder = - decodeTyped - [ ( "all", Range.decoder |> JD.map All ) - , ( "explicit", JD.list topLevelExposeDecoder |> JD.map Explicit ) - ] - - -encodeTopLevelExpose : Node TopLevelExpose -> Value -encodeTopLevelExpose = - Node.encode - (\exp -> - case exp of - InfixExpose x -> - encodeTyped "infix" <| - JE.object - [ ( "name", JE.string x ) - ] - - FunctionExpose x -> - encodeTyped "function" <| - JE.object - [ ( "name", JE.string x ) - ] - - TypeOrAliasExpose x -> - encodeTyped "typeOrAlias" <| - JE.object - [ ( "name", JE.string x ) - ] - - TypeExpose exposedType -> - encodeTyped "typeexpose" (encodeExposedType exposedType) - ) - - -encodeExposedType : ExposedType -> Value -encodeExposedType { name, open } = - JE.object - [ ( "name", JE.string name ) - , ( "open", open |> Maybe.map Range.encode |> Maybe.withDefault JE.null ) - ] - - -topLevelExposeDecoder : Decoder (Node TopLevelExpose) -topLevelExposeDecoder = - Node.decoder - (decodeTyped - [ ( "infix", JD.map InfixExpose (JD.field "name" JD.string) ) - , ( "function", JD.map FunctionExpose (JD.field "name" JD.string) ) - , ( "typeOrAlias", JD.map TypeOrAliasExpose (JD.field "name" JD.string) ) - , ( "typeexpose", JD.map TypeExpose exposedTypeDecoder ) - ] - ) - - -exposedTypeDecoder : Decoder ExposedType -exposedTypeDecoder = - JD.map2 ExposedType - (JD.field "name" JD.string) - (JD.field "open" (JD.nullable Range.decoder)) +-- diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index cb665f896..0cc0e6fb9 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -1,7 +1,6 @@ module Elm.Syntax.Expression exposing ( Expression(..), Lambda, LetBlock, LetDeclaration(..), RecordSetter, CaseBlock, Cases, Case, Function, FunctionImplementation , functionRange, isLambda, isLet, isIfElse, isCase, isOperatorApplication - , encode, encodeFunction, decoder, functionDecoder ) {-| This syntax represents all that you can express in Elm. @@ -17,23 +16,15 @@ Although it is a easy and simple language, you can express a lot! See the `Expre @docs functionRange, isLambda, isLet, isIfElse, isCase, isOperatorApplication - -## Serialization - -@docs encode, encodeFunction, decoder, functionDecoder - -} -import Elm.Json.Util exposing (decodeTyped, encodeTyped) -import Elm.Syntax.Documentation as Documentation exposing (Documentation) -import Elm.Syntax.Infix as Infix exposing (InfixDirection) -import Elm.Syntax.ModuleName as ModuleName exposing (ModuleName) +import Elm.Syntax.Documentation exposing (Documentation) +import Elm.Syntax.Infix exposing (InfixDirection) +import Elm.Syntax.ModuleName exposing (ModuleName) import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Pattern as Pattern exposing (Pattern) +import Elm.Syntax.Pattern exposing (Pattern) import Elm.Syntax.Range exposing (Range) -import Elm.Syntax.Signature as Signature exposing (Signature) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Signature exposing (Signature) {-| Type alias for a full function @@ -244,352 +235,3 @@ isOperatorApplication e = _ -> False - - - --- Serialization - - -{-| Encode an `Expression` syntax element to JSON. --} -encode : Expression -> Value -encode expr = - case expr of - UnitExpr -> - encodeTyped "unit" JE.null - - Application l -> - encodeTyped "application" (JE.list (Node.encode encode) l) - - OperatorApplication op dir left right -> - encodeTyped "operatorapplication" (encodeOperatorApplication op dir left right) - - FunctionOrValue moduleName name -> - encodeTyped "functionOrValue" - (JE.object - [ ( "moduleName", ModuleName.encode moduleName ) - , ( "name", JE.string name ) - ] - ) - - IfBlock c t e -> - encodeTyped "ifBlock" <| - JE.object - [ ( "clause", Node.encode encode c ) - , ( "then", Node.encode encode t ) - , ( "else", Node.encode encode e ) - ] - - PrefixOperator x -> - encodeTyped "prefixoperator" (JE.string x) - - Operator x -> - encodeTyped "operator" (JE.string x) - - Hex h -> - encodeTyped "hex" (JE.int h) - - Integer x -> - encodeTyped "integer" (JE.int x) - - Floatable x -> - encodeTyped "float" (JE.float x) - - Negation x -> - encodeTyped "negation" (Node.encode encode x) - - Literal x -> - encodeTyped "literal" (JE.string x) - - CharLiteral c -> - encodeTyped "charLiteral" (JE.string <| String.fromChar c) - - TupledExpression xs -> - encodeTyped "tupled" (JE.list (Node.encode encode) xs) - - ListExpr xs -> - encodeTyped "list" (JE.list (Node.encode encode) xs) - - ParenthesizedExpression x -> - encodeTyped "parenthesized" (Node.encode encode x) - - LetExpression x -> - encodeTyped "let" <| encodeLetBlock x - - CaseExpression x -> - encodeTyped "case" <| encodeCaseBlock x - - LambdaExpression x -> - encodeTyped "lambda" <| encodeLambda x - - RecordAccess exp name -> - encodeTyped "recordAccess" <| - JE.object - [ ( "expression", Node.encode encode exp ) - , ( "name", Node.encode JE.string name ) - ] - - RecordAccessFunction x -> - encodeTyped "recordAccessFunction" (JE.string x) - - RecordExpr xs -> - encodeTyped "record" (JE.list (Node.encode encodeRecordSetter) xs) - - RecordUpdateExpression name updates -> - encodeTyped "recordUpdate" (encodeRecordUpdate name updates) - - GLSLExpression x -> - encodeTyped "glsl" (JE.string x) - - -encodeOperatorApplication : String -> InfixDirection -> Node Expression -> Node Expression -> Value -encodeOperatorApplication operator direction left right = - JE.object - [ ( "operator", JE.string operator ) - , ( "direction", Infix.encodeDirection direction ) - , ( "left", Node.encode encode left ) - , ( "right", Node.encode encode right ) - ] - - -encodeLetBlock : LetBlock -> Value -encodeLetBlock { declarations, expression } = - JE.object - [ ( "declarations", JE.list (Node.encode encodeLetDeclaration) declarations ) - , ( "expression", Node.encode encode expression ) - ] - - -encodeRecordUpdate : Node String -> List (Node RecordSetter) -> Value -encodeRecordUpdate name updates = - JE.object - [ ( "name", Node.encode JE.string name ) - , ( "updates", JE.list (Node.encode encodeRecordSetter) updates ) - ] - - -encodeRecordSetter : RecordSetter -> Value -encodeRecordSetter ( field, expression ) = - JE.object - [ ( "field", Node.encode JE.string field ) - , ( "expression", Node.encode encode expression ) - ] - - -encodeLetDeclaration : LetDeclaration -> Value -encodeLetDeclaration letDeclaration = - case letDeclaration of - LetFunction f -> - encodeTyped "function" (encodeFunction f) - - LetDestructuring pattern expression -> - encodeTyped "destructuring" (encodeDestructuring pattern expression) - - -{-| Encode a `Function` syntax element to JSON. --} -encodeFunction : Function -> Value -encodeFunction { documentation, signature, declaration } = - JE.object - [ ( "documentation", Maybe.map (Node.encode Documentation.encode) documentation |> Maybe.withDefault JE.null ) - , ( "signature", Maybe.map (Node.encode Signature.encode) signature |> Maybe.withDefault JE.null ) - , ( "declaration", Node.encode encodeFunctionDeclaration declaration ) - ] - - -encodeFunctionDeclaration : FunctionImplementation -> Value -encodeFunctionDeclaration { name, arguments, expression } = - JE.object - [ ( "name", Node.encode JE.string name ) - , ( "arguments", JE.list (Node.encode Pattern.encode) arguments ) - , ( "expression", Node.encode encode expression ) - ] - - -encodeDestructuring : Node Pattern -> Node Expression -> Value -encodeDestructuring pattern expression = - JE.object - [ ( "pattern", Node.encode Pattern.encode pattern ) - , ( "expression", Node.encode encode expression ) - ] - - -encodeCaseBlock : CaseBlock -> Value -encodeCaseBlock { expression, cases } = - JE.object - [ ( "cases", JE.list encodeCase cases ) - , ( "expression", Node.encode encode expression ) - ] - - -encodeCase : Case -> Value -encodeCase ( pattern, expression ) = - JE.object - [ ( "pattern", Node.encode Pattern.encode pattern ) - , ( "expression", Node.encode encode expression ) - ] - - -encodeLambda : Lambda -> Value -encodeLambda { args, expression } = - JE.object - [ ( "patterns", JE.list (Node.encode Pattern.encode) args ) - , ( "expression", Node.encode encode expression ) - ] - - -decodeNested : Decoder (Node Expression) -decodeNested = - JD.lazy (\() -> Node.decoder decoder) - - -{-| JSON decoder for an `Expression` syntax element. --} -decoder : Decoder Expression -decoder = - JD.lazy - (\() -> - decodeTyped - [ ( "unit", JD.succeed UnitExpr ) - , ( "application", JD.list decodeNested |> JD.map Application ) - , ( "operatorapplication", decodeOperatorApplication ) - , ( "functionOrValue", JD.map2 FunctionOrValue (JD.field "moduleName" ModuleName.decoder) (JD.field "name" JD.string) ) - , ( "ifBlock", JD.map3 IfBlock (JD.field "clause" decodeNested) (JD.field "then" decodeNested) (JD.field "else" decodeNested) ) - , ( "prefixoperator", JD.string |> JD.map PrefixOperator ) - , ( "operator", JD.string |> JD.map Operator ) - , ( "hex", JD.int |> JD.map Hex ) - , ( "integer", JD.int |> JD.map Integer ) - , ( "float", JD.float |> JD.map Floatable ) - , ( "negation", decodeNested |> JD.map Negation ) - , ( "literal", JD.string |> JD.map Literal ) - , ( "charLiteral", decodeChar |> JD.map CharLiteral ) - , ( "tupled", JD.list decodeNested |> JD.map TupledExpression ) - , ( "list", JD.list decodeNested |> JD.map ListExpr ) - , ( "parenthesized", decodeNested |> JD.map ParenthesizedExpression ) - , ( "let", decodeLetBlock |> JD.map LetExpression ) - , ( "case", decodeCaseBlock |> JD.map CaseExpression ) - , ( "lambda", decodeLambda |> JD.map LambdaExpression ) - , ( "recordAccess", JD.map2 RecordAccess (JD.field "expression" decodeNested) (JD.field "name" (Node.decoder JD.string)) ) - , ( "recordAccessFunction", JD.string |> JD.map RecordAccessFunction ) - , ( "record", JD.list (Node.decoder decodeRecordSetter) |> JD.map RecordExpr ) - , ( "recordUpdate" - , JD.map2 RecordUpdateExpression - (JD.field "name" <| Node.decoder JD.string) - (JD.field "updates" (JD.list <| Node.decoder decodeRecordSetter)) - ) - , ( "glsl", JD.string |> JD.map GLSLExpression ) - ] - ) - - -decodeRecordSetter : Decoder RecordSetter -decodeRecordSetter = - JD.lazy - (\() -> - JD.map2 Tuple.pair - (JD.field "field" <| Node.decoder JD.string) - (JD.field "expression" decodeNested) - ) - - -decodeLambda : Decoder Lambda -decodeLambda = - JD.lazy - (\() -> - JD.map2 Lambda - (JD.field "patterns" (JD.list (Node.decoder Pattern.decoder))) - (JD.field "expression" decodeNested) - ) - - -decodeCaseBlock : Decoder CaseBlock -decodeCaseBlock = - JD.lazy - (\() -> - JD.map2 CaseBlock - (JD.field "expression" decodeNested) - (JD.field "cases" (JD.list decodeCase)) - ) - - -decodeCase : Decoder Case -decodeCase = - JD.lazy - (\() -> - JD.map2 Tuple.pair - (JD.field "pattern" (Node.decoder Pattern.decoder)) - (JD.field "expression" decodeNested) - ) - - -decodeLetBlock : Decoder LetBlock -decodeLetBlock = - JD.lazy - (\() -> - JD.map2 LetBlock - (JD.field "declarations" (JD.list decodeLetDeclaration)) - (JD.field "expression" decodeNested) - ) - - -decodeLetDeclaration : Decoder (Node LetDeclaration) -decodeLetDeclaration = - JD.lazy - (\() -> - Node.decoder - (decodeTyped - [ ( "function", JD.map LetFunction functionDecoder ) - , ( "destructuring", JD.map2 LetDestructuring (JD.field "pattern" (Node.decoder Pattern.decoder)) (JD.field "expression" decodeNested) ) - ] - ) - ) - - -decodeOperatorApplication : Decoder Expression -decodeOperatorApplication = - JD.lazy - (\() -> - JD.map4 OperatorApplication - (JD.field "operator" JD.string) - (JD.field "direction" Infix.decodeDirection) - (JD.field "left" decodeNested) - (JD.field "right" decodeNested) - ) - - -decodeChar : Decoder Char -decodeChar = - JD.string - |> JD.andThen - (\s -> - case String.uncons s of - Just ( c, _ ) -> - JD.succeed c - - Nothing -> - JD.fail "Not a char" - ) - - -{-| JSON decoder for an `Function` syntax element. --} -functionDecoder : Decoder Function -functionDecoder = - JD.lazy - (\() -> - JD.map3 Function - (JD.field "documentation" (JD.nullable <| Node.decoder Documentation.decoder)) - (JD.field "signature" (JD.nullable (Node.decoder Signature.decoder))) - (JD.field "declaration" (Node.decoder decodeFunctionDeclaration)) - ) - - -decodeFunctionDeclaration : Decoder FunctionImplementation -decodeFunctionDeclaration = - JD.lazy - (\() -> - JD.map3 FunctionImplementation - (JD.field "name" (Node.decoder JD.string)) - (JD.field "arguments" (JD.list (Node.decoder Pattern.decoder))) - (JD.field "expression" decodeNested) - ) diff --git a/src/Elm/Syntax/File.elm b/src/Elm/Syntax/File.elm index 0fa8ffb7d..8ec405d17 100644 --- a/src/Elm/Syntax/File.elm +++ b/src/Elm/Syntax/File.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.File exposing - ( File - , encode, decoder - ) +module Elm.Syntax.File exposing (File) {-| This syntax represents a whole Elm file. @@ -10,20 +7,13 @@ module Elm.Syntax.File exposing @docs File - -## Serialization - -@docs encode, decoder - -} -import Elm.Syntax.Comments as Comments exposing (Comment) -import Elm.Syntax.Declaration as Declaration exposing (Declaration) -import Elm.Syntax.Import as Import exposing (Import) -import Elm.Syntax.Module as Module exposing (Module) -import Elm.Syntax.Node as Node exposing (Node) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Comments exposing (Comment) +import Elm.Syntax.Declaration exposing (Declaration) +import Elm.Syntax.Import exposing (Import) +import Elm.Syntax.Module exposing (Module) +import Elm.Syntax.Node exposing (Node) {-| Type annotation for a file @@ -34,26 +24,3 @@ type alias File = , declarations : List (Node Declaration) , comments : List (Node Comment) } - - -{-| Encode a `File` syntax element to JSON. --} -encode : File -> Value -encode { moduleDefinition, imports, declarations, comments } = - JE.object - [ ( "moduleDefinition", Node.encode Module.encode moduleDefinition ) - , ( "imports", JE.list (Node.encode Import.encode) imports ) - , ( "declarations", JE.list (Node.encode Declaration.encode) declarations ) - , ( "comments", JE.list (Node.encode Comments.encode) comments ) - ] - - -{-| JSON decoder for a `File` syntax element. --} -decoder : Decoder File -decoder = - JD.map4 File - (JD.field "moduleDefinition" (Node.decoder Module.decoder)) - (JD.field "imports" (JD.list (Node.decoder Import.decoder))) - (JD.field "declarations" (JD.list (Node.decoder Declaration.decoder))) - (JD.field "comments" (JD.list (Node.decoder Comments.decoder))) diff --git a/src/Elm/Syntax/Import.elm b/src/Elm/Syntax/Import.elm index 67cbc101e..9456de941 100644 --- a/src/Elm/Syntax/Import.elm +++ b/src/Elm/Syntax/Import.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.Import exposing - ( Import - , encode, decoder - ) +module Elm.Syntax.Import exposing (Import) {-| This syntax represents imports in Elm. For example: @@ -13,18 +10,11 @@ For example: @docs Import - -## Serialization - -@docs encode, decoder - -} -import Elm.Syntax.Exposing as Exposing exposing (Exposing) -import Elm.Syntax.ModuleName as ModuleName exposing (ModuleName) -import Elm.Syntax.Node as Node exposing (Node) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Exposing exposing (Exposing) +import Elm.Syntax.ModuleName exposing (ModuleName) +import Elm.Syntax.Node exposing (Node) {-| Type alias representing an Import @@ -34,32 +24,3 @@ type alias Import = , moduleAlias : Maybe (Node ModuleName) , exposingList : Maybe (Node Exposing) } - - -{-| Encode a `Import` syntax element to JSON. --} -encode : Import -> Value -encode { moduleName, moduleAlias, exposingList } = - JE.object - [ ( "moduleName", Node.encode ModuleName.encode moduleName ) - , ( "moduleAlias" - , moduleAlias - |> Maybe.map (Node.encode ModuleName.encode) - |> Maybe.withDefault JE.null - ) - , ( "exposingList" - , exposingList - |> Maybe.map (Node.encode Exposing.encode) - |> Maybe.withDefault JE.null - ) - ] - - -{-| JSON decoder for a `Import` syntax element. --} -decoder : Decoder Import -decoder = - JD.map3 Import - (JD.field "moduleName" <| Node.decoder ModuleName.decoder) - (JD.field "moduleAlias" (JD.nullable <| Node.decoder ModuleName.decoder)) - (JD.field "exposingList" (JD.nullable <| Node.decoder Exposing.decoder)) diff --git a/src/Elm/Syntax/Infix.elm b/src/Elm/Syntax/Infix.elm index 6bdbf5808..7a6c97a29 100644 --- a/src/Elm/Syntax/Infix.elm +++ b/src/Elm/Syntax/Infix.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.Infix exposing - ( Infix, InfixDirection(..) - , encode, encodeDirection, decoder, decodeDirection - ) +module Elm.Syntax.Infix exposing (Infix, InfixDirection(..)) {-| @@ -10,16 +7,9 @@ module Elm.Syntax.Infix exposing @docs Infix, InfixDirection - -## Serialization - -@docs encode, encodeDirection, decoder, decodeDirection - -} -import Elm.Syntax.Node as Node exposing (Node) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Node exposing (Node) {-| Type annotation for a infix definition @@ -38,63 +28,3 @@ type InfixDirection = Left | Right | Non - - -{-| Encode an infix --} -encode : Infix -> Value -encode inf = - JE.object - [ ( "direction", Node.encode encodeDirection inf.direction ) - , ( "precedence", Node.encode JE.int inf.precedence ) - , ( "operator", Node.encode JE.string inf.operator ) - , ( "function", Node.encode JE.string inf.function ) - ] - - -{-| Encode the infix direction --} -encodeDirection : InfixDirection -> Value -encodeDirection d = - case d of - Left -> - JE.string "left" - - Right -> - JE.string "right" - - Non -> - JE.string "non" - - -{-| Decode an infix --} -decoder : Decoder Infix -decoder = - JD.map4 Infix - (JD.field "direction" (Node.decoder decodeDirection)) - (JD.field "precedence" (Node.decoder JD.int)) - (JD.field "operator" (Node.decoder JD.string)) - (JD.field "function" (Node.decoder JD.string)) - - -{-| Decode a infix direction --} -decodeDirection : Decoder InfixDirection -decodeDirection = - JD.string - |> JD.andThen - (\v -> - case v of - "left" -> - JD.succeed Left - - "right" -> - JD.succeed Right - - "non" -> - JD.succeed Non - - _ -> - JD.fail "Invalid direction" - ) diff --git a/src/Elm/Syntax/Module.elm b/src/Elm/Syntax/Module.elm index cf54bbc7f..e64858211 100644 --- a/src/Elm/Syntax/Module.elm +++ b/src/Elm/Syntax/Module.elm @@ -1,7 +1,6 @@ module Elm.Syntax.Module exposing ( Module(..), DefaultModuleData, EffectModuleData , exposingList, moduleName, isPortModule, isEffectModule - , encode, decoder ) {-| This syntax represents module definitions in Elm. @@ -16,19 +15,11 @@ For example: @docs exposingList, moduleName, isPortModule, isEffectModule - -## Serialization - -@docs encode, decoder - -} -import Elm.Json.Util exposing (decodeTyped, encodeTyped) -import Elm.Syntax.Exposing as Exposing exposing (Exposing) -import Elm.Syntax.ModuleName as ModuleName exposing (ModuleName) +import Elm.Syntax.Exposing exposing (Exposing) +import Elm.Syntax.ModuleName exposing (ModuleName) import Elm.Syntax.Node as Node exposing (Node) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) {-| Union type for different kind of modules @@ -112,64 +103,4 @@ isEffectModule m = --- Serialization - - -{-| Encode a `Module` syntax element to JSON. --} -encode : Module -> Value -encode m = - case m of - NormalModule d -> - encodeTyped "normal" (encodeDefaultModuleData d) - - PortModule d -> - encodeTyped "port" (encodeDefaultModuleData d) - - EffectModule d -> - encodeTyped "effect" (encodeEffectModuleData d) - - -encodeEffectModuleData : EffectModuleData -> Value -encodeEffectModuleData moduleData = - JE.object - [ ( "moduleName", Node.encode ModuleName.encode moduleData.moduleName ) - , ( "exposingList", Node.encode Exposing.encode moduleData.exposingList ) - , ( "command", moduleData.command |> Maybe.map (Node.encode JE.string) |> Maybe.withDefault JE.null ) - , ( "subscription", moduleData.subscription |> Maybe.map (Node.encode JE.string) |> Maybe.withDefault JE.null ) - ] - - -encodeDefaultModuleData : DefaultModuleData -> Value -encodeDefaultModuleData moduleData = - JE.object - [ ( "moduleName", Node.encode ModuleName.encode moduleData.moduleName ) - , ( "exposingList", Node.encode Exposing.encode moduleData.exposingList ) - ] - - -{-| JSON decoder for a `Module` syntax element. --} -decoder : Decoder Module -decoder = - decodeTyped - [ ( "normal", decodeDefaultModuleData |> JD.map NormalModule ) - , ( "port", decodeDefaultModuleData |> JD.map PortModule ) - , ( "effect", decodeEffectModuleData |> JD.map EffectModule ) - ] - - -decodeDefaultModuleData : Decoder DefaultModuleData -decodeDefaultModuleData = - JD.map2 DefaultModuleData - (JD.field "moduleName" <| Node.decoder ModuleName.decoder) - (JD.field "exposingList" <| Node.decoder Exposing.decoder) - - -decodeEffectModuleData : Decoder EffectModuleData -decodeEffectModuleData = - JD.map4 EffectModuleData - (JD.field "moduleName" <| Node.decoder ModuleName.decoder) - (JD.field "exposingList" <| Node.decoder Exposing.decoder) - (JD.field "command" (JD.nullable <| Node.decoder JD.string)) - (JD.field "subscription" (JD.nullable <| Node.decoder JD.string)) +-- diff --git a/src/Elm/Syntax/ModuleName.elm b/src/Elm/Syntax/ModuleName.elm index f006134f5..8eb2bfa5d 100644 --- a/src/Elm/Syntax/ModuleName.elm +++ b/src/Elm/Syntax/ModuleName.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.ModuleName exposing - ( ModuleName - , encode, decoder - ) +module Elm.Syntax.ModuleName exposing (ModuleName) {-| This syntax represents the module names in Elm. These can be used for imports, module names (duh), and for qualified access. For example: @@ -21,16 +18,8 @@ For example: @docs ModuleName - -## Serialization - -@docs encode, decoder - -} -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) - {-| Base representation for a module name -} @@ -39,18 +28,4 @@ type alias ModuleName = --- Serialization - - -{-| Encode a `ModuleName` syntax element to JSON. --} -encode : ModuleName -> Value -encode = - JE.list JE.string - - -{-| JSON decoder for a `ModuleName` syntax element. --} -decoder : Decoder ModuleName -decoder = - JD.list JD.string +-- diff --git a/src/Elm/Syntax/Node.elm b/src/Elm/Syntax/Node.elm index a93bee11c..69ceef5e3 100644 --- a/src/Elm/Syntax/Node.elm +++ b/src/Elm/Syntax/Node.elm @@ -1,7 +1,6 @@ module Elm.Syntax.Node exposing ( Node(..) , empty, combine, range, value, map - , encode, decoder ) {-| Represents a `Node` of the AST (Abstract Syntax Tree). @@ -19,16 +18,9 @@ element of the tree was found. @docs empty, combine, range, value, map - -## Serialization - -@docs encode, decoder - -} import Elm.Syntax.Range as Range exposing (Range) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) {-| Base representation for a syntax node in a source file. @@ -72,22 +64,3 @@ range (Node r _) = value : Node a -> a value (Node _ v) = v - - -{-| Encode a `Node` into JSON --} -encode : (a -> Value) -> Node a -> Value -encode f (Node r v) = - JE.object - [ ( "range", Range.encode r ) - , ( "value", f v ) - ] - - -{-| A JSON decoder for `Node` --} -decoder : Decoder a -> Decoder (Node a) -decoder sub = - JD.map2 Node - (JD.field "range" Range.decoder) - (JD.field "value" sub) diff --git a/src/Elm/Syntax/Pattern.elm b/src/Elm/Syntax/Pattern.elm index 2843adfe2..8bde8a49e 100644 --- a/src/Elm/Syntax/Pattern.elm +++ b/src/Elm/Syntax/Pattern.elm @@ -1,7 +1,6 @@ module Elm.Syntax.Pattern exposing ( Pattern(..), QualifiedNameRef , moduleNames - , encode, decoder ) {-| This syntax represents the patterns. @@ -20,18 +19,10 @@ For example: @docs moduleNames - -## Serialization - -@docs encode, decoder - -} -import Elm.Json.Util exposing (decodeTyped, encodeTyped) -import Elm.Syntax.ModuleName as ModuleName exposing (ModuleName) -import Elm.Syntax.Node as Node exposing (Node(..)) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.ModuleName exposing (ModuleName) +import Elm.Syntax.Node exposing (Node(..)) {-| Custom type for all patterns such as: @@ -113,160 +104,4 @@ moduleNames p = --- Serialization - - -{-| Encode a `Pattern` syntax element to JSON. --} -encode : Pattern -> Value -encode pattern = - case pattern of - AllPattern -> - encodeTyped "all" (JE.object []) - - UnitPattern -> - encodeTyped "unit" (JE.object []) - - CharPattern c -> - encodeTyped "char" - (JE.object - [ ( "value", JE.string <| String.fromChar c ) - ] - ) - - StringPattern v -> - encodeTyped "string" - (JE.object - [ ( "value", JE.string v ) - ] - ) - - HexPattern h -> - encodeTyped "hex" - (JE.object - [ ( "value", JE.int h ) - ] - ) - - IntPattern i -> - encodeTyped "int" - (JE.object - [ ( "value", JE.int i ) - ] - ) - - FloatPattern f -> - encodeTyped "float" - (JE.object - [ ( "value", JE.float f ) - ] - ) - - TuplePattern patterns -> - encodeTyped "tuple" - (JE.object - [ ( "value", JE.list (Node.encode encode) patterns ) - ] - ) - - RecordPattern pointers -> - encodeTyped "record" - (JE.object - [ ( "value", JE.list (Node.encode JE.string) pointers ) - ] - ) - - UnConsPattern p1 p2 -> - encodeTyped "uncons" - (JE.object - [ ( "left", Node.encode encode p1 ) - , ( "right", Node.encode encode p2 ) - ] - ) - - ListPattern patterns -> - encodeTyped "list" - (JE.object - [ ( "value", JE.list (Node.encode encode) patterns ) - ] - ) - - VarPattern name -> - encodeTyped "var" - (JE.object - [ ( "value", JE.string name ) - ] - ) - - NamedPattern qualifiedNameRef patterns -> - encodeTyped "named" <| - JE.object - [ ( "qualified" - , JE.object - [ ( "moduleName", ModuleName.encode qualifiedNameRef.moduleName ) - , ( "name", JE.string qualifiedNameRef.name ) - ] - ) - , ( "patterns", JE.list (Node.encode encode) patterns ) - ] - - AsPattern destructured name -> - encodeTyped "as" <| - JE.object - [ ( "name", Node.encode JE.string name ) - , ( "pattern", Node.encode encode destructured ) - ] - - ParenthesizedPattern p1 -> - encodeTyped "parentisized" - (JE.object - [ ( "value", Node.encode encode p1 ) - ] - ) - - -{-| JSON decoder for a `Pattern` syntax element. --} -decoder : Decoder Pattern -decoder = - JD.lazy - (\() -> - decodeTyped - [ ( "all", JD.succeed AllPattern ) - , ( "unit", JD.succeed UnitPattern ) - , ( "char", JD.field "value" decodeChar |> JD.map CharPattern ) - , ( "string", JD.field "value" JD.string |> JD.map StringPattern ) - , ( "hex", JD.int |> JD.map HexPattern ) - , ( "int", JD.field "value" JD.int |> JD.map IntPattern ) - , ( "float", JD.field "value" JD.float |> JD.map FloatPattern ) - , ( "tuple", JD.field "value" (JD.list (Node.decoder decoder)) |> JD.map TuplePattern ) - , ( "record", JD.field "value" (JD.list (Node.decoder JD.string)) |> JD.map RecordPattern ) - , ( "uncons", JD.map2 UnConsPattern (JD.field "left" (Node.decoder decoder)) (JD.field "right" (Node.decoder decoder)) ) - , ( "list", JD.field "value" (JD.list (Node.decoder decoder)) |> JD.map ListPattern ) - , ( "var", JD.field "value" JD.string |> JD.map VarPattern ) - , ( "named", JD.map2 NamedPattern (JD.field "qualified" decodeQualifiedNameRef) (JD.field "patterns" (JD.list (Node.decoder decoder))) ) - , ( "as", JD.map2 AsPattern (JD.field "pattern" (Node.decoder decoder)) (JD.field "name" (Node.decoder JD.string)) ) - , ( "parentisized", JD.map ParenthesizedPattern (JD.field "value" (Node.decoder decoder)) ) - ] - ) - - -decodeQualifiedNameRef : Decoder QualifiedNameRef -decodeQualifiedNameRef = - JD.map2 QualifiedNameRef - (JD.field "moduleName" ModuleName.decoder) - (JD.field "name" JD.string) - - -decodeChar : Decoder Char -decodeChar = - JD.string - |> JD.andThen - (\s -> - case String.uncons s of - Just ( c, _ ) -> - JD.succeed c - - Nothing -> - JD.fail "Not a char" - ) +-- diff --git a/src/Elm/Syntax/Range.elm b/src/Elm/Syntax/Range.elm index f65d767a5..5f4e02b2c 100644 --- a/src/Elm/Syntax/Range.elm +++ b/src/Elm/Syntax/Range.elm @@ -2,7 +2,6 @@ module Elm.Syntax.Range exposing ( Range, Location , empty, combine , compare, compareLocations - , encode, decoder , emptyRange ) @@ -26,20 +25,12 @@ See also [Basics.compare](https://package.elm-lang.org/packages/elm/core/latest/ @docs compare, compareLocations -## Serialization - -@docs encode, decoder - - ## Deprecated @docs emptyRange -} -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) - {-| Source location -} @@ -76,39 +67,6 @@ emptyRange = empty -{-| Encode a range --} -encode : Range -> Value -encode { start, end } = - JE.list JE.int - [ start.row - , start.column - , end.row - , end.column - ] - - -{-| Decode a range --} -decoder : Decoder Range -decoder = - JD.list JD.int - |> JD.andThen fromList - - -fromList : List Int -> Decoder Range -fromList input = - case input of - [ a, b, c, d ] -> - JD.succeed - { start = { row = a, column = b } - , end = { row = c, column = d } - } - - _ -> - JD.fail "Invalid input list" - - {-| Compute the largest area of a list of ranges. -} combine : List Range -> Range diff --git a/src/Elm/Syntax/Signature.elm b/src/Elm/Syntax/Signature.elm index cfff9e1f2..76ce36e4d 100644 --- a/src/Elm/Syntax/Signature.elm +++ b/src/Elm/Syntax/Signature.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.Signature exposing - ( Signature - , encode, decoder - ) +module Elm.Syntax.Signature exposing (Signature) {-| This syntax represents type signatures in Elm. @@ -14,17 +11,10 @@ For example : @docs Signature - -## Serialization - -@docs encode, decoder - -} -import Elm.Syntax.Node as Node exposing (Node) -import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Node exposing (Node) +import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation) {-| Type alias representing a signature in Elm. @@ -33,22 +23,3 @@ type alias Signature = { name : Node String , typeAnnotation : Node TypeAnnotation } - - -{-| Encode a `Signature` syntax element to JSON. --} -encode : Signature -> Value -encode { name, typeAnnotation } = - JE.object - [ ( "name", Node.encode JE.string name ) - , ( "typeAnnotation", Node.encode TypeAnnotation.encode typeAnnotation ) - ] - - -{-| JSON decoder for a `Signature` syntax element. --} -decoder : Decoder Signature -decoder = - JD.map2 Signature - (JD.field "name" (Node.decoder JD.string)) - (JD.field "typeAnnotation" (Node.decoder TypeAnnotation.decoder)) diff --git a/src/Elm/Syntax/Type.elm b/src/Elm/Syntax/Type.elm index bf1d16b40..1a192a0ed 100644 --- a/src/Elm/Syntax/Type.elm +++ b/src/Elm/Syntax/Type.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.Type exposing - ( Type, ValueConstructor - , encode, decoder - ) +module Elm.Syntax.Type exposing (Type, ValueConstructor) {-| This syntax represents custom types. For example: @@ -17,18 +14,11 @@ For example: @docs Type, ValueConstructor - -## Serialization - -@docs encode, decoder - -} -import Elm.Syntax.Documentation as Documentation exposing (Documentation) -import Elm.Syntax.Node as Node exposing (Node) -import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Documentation exposing (Documentation) +import Elm.Syntax.Node exposing (Node) +import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation) {-| Type alias that defines the syntax for a custom type. @@ -51,42 +41,4 @@ type alias ValueConstructor = --- Serialization - - -{-| Encode a `Type` syntax element to JSON. --} -encode : Type -> Value -encode { documentation, name, generics, constructors } = - JE.object - [ ( "documentation", Maybe.map (Node.encode Documentation.encode) documentation |> Maybe.withDefault JE.null ) - , ( "name", Node.encode JE.string name ) - , ( "generics", JE.list (Node.encode JE.string) generics ) - , ( "constructors", JE.list (Node.encode encodeValueConstructor) constructors ) - ] - - -encodeValueConstructor : ValueConstructor -> Value -encodeValueConstructor { name, arguments } = - JE.object - [ ( "name", Node.encode JE.string name ) - , ( "arguments", JE.list (Node.encode TypeAnnotation.encode) arguments ) - ] - - -{-| JSON decoder for a `Type` syntax element. --} -decoder : Decoder Type -decoder = - JD.map4 Type - (JD.field "documentation" <| JD.nullable <| Node.decoder JD.string) - (JD.field "name" <| Node.decoder JD.string) - (JD.field "generics" (JD.list (Node.decoder JD.string))) - (JD.field "constructors" (JD.list (Node.decoder valueConstructorDecoder))) - - -valueConstructorDecoder : Decoder ValueConstructor -valueConstructorDecoder = - JD.map2 ValueConstructor - (JD.field "name" (Node.decoder JD.string)) - (JD.field "arguments" (JD.list (Node.decoder TypeAnnotation.decoder))) +-- diff --git a/src/Elm/Syntax/TypeAlias.elm b/src/Elm/Syntax/TypeAlias.elm index 68df81b40..1f7f4aeae 100644 --- a/src/Elm/Syntax/TypeAlias.elm +++ b/src/Elm/Syntax/TypeAlias.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.TypeAlias exposing - ( TypeAlias - , encode, decoder - ) +module Elm.Syntax.TypeAlias exposing (TypeAlias) {-| This syntax represents type aliases. For example: @@ -18,18 +15,11 @@ For example: @docs TypeAlias - -## Serialization - -@docs encode, decoder - -} -import Elm.Syntax.Documentation as Documentation exposing (Documentation) -import Elm.Syntax.Node as Node exposing (Node) -import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (TypeAnnotation) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.Documentation exposing (Documentation) +import Elm.Syntax.Node exposing (Node) +import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation) {-| Type alias that defines the syntax for a type alias. @@ -44,27 +34,4 @@ type alias TypeAlias = --- Serialization - - -{-| Encode a `TypeAlias` syntax element to JSON. --} -encode : TypeAlias -> Value -encode { documentation, name, generics, typeAnnotation } = - JE.object - [ ( "documentation", Maybe.map (Node.encode Documentation.encode) documentation |> Maybe.withDefault JE.null ) - , ( "name", Node.encode JE.string name ) - , ( "generics", JE.list (Node.encode JE.string) generics ) - , ( "typeAnnotation", Node.encode TypeAnnotation.encode typeAnnotation ) - ] - - -{-| JSON decoder for a `Declaration` syntax element. --} -decoder : Decoder TypeAlias -decoder = - JD.map4 TypeAlias - (JD.field "documentation" (JD.nullable <| Node.decoder Documentation.decoder)) - (JD.field "name" <| Node.decoder JD.string) - (JD.field "generics" (JD.list <| Node.decoder JD.string)) - (JD.field "typeAnnotation" (Node.decoder TypeAnnotation.decoder)) +-- diff --git a/src/Elm/Syntax/TypeAnnotation.elm b/src/Elm/Syntax/TypeAnnotation.elm index 7d9cf2ab7..b6af425da 100644 --- a/src/Elm/Syntax/TypeAnnotation.elm +++ b/src/Elm/Syntax/TypeAnnotation.elm @@ -1,7 +1,4 @@ -module Elm.Syntax.TypeAnnotation exposing - ( TypeAnnotation(..), RecordDefinition, RecordField - , encode, decoder - ) +module Elm.Syntax.TypeAnnotation exposing (TypeAnnotation(..), RecordDefinition, RecordField) {-| This syntax represents the type annotation syntax. For example: @@ -13,18 +10,10 @@ For example: @docs TypeAnnotation, RecordDefinition, RecordField - -## Serialization - -@docs encode, decoder - -} -import Elm.Json.Util exposing (decodeTyped, encodeTyped) -import Elm.Syntax.ModuleName as ModuleName exposing (ModuleName) -import Elm.Syntax.Node as Node exposing (Node) -import Json.Decode as JD exposing (Decoder) -import Json.Encode as JE exposing (Value) +import Elm.Syntax.ModuleName exposing (ModuleName) +import Elm.Syntax.Node exposing (Node) {-| Custom type for different type annotations. For example: @@ -58,133 +47,3 @@ type alias RecordDefinition = -} type alias RecordField = ( Node String, Node TypeAnnotation ) - - - --- Serialization - - -{-| Encode a `TypeAnnotation` syntax element to JSON. --} -encode : TypeAnnotation -> Value -encode typeAnnotation = - case typeAnnotation of - GenericType name -> - encodeTyped "generic" <| - JE.object - [ ( "value", JE.string name ) - ] - - Typed moduleNameAndName args -> - let - inner : ( ModuleName, String ) -> Value - inner ( mod, n ) = - JE.object - [ ( "moduleName", ModuleName.encode mod ) - , ( "name", JE.string n ) - ] - in - encodeTyped "typed" <| - JE.object - [ ( "moduleNameAndName", Node.encode inner moduleNameAndName ) - , ( "args", JE.list (Node.encode encode) args ) - ] - - Unit -> - encodeTyped "unit" (JE.object []) - - Tupled t -> - encodeTyped "tupled" <| - JE.object - [ ( "values", JE.list (Node.encode encode) t ) - ] - - FunctionTypeAnnotation left right -> - encodeTyped "function" <| - JE.object - [ ( "left", Node.encode encode left ) - , ( "right", Node.encode encode right ) - ] - - Record recordDefinition -> - encodeTyped "record" <| - JE.object - [ ( "value", encodeRecordDefinition recordDefinition ) - ] - - GenericRecord name recordDefinition -> - encodeTyped "genericRecord" <| - JE.object - [ ( "name", Node.encode JE.string name ) - , ( "values", Node.encode encodeRecordDefinition recordDefinition ) - ] - - -encodeRecordDefinition : RecordDefinition -> Value -encodeRecordDefinition = - JE.list (Node.encode encodeRecordField) - - -encodeRecordField : RecordField -> Value -encodeRecordField ( name, ref ) = - JE.object - [ ( "name", Node.encode JE.string name ) - , ( "typeAnnotation", Node.encode encode ref ) - ] - - -decodeModuleNameAndName : Decoder ( ModuleName, String ) -decodeModuleNameAndName = - JD.map2 Tuple.pair - (JD.field "moduleName" <| ModuleName.decoder) - (JD.field "name" <| JD.string) - - -{-| JSON decoder for a `TypeAnnotation` syntax element. --} -decoder : Decoder TypeAnnotation -decoder = - JD.lazy - (\() -> - decodeTyped - [ ( "generic", JD.map GenericType (JD.field "value" JD.string) ) - , ( "typed" - , JD.map2 Typed - (JD.field "moduleNameAndName" <| Node.decoder decodeModuleNameAndName) - (JD.field "args" (JD.list nestedDecoder)) - ) - , ( "unit", JD.succeed Unit ) - , ( "tupled", JD.map Tupled (JD.field "values" (JD.list nestedDecoder)) ) - , ( "function" - , JD.map2 FunctionTypeAnnotation - (JD.field "left" nestedDecoder) - (JD.field "right" nestedDecoder) - ) - , ( "record", JD.map Record (JD.field "value" recordDefinitionDecoder) ) - , ( "genericRecord" - , JD.map2 GenericRecord - (JD.field "name" <| Node.decoder JD.string) - (JD.field "values" <| Node.decoder recordDefinitionDecoder) - ) - ] - ) - - -nestedDecoder : Decoder (Node TypeAnnotation) -nestedDecoder = - JD.lazy (\() -> Node.decoder decoder) - - -recordDefinitionDecoder : Decoder RecordDefinition -recordDefinitionDecoder = - JD.lazy (\() -> JD.list <| Node.decoder recordFieldDecoder) - - -recordFieldDecoder : Decoder RecordField -recordFieldDecoder = - JD.lazy - (\() -> - JD.map2 Tuple.pair - (JD.field "name" <| Node.decoder JD.string) - (JD.field "typeAnnotation" nestedDecoder) - ) diff --git a/tests/Elm/Syntax/ExposingTests.elm b/tests/Elm/Syntax/ExposingTests.elm deleted file mode 100644 index 9d3a7ed89..000000000 --- a/tests/Elm/Syntax/ExposingTests.elm +++ /dev/null @@ -1,32 +0,0 @@ -module Elm.Syntax.ExposingTests exposing (suite) - -import Elm.Syntax.Exposing as Exposing exposing (..) -import Elm.Syntax.Node as Node -import Expect -import Json.Decode exposing (Decoder, Value) -import Test exposing (..) - - -symmetric : a -> (a -> Value) -> Decoder a -> Expect.Expectation -symmetric v enc dec = - Expect.equal (Json.Decode.decodeValue dec (enc v)) (Ok v) - - -suite : Test -suite = - describe "Elm.Syntax.Exposing" - [ describe "serialization" - [ test "exposing (beginnerProgram, div, button, text)" <| - \() -> - symmetric - (Explicit - [ Node.empty (FunctionExpose "beginnerProgram") - , Node.empty (FunctionExpose "div") - , Node.empty (FunctionExpose "button") - , Node.empty (FunctionExpose "text") - ] - ) - Exposing.encode - Exposing.decoder - ] - ] diff --git a/tests/Elm/Syntax/ImportTests.elm b/tests/Elm/Syntax/ImportTests.elm deleted file mode 100644 index 77264356d..000000000 --- a/tests/Elm/Syntax/ImportTests.elm +++ /dev/null @@ -1,44 +0,0 @@ -module Elm.Syntax.ImportTests exposing (suite) - -import Elm.Syntax.Exposing exposing (..) -import Elm.Syntax.Import as Import exposing (Import) -import Elm.Syntax.Node as Node -import Elm.Syntax.Range exposing (empty) -import Expect -import Json.Decode exposing (Decoder, Value) -import Test exposing (..) - - -symmetric : a -> (a -> Value) -> Decoder a -> Expect.Expectation -symmetric v enc dec = - Expect.equal (Json.Decode.decodeValue dec (enc v)) (Ok v) - - -suite : Test -suite = - describe "Elm.Syntax.Import" - [ describe "serialization" - [ test "case 1" <| - \() -> - symmetric (Import (Node.empty [ "A", "B" ]) (Just <| Node.empty [ "C" ]) (Just <| Node.empty <| All empty)) - Import.encode - Import.decoder - , test "import Html exposing (beginnerProgram, div, button, text)" <| - \() -> - symmetric - (Import (Node.empty [ "Html" ]) - Nothing - (Just <| - Node.empty <| - Explicit - [ Node.empty (FunctionExpose "beginnerProgram") - , Node.empty (FunctionExpose "div") - , Node.empty (FunctionExpose "button") - , Node.empty (FunctionExpose "text") - ] - ) - ) - Import.encode - Import.decoder - ] - ] From 50c202cc93ffa01cf05204c7ae98884b5aeb53c9 Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Wed, 10 Jun 2020 22:19:58 +0200 Subject: [PATCH 06/44] Change type signature on Application expression --- CHANGELOG.md | 3 + src/Elm/Parser/Expression.elm | 12 ++-- src/Elm/Syntax/Expression.elm | 2 +- tests/Elm/Parser/DeclarationsTests.elm | 21 ++++--- tests/Elm/Parser/ExpressionTests.elm | 74 ++++++++++--------------- tests/Elm/Parser/LetExpressionTests.elm | 4 +- tests/Elm/Parser/ModuleTests.elm | 12 ++-- 7 files changed, 57 insertions(+), 71 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cd5ff9cd..485e9bf76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ - `Elm.Processing` and `Elm.RawFile` modules - All `encode` and `decode` functions +- Changed `Elm.Syntax.Expression.Expression`: + - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) + ## [7.3.4] - 2024-07-26 Parsing is faster by ~90%. A big thank you to [@lue-bird](https://github.com/lue-bird) for finding and introducing a huge amount of performance improvements. diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 5add7524c..e02128c55 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -1112,14 +1112,12 @@ applyExtensionRight extensionRight ((Node { start } left) as leftNode) = ExtendRightByApplication ((Node { end } _) as right) -> Node { start = start, end = end } - (Expression.Application - (case left of - Expression.Application (called :: firstArg :: secondArgUp) -> - called :: firstArg :: (secondArgUp ++ [ right ]) + (case left of + Expression.Application called (firstArg :: secondArgUp) -> + Expression.Application called (firstArg :: (secondArgUp ++ [ right ])) - _ -> - [ leftNode, right ] - ) + _ -> + Expression.Application leftNode [ right ] ) ExtendRightByOperation extendRightOperation -> diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 0cc0e6fb9..3ef6400c1 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -103,7 +103,7 @@ type alias FunctionImplementation = -} type Expression = UnitExpr - | Application (List (Node Expression)) + | Application (Node Expression) (List (Node Expression)) | OperatorApplication String InfixDirection (Node Expression) (Node Expression) | FunctionOrValue ModuleName String | IfBlock (Node Expression) (Node Expression) (Node Expression) diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 7b7a88aab..fca7a62c0 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -263,8 +263,8 @@ foo = bar""" , expression = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 62 } } (Application - [ Node { start = { row = 2, column = 3 }, end = { row = 2, column = 18 } } (FunctionOrValue [] "beginnerProgram") - , Node { start = { row = 2, column = 19 }, end = { row = 2, column = 62 } } + (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 18 } } (FunctionOrValue [] "beginnerProgram")) + [ Node { start = { row = 2, column = 19 }, end = { row = 2, column = 62 } } (RecordExpr [ Node { start = { row = 2, column = 21 }, end = { row = 2, column = 30 } } ( Node { start = { row = 2, column = 21 }, end = { row = 2, column = 26 } } "model" @@ -414,8 +414,8 @@ foo = bar""" , expression = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } (Application - [ Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text") - , Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal "Hello, World!") + (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) + [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal "Hello, World!") ] ) } @@ -438,8 +438,8 @@ foo = bar""" , expression = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } (Application - [ Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text") - , Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal "Hello, World!") + (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) + [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal "Hello, World!") ] ) } @@ -490,17 +490,16 @@ foo = bar""" (ParenthesizedExpression (Node { start = { row = 1, column = 41 }, end = { row = 1, column = 55 } } (Application - [ Node { start = { row = 1, column = 41 }, end = { row = 1, column = 48 } } (FunctionOrValue [] "uncurry") - , Node { start = { row = 1, column = 49 }, end = { row = 1, column = 55 } } (FunctionOrValue [] "update") + (Node { start = { row = 1, column = 41 }, end = { row = 1, column = 48 } } (FunctionOrValue [] "uncurry")) + [ Node { start = { row = 1, column = 49 }, end = { row = 1, column = 55 } } (FunctionOrValue [] "update") ] ) ) ) ) (Node { start = { row = 1, column = 60 }, end = { row = 1, column = 83 } } - (Application - [ Node { start = { row = 1, column = 60 }, end = { row = 1, column = 74 } } (FunctionOrValue [] "batchStateCmds") - , Node { start = { row = 1, column = 75 }, end = { row = 1, column = 83 } } (FunctionOrValue [] "sendPort") + (Application (Node { start = { row = 1, column = 60 }, end = { row = 1, column = 74 } } (FunctionOrValue [] "batchStateCmds")) + [ Node { start = { row = 1, column = 75 }, end = { row = 1, column = 83 } } (FunctionOrValue [] "sendPort") ] ) ) diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index dda2dae7d..5fc253515 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -110,9 +110,8 @@ all = "List.concat []" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } } <| - Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } <| FunctionOrValue [ "List" ] "concat" - , Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } <| ListExpr [] + Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } <| FunctionOrValue [ "List" ] "concat") + [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } <| ListExpr [] ] ) , test "application expression with operator" <| @@ -133,15 +132,12 @@ all = TupledExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } <| Literal "" , Node { start = { row = 1, column = 6 }, end = { row = 1, column = 47 } } <| - Application - [ Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always" - , Node { start = { row = 1, column = 13 }, end = { row = 1, column = 47 } } <| + Application (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") + [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 47 } } <| ParenthesizedExpression (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 46 } } <| - Application - [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } <| - FunctionOrValue [ "List" ] "concat" - , Node { start = { row = 1, column = 26 }, end = { row = 1, column = 46 } } <| + Application (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } (FunctionOrValue [ "List" ] "concat")) + [ Node { start = { row = 1, column = 26 }, end = { row = 1, column = 46 } } <| ListExpr [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 40 } } <| ListExpr @@ -165,9 +161,8 @@ all = "Task.succeed ()" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } - (Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionOrValue [ "Task" ] "succeed") - , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 16 } } UnitExpr + (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionOrValue [ "Task" ] "succeed")) + [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 16 } } UnitExpr ] ) ) @@ -176,9 +171,8 @@ all = "foo bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } - (Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo") - , Node { start = { row = 1, column = 5 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "bar") + (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) + [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "bar") ] ) ) @@ -261,15 +255,13 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } (ListExpr [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } - (Application - [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class") - , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (Literal "a") + (Application (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class")) + [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (Literal "a") ] ) , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 24 } } - (Application - [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "text") - , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (Literal "Foo") + (Application (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "text")) + [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (Literal "Foo") ] ) ] @@ -379,9 +371,8 @@ all = "List.map .name people" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 22 } } - (Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } (FunctionOrValue [ "List" ] "map") - , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (RecordAccessFunction ".name") + (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } (FunctionOrValue [ "List" ] "map")) + [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (RecordAccessFunction ".name") , Node { start = { row = 1, column = 16 }, end = { row = 1, column = 22 } } (FunctionOrValue [] "people") ] ) @@ -394,8 +385,8 @@ all = (ParenthesizedExpression (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 37 } } (Application - [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 14 } } (RecordAccessFunction ".spaceEvenly") - , Node { start = { row = 1, column = 15 }, end = { row = 1, column = 37 } } (FunctionOrValue [ "Internal", "Style" ] "classes") + (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 14 } } (RecordAccessFunction ".spaceEvenly")) + [ Node { start = { row = 1, column = 15 }, end = { row = 1, column = 37 } } (FunctionOrValue [ "Internal", "Style" ] "classes") ] ) ) @@ -414,9 +405,8 @@ all = "(::) x" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } - (Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } (PrefixOperator "::") - , Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "x") + (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } (PrefixOperator "::")) + [ Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "x") ] ) ) @@ -443,9 +433,8 @@ all = "toFloat -5" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } - (Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "toFloat") - , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 11 } } + (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "toFloat")) + [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 11 } } (Negation (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } (Integer 5))) ] ) @@ -542,9 +531,8 @@ all = "chompWhile (\\c -> c == ' ' || c == '\\n' || c == '\\r')" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 54 } } - (Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "chompWhile") - , Node { start = { row = 1, column = 12 }, end = { row = 1, column = 54 } } + (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "chompWhile")) + [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 54 } } (ParenthesizedExpression (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 53 } } (LambdaExpression @@ -596,18 +584,16 @@ all = "foo { d | b = f x y }.b" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 24 } } - (Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo") - , Node { start = { row = 1, column = 5 }, end = { row = 1, column = 24 } } + (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) + [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 24 } } (RecordAccess (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 22 } } (RecordUpdateExpression (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } "d") [ Node { start = { row = 1, column = 11 }, end = { row = 1, column = 21 } } ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } "b" , Node { start = { row = 1, column = 15 }, end = { row = 1, column = 20 } } - (Application - [ Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "f") - , Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "x") + (Application (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "f")) + [ Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "x") , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (FunctionOrValue [] "y") ] ) @@ -626,8 +612,8 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } (Application - [ Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } (FunctionOrValue [ "Random" ] "list") - , Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } (FunctionOrValue [ "Random" ] "list")) + [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } (Negation (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (Integer 1) diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index 80e88bb60..26d2d82f3 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -356,8 +356,8 @@ all = , expression = Node { start = { row = 1, column = 14 }, end = { row = 1, column = 29 } } (Application - [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 27 } } (FunctionOrValue [ "String" ] "length") - , Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (FunctionOrValue [] "s") + (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 27 } } (FunctionOrValue [ "String" ] "length")) + [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (FunctionOrValue [] "s") ] ) } diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index b4513b220..4fa33dd74 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -454,15 +454,15 @@ fun2 n = Left (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 9 } } (Application - [ Node { start = { row = 4, column = 3 }, end = { row = 4, column = 7 } } (FunctionOrValue [] "fun2") - , Node { start = { row = 4, column = 8 }, end = { row = 4, column = 9 } } (FunctionOrValue [] "n") + (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 7 } } (FunctionOrValue [] "fun2")) + [ Node { start = { row = 4, column = 8 }, end = { row = 4, column = 9 } } (FunctionOrValue [] "n") ] ) ) (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 11 } } (Application - [ Node { start = { row = 5, column = 5 }, end = { row = 5, column = 9 } } (FunctionOrValue [] "fun2") - , Node { start = { row = 5, column = 10 }, end = { row = 5, column = 11 } } (FunctionOrValue [] "n") + (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 9 } } (FunctionOrValue [] "fun2")) + [ Node { start = { row = 5, column = 10 }, end = { row = 5, column = 11 } } (FunctionOrValue [] "n") ] ) ) @@ -481,8 +481,8 @@ fun2 n = , expression = Node { start = { row = 8, column = 3 }, end = { row = 8, column = 9 } } (Application - [ Node { start = { row = 8, column = 3 }, end = { row = 8, column = 7 } } (FunctionOrValue [] "fun1") - , Node { start = { row = 8, column = 8 }, end = { row = 8, column = 9 } } (FunctionOrValue [] "n") + (Node { start = { row = 8, column = 3 }, end = { row = 8, column = 7 } } (FunctionOrValue [] "fun1")) + [ Node { start = { row = 8, column = 8 }, end = { row = 8, column = 9 } } (FunctionOrValue [] "n") ] ) } From fbfd4d4b1252b9903645620fdf6bf4bbf04cfe58 Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Mon, 15 Jun 2020 14:37:15 +0200 Subject: [PATCH 07/44] Make RecordUpdateExpression nonempty --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 2 +- tests/Elm/Parser/ExpressionTests.elm | 15 +++++++++------ 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 485e9bf76..d645c8eee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Changed `Elm.Syntax.Expression.Expression`: - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) + - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) ## [7.3.4] - 2024-07-26 diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index e02128c55..f3d79710c 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -243,7 +243,7 @@ recordContentsCurlyEnd = , syntax = case afterNameBeforeFields.syntax of RecordUpdateFirstSetter firstField -> - RecordUpdateExpression nameNode (firstField :: tailFields.syntax) + RecordUpdateExpression nameNode firstField tailFields.syntax FieldsFirstValue firstFieldValue -> RecordExpr (Node.combine Tuple.pair nameNode firstFieldValue :: tailFields.syntax) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 3ef6400c1..09aa69a27 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -124,7 +124,7 @@ type Expression | ListExpr (List (Node Expression)) | RecordAccess (Node Expression) (Node String) | RecordAccessFunction String - | RecordUpdateExpression (Node String) (List (Node RecordSetter)) + | RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter)) | GLSLExpression String diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 5fc253515..bbcae478c 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -337,11 +337,12 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 38 } } (RecordUpdateExpression (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } "model") - [ Node { start = { row = 1, column = 11 }, end = { row = 1, column = 20 } } + (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 20 } } ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } "count" , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (Integer 1) ) - , Node { start = { row = 1, column = 22 }, end = { row = 1, column = 37 } } + ) + [ Node { start = { row = 1, column = 22 }, end = { row = 1, column = 37 } } ( Node { start = { row = 1, column = 22 }, end = { row = 1, column = 29 } } "loading" , Node { start = { row = 1, column = 32 }, end = { row = 1, column = 36 } } (FunctionOrValue [] "True") ) @@ -355,11 +356,12 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 36 } } (RecordUpdateExpression (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } "model") - [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 18 } } + (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 18 } } ( Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } "count" , Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (Integer 1) ) - , Node { start = { row = 1, column = 20 }, end = { row = 1, column = 35 } } + ) + [ Node { start = { row = 1, column = 20 }, end = { row = 1, column = 35 } } ( Node { start = { row = 1, column = 20 }, end = { row = 1, column = 27 } } "loading" , Node { start = { row = 1, column = 30 }, end = { row = 1, column = 34 } } (FunctionOrValue [] "True") ) @@ -589,7 +591,7 @@ all = (RecordAccess (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 22 } } (RecordUpdateExpression (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } "d") - [ Node { start = { row = 1, column = 11 }, end = { row = 1, column = 21 } } + (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 21 } } ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } "b" , Node { start = { row = 1, column = 15 }, end = { row = 1, column = 20 } } (Application (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "f")) @@ -598,7 +600,8 @@ all = ] ) ) - ] + ) + [] ) ) (Node { start = { row = 1, column = 23 }, end = { row = 1, column = 24 } } "b") From 97411f0c295929b9c52d3d72e352eca11dc2537e Mon Sep 17 00:00:00 2001 From: Mats Stijlaart Date: Mon, 15 Jun 2020 20:13:50 +0200 Subject: [PATCH 08/44] Remove Unit, it is a tuple with 0 elements --- CHANGELOG.md | 3 +++ src/Elm/Parser/TypeAnnotation.elm | 2 +- src/Elm/Syntax/TypeAnnotation.elm | 4 +--- tests/Elm/Parser/TypeAnnotationTests.elm | 14 +++++++------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d645c8eee..b265ca274 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,9 @@ - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) +- Changed `Elm.Syntax.TypeAnnotation.TypeAnnotation`: + - `Unit` -> `Tupled []` + ## [7.3.4] - 2024-07-26 Parsing is faster by ~90%. A big thank you to [@lue-bird](https://github.com/lue-bird) for finding and introducing a huge amount of performance improvements. diff --git a/src/Elm/Parser/TypeAnnotation.elm b/src/Elm/Parser/TypeAnnotation.elm index c3fec280f..67659119f 100644 --- a/src/Elm/Parser/TypeAnnotation.elm +++ b/src/Elm/Parser/TypeAnnotation.elm @@ -70,7 +70,7 @@ parensTypeAnnotation : Parser (WithComments (Node TypeAnnotation)) parensTypeAnnotation = ParserFast.symbolFollowedBy "(" (ParserFast.oneOf2 - (ParserFast.symbol ")" { comments = Rope.empty, syntax = TypeAnnotation.Unit }) + (ParserFast.symbol ")" { comments = Rope.empty, syntax = TypeAnnotation.Tupled [] }) (ParserFast.map4 (\commentsBeforeFirstPart firstPart commentsAfterFirstPart lastToSecondPart -> { comments = diff --git a/src/Elm/Syntax/TypeAnnotation.elm b/src/Elm/Syntax/TypeAnnotation.elm index b6af425da..7a345c73f 100644 --- a/src/Elm/Syntax/TypeAnnotation.elm +++ b/src/Elm/Syntax/TypeAnnotation.elm @@ -20,8 +20,7 @@ import Elm.Syntax.Node exposing (Node) - `GenericType`: `a` - `Typed`: `Maybe (Int -> String)` - - `Unit`: `()` - - `Tuples`: `(a, b, c)` + - `Tuples`: `(a, b, c)` or Unit `()` - `Record`: `{ name : String}` - `GenericRecord`: `{ a | name : String}` - `FunctionTypeAnnotation`: `Int -> String` @@ -30,7 +29,6 @@ import Elm.Syntax.Node exposing (Node) type TypeAnnotation = GenericType String | Typed (Node ( ModuleName, String )) (List (Node TypeAnnotation)) - | Unit | Tupled (List (Node TypeAnnotation)) | Record RecordDefinition | GenericRecord (Node String) (Node RecordDefinition) diff --git a/tests/Elm/Parser/TypeAnnotationTests.elm b/tests/Elm/Parser/TypeAnnotationTests.elm index b62dac582..5f8cac3e1 100644 --- a/tests/Elm/Parser/TypeAnnotationTests.elm +++ b/tests/Elm/Parser/TypeAnnotationTests.elm @@ -17,7 +17,7 @@ all = \() -> "()" |> expectAst - (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 3 } } Unit) + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 3 } } (Tupled [])) , test "unitTypeReference with spaces" <| \() -> "( )" @@ -28,8 +28,8 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } } (Tupled - [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } Unit - , Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } Unit + [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } (Tupled []) + , Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (Tupled []) ] ) ) @@ -38,14 +38,14 @@ all = -- TODO This feels incorrect, there should be a Parenthesized type for this "( () )" |> expectAst - (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } Unit) + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } (Tupled [])) , test "tupledTypeReference 3" <| \() -> "( () , Maybe m )" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 17 } } (Tupled - [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } Unit + [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } (Tupled []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 15 } } (Typed (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 13 } } ( [], "Maybe" )) @@ -78,7 +78,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) - [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } Unit + [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tupled []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (GenericType "a") , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } (Typed (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) @@ -91,7 +91,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) - [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } Unit + [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tupled []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (GenericType "a") , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } (Typed (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) From cb618e99ad954a476b2a65adf3e080c5ac71e5ce Mon Sep 17 00:00:00 2001 From: Mats Stijlaart Date: Tue, 16 Jun 2020 18:43:45 +0200 Subject: [PATCH 09/44] Rename Tupled to Tuple --- CHANGELOG.md | 3 ++- src/Elm/Parser/TypeAnnotation.elm | 4 ++-- src/Elm/Syntax/TypeAnnotation.elm | 2 +- tests/Elm/Parser/DeclarationsTests.elm | 2 +- tests/Elm/Parser/TypeAnnotationTests.elm | 20 ++++++++++---------- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b265ca274..4e3d19633 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,8 @@ - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Changed `Elm.Syntax.TypeAnnotation.TypeAnnotation`: - - `Unit` -> `Tupled []` + - `Tupled` -> `Tuple` + - `Unit` -> `Tuple []` ## [7.3.4] - 2024-07-26 diff --git a/src/Elm/Parser/TypeAnnotation.elm b/src/Elm/Parser/TypeAnnotation.elm index 67659119f..1dd55e38c 100644 --- a/src/Elm/Parser/TypeAnnotation.elm +++ b/src/Elm/Parser/TypeAnnotation.elm @@ -70,7 +70,7 @@ parensTypeAnnotation : Parser (WithComments (Node TypeAnnotation)) parensTypeAnnotation = ParserFast.symbolFollowedBy "(" (ParserFast.oneOf2 - (ParserFast.symbol ")" { comments = Rope.empty, syntax = TypeAnnotation.Tupled [] }) + (ParserFast.symbol ")" { comments = Rope.empty, syntax = TypeAnnotation.Tuple [] }) (ParserFast.map4 (\commentsBeforeFirstPart firstPart commentsAfterFirstPart lastToSecondPart -> { comments = @@ -88,7 +88,7 @@ parensTypeAnnotation = firstPartValue _ -> - TypeAnnotation.Tupled (firstPart.syntax :: List.reverse lastToSecondPart.syntax) + TypeAnnotation.Tuple (firstPart.syntax :: List.reverse lastToSecondPart.syntax) } ) Layout.maybeLayout diff --git a/src/Elm/Syntax/TypeAnnotation.elm b/src/Elm/Syntax/TypeAnnotation.elm index 7a345c73f..fdc1efb02 100644 --- a/src/Elm/Syntax/TypeAnnotation.elm +++ b/src/Elm/Syntax/TypeAnnotation.elm @@ -29,7 +29,7 @@ import Elm.Syntax.Node exposing (Node) type TypeAnnotation = GenericType String | Typed (Node ( ModuleName, String )) (List (Node TypeAnnotation)) - | Tupled (List (Node TypeAnnotation)) + | Tuple (List (Node TypeAnnotation)) | Record RecordDefinition | GenericRecord (Node String) (Node RecordDefinition) | FunctionTypeAnnotation (Node TypeAnnotation) (Node TypeAnnotation) diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index fca7a62c0..353f99c5e 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -346,7 +346,7 @@ foo = bar""" Node { start = { row = 1, column = 22 }, end = { row = 1, column = 51 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 40 } } - (Tupled + (Tuple [ Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } (Typed (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } ( [], "String" )) []) , Node { start = { row = 1, column = 32 }, end = { row = 1, column = 38 } } (Typed diff --git a/tests/Elm/Parser/TypeAnnotationTests.elm b/tests/Elm/Parser/TypeAnnotationTests.elm index 5f8cac3e1..ffce5ef89 100644 --- a/tests/Elm/Parser/TypeAnnotationTests.elm +++ b/tests/Elm/Parser/TypeAnnotationTests.elm @@ -17,7 +17,7 @@ all = \() -> "()" |> expectAst - (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 3 } } (Tupled [])) + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 3 } } (Tuple [])) , test "unitTypeReference with spaces" <| \() -> "( )" @@ -27,9 +27,9 @@ all = "( (), ())" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } } - (Tupled - [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } (Tupled []) - , Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (Tupled []) + (Tuple + [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } (Tuple []) + , Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (Tuple []) ] ) ) @@ -38,14 +38,14 @@ all = -- TODO This feels incorrect, there should be a Parenthesized type for this "( () )" |> expectAst - (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } (Tupled [])) + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } (Tuple [])) , test "tupledTypeReference 3" <| \() -> "( () , Maybe m )" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 17 } } - (Tupled - [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } (Tupled []) + (Tuple + [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } (Tuple []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 15 } } (Typed (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 13 } } ( [], "Maybe" )) @@ -78,7 +78,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) - [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tupled []) + [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tuple []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (GenericType "a") , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } (Typed (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) @@ -91,7 +91,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) - [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tupled []) + [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tuple []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (GenericType "a") , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } (Typed (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) @@ -272,7 +272,7 @@ all = (Typed (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 13 } } ( [], "Model" )) []) ) (Node { start = { row = 1, column = 17 }, end = { row = 1, column = 33 } } - (Tupled + (Tuple [ Node { start = { row = 1, column = 18 }, end = { row = 1, column = 23 } } (Typed (Node { start = { row = 1, column = 18 }, end = { row = 1, column = 23 } } ( [], "Model" )) []) , Node { start = { row = 1, column = 25 }, end = { row = 1, column = 32 } } From 1089b0d06d69bc0b0287a7915244efd34b770e24 Mon Sep 17 00:00:00 2001 From: Mats Stijlaart Date: Tue, 16 Jun 2020 18:45:31 +0200 Subject: [PATCH 10/44] Rename TupledExpression to TupleExpression --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 4 ++-- tests/Elm/Parser/DeclarationsTests.elm | 2 +- tests/Elm/Parser/ExpressionTests.elm | 6 +++--- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e3d19633..1e4eade47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Changed `Elm.Syntax.Expression.Expression`: - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) + - Renamed `TupledExpression` to `TupleExpression` - Changed `Elm.Syntax.TypeAnnotation.TypeAnnotation`: - `Tupled` -> `Tuple` diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index f3d79710c..e47d99582 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -983,7 +983,7 @@ tupledExpressionInnerAfterOpeningParens = |> Rope.prependTo firstPart.comments |> Rope.prependTo commentsAfterFirstPart |> Rope.prependTo tailPartsReverse.comments - , syntax = TupledExpression (firstPart.syntax :: List.reverse tailPartsReverse.syntax) + , syntax = TupleExpression (firstPart.syntax :: List.reverse tailPartsReverse.syntax) } ) Layout.maybeLayout diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 09aa69a27..46c021e76 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -88,7 +88,7 @@ type alias FunctionImplementation = - `Negation`: `-a` - `Literal`: `"text"` - `CharLiteral`: `'a'` - - `TupledExpression`: `(a, b)` or `(a, b, c)` + - `TupleExpression`: `(a, b)` or `(a, b, c)` - `ParenthesizedExpression`: `(a)` - `LetExpression`: `let a = 4 in a` - `CaseExpression`: `case a of` followed by pattern matches @@ -115,7 +115,7 @@ type Expression | Negation (Node Expression) | Literal String | CharLiteral Char - | TupledExpression (List (Node Expression)) + | TupleExpression (List (Node Expression)) | ParenthesizedExpression (Node Expression) | LetExpression LetBlock | CaseExpression CaseBlock diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 353f99c5e..5bc33f8b8 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -232,7 +232,7 @@ foo = bar""" ) ) (Node { start = { row = 3, column = 10 }, end = { row = 3, column = 16 } } - (TupledExpression + (TupleExpression [ Node { start = { row = 3, column = 11 }, end = { row = 3, column = 12 } } (Integer 1) , Node { start = { row = 3, column = 14 }, end = { row = 3, column = 15 } } (Integer 2) ] diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index bbcae478c..53ed4d8b0 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -34,7 +34,7 @@ all = "(1,2)" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } - (TupledExpression + (TupleExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (Integer 1) , Node { start = { row = 1, column = 4 }, end = { row = 1, column = 5 } } (Integer 2) ] @@ -45,7 +45,7 @@ all = "( 1 , 2 )" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } - (TupledExpression + (TupleExpression [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (Integer 1) , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (Integer 2) ] @@ -129,7 +129,7 @@ all = "(\"\", always (List.concat [ [ fileName ], [] ]))" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 48 } } <| - TupledExpression + TupleExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } <| Literal "" , Node { start = { row = 1, column = 6 }, end = { row = 1, column = 47 } } <| Application (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") From c636d9f593b35f54bc8dc28323d91f218547253a Mon Sep 17 00:00:00 2001 From: Mats Stijlaart Date: Tue, 16 Jun 2020 18:54:17 +0200 Subject: [PATCH 11/44] Rename Typed to Type --- CHANGELOG.md | 1 + src/Elm/Parser/TypeAnnotation.elm | 4 +- src/Elm/Syntax/TypeAnnotation.elm | 4 +- tests/Elm/Parser/DeclarationsTests.elm | 26 ++++----- tests/Elm/Parser/FileTests.elm | 4 +- tests/Elm/Parser/LetExpressionTests.elm | 4 +- tests/Elm/Parser/ModuleTests.elm | 4 +- tests/Elm/Parser/TypeAnnotationTests.elm | 70 ++++++++++++------------ 8 files changed, 59 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e4eade47..dd8e81fa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ - Changed `Elm.Syntax.TypeAnnotation.TypeAnnotation`: - `Tupled` -> `Tuple` - `Unit` -> `Tuple []` + - Renamed `Typed` to `Type` ## [7.3.4] - 2024-07-26 diff --git a/src/Elm/Parser/TypeAnnotation.elm b/src/Elm/Parser/TypeAnnotation.elm index 1dd55e38c..fb45cd9b0 100644 --- a/src/Elm/Parser/TypeAnnotation.elm +++ b/src/Elm/Parser/TypeAnnotation.elm @@ -264,7 +264,7 @@ typedTypeAnnotationWithoutArguments = { comments = Rope.empty , syntax = Node range - (TypeAnnotation.Typed (Node range name) []) + (TypeAnnotation.Type (Node range name) []) } ) (ParserFast.map2 @@ -304,7 +304,7 @@ typedTypeAnnotationWithArguments = ParserFast.map2 (\nameNode args -> { comments = args.comments - , syntax = TypeAnnotation.Typed nameNode args.syntax + , syntax = TypeAnnotation.Type nameNode args.syntax } ) (ParserFast.mapWithStartAndEndPosition diff --git a/src/Elm/Syntax/TypeAnnotation.elm b/src/Elm/Syntax/TypeAnnotation.elm index fdc1efb02..7d27722fe 100644 --- a/src/Elm/Syntax/TypeAnnotation.elm +++ b/src/Elm/Syntax/TypeAnnotation.elm @@ -19,7 +19,7 @@ import Elm.Syntax.Node exposing (Node) {-| Custom type for different type annotations. For example: - `GenericType`: `a` - - `Typed`: `Maybe (Int -> String)` + - `Type`: `Maybe (Int -> String)` - `Tuples`: `(a, b, c)` or Unit `()` - `Record`: `{ name : String}` - `GenericRecord`: `{ a | name : String}` @@ -28,7 +28,7 @@ import Elm.Syntax.Node exposing (Node) -} type TypeAnnotation = GenericType String - | Typed (Node ( ModuleName, String )) (List (Node TypeAnnotation)) + | Type (Node ( ModuleName, String )) (List (Node TypeAnnotation)) | Tuple (List (Node TypeAnnotation)) | Record RecordDefinition | GenericRecord (Node String) (Node RecordDefinition) diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 5bc33f8b8..614be76c3 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -347,9 +347,9 @@ foo = bar""" (FunctionTypeAnnotation (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 40 } } (Tuple - [ Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } (Typed (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } ( [], "String" )) []) + [ Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } (Type (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } ( [], "String" )) []) , Node { start = { row = 1, column = 32 }, end = { row = 1, column = 38 } } - (Typed + (Type (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 38 } } ( [], "String" )) [] ) @@ -357,7 +357,7 @@ foo = bar""" ) ) (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 51 } } - (Typed + (Type (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 47 } } ( [], "Cmd" )) [ Node { start = { row = 1, column = 48 }, end = { row = 1, column = 51 } } (GenericType "msg") ] ) @@ -379,13 +379,13 @@ foo = bar""" (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 28 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } - (Typed (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } ( [], "Move" )) []) + (Type (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } ( [], "Move" )) []) ) (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 27 } } (GenericType "msg")) ) ) (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 39 } } - (Typed (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 35 } } ( [], "Sub" )) + (Type (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 35 } } ( [], "Sub" )) [ Node { start = { row = 1, column = 36 }, end = { row = 1, column = 39 } } (GenericType "msg") ] ) @@ -572,7 +572,7 @@ update msg model = Just (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } } { name = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } "update" - , typeAnnotation = Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (Typed (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } ( [], "Model" )) []) + , typeAnnotation = Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (Type (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } ( [], "Model" )) []) } ) , declaration = @@ -602,7 +602,7 @@ update msg model = [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 32 } } ( Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } "color" , Node { start = { row = 1, column = 26 }, end = { row = 1, column = 32 } } - (Typed (Node { start = { row = 1, column = 26 }, end = { row = 1, column = 32 } } ( [], "String" )) []) + (Type (Node { start = { row = 1, column = 26 }, end = { row = 1, column = 32 } } ( [], "String" )) []) ) ] ) @@ -625,7 +625,7 @@ type alias Foo = {color: String }""" [ Node { start = { row = 2, column = 19 }, end = { row = 2, column = 32 } } ( Node { start = { row = 2, column = 19 }, end = { row = 2, column = 24 } } "color" , Node { start = { row = 2, column = 26 }, end = { row = 2, column = 32 } } - (Typed (Node { start = { row = 2, column = 26 }, end = { row = 2, column = 32 } } ( [], "String" )) []) + (Type (Node { start = { row = 2, column = 26 }, end = { row = 2, column = 32 } } ( [], "String" )) []) ) ] ) @@ -647,7 +647,7 @@ type alias Foo = {color: String }""" [ Node { start = { row = 1, column = 17 }, end = { row = 1, column = 30 } } ( Node { start = { row = 1, column = 17 }, end = { row = 1, column = 22 } } "color" , Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } - (Typed (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } ( [], "String" )) []) + (Type (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } ( [], "String" )) []) ) ] ) @@ -689,7 +689,7 @@ type alias Foo = {color: String }""" { name = Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } "Blue" , arguments = [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 25 } } - (Typed (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 25 } } ( [], "String" )) []) + (Type (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 25 } } ( [], "String" )) []) ] } , Node { start = { row = 1, column = 28 }, end = { row = 1, column = 31 } } @@ -722,7 +722,7 @@ type Color = Blue String | Red | Green""" { name = Node { start = { row = 2, column = 14 }, end = { row = 2, column = 18 } } "Blue" , arguments = [ Node { start = { row = 2, column = 19 }, end = { row = 2, column = 25 } } - (Typed (Node { start = { row = 2, column = 19 }, end = { row = 2, column = 25 } } ( [], "String" )) []) + (Type (Node { start = { row = 2, column = 19 }, end = { row = 2, column = 25 } } ( [], "String" )) []) ] } , Node { start = { row = 2, column = 28 }, end = { row = 2, column = 31 } } @@ -752,7 +752,7 @@ type Color = Blue String | Red | Green""" , arguments = [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } (GenericType "a") , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } - (Typed (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } ( [], "B" )) []) + (Type (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } ( [], "B" )) []) ] } ] @@ -773,7 +773,7 @@ type Color = Blue String | Red | Green""" { name = Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } "C" , arguments = [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } - (Typed (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } ( [], "B" )) []) + (Type (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } ( [], "B" )) []) , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (GenericType "a") ] } diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index 03ba2dcbb..c68381c8b 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -429,10 +429,10 @@ port sendResponse : String -> Cmd msg Node { start = { row = 8, column = 21 }, end = { row = 8, column = 38 } } (FunctionTypeAnnotation (Node { start = { row = 8, column = 21 }, end = { row = 8, column = 27 } } - (Typed (Node { start = { row = 8, column = 21 }, end = { row = 8, column = 27 } } ( [], "String" )) []) + (Type (Node { start = { row = 8, column = 21 }, end = { row = 8, column = 27 } } ( [], "String" )) []) ) (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 38 } } - (Typed (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 34 } } ( [], "Cmd" )) + (Type (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 34 } } ( [], "Cmd" )) [ Node { start = { row = 8, column = 35 }, end = { row = 8, column = 38 } } (GenericType "msg") ] ) ) diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index 26d2d82f3..88303c656 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -141,7 +141,7 @@ all = { name = Node { start = { row = 2, column = 5 }, end = { row = 2, column = 8 } } "bar" , typeAnnotation = Node { start = { row = 2, column = 11 }, end = { row = 2, column = 14 } } - (Typed (Node { start = { row = 2, column = 11 }, end = { row = 2, column = 14 } } ( [], "Int" )) []) + (Type (Node { start = { row = 2, column = 11 }, end = { row = 2, column = 14 } } ( [], "Int" )) []) } ) , declaration = @@ -177,7 +177,7 @@ all = Just (Node { start = { row = 2, column = 5 }, end = { row = 2, column = 14 } } { name = Node { start = { row = 2, column = 5 }, end = { row = 2, column = 8 } } "bar" - , typeAnnotation = Node { start = { row = 2, column = 11 }, end = { row = 2, column = 14 } } (Typed (Node { start = { row = 2, column = 11 }, end = { row = 2, column = 14 } } ( [], "Int" )) []) + , typeAnnotation = Node { start = { row = 2, column = 11 }, end = { row = 2, column = 14 } } (Type (Node { start = { row = 2, column = 11 }, end = { row = 2, column = 14 } } ( [], "Int" )) []) } ) , declaration = diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index 4fa33dd74..bd9ec2f5d 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -383,7 +383,7 @@ b = 2 , generics = [] , typeAnnotation = Node { start = { row = 4, column = 16 }, end = { row = 4, column = 17 } } - (Typed (Node { start = { row = 4, column = 16 }, end = { row = 4, column = 17 } } ( [], "A" )) []) + (Type (Node { start = { row = 4, column = 16 }, end = { row = 4, column = 17 } } ( [], "A" )) []) } ) , Node { start = { row = 5, column = 1 }, end = { row = 6, column = 6 } } @@ -393,7 +393,7 @@ b = 2 Just (Node { start = { row = 5, column = 1 }, end = { row = 5, column = 8 } } { name = Node { start = { row = 5, column = 1 }, end = { row = 5, column = 2 } } "b" - , typeAnnotation = Node { start = { row = 5, column = 5 }, end = { row = 5, column = 8 } } (Typed (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 8 } } ( [], "Int" )) []) + , typeAnnotation = Node { start = { row = 5, column = 5 }, end = { row = 5, column = 8 } } (Type (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 8 } } ( [], "Int" )) []) } ) , declaration = diff --git a/tests/Elm/Parser/TypeAnnotationTests.elm b/tests/Elm/Parser/TypeAnnotationTests.elm index ffce5ef89..c9fc6c10d 100644 --- a/tests/Elm/Parser/TypeAnnotationTests.elm +++ b/tests/Elm/Parser/TypeAnnotationTests.elm @@ -47,7 +47,7 @@ all = (Tuple [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 5 } } (Tuple []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 15 } } - (Typed + (Type (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 13 } } ( [], "Maybe" )) [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (GenericType "m") ] ) @@ -59,14 +59,14 @@ all = "Foo.Bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } - (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } ( [ "Foo" ], "Bar" )) []) + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } ( [ "Foo" ], "Bar" )) []) ) , test "typeAnnotationNoFn" <| \() -> "Bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } - (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Bar" )) []) + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Bar" )) []) ) , test "types with and without spacing should parse to the same" <| \() -> @@ -77,11 +77,11 @@ all = "Foo () a Bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } - (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tuple []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (GenericType "a") , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } - (Typed (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) + (Type (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) ] ) ) @@ -90,11 +90,11 @@ all = "Foo () a Bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } - (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tuple []) , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (GenericType "a") , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } - (Typed (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) + (Type (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) ] ) ) @@ -112,7 +112,7 @@ all = [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 15 } } ( Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } "color" , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 15 } } - (Typed (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 15 } } ( [], "String" )) []) + (Type (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 15 } } ( [], "String" )) []) ) ] ) @@ -127,12 +127,12 @@ all = [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 25 } } ( Node { start = { row = 1, column = 10 }, end = { row = 1, column = 18 } } "position" , Node { start = { row = 1, column = 21 }, end = { row = 1, column = 25 } } - (Typed (Node { start = { row = 1, column = 21 }, end = { row = 1, column = 25 } } ( [], "Vec2" )) []) + (Type (Node { start = { row = 1, column = 21 }, end = { row = 1, column = 25 } } ( [], "Vec2" )) []) ) , Node { start = { row = 1, column = 27 }, end = { row = 1, column = 42 } } ( Node { start = { row = 1, column = 27 }, end = { row = 1, column = 34 } } "texture" , Node { start = { row = 1, column = 37 }, end = { row = 1, column = 41 } } - (Typed (Node { start = { row = 1, column = 37 }, end = { row = 1, column = 41 } } ( [], "Vec2" )) []) + (Type (Node { start = { row = 1, column = 37 }, end = { row = 1, column = 41 } } ( [], "Vec2" )) []) ) ] ) @@ -155,17 +155,17 @@ all = [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 17 } } ( Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } "r" , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 17 } } - (Typed (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 17 } } ( [], "Int" )) []) + (Type (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 17 } } ( [], "Int" )) []) ) , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 25 } } ( Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } "g" , Node { start = { row = 1, column = 22 }, end = { row = 1, column = 25 } } - (Typed (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 25 } } ( [], "Int" )) []) + (Type (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 25 } } ( [], "Int" )) []) ) , Node { start = { row = 1, column = 27 }, end = { row = 1, column = 34 } } ( Node { start = { row = 1, column = 27 }, end = { row = 1, column = 28 } } "b" , Node { start = { row = 1, column = 30 }, end = { row = 1, column = 33 } } - (Typed (Node { start = { row = 1, column = 30 }, end = { row = 1, column = 33 } } ( [], "Int" )) []) + (Type (Node { start = { row = 1, column = 30 }, end = { row = 1, column = 33 } } ( [], "Int" )) []) ) ] ) @@ -182,17 +182,17 @@ all = [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } ( Node { start = { row = 1, column = 3 }, end = { row = 1, column = 6 } } "foo" , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } <| - Typed (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } ( [], "Int" )) [] + Type (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } ( [], "Int" )) [] ) , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 23 } } ( Node { start = { row = 1, column = 14 }, end = { row = 1, column = 17 } } "bar" , Node { start = { row = 1, column = 20 }, end = { row = 1, column = 23 } } <| - Typed (Node { start = { row = 1, column = 20 }, end = { row = 1, column = 23 } } ( [], "Int" )) [] + Type (Node { start = { row = 1, column = 20 }, end = { row = 1, column = 23 } } ( [], "Int" )) [] ) , Node { start = { row = 1, column = 25 }, end = { row = 1, column = 35 } } ( Node { start = { row = 1, column = 25 }, end = { row = 1, column = 28 } } "baz" , Node { start = { row = 1, column = 31 }, end = { row = 1, column = 34 } } <| - Typed (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 34 } } ( [], "Int" )) [] + Type (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 34 } } ( [], "Int" )) [] ) ] ) @@ -216,10 +216,10 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } - (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) []) + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) []) ) (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } - (Typed (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } ( [], "Bar" )) []) + (Type (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } ( [], "Bar" )) []) ) ) ) @@ -230,12 +230,12 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 18 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } - (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) []) + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) []) ) (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 18 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } - (Typed (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } ( [], "Bar" )) []) + (Type (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } ( [], "Bar" )) []) ) (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 18 } } (GenericType "baz")) ) @@ -264,21 +264,21 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 33 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } - (Typed (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Msg" )) []) + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Msg" )) []) ) (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 33 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 13 } } - (Typed (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 13 } } ( [], "Model" )) []) + (Type (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 13 } } ( [], "Model" )) []) ) (Node { start = { row = 1, column = 17 }, end = { row = 1, column = 33 } } (Tuple [ Node { start = { row = 1, column = 18 }, end = { row = 1, column = 23 } } - (Typed (Node { start = { row = 1, column = 18 }, end = { row = 1, column = 23 } } ( [], "Model" )) []) + (Type (Node { start = { row = 1, column = 18 }, end = { row = 1, column = 23 } } ( [], "Model" )) []) , Node { start = { row = 1, column = 25 }, end = { row = 1, column = 32 } } - (Typed (Node { start = { row = 1, column = 25 }, end = { row = 1, column = 28 } } ( [], "Cmd" )) + (Type (Node { start = { row = 1, column = 25 }, end = { row = 1, column = 28 } } ( [], "Cmd" )) [ Node { start = { row = 1, column = 29 }, end = { row = 1, column = 32 } } - (Typed (Node { start = { row = 1, column = 29 }, end = { row = 1, column = 32 } } ( [], "Msg" )) []) + (Type (Node { start = { row = 1, column = 29 }, end = { row = 1, column = 32 } } ( [], "Msg" )) []) ] ) ] @@ -314,13 +314,13 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 5 } } - (Typed + (Type (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 5 } } ( [], "Foo" )) [] ) ) (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } - (Typed + (Type (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } ( [], "Bar" )) [] ) @@ -336,13 +336,13 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionTypeAnnotation (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 5 } } - (Typed + (Type (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 5 } } ( [], "Foo" )) [] ) ) (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } - (Typed + (Type (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } ( [], "Bar" )) [] ) @@ -361,7 +361,7 @@ all = "Maybe\n a" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 3 } } - (Typed + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } ( [], "Maybe" )) [ Node { start = { row = 2, column = 2 }, end = { row = 2, column = 3 } } (GenericType "a") ] ) @@ -371,10 +371,10 @@ all = "List(String)" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } - (Typed + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } ( [], "List" )) [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 13 } } - (Typed + (Type (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } ( [], "String" )) [] ) @@ -386,15 +386,15 @@ all = "Dict String Int" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } - (Typed + (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } ( [], "Dict" )) [ Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } - (Typed + (Type (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } ( [], "String" )) [] ) , Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } - (Typed (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } ( [], "Int" )) []) + (Type (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } ( [], "Int" )) []) ] ) ) From 772480cc0ada4f867e53adc18377fd80d9f466f0 Mon Sep 17 00:00:00 2001 From: Mats Stijlaart Date: Tue, 16 Jun 2020 19:54:55 +0200 Subject: [PATCH 12/44] Rename GenericType to Var --- CHANGELOG.md | 1 + src/Elm/Parser/TypeAnnotation.elm | 2 +- src/Elm/Syntax/TypeAnnotation.elm | 4 ++-- tests/Elm/Parser/DeclarationsTests.elm | 18 +++++++-------- tests/Elm/Parser/FileTests.elm | 2 +- tests/Elm/Parser/TypeAnnotationTests.elm | 28 ++++++++++++------------ 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd8e81fa3..7f4416c2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - `Tupled` -> `Tuple` - `Unit` -> `Tuple []` - Renamed `Typed` to `Type` + - Renamed `GenericType` to `Var` ## [7.3.4] - 2024-07-26 diff --git a/src/Elm/Parser/TypeAnnotation.elm b/src/Elm/Parser/TypeAnnotation.elm index fb45cd9b0..ccf3e81de 100644 --- a/src/Elm/Parser/TypeAnnotation.elm +++ b/src/Elm/Parser/TypeAnnotation.elm @@ -123,7 +123,7 @@ genericTypeAnnotation = { comments = Rope.empty , syntax = Node { start = start, end = end } - (TypeAnnotation.GenericType var) + (TypeAnnotation.Var var) } ) diff --git a/src/Elm/Syntax/TypeAnnotation.elm b/src/Elm/Syntax/TypeAnnotation.elm index 7d27722fe..3a1a371aa 100644 --- a/src/Elm/Syntax/TypeAnnotation.elm +++ b/src/Elm/Syntax/TypeAnnotation.elm @@ -18,7 +18,7 @@ import Elm.Syntax.Node exposing (Node) {-| Custom type for different type annotations. For example: - - `GenericType`: `a` + - `Var`: `a` - `Type`: `Maybe (Int -> String)` - `Tuples`: `(a, b, c)` or Unit `()` - `Record`: `{ name : String}` @@ -27,7 +27,7 @@ import Elm.Syntax.Node exposing (Node) -} type TypeAnnotation - = GenericType String + = Var String | Type (Node ( ModuleName, String )) (List (Node TypeAnnotation)) | Tuple (List (Node TypeAnnotation)) | Record RecordDefinition diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 614be76c3..386beadf6 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -359,7 +359,7 @@ foo = bar""" (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 51 } } (Type (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 47 } } ( [], "Cmd" )) - [ Node { start = { row = 1, column = 48 }, end = { row = 1, column = 51 } } (GenericType "msg") ] + [ Node { start = { row = 1, column = 48 }, end = { row = 1, column = 51 } } (Var "msg") ] ) ) ) @@ -381,12 +381,12 @@ foo = bar""" (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } (Type (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } ( [], "Move" )) []) ) - (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 27 } } (GenericType "msg")) + (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 27 } } (Var "msg")) ) ) (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 39 } } (Type (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 35 } } ( [], "Sub" )) - [ Node { start = { row = 1, column = 36 }, end = { row = 1, column = 39 } } (GenericType "msg") + [ Node { start = { row = 1, column = 36 }, end = { row = 1, column = 39 } } (Var "msg") ] ) ) @@ -654,7 +654,7 @@ type alias Foo = {color: String }""" } ) ) - , test "type alias with GenericType " <| + , test "type alias with Var " <| \() -> "type alias Foo a = {some : a }" |> expectAst @@ -668,7 +668,7 @@ type alias Foo = {color: String }""" (Record [ Node { start = { row = 1, column = 21 }, end = { row = 1, column = 29 } } ( Node { start = { row = 1, column = 21 }, end = { row = 1, column = 25 } } "some" - , Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (GenericType "a") + , Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (Var "a") ) ] ) @@ -750,7 +750,7 @@ type Color = Blue String | Red | Green""" [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } { name = Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } "C" , arguments = - [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } (GenericType "a") + [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } (Var "a") , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (Type (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } ( [], "B" )) []) ] @@ -774,7 +774,7 @@ type Color = Blue String | Red | Green""" , arguments = [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } (Type (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } ( [], "B" )) []) - , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (GenericType "a") + , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (Var "a") ] } ] @@ -785,7 +785,7 @@ type Color = Blue String | Red | Green""" \() -> "type D = C B\na" |> expectInvalid - , test "type with GenericType" <| + , test "type with Var" <| \() -> "type Maybe a = Just a | Nothing" |> expectAst @@ -797,7 +797,7 @@ type Color = Blue String | Red | Green""" , constructors = [ Node { start = { row = 1, column = 16 }, end = { row = 1, column = 22 } } { name = Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } "Just" - , arguments = [ Node { start = { row = 1, column = 21 }, end = { row = 1, column = 22 } } (GenericType "a") ] + , arguments = [ Node { start = { row = 1, column = 21 }, end = { row = 1, column = 22 } } (Var "a") ] } , Node { start = { row = 1, column = 25 }, end = { row = 1, column = 32 } } { name = Node { start = { row = 1, column = 25 }, end = { row = 1, column = 32 } } "Nothing" diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index c68381c8b..02cda625e 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -433,7 +433,7 @@ port sendResponse : String -> Cmd msg ) (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 38 } } (Type (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 34 } } ( [], "Cmd" )) - [ Node { start = { row = 8, column = 35 }, end = { row = 8, column = 38 } } (GenericType "msg") ] + [ Node { start = { row = 8, column = 35 }, end = { row = 8, column = 38 } } (Var "msg") ] ) ) ) diff --git a/tests/Elm/Parser/TypeAnnotationTests.elm b/tests/Elm/Parser/TypeAnnotationTests.elm index c9fc6c10d..6a1fe9e3f 100644 --- a/tests/Elm/Parser/TypeAnnotationTests.elm +++ b/tests/Elm/Parser/TypeAnnotationTests.elm @@ -49,7 +49,7 @@ all = , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 15 } } (Type (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 13 } } ( [], "Maybe" )) - [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (GenericType "m") ] + [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (Var "m") ] ) ] ) @@ -79,7 +79,7 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tuple []) - , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (GenericType "a") + , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (Var "a") , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } (Type (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) ] @@ -92,7 +92,7 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } ( [], "Foo" )) [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 7 } } (Tuple []) - , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (GenericType "a") + , Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } (Var "a") , Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } (Type (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 13 } } ( [], "Bar" )) []) ] @@ -204,7 +204,7 @@ all = (Record [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 10 } } ( Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } "color" - , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (GenericType "s") + , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (Var "s") ) ] ) @@ -237,7 +237,7 @@ all = (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } (Type (Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } ( [], "Bar" )) []) ) - (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 18 } } (GenericType "baz")) + (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 18 } } (Var "baz")) ) ) ) @@ -248,11 +248,11 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 20 } } (FunctionTypeAnnotation - (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } (GenericType "cMsg")) + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } (Var "cMsg")) (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 20 } } (FunctionTypeAnnotation - (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 15 } } (GenericType "cModel")) - (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (GenericType "a")) + (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 15 } } (Var "cModel")) + (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (Var "a")) ) ) ) @@ -296,15 +296,15 @@ all = (FunctionTypeAnnotation (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 24 } } (FunctionTypeAnnotation - (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 7 } } (GenericType "cMsg")) + (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 7 } } (Var "cMsg")) (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 22 } } - (FunctionTypeAnnotation (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 17 } } (GenericType "cModel")) - (Node { start = { row = 1, column = 21 }, end = { row = 1, column = 22 } } (GenericType "a")) + (FunctionTypeAnnotation (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 17 } } (Var "cModel")) + (Node { start = { row = 1, column = 21 }, end = { row = 1, column = 22 } } (Var "a")) ) ) ) ) - (Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (GenericType "b")) + (Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (Var "b")) ) ) , test "type with params" <| @@ -349,7 +349,7 @@ all = ) ) ) - (Node { start = { row = 1, column = 17 }, end = { row = 1, column = 20 } } (GenericType "baz")) + (Node { start = { row = 1, column = 17 }, end = { row = 1, column = 20 } } (Var "baz")) ) ) , test "parseTypeWith wrong indent" <| @@ -363,7 +363,7 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 3 } } (Type (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } ( [], "Maybe" )) - [ Node { start = { row = 2, column = 2 }, end = { row = 2, column = 3 } } (GenericType "a") ] + [ Node { start = { row = 2, column = 2 }, end = { row = 2, column = 3 } } (Var "a") ] ) ) , test "issue #5 - no spaces between type and generic with parens" <| From 5aaaab3e78afa597f6f251bf129f58d47db3276b Mon Sep 17 00:00:00 2001 From: Mats Stijlaart Date: Wed, 17 Jun 2020 21:10:36 +0200 Subject: [PATCH 13/44] issue-61: Remove Destructuring declaration value constructor --- CHANGELOG.md | 3 +++ src/Elm/Syntax/Declaration.elm | 10 +--------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f4416c2c..b252af967 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ - `Elm.Processing` and `Elm.RawFile` modules - All `encode` and `decode` functions +- Changed `Elm.Syntax.Declaration.Declaration`: + - Removed `Destructuring` variant (it was not possible to get) + - Changed `Elm.Syntax.Expression.Expression`: - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) diff --git a/src/Elm/Syntax/Declaration.elm b/src/Elm/Syntax/Declaration.elm index d170175bf..ff450e7f4 100644 --- a/src/Elm/Syntax/Declaration.elm +++ b/src/Elm/Syntax/Declaration.elm @@ -7,7 +7,6 @@ These can be one of the following (all declared in `Declaration`): - Custom types: `type Color = Blue | Red` - Type aliases: `type alias Status = Int` - Port declaration: `port sendMessage: String -> Cmd msg` - - Destructuring: `{name, age} = person` - Infix declarations. You will probably not need this, while only core packages can define these. @@ -17,10 +16,8 @@ These can be one of the following (all declared in `Declaration`): -} -import Elm.Syntax.Expression exposing (Expression, Function) +import Elm.Syntax.Expression exposing (Function) import Elm.Syntax.Infix exposing (Infix) -import Elm.Syntax.Node exposing (Node) -import Elm.Syntax.Pattern exposing (Pattern) import Elm.Syntax.Signature exposing (Signature) import Elm.Syntax.Type exposing (Type) import Elm.Syntax.TypeAlias exposing (TypeAlias) @@ -34,8 +31,3 @@ type Declaration | CustomTypeDeclaration Type | PortDeclaration Signature | InfixDeclaration Infix - | Destructuring (Node Pattern) (Node Expression) - - - --- From 277256a19d1e72a6313ead30020ce9432d2a4d22 Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Sat, 20 Jun 2020 11:04:32 +0200 Subject: [PATCH 14/44] Require at least one exposed item in an explicit exposing list --- CHANGELOG.md | 3 +++ src/Elm/Parser/Expose.elm | 5 ++--- src/Elm/Syntax/Exposing.elm | 10 +++------- tests/Elm/Parser/ExposeTests.elm | 19 +++++++------------ tests/Elm/Parser/ImportsTests.elm | 7 +++---- tests/Elm/Parser/ModuleTests.elm | 30 ++++++++++++++++++++---------- 6 files changed, 38 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b252af967..58f3328bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,9 @@ - Renamed `Typed` to `Type` - Renamed `GenericType` to `Var` +- Changed `Elm.Syntax.Exposing.Exposing`: + - `Explicit (List (Node TopLevelExpose))` -> `Explicit (Node TopLevelExpose) (List (Node TopLevelExpose))` (takes a non-empty list of elements) + ## [7.3.4] - 2024-07-26 Parsing is faster by ~90%. A big thank you to [@lue-bird](https://github.com/lue-bird) for finding and introducing a huge amount of performance improvements. diff --git a/src/Elm/Parser/Expose.elm b/src/Elm/Parser/Expose.elm index 8549951d6..36ea0af3a 100644 --- a/src/Elm/Parser/Expose.elm +++ b/src/Elm/Parser/Expose.elm @@ -41,9 +41,8 @@ exposingListInner = |> Rope.prependTo tailElements.comments , syntax = Explicit - (headElement.syntax - :: tailElements.syntax - ) + headElement.syntax + tailElements.syntax } ) exposable diff --git a/src/Elm/Syntax/Exposing.elm b/src/Elm/Syntax/Exposing.elm index 11dae9985..b07f2bfb8 100644 --- a/src/Elm/Syntax/Exposing.elm +++ b/src/Elm/Syntax/Exposing.elm @@ -29,7 +29,7 @@ import Elm.Syntax.Range exposing (Range) -} type Exposing = All Range - | Explicit (List (Node TopLevelExpose)) + | Explicit (Node TopLevelExpose) (List (Node TopLevelExpose)) {-| An exposed entity @@ -68,7 +68,7 @@ exposesFunction s exposure = All _ -> True - Explicit l -> + Explicit head rest -> List.any (\(Node _ value) -> case value of @@ -78,7 +78,7 @@ exposesFunction s exposure = _ -> False ) - l + (head :: rest) {-| Collect all operator names from a list of TopLevelExposes @@ -96,7 +96,3 @@ operator t = _ -> Nothing - - - --- diff --git a/tests/Elm/Parser/ExposeTests.elm b/tests/Elm/Parser/ExposeTests.elm index b3d9925df..f0f8e8d40 100644 --- a/tests/Elm/Parser/ExposeTests.elm +++ b/tests/Elm/Parser/ExposeTests.elm @@ -51,8 +51,8 @@ all = "exposing (Model,Msg(..),Info(..),init,(::))" |> expectAst (Explicit - [ Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } (TypeOrAliasExpose "Model") - , Node { start = { row = 1, column = 17 }, end = { row = 1, column = 24 } } + (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } (TypeOrAliasExpose "Model")) + [ Node { start = { row = 1, column = 17 }, end = { row = 1, column = 24 } } (TypeExpose { name = "Msg" , open = Just { start = { row = 1, column = 20 }, end = { row = 1, column = 24 } } @@ -72,9 +72,8 @@ all = \() -> "exposing (Model, Msg, Info (..) ,init,(::) )" |> expectAst - (Explicit - [ Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } (TypeOrAliasExpose "Model") - , Node { start = { row = 1, column = 18 }, end = { row = 1, column = 21 } } (TypeOrAliasExpose "Msg") + (Explicit (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } (TypeOrAliasExpose "Model")) + [ Node { start = { row = 1, column = 18 }, end = { row = 1, column = 21 } } (TypeOrAliasExpose "Msg") , Node { start = { row = 1, column = 23 }, end = { row = 1, column = 34 } } (TypeExpose { name = "Info" @@ -95,9 +94,8 @@ all = (::) )""" |> expectAst - (Explicit - [ Node { start = { row = 2, column = 7 }, end = { row = 2, column = 8 } } (TypeOrAliasExpose "A") - , Node { start = { row = 3, column = 7 }, end = { row = 3, column = 12 } } + (Explicit (Node { start = { row = 2, column = 7 }, end = { row = 2, column = 8 } } (TypeOrAliasExpose "A")) + [ Node { start = { row = 3, column = 7 }, end = { row = 3, column = 12 } } (TypeExpose { name = "B" , open = Just { start = { row = 3, column = 8 }, end = { row = 3, column = 12 } } @@ -118,10 +116,7 @@ all = "exposing (foo\n --bar\n )" |> expectAstWithComments { ast = - Explicit - [ Node { start = { row = 1, column = 11 }, end = { row = 1, column = 14 } } - (FunctionExpose "foo") - ] + Explicit (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 14 } } (FunctionExpose "foo")) [] , comments = [ Node { start = { row = 2, column = 2 }, end = { row = 2, column = 7 } } "--bar" ] } ] diff --git a/tests/Elm/Parser/ImportsTests.elm b/tests/Elm/Parser/ImportsTests.elm index 34f4f5e5b..4095a029c 100644 --- a/tests/Elm/Parser/ImportsTests.elm +++ b/tests/Elm/Parser/ImportsTests.elm @@ -23,7 +23,8 @@ all = Just (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 37 } } (Explicit - [ Node { start = { row = 1, column = 22 }, end = { row = 1, column = 27 } } (TypeOrAliasExpose "Model"), Node { start = { row = 1, column = 29 }, end = { row = 1, column = 36 } } (TypeExpose { name = "Msg", open = Just { start = { row = 1, column = 32 }, end = { row = 1, column = 36 } } }) ] + (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 27 } } (TypeOrAliasExpose "Model")) + [ Node { start = { row = 1, column = 29 }, end = { row = 1, column = 36 } } (TypeExpose { name = "Msg", open = Just { start = { row = 1, column = 32 }, end = { row = 1, column = 36 } } }) ] ) ) } @@ -38,9 +39,7 @@ all = , exposingList = Just (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 28 } } - (Explicit - [ Node { start = { row = 1, column = 23 }, end = { row = 1, column = 27 } } (FunctionExpose "text") ] - ) + (Explicit (Node { start = { row = 1, column = 23 }, end = { row = 1, column = 27 } } (FunctionExpose "text")) []) ) } ) diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index bd9ec2f5d..0d7a47550 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -28,8 +28,8 @@ all = , exposingList = Node { start = { row = 1, column = 12 }, end = { row = 1, column = 26 } } (Explicit - [ Node { start = { row = 1, column = 22 }, end = { row = 1, column = 25 } } (TypeOrAliasExpose "Bar") - ] + (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 25 } } (TypeOrAliasExpose "Bar")) + [] ) } ) @@ -41,9 +41,7 @@ all = { moduleName = Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } [ "Foo" ] , exposingList = Node { start = { row = 1, column = 17 }, end = { row = 1, column = 31 } } - (Explicit - [ Node { start = { row = 1, column = 27 }, end = { row = 1, column = 30 } } (TypeOrAliasExpose "Bar") ] - ) + (Explicit (Node { start = { row = 1, column = 27 }, end = { row = 1, column = 30 } } (TypeOrAliasExpose "Bar")) []) } ) , test "port moduleDefinition with spacing" <| @@ -54,9 +52,7 @@ all = { moduleName = Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } [ "Foo" ] , exposingList = Node { start = { row = 1, column = 17 }, end = { row = 1, column = 33 } } - (Explicit - [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 31 } } (TypeOrAliasExpose "Bar") ] - ) + (Explicit (Node { start = { row = 1, column = 28 }, end = { row = 1, column = 31 } } (TypeOrAliasExpose "Bar")) []) } ) , test "effect moduleDefinition" <| @@ -65,7 +61,9 @@ all = |> expectAst (EffectModule { moduleName = Node { start = { row = 1, column = 15 }, end = { row = 1, column = 18 } } [ "Foo" ] - , exposingList = Node { start = { row = 1, column = 66 }, end = { row = 1, column = 80 } } (Explicit [ Node { start = { row = 1, column = 76 }, end = { row = 1, column = 79 } } (TypeOrAliasExpose "Bar") ]) + , exposingList = + Node { start = { row = 1, column = 66 }, end = { row = 1, column = 80 } } + (Explicit (Node { start = { row = 1, column = 76 }, end = { row = 1, column = 79 } } (TypeOrAliasExpose "Bar")) []) , command = Just (Node { start = { row = 1, column = 36 }, end = { row = 1, column = 41 } } "MyCmd") , subscription = Just (Node { start = { row = 1, column = 58 }, end = { row = 1, column = 63 } } "MySub") } @@ -437,7 +435,19 @@ fun2 n = File.file |> Expect.equal (Just - { moduleDefinition = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 31 } } (NormalModule { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } [ "A" ], exposingList = Node { start = { row = 1, column = 10 }, end = { row = 1, column = 31 } } (Explicit [ Node { start = { row = 1, column = 20 }, end = { row = 1, column = 24 } } (FunctionExpose "fun1"), Node { start = { row = 1, column = 26 }, end = { row = 1, column = 30 } } (FunctionExpose "fun2") ]) }) + { moduleDefinition = + Node { start = { row = 1, column = 1 }, end = { row = 1, column = 31 } } + (NormalModule + { moduleName = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 9 } } [ "A" ] + , exposingList = + Node { start = { row = 1, column = 10 }, end = { row = 1, column = 31 } } + (Explicit + (Node { start = { row = 1, column = 20 }, end = { row = 1, column = 24 } } (FunctionExpose "fun1")) + [ Node { start = { row = 1, column = 26 }, end = { row = 1, column = 30 } } (FunctionExpose "fun2") + ] + ) + } + ) , imports = [] , declarations = [ Node { start = { row = 3, column = 1 }, end = { row = 5, column = 11 } } From a4c18bf0e1434707a92a347c7fecd027b3a4bc20 Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Fri, 19 Jun 2020 16:02:02 +0200 Subject: [PATCH 15/44] Require at least one case statement to appear in case block --- CHANGELOG.md | 2 + src/Elm/Parser/Expression.elm | 3 +- src/Elm/Syntax/Expression.elm | 13 ++-- tests/Elm/Parser/CaseExpressionTests.elm | 76 +++++++++++++----------- tests/Elm/Parser/DeclarationsTests.elm | 54 +++++++++-------- tests/Elm/Parser/FileTests.elm | 11 ++-- 6 files changed, 83 insertions(+), 76 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 58f3328bc..4c5e971ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,8 @@ - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` + - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) + - `Elm.Syntax.Expression.CaseBlock`'s `cases : List Case` field is split into `firstCase : Case` and `restOfCases : List Case` (takes a non-empty list of cases) - Changed `Elm.Syntax.TypeAnnotation.TypeAnnotation`: - `Tupled` -> `Tuple` diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index e47d99582..1b703d625 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -427,7 +427,8 @@ caseExpression = } (CaseExpression { expression = caseBlock.casedExpression - , cases = caseBlock.firstCase :: List.reverse caseBlock.lastToSecondCase + , firstCase = caseBlock.firstCase + , restOfCases = List.reverse caseBlock.lastToSecondCase } ) } diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 46c021e76..cabbfb542 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -1,5 +1,5 @@ module Elm.Syntax.Expression exposing - ( Expression(..), Lambda, LetBlock, LetDeclaration(..), RecordSetter, CaseBlock, Cases, Case, Function, FunctionImplementation + ( Expression(..), Lambda, LetBlock, LetDeclaration(..), RecordSetter, CaseBlock, Case, Function, FunctionImplementation , functionRange, isLambda, isLet, isIfElse, isCase, isOperatorApplication ) @@ -9,7 +9,7 @@ Although it is a easy and simple language, you can express a lot! See the `Expre ## Types -@docs Expression, Lambda, LetBlock, LetDeclaration, RecordSetter, CaseBlock, Cases, Case, Function, FunctionImplementation +@docs Expression, Lambda, LetBlock, LetDeclaration, RecordSetter, CaseBlock, Case, Function, FunctionImplementation ## Functions @@ -161,7 +161,8 @@ type alias Lambda = -} type alias CaseBlock = { expression : Node Expression - , cases : Cases + , firstCase : Case + , restOfCases : List Case } @@ -171,12 +172,6 @@ type alias Case = ( Node Pattern, Node Expression ) -{-| Type alias for a list of cases --} -type alias Cases = - List Case - - {-| Check whether an expression is a lambda-expression -} isLambda : Expression -> Bool diff --git a/tests/Elm/Parser/CaseExpressionTests.elm b/tests/Elm/Parser/CaseExpressionTests.elm index af198440f..806122f3f 100644 --- a/tests/Elm/Parser/CaseExpressionTests.elm +++ b/tests/Elm/Parser/CaseExpressionTests.elm @@ -47,13 +47,14 @@ True -> 1""" { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } <| FunctionOrValue [] "f" - , cases = - [ ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } <| - NamedPattern (QualifiedNameRef [] "True") [] - , Node { start = { row = 2, column = 11 }, end = { row = 2, column = 12 } } <| - Integer 1 - ) - , ( Node { start = { row = 3, column = 3 }, end = { row = 3, column = 8 } } <| + , firstCase = + ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } <| + NamedPattern (QualifiedNameRef [] "True") [] + , Node { start = { row = 2, column = 11 }, end = { row = 2, column = 12 } } <| + Integer 1 + ) + , restOfCases = + [ ( Node { start = { row = 3, column = 3 }, end = { row = 3, column = 8 } } <| NamedPattern (QualifiedNameRef [] "False") [] , Node { start = { row = 3, column = 12 }, end = { row = 3, column = 13 } } <| Integer 2 @@ -72,13 +73,13 @@ True -> 1""" { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } <| FunctionOrValue [] "f" - , cases = - [ ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 10 } } <| - NamedPattern (QualifiedNameRef [ "Foo" ] "Bar") [] - , Node { start = { row = 2, column = 14 }, end = { row = 2, column = 15 } } <| - Integer 1 - ) - ] + , firstCase = + ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 10 } } <| + NamedPattern (QualifiedNameRef [ "Foo" ] "Bar") [] + , Node { start = { row = 2, column = 14 }, end = { row = 2, column = 15 } } <| + Integer 1 + ) + , restOfCases = [] } ) ) @@ -92,13 +93,13 @@ True -> 1""" { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } <| FunctionOrValue [] "f" - , cases = - [ ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 4 } } <| - VarPattern "x" - , Node { start = { row = 2, column = 6 }, end = { row = 2, column = 7 } } <| - Integer 1 - ) - ] + , firstCase = + ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 4 } } <| + VarPattern "x" + , Node { start = { row = 2, column = 6 }, end = { row = 2, column = 7 } } <| + Integer 1 + ) + , restOfCases = [] } ) ) @@ -110,11 +111,12 @@ True -> 1""" (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 21 } } (CaseExpression { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "x") - , cases = - [ ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 15 } } (NamedPattern { moduleName = [], name = "True" } []) - , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (Integer 1) - ) - , ( Node { start = { row = 2, column = 11 }, end = { row = 2, column = 16 } } (NamedPattern { moduleName = [], name = "False" } []) + , firstCase = + ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 15 } } (NamedPattern { moduleName = [], name = "True" } []) + , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (Integer 1) + ) + , restOfCases = + [ ( Node { start = { row = 2, column = 11 }, end = { row = 2, column = 16 } } (NamedPattern { moduleName = [], name = "False" } []) , Node { start = { row = 2, column = 20 }, end = { row = 2, column = 21 } } (Integer 2) ) ] @@ -139,11 +141,12 @@ True -> 1""" , end = { row = 1, column = 7 } } (FunctionOrValue [] "x") - , cases = - [ ( Node { start = { row = 2, column = 9 }, end = { row = 2, column = 39 } } (StringPattern "single line triple quote") - , Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (Integer 1) - ) - , ( Node { start = { row = 4, column = 9 }, end = { row = 5, column = 28 } } (StringPattern "multi line\n triple quote") + , firstCase = + ( Node { start = { row = 2, column = 9 }, end = { row = 2, column = 39 } } (StringPattern "single line triple quote") + , Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (Integer 1) + ) + , restOfCases = + [ ( Node { start = { row = 4, column = 9 }, end = { row = 5, column = 28 } } (StringPattern "multi line\n triple quote") , Node { start = { row = 6, column = 13 }, end = { row = 6, column = 14 } } (Integer 2) ) , ( Node { start = { row = 7, column = 9 }, end = { row = 7, column = 10 } } AllPattern @@ -177,11 +180,12 @@ True -> 1""" (Node { start = { row = 1, column = 1 }, end = { row = 6, column = 6 } } (CaseExpression { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 9 } } (FunctionOrValue [] "msg") - , cases = - [ ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 12 } } (NamedPattern { moduleName = [], name = "Increment" } []) - , Node { start = { row = 3, column = 5 }, end = { row = 3, column = 6 } } (Integer 1) - ) - , ( Node { start = { row = 5, column = 3 }, end = { row = 5, column = 12 } } (NamedPattern { moduleName = [], name = "Decrement" } []) + , firstCase = + ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 12 } } (NamedPattern { moduleName = [], name = "Increment" } []) + , Node { start = { row = 3, column = 5 }, end = { row = 3, column = 6 } } (Integer 1) + ) + , restOfCases = + [ ( Node { start = { row = 5, column = 3 }, end = { row = 5, column = 12 } } (NamedPattern { moduleName = [], name = "Decrement" } []) , Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (Integer 2) ) ] diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 386beadf6..5b9074117 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -101,11 +101,11 @@ foo = bar""" Node { start = { row = 4, column = 7 }, end = { row = 5, column = 18 } } (CaseExpression { expression = Node { start = { row = 4, column = 12 }, end = { row = 4, column = 13 } } (FunctionOrValue [] "x") - , cases = - [ ( Node { start = { row = 5, column = 9 }, end = { row = 5, column = 13 } } (NamedPattern { moduleName = [], name = "True" } []) - , Node { start = { row = 5, column = 17 }, end = { row = 5, column = 18 } } (FunctionOrValue [] "z") - ) - ] + , firstCase = + ( Node { start = { row = 5, column = 9 }, end = { row = 5, column = 13 } } (NamedPattern { moduleName = [], name = "True" } []) + , Node { start = { row = 5, column = 17 }, end = { row = 5, column = 18 } } (FunctionOrValue [] "z") + ) + , restOfCases = [] } ) } @@ -311,16 +311,17 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 7, column = 16 } } (CaseExpression { expression = Node { start = { row = 2, column = 8 }, end = { row = 2, column = 11 } } (FunctionOrValue [] "msg") - , cases = - [ ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } (NamedPattern { moduleName = [], name = "Increment" } []) - , Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } } - (OperatorApplication "+" - Left - (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) - (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (Integer 1)) - ) - ) - , ( Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } (NamedPattern { moduleName = [], name = "Decrement" } []) + , firstCase = + ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } (NamedPattern { moduleName = [], name = "Increment" } []) + , Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } } + (OperatorApplication "+" + Left + (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) + (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (Integer 1)) + ) + ) + , restOfCases = + [ ( Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } (NamedPattern { moduleName = [], name = "Decrement" } []) , Node { start = { row = 7, column = 7 }, end = { row = 7, column = 16 } } (OperatorApplication "-" Left @@ -535,16 +536,19 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 7, column = 16 } } (CaseExpression { expression = Node { start = { row = 2, column = 8 }, end = { row = 2, column = 11 } } (FunctionOrValue [] "msg") - , cases = - [ ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } (NamedPattern { moduleName = [], name = "Increment" } []) - , Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } } - (OperatorApplication "+" - Left - (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) - (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (Integer 1)) - ) - ) - , ( Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } (NamedPattern { moduleName = [], name = "Decrement" } []) + , firstCase = + ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } + (NamedPattern { moduleName = [], name = "Increment" } []) + , Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } } + (OperatorApplication "+" + Left + (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) + (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (Integer 1)) + ) + ) + , restOfCases = + [ ( Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } + (NamedPattern { moduleName = [], name = "Decrement" } []) , Node { start = { row = 7, column = 7 }, end = { row = 7, column = 16 } } (OperatorApplication "-" Left diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index 02cda625e..b776d4689 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -160,11 +160,12 @@ caseWhitespace f = case f of Node { start = { row = 4, column = 20 }, end = { row = 11, column = 11 } } (CaseExpression { expression = Node { start = { row = 4, column = 25 }, end = { row = 4, column = 26 } } (FunctionOrValue [] "f") - , cases = - [ ( Node { start = { row = 5, column = 3 }, end = { row = 5, column = 7 } } (NamedPattern { moduleName = [], name = "True" } []) - , Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (Integer 1) - ) - , ( Node { start = { row = 7, column = 3 }, end = { row = 7, column = 8 } } (NamedPattern { moduleName = [], name = "False" } []) + , firstCase = + ( Node { start = { row = 5, column = 3 }, end = { row = 5, column = 7 } } (NamedPattern { moduleName = [], name = "True" } []) + , Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (Integer 1) + ) + , restOfCases = + [ ( Node { start = { row = 7, column = 3 }, end = { row = 7, column = 8 } } (NamedPattern { moduleName = [], name = "False" } []) , Node { start = { row = 11, column = 10 }, end = { row = 11, column = 11 } } (Integer 2) ) ] From 84fac3aad0ff12a726e98b8d7700a64ee9e93dca Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Thu, 25 Jul 2024 17:00:09 +0200 Subject: [PATCH 16/44] issue-35: Add documentation to port type --- CHANGELOG.md | 3 + elm.json | 1 + src/Elm/Parser/Declarations.elm | 28 ++++++--- src/Elm/Syntax/Declaration.elm | 4 +- src/Elm/Syntax/Port.elm | 32 +++++++++++ tests/Elm/Parser/DeclarationsTests.elm | 78 ++++++++++++++------------ tests/Elm/Parser/FileTests.elm | 34 ++++++----- 7 files changed, 120 insertions(+), 60 deletions(-) create mode 100644 src/Elm/Syntax/Port.elm diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c5e971ca..06ec9d6b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ - Changed `Elm.Syntax.Declaration.Declaration`: - Removed `Destructuring` variant (it was not possible to get) + - `PortDeclaration` documentation's is now attached to the declaration + - `PortDeclaration Signature` -> `PortDeclaration Port` where `type alias Port = { documentation : Maybe (Node Documentation), signature : Signature }` + - The comment for the port declaration is now removed from the `Elm.Syntax.File.File.comments` field. - Changed `Elm.Syntax.Expression.Expression`: - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) diff --git a/elm.json b/elm.json index 590fcb2d4..6811e4de6 100644 --- a/elm.json +++ b/elm.json @@ -18,6 +18,7 @@ "Elm.Syntax.ModuleName", "Elm.Syntax.Node", "Elm.Syntax.Pattern", + "Elm.Syntax.Port", "Elm.Syntax.Range", "Elm.Syntax.Signature", "Elm.Syntax.TypeAlias", diff --git a/src/Elm/Parser/Declarations.elm b/src/Elm/Parser/Declarations.elm index 65df12b9e..138130e14 100644 --- a/src/Elm/Parser/Declarations.elm +++ b/src/Elm/Parser/Declarations.elm @@ -159,17 +159,22 @@ declarationWithDocumentation = (Node typeAnnotationRange _) = portDeclarationAfterName.typeAnnotation in - { comments = - Rope.one documentation - |> Rope.filledPrependTo afterDocumentation.comments + { comments = afterDocumentation.comments , syntax = Node - { start = portDeclarationAfterName.startLocation + { start = start , end = typeAnnotationRange.end } (Declaration.PortDeclaration - { name = portDeclarationAfterName.name - , typeAnnotation = portDeclarationAfterName.typeAnnotation + { documentation = Just documentation + , signature = + Node + { start = (Node.range portDeclarationAfterName.name).start + , end = typeAnnotationRange.end + } + { name = portDeclarationAfterName.name + , typeAnnotation = portDeclarationAfterName.typeAnnotation + } } ) } @@ -495,8 +500,15 @@ portDeclarationWithoutDocumentation = , end = end } (Declaration.PortDeclaration - { name = name - , typeAnnotation = typeAnnotationResult.syntax + { documentation = Nothing + , signature = + Node + { start = nameRange.start + , end = end + } + { name = name + , typeAnnotation = typeAnnotationResult.syntax + } } ) } diff --git a/src/Elm/Syntax/Declaration.elm b/src/Elm/Syntax/Declaration.elm index ff450e7f4..4e03dc62a 100644 --- a/src/Elm/Syntax/Declaration.elm +++ b/src/Elm/Syntax/Declaration.elm @@ -18,7 +18,7 @@ These can be one of the following (all declared in `Declaration`): import Elm.Syntax.Expression exposing (Function) import Elm.Syntax.Infix exposing (Infix) -import Elm.Syntax.Signature exposing (Signature) +import Elm.Syntax.Port exposing (Port) import Elm.Syntax.Type exposing (Type) import Elm.Syntax.TypeAlias exposing (TypeAlias) @@ -29,5 +29,5 @@ type Declaration = FunctionDeclaration Function | AliasDeclaration TypeAlias | CustomTypeDeclaration Type - | PortDeclaration Signature + | PortDeclaration Port | InfixDeclaration Infix diff --git a/src/Elm/Syntax/Port.elm b/src/Elm/Syntax/Port.elm new file mode 100644 index 000000000..da56fb815 --- /dev/null +++ b/src/Elm/Syntax/Port.elm @@ -0,0 +1,32 @@ +module Elm.Syntax.Port exposing (Port) + +{-| This syntax represents ports. +For example: + + {-| This is a port. + -} + port send : String -> Cmd msg + + {-| This is another port. + -} + port scroll : (Move -> msg) -> Sub msg + + +## Types + +@docs Port + +-} + +import Elm.Syntax.Documentation exposing (Documentation) +import Elm.Syntax.Node exposing (Node) +import Elm.Syntax.Signature exposing (Signature) + + +{-| Information associated with a Port. +A bit meta, but you get the idea. All information that you can define in a type alias is embedded. +-} +type alias Port = + { documentation : Maybe (Node Documentation) + , signature : Node Signature + } diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 5b9074117..6f36d5c93 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -342,28 +342,32 @@ foo = bar""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 51 } } (PortDeclaration - { name = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 19 } } "parseResponse" - , typeAnnotation = - Node { start = { row = 1, column = 22 }, end = { row = 1, column = 51 } } - (FunctionTypeAnnotation - (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 40 } } - (Tuple - [ Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } (Type (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } ( [], "String" )) []) - , Node { start = { row = 1, column = 32 }, end = { row = 1, column = 38 } } + { documentation = Nothing + , signature = + Node { start = { row = 1, column = 6 }, end = { row = 1, column = 51 } } <| + { name = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 19 } } "parseResponse" + , typeAnnotation = + Node { start = { row = 1, column = 22 }, end = { row = 1, column = 51 } } + (FunctionTypeAnnotation + (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 40 } } + (Tuple + [ Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } (Type (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } ( [], "String" )) []) + , Node { start = { row = 1, column = 32 }, end = { row = 1, column = 38 } } + (Type + (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 38 } } ( [], "String" )) + [] + ) + ] + ) + ) + (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 51 } } (Type - (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 38 } } ( [], "String" )) - [] + (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 47 } } ( [], "Cmd" )) + [ Node { start = { row = 1, column = 48 }, end = { row = 1, column = 51 } } (Var "msg") ] ) - ] - ) - ) - (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 51 } } - (Type - (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 47 } } ( [], "Cmd" )) - [ Node { start = { row = 1, column = 48 }, end = { row = 1, column = 51 } } (Var "msg") ] + ) ) - ) - ) + } } ) ) @@ -373,25 +377,29 @@ foo = bar""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 39 } } (PortDeclaration - { name = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } "scroll" - , typeAnnotation = - Node { start = { row = 1, column = 15 }, end = { row = 1, column = 39 } } - (FunctionTypeAnnotation - (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 28 } } + { documentation = Nothing + , signature = + Node { start = { row = 1, column = 6 }, end = { row = 1, column = 39 } } <| + { name = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } "scroll" + , typeAnnotation = + Node { start = { row = 1, column = 15 }, end = { row = 1, column = 39 } } (FunctionTypeAnnotation - (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } - (Type (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } ( [], "Move" )) []) + (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 28 } } + (FunctionTypeAnnotation + (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } + (Type (Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } ( [], "Move" )) []) + ) + (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 27 } } (Var "msg")) + ) + ) + (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 39 } } + (Type (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 35 } } ( [], "Sub" )) + [ Node { start = { row = 1, column = 36 }, end = { row = 1, column = 39 } } (Var "msg") + ] + ) ) - (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 27 } } (Var "msg")) - ) - ) - (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 39 } } - (Type (Node { start = { row = 1, column = 32 }, end = { row = 1, column = 35 } } ( [], "Sub" )) - [ Node { start = { row = 1, column = 36 }, end = { row = 1, column = 39 } } (Var "msg") - ] ) - ) - ) + } } ) ) diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index b776d4689..b6c63ff23 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -392,7 +392,7 @@ type Configuration , comments = [ Node { start = { row = 4, column = 1 }, end = { row = 5, column = 3 } } "{-| actually module doc\n-}" ] } ) - , test "documentation on a port declaration is treated as a normal comment" <| + , test "documentation on a port declaration" <| \() -> """ port module Foo exposing (..) @@ -423,25 +423,29 @@ port sendResponse : String -> Cmd msg } ] , declarations = - [ Node { start = { row = 8, column = 1 }, end = { row = 8, column = 38 } } + [ Node { start = { row = 6, column = 1 }, end = { row = 8, column = 38 } } (PortDeclaration - { name = Node { start = { row = 8, column = 6 }, end = { row = 8, column = 18 } } "sendResponse" - , typeAnnotation = - Node { start = { row = 8, column = 21 }, end = { row = 8, column = 38 } } - (FunctionTypeAnnotation - (Node { start = { row = 8, column = 21 }, end = { row = 8, column = 27 } } - (Type (Node { start = { row = 8, column = 21 }, end = { row = 8, column = 27 } } ( [], "String" )) []) - ) - (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 38 } } - (Type (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 34 } } ( [], "Cmd" )) - [ Node { start = { row = 8, column = 35 }, end = { row = 8, column = 38 } } (Var "msg") ] + { documentation = Just (Node { start = { row = 6, column = 1 }, end = { row = 7, column = 3 } } "{-| foo\n-}") + , signature = + Node { start = { row = 8, column = 6 }, end = { row = 8, column = 38 } } + { name = Node { start = { row = 8, column = 6 }, end = { row = 8, column = 18 } } "sendResponse" + , typeAnnotation = + Node { start = { row = 8, column = 21 }, end = { row = 8, column = 38 } } + (FunctionTypeAnnotation + (Node { start = { row = 8, column = 21 }, end = { row = 8, column = 27 } } + (Type (Node { start = { row = 8, column = 21 }, end = { row = 8, column = 27 } } ( [], "String" )) []) + ) + (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 38 } } + (Type (Node { start = { row = 8, column = 31 }, end = { row = 8, column = 34 } } ( [], "Cmd" )) + [ Node { start = { row = 8, column = 35 }, end = { row = 8, column = 38 } } (Var "msg") ] + ) + ) ) - ) - ) + } } ) ] - , comments = [ Node { start = { row = 6, column = 1 }, end = { row = 7, column = 3 } } "{-| foo\n-}" ] + , comments = [] } ) ] From a812745f40617defa16f42faf5eb6a673cd9dd55 Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Thu, 25 Jun 2020 20:32:48 +0200 Subject: [PATCH 17/44] Made constructors for Type nonempty --- CHANGELOG.md | 1 + src/Elm/Parser/Declarations.elm | 10 ++++---- src/Elm/Syntax/Type.elm | 7 ++---- tests/Elm/Parser/DeclarationsTests.elm | 33 ++++++++++++++------------ tests/Elm/Parser/FileTests.elm | 12 +++++----- tests/Elm/Parser/ModuleTests.elm | 7 +++--- 6 files changed, 35 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06ec9d6b1..6851cdb8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ - `Tupled` -> `Tuple` - `Unit` -> `Tuple []` - Renamed `Typed` to `Type` + - `Elm.Syntax.TypeAnnotation.Type`'s `constructors : List (Node ValueConstructor)` field is split into `firstConstructor : Node ValueConstructor` and `restOfConstructors : List (Node ValueConstructor)` (takes a non-empty list of constructors) - Renamed `GenericType` to `Var` - Changed `Elm.Syntax.Exposing.Exposing`: diff --git a/src/Elm/Parser/Declarations.elm b/src/Elm/Parser/Declarations.elm index 138130e14..e782fbf71 100644 --- a/src/Elm/Parser/Declarations.elm +++ b/src/Elm/Parser/Declarations.elm @@ -128,9 +128,8 @@ declarationWithDocumentation = { documentation = Just documentation , name = typeDeclarationAfterDocumentation.name , generics = typeDeclarationAfterDocumentation.parameters - , constructors = - typeDeclarationAfterDocumentation.headVariant - :: List.reverse typeDeclarationAfterDocumentation.tailVariantsReverse + , firstConstructor = typeDeclarationAfterDocumentation.headVariant + , restOfConstructors = List.reverse typeDeclarationAfterDocumentation.tailVariantsReverse } ) } @@ -641,9 +640,8 @@ typeOrTypeAliasDefinitionWithoutDocumentation = { documentation = Nothing , name = typeDeclarationAfterDocumentation.name , generics = typeDeclarationAfterDocumentation.parameters - , constructors = - typeDeclarationAfterDocumentation.headVariant - :: List.reverse typeDeclarationAfterDocumentation.tailVariantsReverse + , firstConstructor = typeDeclarationAfterDocumentation.headVariant + , restOfConstructors = List.reverse typeDeclarationAfterDocumentation.tailVariantsReverse } , end = end } diff --git a/src/Elm/Syntax/Type.elm b/src/Elm/Syntax/Type.elm index 1a192a0ed..2f0c5a89b 100644 --- a/src/Elm/Syntax/Type.elm +++ b/src/Elm/Syntax/Type.elm @@ -28,7 +28,8 @@ type alias Type = { documentation : Maybe (Node Documentation) , name : Node String , generics : List (Node String) - , constructors : List (Node ValueConstructor) + , firstConstructor : Node ValueConstructor + , restOfConstructors : List (Node ValueConstructor) } @@ -38,7 +39,3 @@ type alias ValueConstructor = { name : Node String , arguments : List (Node TypeAnnotation) } - - - --- diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 6f36d5c93..7b24d3fde 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -696,15 +696,16 @@ type alias Foo = {color: String }""" { documentation = Nothing , name = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 11 } } "Color" , generics = [] - , constructors = - [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } + , firstConstructor = + Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } { name = Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } "Blue" , arguments = [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 25 } } (Type (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 25 } } ( [], "String" )) []) ] } - , Node { start = { row = 1, column = 28 }, end = { row = 1, column = 31 } } + , restOfConstructors = + [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 31 } } { name = Node { start = { row = 1, column = 28 }, end = { row = 1, column = 31 } } "Red" , arguments = [] } @@ -726,8 +727,8 @@ type Color = Blue String | Red | Green""" { documentation = Just (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 19 } } "{-| Classic RGB -}") , name = Node { start = { row = 2, column = 6 }, end = { row = 2, column = 11 } } "Color" , generics = [] - , constructors = - [ Node + , firstConstructor = + Node { start = { row = 2, column = 14 } , end = { row = 2, column = 25 } } @@ -737,7 +738,8 @@ type Color = Blue String | Red | Green""" (Type (Node { start = { row = 2, column = 19 }, end = { row = 2, column = 25 } } ( [], "String" )) []) ] } - , Node { start = { row = 2, column = 28 }, end = { row = 2, column = 31 } } + , restOfConstructors = + [ Node { start = { row = 2, column = 28 }, end = { row = 2, column = 31 } } { name = Node { start = { row = 2, column = 28 }, end = { row = 2, column = 31 } } "Red" , arguments = [] } @@ -758,8 +760,8 @@ type Color = Blue String | Red | Green""" { documentation = Nothing , name = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } "D" , generics = [] - , constructors = - [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } + , firstConstructor = + Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } { name = Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } "C" , arguments = [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } (Var "a") @@ -767,7 +769,7 @@ type Color = Blue String | Red | Green""" (Type (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } ( [], "B" )) []) ] } - ] + , restOfConstructors = [] } ) ) @@ -780,8 +782,8 @@ type Color = Blue String | Red | Green""" { documentation = Nothing , name = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } "D" , generics = [] - , constructors = - [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } + , firstConstructor = + Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } { name = Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } "C" , arguments = [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } @@ -789,7 +791,7 @@ type Color = Blue String | Red | Green""" , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (Var "a") ] } - ] + , restOfConstructors = [] } ) ) @@ -806,12 +808,13 @@ type Color = Blue String | Red | Green""" { documentation = Nothing , name = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 11 } } "Maybe" , generics = [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 13 } } "a" ] - , constructors = - [ Node { start = { row = 1, column = 16 }, end = { row = 1, column = 22 } } + , firstConstructor = + Node { start = { row = 1, column = 16 }, end = { row = 1, column = 22 } } { name = Node { start = { row = 1, column = 16 }, end = { row = 1, column = 20 } } "Just" , arguments = [ Node { start = { row = 1, column = 21 }, end = { row = 1, column = 22 } } (Var "a") ] } - , Node { start = { row = 1, column = 25 }, end = { row = 1, column = 32 } } + , restOfConstructors = + [ Node { start = { row = 1, column = 25 }, end = { row = 1, column = 32 } } { name = Node { start = { row = 1, column = 25 }, end = { row = 1, column = 32 } } "Nothing" , arguments = [] } diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index b6c63ff23..79c4f75fe 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -339,12 +339,12 @@ type Configuration { documentation = Just (Node { start = { row = 6, column = 1 }, end = { row = 7, column = 3 } } "{-| Config goes here\n-}") , name = Node { start = { row = 8, column = 6 }, end = { row = 8, column = 19 } } "Configuration" , generics = [] - , constructors = - [ Node { start = { row = 9, column = 7 }, end = { row = 9, column = 20 } } + , firstConstructor = + Node { start = { row = 9, column = 7 }, end = { row = 9, column = 20 } } { name = Node { start = { row = 9, column = 7 }, end = { row = 9, column = 20 } } "Configuration" , arguments = [] } - ] + , restOfConstructors = [] } ) ] @@ -380,12 +380,12 @@ type Configuration { documentation = Nothing , name = Node { start = { row = 6, column = 6 }, end = { row = 6, column = 19 } } "Configuration" , generics = [] - , constructors = - [ Node { start = { row = 7, column = 7 }, end = { row = 7, column = 20 } } + , firstConstructor = + Node { start = { row = 7, column = 7 }, end = { row = 7, column = 20 } } { name = Node { start = { row = 7, column = 7 }, end = { row = 7, column = 20 } } "Configuration" , arguments = [] } - ] + , restOfConstructors = [] } ) ] diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index 0d7a47550..6cad4c15d 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -350,12 +350,13 @@ b = 2 { documentation = Nothing , name = Node { start = { row = 2, column = 6 }, end = { row = 2, column = 7 } } "A" , generics = [] - , constructors = - [ Node { start = { row = 2, column = 10 }, end = { row = 2, column = 11 } } + , firstConstructor = + Node { start = { row = 2, column = 10 }, end = { row = 2, column = 11 } } { name = Node { start = { row = 2, column = 10 }, end = { row = 2, column = 11 } } "B" , arguments = [] } - , Node { start = { row = 2, column = 14 }, end = { row = 2, column = 15 } } + , restOfConstructors = + [ Node { start = { row = 2, column = 14 }, end = { row = 2, column = 15 } } { name = Node { start = { row = 2, column = 14 }, end = { row = 2, column = 15 } } "C" , arguments = [] } From 7470bb30c50b9dd90ba1237cbf311ebc19f7c596 Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Fri, 26 Jun 2020 19:49:08 +0200 Subject: [PATCH 18/44] Remove Elm.Syntax.Pattern.FloatPattern --- CHANGELOG.md | 3 +++ src/Elm/Syntax/Pattern.elm | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6851cdb8d..d585c9d88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,9 @@ - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) - `Elm.Syntax.Expression.CaseBlock`'s `cases : List Case` field is split into `firstCase : Case` and `restOfCases : List Case` (takes a non-empty list of cases) +- Changed `Elm.Syntax.Pattern.Pattern`: + - Removed `FloatPattern` (it was not possible to get) + - Changed `Elm.Syntax.TypeAnnotation.TypeAnnotation`: - `Tupled` -> `Tuple` - `Unit` -> `Tuple []` diff --git a/src/Elm/Syntax/Pattern.elm b/src/Elm/Syntax/Pattern.elm index 8bde8a49e..a3cd8a8d0 100644 --- a/src/Elm/Syntax/Pattern.elm +++ b/src/Elm/Syntax/Pattern.elm @@ -51,7 +51,6 @@ type Pattern | StringPattern String | IntPattern Int | HexPattern Int - | FloatPattern Float | TuplePattern (List (Node Pattern)) | RecordPattern (List (Node String)) | UnConsPattern (Node Pattern) (Node Pattern) @@ -101,7 +100,3 @@ moduleNames p = _ -> [] - - - --- From e30667592a28e687638f471a183d37402b05ba55 Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Mon, 29 Jun 2020 17:51:45 +0200 Subject: [PATCH 19/44] Remove UnitExpr and ParenthesizedExpression --- CHANGELOG.md | 2 ++ src/Elm/Parser/Expression.elm | 15 +++++++---- src/Elm/Syntax/Expression.elm | 4 +-- tests/Elm/Parser/DeclarationsTests.elm | 6 ++--- tests/Elm/Parser/ExpressionTests.elm | 36 +++++++++++++------------- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d585c9d88..623ab6c9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` + - `UnitExpr` -> `TupleExpression []` + - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) - `Elm.Syntax.Expression.CaseBlock`'s `cases : List Case` field is split into `firstCase : Case` and `restOfCases : List Case` (takes a non-empty list of cases) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 1b703d625..b43d92f7b 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -25,7 +25,7 @@ subExpression = , unqualifiedFunctionReferenceExpression , literalExpression , numberExpression - , tupledExpression + , tupleExpression , listOrGlslExpression , recordExpression , caseExpression @@ -897,8 +897,8 @@ recordAccessFunctionExpression = (ParserFast.symbolFollowedBy "." Tokens.functionName) -tupledExpression : Parser (WithComments (Node Expression)) -tupledExpression = +tupleExpression : Parser (WithComments (Node Expression)) +tupleExpression = ParserFast.symbolFollowedBy "(" (ParserFast.oneOf (ParserFast.mapWithEndPosition @@ -906,7 +906,7 @@ tupledExpression = { comments = Rope.empty , syntax = Node { start = { row = end.row, column = end.column - 2 }, end = end } - UnitExpr + unit } ) (ParserFast.symbol ")" ()) @@ -929,6 +929,11 @@ tupledExpression = ) +unit : Expression +unit = + TupleExpression [] + + expressionPrefixOperatorMinus : Expression expressionPrefixOperatorMinus = PrefixOperator "-" @@ -975,7 +980,7 @@ tupledExpressionInnerAfterOpeningParens = commentsBeforeFirstPart |> Rope.prependTo firstPart.comments |> Rope.prependTo commentsAfterFirstPart - , syntax = ParenthesizedExpression firstPart.syntax + , syntax = TupleExpression [ firstPart.syntax ] } _ -> diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index cabbfb542..f4250cda8 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -102,8 +102,7 @@ type alias FunctionImplementation = -} type Expression - = UnitExpr - | Application (Node Expression) (List (Node Expression)) + = Application (Node Expression) (List (Node Expression)) | OperatorApplication String InfixDirection (Node Expression) (Node Expression) | FunctionOrValue ModuleName String | IfBlock (Node Expression) (Node Expression) (Node Expression) @@ -116,7 +115,6 @@ type Expression | Literal String | CharLiteral Char | TupleExpression (List (Node Expression)) - | ParenthesizedExpression (Node Expression) | LetExpression LetBlock | CaseExpression CaseBlock | LambdaExpression Lambda diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 7b24d3fde..97956783b 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -496,14 +496,14 @@ foo = bar""" (OperatorApplication ">>" Right (Node { start = { row = 1, column = 40 }, end = { row = 1, column = 56 } } - (ParenthesizedExpression - (Node { start = { row = 1, column = 41 }, end = { row = 1, column = 55 } } + (TupleExpression + [ Node { start = { row = 1, column = 41 }, end = { row = 1, column = 55 } } (Application (Node { start = { row = 1, column = 41 }, end = { row = 1, column = 48 } } (FunctionOrValue [] "uncurry")) [ Node { start = { row = 1, column = 49 }, end = { row = 1, column = 55 } } (FunctionOrValue [] "update") ] ) - ) + ] ) ) (Node { start = { row = 1, column = 60 }, end = { row = 1, column = 83 } } diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 53ed4d8b0..a68255795 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -84,8 +84,8 @@ all = "(bar)" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } - (ParenthesizedExpression - (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 5 } } (FunctionOrValue [] "bar")) + (TupleExpression + [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 5 } } (FunctionOrValue [] "bar") ] ) ) , test "parenthesized expression starting with a negation" <| @@ -93,8 +93,8 @@ all = "(-1 * sign)" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } - (ParenthesizedExpression - (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 11 } } + (TupleExpression + [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 11 } } (OperatorApplication "*" Left (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } @@ -102,7 +102,7 @@ all = ) (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "sign")) ) - ) + ] ) ) , test "application expression" <| @@ -134,8 +134,8 @@ all = , Node { start = { row = 1, column = 6 }, end = { row = 1, column = 47 } } <| Application (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 47 } } <| - ParenthesizedExpression - (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 46 } } <| + TupleExpression + [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 46 } } <| Application (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } (FunctionOrValue [ "List" ] "concat")) [ Node { start = { row = 1, column = 26 }, end = { row = 1, column = 46 } } <| ListExpr @@ -148,7 +148,7 @@ all = ListExpr [] ] ] - ) + ] ] ] ) @@ -162,7 +162,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionOrValue [ "Task" ] "succeed")) - [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 16 } } UnitExpr + [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 16 } } (TupleExpression []) ] ) ) @@ -384,14 +384,14 @@ all = "(.spaceEvenly Internal.Style.classes)" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 38 } } - (ParenthesizedExpression - (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 37 } } + (TupleExpression + [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 37 } } (Application (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 14 } } (RecordAccessFunction ".spaceEvenly")) [ Node { start = { row = 1, column = 15 }, end = { row = 1, column = 37 } } (FunctionOrValue [ "Internal", "Style" ] "classes") ] ) - ) + ] ) ) , test "positive integer should be invalid" <| @@ -448,14 +448,14 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } (Negation (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 9 } } - (ParenthesizedExpression - (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } + (TupleExpression + [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (OperatorApplication "-" Left (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "x")) (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "y")) ) - ) + ] ) ) ) @@ -535,8 +535,8 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 54 } } (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "chompWhile")) [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 54 } } - (ParenthesizedExpression - (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 53 } } + (TupleExpression + [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 53 } } (LambdaExpression { args = [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (VarPattern "c") ] , expression = @@ -576,7 +576,7 @@ all = ) } ) - ) + ] ) ] ) From 73b63c6347f87b3ce97da44941c32c0d0735604a Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Sun, 25 Jun 2023 18:26:23 +0200 Subject: [PATCH 20/44] Add DeconstructPattern for deconstructing instead of reusing pattern --- CHANGELOG.md | 3 + elm.json | 1 + src/Elm/Parser/Declarations.elm | 10 +- src/Elm/Parser/DestructurePatterns.elm | 273 +++++++++++++++++++++ src/Elm/Parser/Expression.elm | 21 +- src/Elm/Parser/Patterns.elm | 2 +- src/Elm/Syntax/DestructurePattern.elm | 42 ++++ src/Elm/Syntax/Expression.elm | 8 +- tests/Elm/Parser/DeclarationsTests.elm | 25 +- tests/Elm/Parser/ExpressionTests.elm | 5 +- tests/Elm/Parser/FileTests.elm | 10 +- tests/Elm/Parser/LambdaExpressionTests.elm | 29 ++- tests/Elm/Parser/LetExpressionTests.elm | 35 ++- tests/Elm/Parser/ModuleTests.elm | 6 +- 14 files changed, 405 insertions(+), 65 deletions(-) create mode 100644 src/Elm/Parser/DestructurePatterns.elm create mode 100644 src/Elm/Syntax/DestructurePattern.elm diff --git a/CHANGELOG.md b/CHANGELOG.md index 623ab6c9e..be7de78d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ - `PortDeclaration Signature` -> `PortDeclaration Port` where `type alias Port = { documentation : Maybe (Node Documentation), signature : Signature }` - The comment for the port declaration is now removed from the `Elm.Syntax.File.File.comments` field. +- Add a new module `Elm.Syntax.DeconstructPattern` which mimics `Elm.Syntax.Pattern` but for patterns in functions and let declarations. + - This removes the need to handle impossible patterns. For instance, you can't find a string pattern in `someFn (X "impossible") = x` in a function declaration. + - Changed `Elm.Syntax.Expression.Expression`: - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) diff --git a/elm.json b/elm.json index 6811e4de6..0b896574e 100644 --- a/elm.json +++ b/elm.json @@ -8,6 +8,7 @@ "Elm.Parser", "Elm.Syntax.Comments", "Elm.Syntax.Declaration", + "Elm.Syntax.DestructurePattern", "Elm.Syntax.Documentation", "Elm.Syntax.Exposing", "Elm.Syntax.Expression", diff --git a/src/Elm/Parser/Declarations.elm b/src/Elm/Parser/Declarations.elm index e782fbf71..2c1c17bed 100644 --- a/src/Elm/Parser/Declarations.elm +++ b/src/Elm/Parser/Declarations.elm @@ -1,17 +1,17 @@ module Elm.Parser.Declarations exposing (declaration) import Elm.Parser.Comments as Comments +import Elm.Parser.DestructurePatterns as DestructurePatterns import Elm.Parser.Expression exposing (expression) import Elm.Parser.Layout as Layout import Elm.Parser.Node as Node -import Elm.Parser.Patterns as Patterns import Elm.Parser.Tokens as Tokens import Elm.Parser.TypeAnnotation as TypeAnnotation exposing (typeAnnotation, typeAnnotationNoFnExcludingTypedWithArguments) import Elm.Syntax.Declaration as Declaration exposing (Declaration) +import Elm.Syntax.DestructurePattern exposing (DestructurePattern) import Elm.Syntax.Expression exposing (Expression) import Elm.Syntax.Infix as Infix import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (Pattern) import Elm.Syntax.Range exposing (Location) import Elm.Syntax.Signature exposing (Signature) import Elm.Syntax.Type exposing (ValueConstructor) @@ -199,7 +199,7 @@ type DeclarationAfterDocumentation { typeAnnotation : Node TypeAnnotation , implementationName : Node String } - , arguments : List (Node Pattern) + , arguments : List (Node DestructurePattern) , expression : Node Expression } | TypeDeclarationAfterDocumentation @@ -400,7 +400,7 @@ functionDeclarationWithoutDocumentation = |> ParserFast.andThen identity -parameterPatternsEqual : Parser (WithComments (List (Node Pattern))) +parameterPatternsEqual : Parser (WithComments (List (Node DestructurePattern))) parameterPatternsEqual = ParserWithComments.until Tokens.equal (ParserFast.map2 @@ -409,7 +409,7 @@ parameterPatternsEqual = , syntax = patternResult.syntax } ) - Patterns.patternNotDirectlyComposing + DestructurePatterns.destructurePattern Layout.maybeLayout ) diff --git a/src/Elm/Parser/DestructurePatterns.elm b/src/Elm/Parser/DestructurePatterns.elm new file mode 100644 index 000000000..1ff53d24b --- /dev/null +++ b/src/Elm/Parser/DestructurePatterns.elm @@ -0,0 +1,273 @@ +module Elm.Parser.DestructurePatterns exposing (destructurePattern) + +import Elm.Parser.Layout as Layout +import Elm.Parser.Node as Node +import Elm.Parser.Tokens as Tokens +import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) +import Elm.Syntax.Node as Node exposing (Node(..)) +import ParserFast exposing (Parser) +import ParserWithComments exposing (WithComments) +import Rope + + +type PatternComposedWith + = PatternComposedWithNothing () + | PatternComposedWithAs (Node String) + + +subDestructurePattern : Parser (WithComments (Node DestructurePattern)) +subDestructurePattern = + ParserFast.lazy (\() -> composablePatternTryToCompose) + + +composablePatternTryToCompose : Parser (WithComments (Node DestructurePattern)) +composablePatternTryToCompose = + ParserFast.map3 + (\x commentsAfterLeft maybeComposedWithResult -> + { comments = + x.comments + |> Rope.prependTo commentsAfterLeft + |> Rope.prependTo maybeComposedWithResult.comments + , syntax = + case maybeComposedWithResult.syntax of + PatternComposedWithNothing () -> + x.syntax + + PatternComposedWithAs anotherName -> + Node.combine AsPattern_ x.syntax anotherName + } + ) + composablePattern + Layout.maybeLayout + maybeComposedWith + + +maybeComposedWith : Parser { comments : ParserWithComments.Comments, syntax : PatternComposedWith } +maybeComposedWith = + ParserFast.oneOf + [ ParserFast.map2 + (\commentsAfterAs name -> + { comments = commentsAfterAs + , syntax = PatternComposedWithAs name + } + ) + (ParserFast.keywordFollowedBy "as" Layout.maybeLayout) + (Node.parserCore Tokens.functionName) + , ParserFast.succeed { comments = Rope.empty, syntax = PatternComposedWithNothing () } + ] + + +parensPattern : Parser (WithComments (Node DestructurePattern)) +parensPattern = + ParserFast.map2 + (\commentsBeforeHead contentResult -> + { comments = + commentsBeforeHead + |> Rope.prependTo contentResult.comments + , syntax = contentResult.syntax + } + ) + (ParserFast.symbolFollowedBy "(" Layout.maybeLayout) + -- yes, ( ) is a valid pattern but not a valid type or expression + (ParserFast.oneOf2 + (ParserFast.map3 + (\headResult commentsAfterHead tailResult -> + { comments = + headResult.comments + |> Rope.prependTo commentsAfterHead + |> Rope.prependTo tailResult.comments + , syntax = + case tailResult.syntax of + [] -> + ParenthesizedPattern_ headResult.syntax + + _ -> + TuplePattern_ (headResult.syntax :: tailResult.syntax) + } + ) + subDestructurePattern + Layout.maybeLayout + (ParserWithComments.until + Tokens.parensEnd + (ParserFast.symbolFollowedBy "," + (Layout.maybeAroundBothSides subDestructurePattern) + ) + ) + ) + (ParserFast.symbol ")" { comments = Rope.empty, syntax = UnitPattern_ }) + ) + |> Node.parser + + +varPattern : Parser (WithComments (Node DestructurePattern)) +varPattern = + Tokens.functionName + |> ParserFast.mapWithStartAndEndPosition + (\start var end -> + { comments = Rope.empty + , syntax = + Node { start = start, end = end } (VarPattern_ var) + } + ) + + +composablePattern : Parser (WithComments (Node DestructurePattern)) +composablePattern = + ParserFast.oneOf + [ varPattern + , qualifiedPatternWithConsumeArgs + , allPattern + , unitPattern + , parensPattern + , recordPattern + ] + + +destructurePattern : Parser (WithComments (Node DestructurePattern)) +destructurePattern = + ParserFast.oneOf + [ varPattern + , qualifiedPatternWithoutConsumeArgs + , allPattern + , unitPattern + , parensPattern + , recordPattern + ] + + +allPattern : Parser (WithComments (Node DestructurePattern)) +allPattern = + ParserFast.symbol "_" { comments = Rope.empty, syntax = AllPattern_ } + |> Node.parser + + +unitPattern : Parser (WithComments (Node DestructurePattern)) +unitPattern = + ParserFast.symbol "()" { comments = Rope.empty, syntax = UnitPattern_ } + |> Node.parser + + +maybeDotTypeNamesTuple : ParserFast.Parser (Maybe ( List String, String )) +maybeDotTypeNamesTuple = + ParserFast.orSucceed + (ParserFast.map2 + (\startName afterStartName -> + case afterStartName of + Nothing -> + Just ( [], startName ) + + Just ( qualificationAfter, unqualified ) -> + Just ( startName :: qualificationAfter, unqualified ) + ) + (ParserFast.symbolFollowedBy "." Tokens.typeName) + (ParserFast.lazy (\() -> maybeDotTypeNamesTuple)) + ) + Nothing + + +qualifiedPatternWithConsumeArgs : Parser (WithComments (Node DestructurePattern)) +qualifiedPatternWithConsumeArgs = + ParserFast.map3 + (\startName afterStartName args -> + { comments = args.comments + , syntax = + NamedPattern_ + (case afterStartName of + Nothing -> + { moduleName = [], name = startName } + + Just ( qualificationAfter, unqualified ) -> + { moduleName = startName :: qualificationAfter, name = unqualified } + ) + args.syntax + } + ) + Tokens.typeName + maybeDotTypeNamesTuple + (ParserWithComments.many + (ParserFast.map2 + (\commentsBefore arg -> + { comments = arg.comments |> Rope.prependTo commentsBefore + , syntax = arg.syntax + } + ) + (Layout.maybeLayout |> ParserFast.backtrackable) + destructurePattern + ) + ) + |> Node.parser + + +qualifiedPatternWithoutConsumeArgs : Parser (WithComments (Node DestructurePattern)) +qualifiedPatternWithoutConsumeArgs = + ParserFast.mapWithStartAndEndPosition + (\start name end -> + { comments = Rope.empty + , syntax = + Node { start = start, end = end } (NamedPattern_ name []) + } + ) + (ParserFast.map2 + (\firstName after -> + case after of + Nothing -> + { moduleName = [], name = firstName } + + Just ( qualificationAfter, unqualified ) -> + { moduleName = firstName :: qualificationAfter, name = unqualified } + ) + Tokens.typeName + maybeDotTypeNamesTuple + ) + + +recordPattern : Parser (WithComments (Node DestructurePattern)) +recordPattern = + ParserFast.map2 + (\commentsBeforeElements maybeElements -> + case maybeElements of + Nothing -> + { comments = commentsBeforeElements + , syntax = patternRecordEmpty + } + + Just elements -> + { comments = commentsBeforeElements |> Rope.prependTo elements.comments + , syntax = RecordPattern_ elements.syntax + } + ) + (ParserFast.symbolFollowedBy "{" Layout.maybeLayout) + (ParserFast.oneOf2 + (ParserFast.map4 + (\head commentsAfterHead tail () -> + Just + { comments = + commentsAfterHead + |> Rope.prependTo tail.comments + , syntax = head :: tail.syntax + } + ) + (Node.parserCore Tokens.functionName) + Layout.maybeLayout + (ParserWithComments.many + (ParserFast.map3 + (\beforeName name afterName -> + { comments = beforeName |> Rope.prependTo afterName + , syntax = name + } + ) + (ParserFast.symbolFollowedBy "," Layout.maybeLayout) + (Node.parserCore Tokens.functionName) + Layout.maybeLayout + ) + ) + Tokens.curlyEnd + ) + (ParserFast.symbol "}" Nothing) + ) + |> Node.parser + + +patternRecordEmpty : DestructurePattern +patternRecordEmpty = + RecordPattern_ [] diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index b43d92f7b..c3a2d0d6f 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -1,15 +1,16 @@ module Elm.Parser.Expression exposing (expression) +import Elm.Parser.DestructurePatterns as DestructurePatterns import Elm.Parser.Layout as Layout import Elm.Parser.Node as Node import Elm.Parser.Numbers import Elm.Parser.Patterns as Patterns import Elm.Parser.Tokens as Tokens import Elm.Parser.TypeAnnotation as TypeAnnotation +import Elm.Syntax.DestructurePattern exposing (DestructurePattern) import Elm.Syntax.Expression as Expression exposing (Case, Expression(..), LetDeclaration(..), RecordSetter) import Elm.Syntax.Infix as Infix import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (Pattern) import Elm.Syntax.Range exposing (Location) import Elm.Syntax.Signature exposing (Signature) import ParserFast exposing (Parser) @@ -362,7 +363,8 @@ lambdaExpression = , syntax = Node { start = start, end = expressionRange.end } (LambdaExpression - { args = lambda.args + { firstArg = lambda.firstArg + , restOfArgs = lambda.restOfArgs , expression = lambda.expression } ) @@ -370,18 +372,19 @@ lambdaExpression = ) (ParserFast.map5 (\commentsAfterBackslash firstArg commentsAfterFirstArg secondUpArgs expressionResult -> - { args = firstArg.syntax :: secondUpArgs.syntax - , comments = + { comments = commentsAfterBackslash |> Rope.prependTo firstArg.comments |> Rope.prependTo commentsAfterFirstArg |> Rope.prependTo secondUpArgs.comments |> Rope.prependTo expressionResult.comments , expression = expressionResult.syntax + , firstArg = firstArg.syntax + , restOfArgs = secondUpArgs.syntax } ) (ParserFast.symbolFollowedBy "\\" Layout.maybeLayout) - Patterns.patternNotDirectlyComposing + DestructurePatterns.destructurePattern Layout.maybeLayout (ParserWithComments.until Tokens.arrowRight @@ -393,7 +396,7 @@ lambdaExpression = , syntax = patternResult.syntax } ) - Patterns.patternNotDirectlyComposing + DestructurePatterns.destructurePattern Layout.maybeLayout ) ) @@ -613,7 +616,7 @@ letDestructuringDeclaration = (LetDestructuring pattern.syntax expressionResult.syntax) } ) - Patterns.patternNotDirectlyComposing + DestructurePatterns.destructurePattern Layout.maybeLayout (ParserFast.symbolFollowedBy "=" Layout.maybeLayout) expression @@ -727,7 +730,7 @@ letFunction = |> ParserFast.andThen identity -parameterPatternsEqual : Parser (WithComments (List (Node Pattern))) +parameterPatternsEqual : Parser (WithComments (List (Node DestructurePattern))) parameterPatternsEqual = ParserWithComments.until Tokens.equal (ParserFast.map2 @@ -736,7 +739,7 @@ parameterPatternsEqual = , syntax = patternResult.syntax } ) - Patterns.patternNotDirectlyComposing + DestructurePatterns.destructurePattern Layout.maybeLayout ) diff --git a/src/Elm/Parser/Patterns.elm b/src/Elm/Parser/Patterns.elm index 4840b78e9..de6f3981f 100644 --- a/src/Elm/Parser/Patterns.elm +++ b/src/Elm/Parser/Patterns.elm @@ -1,4 +1,4 @@ -module Elm.Parser.Patterns exposing (pattern, patternNotDirectlyComposing) +module Elm.Parser.Patterns exposing (pattern) import Elm.Parser.Layout as Layout import Elm.Parser.Node as Node diff --git a/src/Elm/Syntax/DestructurePattern.elm b/src/Elm/Syntax/DestructurePattern.elm new file mode 100644 index 000000000..dcc4ce941 --- /dev/null +++ b/src/Elm/Syntax/DestructurePattern.elm @@ -0,0 +1,42 @@ +module Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) + +{-| + + +# Destructure pattern Syntax + +This syntax represents patterns used for destructuring data. +For example: + + Just x as someMaybe + {name, age} + +@docs DestructurePattern + +-} + +import Elm.Syntax.Node exposing (Node) +import Elm.Syntax.Pattern exposing (QualifiedNameRef) + + +{-| Custom type for all destructuring patterns such as: + + - `AllPattern_`: `_` + - `UnitPattern_`: `()` + - `TuplePattern_`: `(a, b)` + - `RecordPattern_`: `{name, age}` + - `VarPattern_`: `x` + - `NamedPattern_`: `Just _` + - `AsPattern_`: `_ as x` + - `ParenthesizedPattern_`: `( _ )` + +-} +type DestructurePattern + = AllPattern_ + | UnitPattern_ + | TuplePattern_ (List (Node DestructurePattern)) + | RecordPattern_ (List (Node String)) + | VarPattern_ String + | NamedPattern_ QualifiedNameRef (List (Node DestructurePattern)) + | AsPattern_ (Node DestructurePattern) (Node String) + | ParenthesizedPattern_ (Node DestructurePattern) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index f4250cda8..c2f879fc6 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -18,6 +18,7 @@ Although it is a easy and simple language, you can express a lot! See the `Expre -} +import Elm.Syntax.DestructurePattern exposing (DestructurePattern) import Elm.Syntax.Documentation exposing (Documentation) import Elm.Syntax.Infix exposing (InfixDirection) import Elm.Syntax.ModuleName exposing (ModuleName) @@ -68,7 +69,7 @@ functionRange function = -} type alias FunctionImplementation = { name : Node String - , arguments : List (Node Pattern) + , arguments : List (Node DestructurePattern) , expression : Node Expression } @@ -144,13 +145,14 @@ type alias LetBlock = -} type LetDeclaration = LetFunction Function - | LetDestructuring (Node Pattern) (Node Expression) + | LetDestructuring (Node DestructurePattern) (Node Expression) {-| Expression for a lambda -} type alias Lambda = - { args : List (Node Pattern) + { firstArg : Node DestructurePattern + , restOfArgs : List (Node DestructurePattern) , expression : Node Expression } diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 97956783b..e84d89cd9 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -3,6 +3,7 @@ module Elm.Parser.DeclarationsTests exposing (all) import Elm.Parser.Declarations exposing (..) import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil exposing (parse) import Elm.Syntax.Declaration as Declaration exposing (..) +import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Expression exposing (..) import Elm.Syntax.Infix as Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) @@ -84,7 +85,7 @@ foo = bar""" , declaration = Node { start = { row = 1, column = 1 }, end = { row = 7, column = 7 } } { name = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } "inc" - , arguments = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 6 } } (VarPattern "x") ] + , arguments = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 6 } } (VarPattern_ "x") ] , expression = Node { start = { row = 2, column = 3 }, end = { row = 7, column = 7 } } (LetExpression @@ -142,7 +143,7 @@ foo = bar""" , declaration = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 14 } } { name = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } "inc" - , arguments = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 6 } } (VarPattern "x") ] + , arguments = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 6 } } (VarPattern_ "x") ] , expression = Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } (OperatorApplication "+" @@ -225,9 +226,9 @@ foo = bar""" [ Node { start = { row = 3, column = 3 }, end = { row = 3, column = 16 } } (LetDestructuring (Node { start = { row = 3, column = 3 }, end = { row = 3, column = 9 } } - (TuplePattern - [ Node { start = { row = 3, column = 4 }, end = { row = 3, column = 5 } } (VarPattern "b") - , Node { start = { row = 3, column = 7 }, end = { row = 3, column = 8 } } (VarPattern "c") + (TuplePattern_ + [ Node { start = { row = 3, column = 4 }, end = { row = 3, column = 5 } } (VarPattern_ "b") + , Node { start = { row = 3, column = 7 }, end = { row = 3, column = 8 } } (VarPattern_ "c") ] ) ) @@ -304,8 +305,8 @@ foo = bar""" Node { start = { row = 1, column = 1 }, end = { row = 7, column = 16 } } { name = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } "update" , arguments = - [ Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } (VarPattern "msg") - , Node { start = { row = 1, column = 12 }, end = { row = 1, column = 17 } } (VarPattern "model") + [ Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } (VarPattern_ "msg") + , Node { start = { row = 1, column = 12 }, end = { row = 1, column = 17 } } (VarPattern_ "model") ] , expression = Node { start = { row = 2, column = 3 }, end = { row = 7, column = 16 } } @@ -486,7 +487,7 @@ foo = bar""" , declaration = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 83 } } { name = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } "updateState" - , arguments = [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 19 } } (VarPattern "update"), Node { start = { row = 1, column = 20 }, end = { row = 1, column = 28 } } (VarPattern "sendPort") ] + , arguments = [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 19 } } (VarPattern_ "update"), Node { start = { row = 1, column = 20 }, end = { row = 1, column = 28 } } (VarPattern_ "sendPort") ] , expression = Node { start = { row = 1, column = 31 }, end = { row = 1, column = 83 } } (OperatorApplication "<|" @@ -537,8 +538,8 @@ foo = bar""" Node { start = { row = 1, column = 1 }, end = { row = 7, column = 16 } } { name = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } "update" , arguments = - [ Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } (VarPattern "msg") - , Node { start = { row = 1, column = 12 }, end = { row = 1, column = 17 } } (VarPattern "model") + [ Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } (VarPattern_ "msg") + , Node { start = { row = 1, column = 12 }, end = { row = 1, column = 17 } } (VarPattern_ "model") ] , expression = Node { start = { row = 2, column = 3 }, end = { row = 7, column = 16 } } @@ -591,8 +592,8 @@ update msg model = Node { start = { row = 2, column = 1 }, end = { row = 3, column = 8 } } { name = Node { start = { row = 2, column = 1 }, end = { row = 2, column = 7 } } "update" , arguments = - [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 11 } } (VarPattern "msg") - , Node { start = { row = 2, column = 12 }, end = { row = 2, column = 17 } } (VarPattern "model") + [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 11 } } (VarPattern_ "msg") + , Node { start = { row = 2, column = 12 }, end = { row = 2, column = 17 } } (VarPattern_ "model") ] , expression = Node { start = { row = 3, column = 5 }, end = { row = 3, column = 8 } } (FunctionOrValue [] "msg") } diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index a68255795..e196b9698 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -2,10 +2,10 @@ module Elm.Parser.ExpressionTests exposing (all) import Elm.Parser.Expression exposing (expression) import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil +import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Expression exposing (Expression(..)) import Elm.Syntax.Infix as Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (..) import Expect import Test exposing (Test, describe, test) @@ -538,7 +538,8 @@ all = (TupleExpression [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 53 } } (LambdaExpression - { args = [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (VarPattern "c") ] + { firstArg = Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (VarPattern_ "c") + , restOfArgs = [] , expression = Node { start = { row = 1, column = 19 }, end = { row = 1, column = 53 } } (OperatorApplication "||" diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index 79c4f75fe..049406495 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -4,6 +4,7 @@ import Elm.Parser import Elm.Parser.File as Parser import Elm.Parser.Samples as Samples import Elm.Syntax.Declaration exposing (Declaration(..)) +import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Exposing exposing (Exposing(..)) import Elm.Syntax.Expression exposing (Expression(..), LetDeclaration(..)) import Elm.Syntax.Infix exposing (InfixDirection(..)) @@ -155,7 +156,7 @@ caseWhitespace f = case f of , declaration = Node { start = { row = 4, column = 1 }, end = { row = 11, column = 11 } } { name = Node { start = { row = 4, column = 1 }, end = { row = 4, column = 15 } } "caseWhitespace" - , arguments = [ Node { start = { row = 4, column = 16 }, end = { row = 4, column = 17 } } (VarPattern "f") ] + , arguments = [ Node { start = { row = 4, column = 16 }, end = { row = 4, column = 17 } } (VarPattern_ "f") ] , expression = Node { start = { row = 4, column = 20 }, end = { row = 11, column = 11 } } (CaseExpression @@ -218,10 +219,9 @@ lambdaWhitespace = \\ a b -> a , expression = Node { start = { row = 4, column = 22 }, end = { row = 8, column = 6 } } (LambdaExpression - { args = - [ Node { start = { row = 4, column = 24 }, end = { row = 4, column = 25 } } (VarPattern "a") - , Node { start = { row = 4, column = 26 }, end = { row = 4, column = 27 } } (VarPattern "b") - ] + { firstArg = Node { start = { row = 4, column = 24 }, end = { row = 4, column = 25 } } (VarPattern_ "a") + , restOfArgs = + [ Node { start = { row = 4, column = 26 }, end = { row = 4, column = 27 } } (VarPattern_ "b") ] , expression = Node { start = { row = 4, column = 34 }, end = { row = 8, column = 6 } } (OperatorApplication "+" diff --git a/tests/Elm/Parser/LambdaExpressionTests.elm b/tests/Elm/Parser/LambdaExpressionTests.elm index 3ef82799f..9f7d5613e 100644 --- a/tests/Elm/Parser/LambdaExpressionTests.elm +++ b/tests/Elm/Parser/LambdaExpressionTests.elm @@ -2,10 +2,10 @@ module Elm.Parser.LambdaExpressionTests exposing (all) import Elm.Parser.Expression exposing (expression) import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil +import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Expression exposing (..) import Elm.Syntax.Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (..) import Expect import Test exposing (..) @@ -19,7 +19,8 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (LambdaExpression - { args = [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } UnitPattern ] + { firstArg = Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } UnitPattern_ + , restOfArgs = [] , expression = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "foo") } ) @@ -30,7 +31,8 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 14 } } (LambdaExpression - { args = [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } (RecordPattern [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 6 } } "foo" ]) ] + { firstArg = Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } (RecordPattern_ [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 6 } } "foo" ]) + , restOfArgs = [] , expression = Node { start = { row = 1, column = 11 }, end = { row = 1, column = 14 } } (FunctionOrValue [] "foo") } ) @@ -41,7 +43,8 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (LambdaExpression - { args = [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } (RecordPattern []) ] + { firstArg = Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } (RecordPattern_ []) + , restOfArgs = [] , expression = Node { start = { row = 1, column = 8 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "foo") } ) @@ -52,9 +55,9 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 14 } } (LambdaExpression - { args = - [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (VarPattern "a") - , Node { start = { row = 1, column = 4 }, end = { row = 1, column = 5 } } (VarPattern "b") + { firstArg = Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (VarPattern_ "a") + , restOfArgs = + [ Node { start = { row = 1, column = 4 }, end = { row = 1, column = 5 } } (VarPattern_ "b") ] , expression = Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } @@ -72,14 +75,14 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } (LambdaExpression - { args = - [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } - (TuplePattern - [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (VarPattern "a") - , Node { start = { row = 1, column = 5 }, end = { row = 1, column = 6 } } (VarPattern "b") + { firstArg = + Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } + (TuplePattern_ + [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (VarPattern_ "a") + , Node { start = { row = 1, column = 5 }, end = { row = 1, column = 6 } } (VarPattern_ "b") ] ) - ] + , restOfArgs = [] , expression = Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } (OperatorApplication "+" diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index 88303c656..8a37cc749 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -2,9 +2,9 @@ module Elm.Parser.LetExpressionTests exposing (all) import Elm.Parser.Expression exposing (expression) import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil +import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Expression exposing (..) import Elm.Syntax.Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (..) import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation(..)) import Expect import Test exposing (..) @@ -42,7 +42,7 @@ all = , declaration = Node { start = { row = 4, column = 3 }, end = { row = 4, column = 13 } } { name = Node { start = { row = 4, column = 3 }, end = { row = 4, column = 7 } } "john" - , arguments = [ Node { start = { row = 4, column = 8 }, end = { row = 4, column = 9 } } (VarPattern "n") ] + , arguments = [ Node { start = { row = 4, column = 8 }, end = { row = 4, column = 9 } } (VarPattern_ "n") ] , expression = Node { start = { row = 4, column = 12 }, end = { row = 4, column = 13 } } (FunctionOrValue [] "n") } } @@ -234,8 +234,8 @@ all = Node { start = { row = 2, column = 11 }, end = { row = 2, column = 24 } } { name = Node { start = { row = 2, column = 11 }, end = { row = 2, column = 14 } } "bar" , arguments = - [ Node { start = { row = 2, column = 15 }, end = { row = 2, column = 18 } } (NamedPattern { moduleName = [], name = "Bar" } []) - , Node { start = { row = 2, column = 19 }, end = { row = 2, column = 20 } } (VarPattern "m") + [ Node { start = { row = 2, column = 15 }, end = { row = 2, column = 18 } } (NamedPattern_ { moduleName = [], name = "Bar" } []) + , Node { start = { row = 2, column = 19 }, end = { row = 2, column = 20 } } (VarPattern_ "m") ] , expression = Node { start = { row = 2, column = 23 }, end = { row = 2, column = 24 } } (Integer 1) } @@ -305,20 +305,20 @@ all = (LetExpression { declarations = [ Node { start = { row = 2, column = 5 }, end = { row = 2, column = 10 } } - (LetDestructuring (Node { start = { row = 2, column = 5 }, end = { row = 2, column = 6 } } AllPattern) (Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } (FunctionOrValue [] "b"))) + (LetDestructuring (Node { start = { row = 2, column = 5 }, end = { row = 2, column = 6 } } AllPattern_) (Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } (FunctionOrValue [] "b"))) , Node { start = { row = 3, column = 5 }, end = { row = 3, column = 12 } } (LetDestructuring (Node { start = { row = 3, column = 5 }, end = { row = 3, column = 8 } } - (RecordPattern [ Node { start = { row = 3, column = 6 }, end = { row = 3, column = 7 } } "a" ]) + (RecordPattern_ [ Node { start = { row = 3, column = 6 }, end = { row = 3, column = 7 } } "a" ]) ) (Node { start = { row = 3, column = 11 }, end = { row = 3, column = 12 } } (FunctionOrValue [] "b")) ) , Node { start = { row = 4, column = 5 }, end = { row = 4, column = 15 } } (LetDestructuring (Node { start = { row = 4, column = 5 }, end = { row = 4, column = 11 } } - (TuplePattern - [ Node { start = { row = 4, column = 6 }, end = { row = 4, column = 7 } } (VarPattern "c") - , Node { start = { row = 4, column = 9 }, end = { row = 4, column = 10 } } (VarPattern "d") + (TuplePattern_ + [ Node { start = { row = 4, column = 6 }, end = { row = 4, column = 7 } } (VarPattern_ "c") + , Node { start = { row = 4, column = 9 }, end = { row = 4, column = 10 } } (VarPattern_ "d") ] ) ) @@ -327,8 +327,14 @@ all = , Node { start = { row = 5, column = 5 }, end = { row = 5, column = 19 } } (LetDestructuring (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 15 } } - (ParenthesizedPattern - (Node { start = { row = 5, column = 6 }, end = { row = 5, column = 14 } } (NamedPattern { moduleName = [], name = "Node" } [ Node { start = { row = 5, column = 11 }, end = { row = 5, column = 12 } } AllPattern, Node { start = { row = 5, column = 13 }, end = { row = 5, column = 14 } } (VarPattern "f") ])) + (ParenthesizedPattern_ + (Node { start = { row = 5, column = 6 }, end = { row = 5, column = 14 } } + (NamedPattern_ { moduleName = [], name = "Node" } + [ Node { start = { row = 5, column = 11 }, end = { row = 5, column = 12 } } AllPattern_ + , Node { start = { row = 5, column = 13 }, end = { row = 5, column = 14 } } (VarPattern_ "f") + ] + ) + ) ) ) (Node { start = { row = 5, column = 18 }, end = { row = 5, column = 19 } } (FunctionOrValue [] "g")) @@ -444,7 +450,12 @@ all = ] , expression = Node { start = { row = 3, column = 7 }, end = { row = 3, column = 14 } } - (LambdaExpression { args = [ Node { start = { row = 3, column = 8 }, end = { row = 3, column = 9 } } AllPattern ], expression = Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (Integer 1) }) + (LambdaExpression + { firstArg = Node { start = { row = 3, column = 8 }, end = { row = 3, column = 9 } } AllPattern_ + , restOfArgs = [] + , expression = Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (Integer 1) + } + ) } ) ) diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index 6cad4c15d..d476d4c61 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -4,12 +4,12 @@ import Elm.Parser.File as File import Elm.Parser.Modules as Parser import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil exposing (..) import Elm.Syntax.Declaration exposing (Declaration(..)) +import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Exposing exposing (..) import Elm.Syntax.Expression exposing (Expression(..)) import Elm.Syntax.Infix exposing (InfixDirection(..)) import Elm.Syntax.Module exposing (..) import Elm.Syntax.Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (Pattern(..)) import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation(..)) import Expect import ParserFast @@ -458,7 +458,7 @@ fun2 n = , declaration = Node { start = { row = 3, column = 1 }, end = { row = 5, column = 11 } } { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 5 } } "fun1" - , arguments = [ Node { start = { row = 3, column = 6 }, end = { row = 3, column = 7 } } (VarPattern "n") ] + , arguments = [ Node { start = { row = 3, column = 6 }, end = { row = 3, column = 7 } } (VarPattern_ "n") ] , expression = Node { start = { row = 4, column = 3 }, end = { row = 5, column = 11 } } (OperatorApplication "+" @@ -488,7 +488,7 @@ fun2 n = , declaration = Node { start = { row = 7, column = 1 }, end = { row = 8, column = 9 } } { name = Node { start = { row = 7, column = 1 }, end = { row = 7, column = 5 } } "fun2" - , arguments = [ Node { start = { row = 7, column = 6 }, end = { row = 7, column = 7 } } (VarPattern "n") ] + , arguments = [ Node { start = { row = 7, column = 6 }, end = { row = 7, column = 7 } } (VarPattern_ "n") ] , expression = Node { start = { row = 8, column = 3 }, end = { row = 8, column = 9 } } (Application From 84ce01324ef6a432e772847e42382567adc8d726 Mon Sep 17 00:00:00 2001 From: Martin Stewart Date: Sat, 17 Jul 2021 19:19:14 +0200 Subject: [PATCH 21/44] Remove dot from record access --- CHANGELOG.md | 2 ++ src/Elm/Parser/Expression.elm | 2 +- tests/Elm/Parser/ExpressionTests.elm | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be7de78d5..613faf8b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ - This removes the need to handle impossible patterns. For instance, you can't find a string pattern in `someFn (X "impossible") = x` in a function declaration. - Changed `Elm.Syntax.Expression.Expression`: + - **WARNING (will not result in compilation error)** Stripped the `.` in the `String` stored in `RecordAccessFunction` (for code like `.field`) + - Example: `RecordAccessFunction ".field"` -> `RecordAccessFunction "field"` - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index c3a2d0d6f..4716f453e 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -894,7 +894,7 @@ recordAccessFunctionExpression = { comments = Rope.empty , syntax = Node { start = start, end = end } - (RecordAccessFunction ("." ++ field)) + (RecordAccessFunction field) } ) (ParserFast.symbolFollowedBy "." Tokens.functionName) diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index e196b9698..9ad50c551 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -374,7 +374,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 22 } } (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } (FunctionOrValue [ "List" ] "map")) - [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (RecordAccessFunction ".name") + [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (RecordAccessFunction "name") , Node { start = { row = 1, column = 16 }, end = { row = 1, column = 22 } } (FunctionOrValue [] "people") ] ) @@ -387,7 +387,7 @@ all = (TupleExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 37 } } (Application - (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 14 } } (RecordAccessFunction ".spaceEvenly")) + (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 14 } } (RecordAccessFunction "spaceEvenly")) [ Node { start = { row = 1, column = 15 }, end = { row = 1, column = 37 } } (FunctionOrValue [ "Internal", "Style" ] "classes") ] ) From da37d2c78b2b69e8d73ea1647f848451f001f4ac Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 27 Jun 2023 20:58:27 +0200 Subject: [PATCH 22/44] Add information to Expression about which quotes a Literal is made of Fixes #57 --- CHANGELOG.md | 5 +++++ elm.json | 2 ++ src/Elm/Parser/Expression.elm | 4 ++-- src/Elm/Parser/Patterns.elm | 2 +- src/Elm/Parser/Tokens.elm | 8 ++++++-- src/Elm/Syntax/Expression.elm | 3 ++- src/Elm/Syntax/StringLiteralType.elm | 14 ++++++++++++++ tests/Elm/Parser/DeclarationsTests.elm | 5 +++-- tests/Elm/Parser/ExpressionTests.elm | 15 ++++++++------- tests/Elm/Parser/TokenTests.elm | 9 +++++---- 10 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 src/Elm/Syntax/StringLiteralType.elm diff --git a/CHANGELOG.md b/CHANGELOG.md index 613faf8b3..e009aeb7f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ - Changed `Elm.Syntax.Expression.Expression`: - **WARNING (will not result in compilation error)** Stripped the `.` in the `String` stored in `RecordAccessFunction` (for code like `.field`) - Example: `RecordAccessFunction ".field"` -> `RecordAccessFunction "field"` + - Added information to `String` literal as to whether `"""` or `"` was used: + - `Literal String` -> `Literal StringLiteralType String` + - Added `type StringLiteralType = TripleQuote | SingleQuote` - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` @@ -44,6 +47,8 @@ - Changed `Elm.Syntax.Exposing.Exposing`: - `Explicit (List (Node TopLevelExpose))` -> `Explicit (Node TopLevelExpose) (List (Node TopLevelExpose))` (takes a non-empty list of elements) +- Added module `Elm.Syntax.StringLiteralType` containing `type StringLiteralType = TripleQuote | SingleQuote` + ## [7.3.4] - 2024-07-26 Parsing is faster by ~90%. A big thank you to [@lue-bird](https://github.com/lue-bird) for finding and introducing a huge amount of performance improvements. diff --git a/elm.json b/elm.json index 0b896574e..3a96a7ff0 100644 --- a/elm.json +++ b/elm.json @@ -22,6 +22,8 @@ "Elm.Syntax.Port", "Elm.Syntax.Range", "Elm.Syntax.Signature", + "Elm.Syntax.StringLiteralType", + "Elm.Syntax.TypeAlias", "Elm.Syntax.TypeAlias", "Elm.Syntax.TypeAnnotation", "Elm.Syntax.Type" diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 4716f453e..4f98f8b64 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -328,9 +328,9 @@ recordSetterNodeWithLayout = literalExpression : Parser (WithComments (Node Expression)) literalExpression = ParserFast.mapWithStartAndEndPosition - (\start string end -> + (\start ( stringLiteralType, string ) end -> { comments = Rope.empty - , syntax = Node { start = start, end = end } (Literal string) + , syntax = Node { start = start, end = end } (Literal stringLiteralType string) } ) Tokens.singleOrTripleQuotedStringLiteral diff --git a/src/Elm/Parser/Patterns.elm b/src/Elm/Parser/Patterns.elm index de6f3981f..0cf563b9d 100644 --- a/src/Elm/Parser/Patterns.elm +++ b/src/Elm/Parser/Patterns.elm @@ -235,7 +235,7 @@ stringPattern : Parser (WithComments (Node Pattern)) stringPattern = Tokens.singleOrTripleQuotedStringLiteral |> ParserFast.mapWithStartAndEndPosition - (\start string end -> + (\start ( _, string ) end -> { comments = Rope.empty , syntax = Node { start = start, end = end } (StringPattern string) diff --git a/src/Elm/Parser/Tokens.elm b/src/Elm/Parser/Tokens.elm index d0ed9a657..4a1957e73 100644 --- a/src/Elm/Parser/Tokens.elm +++ b/src/Elm/Parser/Tokens.elm @@ -22,6 +22,7 @@ module Elm.Parser.Tokens exposing import Char import Char.Extra +import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) import Hex import ParserFast import ParserFast.Advanced @@ -110,14 +111,17 @@ characterLiteral = (ParserFast.symbol "'" ()) -singleOrTripleQuotedStringLiteral : ParserFast.Parser String +singleOrTripleQuotedStringLiteral : ParserFast.Parser ( StringLiteralType, String ) singleOrTripleQuotedStringLiteral = ParserFast.symbolFollowedBy "\"" (ParserFast.oneOf2 (ParserFast.symbolFollowedBy "\"\"" (ParserFast.Advanced.loop "" tripleQuotedStringLiteralStep) + |> ParserFast.map (\str -> ( TripleQuote, str )) + ) + (ParserFast.Advanced.loop "" stringLiteralHelper + |> ParserFast.map (\str -> ( SingleQuote, str )) ) - (ParserFast.Advanced.loop "" stringLiteralHelper) ) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index c2f879fc6..dc121fb66 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -26,6 +26,7 @@ import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (Pattern) import Elm.Syntax.Range exposing (Range) import Elm.Syntax.Signature exposing (Signature) +import Elm.Syntax.StringLiteralType exposing (StringLiteralType) {-| Type alias for a full function @@ -113,7 +114,7 @@ type Expression | Hex Int | Floatable Float | Negation (Node Expression) - | Literal String + | Literal StringLiteralType String | CharLiteral Char | TupleExpression (List (Node Expression)) | LetExpression LetBlock diff --git a/src/Elm/Syntax/StringLiteralType.elm b/src/Elm/Syntax/StringLiteralType.elm new file mode 100644 index 000000000..d84ec6357 --- /dev/null +++ b/src/Elm/Syntax/StringLiteralType.elm @@ -0,0 +1,14 @@ +module Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) + +{-| Information about quotes. + +@docs StringLiteralType + +-} + + +{-| Indicates whether a string literal is single (`"abc"`) or triple-quoted (`"""abc"""`). +-} +type StringLiteralType + = SingleQuote + | TripleQuote diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index e84d89cd9..fad2a4f53 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -8,6 +8,7 @@ import Elm.Syntax.Expression exposing (..) import Elm.Syntax.Infix as Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (..) +import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) import Elm.Syntax.TypeAnnotation exposing (..) import Expect import Test exposing (..) @@ -425,7 +426,7 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } (Application (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal "Hello, World!") + [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal SingleQuote "Hello, World!") ] ) } @@ -449,7 +450,7 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } (Application (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal "Hello, World!") + [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal SingleQuote "Hello, World!") ] ) } diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 9ad50c551..597e83608 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -6,6 +6,7 @@ import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Expression exposing (Expression(..)) import Elm.Syntax.Infix as Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) +import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) import Expect import Test exposing (Test, describe, test) @@ -24,7 +25,7 @@ all = , test "String literal" <| \() -> "\"Bar\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (Literal "Bar")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (Literal SingleQuote "Bar")) , test "character literal" <| \() -> "'c'" @@ -54,7 +55,7 @@ all = , test "String literal multiline" <| \() -> "\"\"\"Bar foo \n a\"\"\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 6 } } (Literal "Bar foo \n a")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 6 } } (Literal TripleQuote "Bar foo \n a")) , test "Regression test for multiline strings with backslashes" <| \() -> "\"\"\"\\{\\}\"\"\"" @@ -62,11 +63,11 @@ all = , test "Regression test 2 for multiline strings with backslashes" <| \() -> "\"\"\"\\\\{\\\\}\"\"\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Literal "\\{\\}")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Literal TripleQuote "\\{\\}")) , test "Regression test 3 for multiline strings with backslashes" <| \() -> "\"\"\"\\\\a-blablabla-\\\\b\"\"\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 24 } } (Literal "\\a-blablabla-\\b")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 24 } } (Literal TripleQuote "\\a-blablabla-\\b")) , test "Type expression for upper case" <| \() -> "Bar" @@ -130,7 +131,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 48 } } <| TupleExpression - [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } <| Literal "" + [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } <| Literal SingleQuote "" , Node { start = { row = 1, column = 6 }, end = { row = 1, column = 47 } } <| Application (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 47 } } <| @@ -256,12 +257,12 @@ all = (ListExpr [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } (Application (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class")) - [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (Literal "a") + [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (Literal SingleQuote "a") ] ) , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 24 } } (Application (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (Literal "Foo") + [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (Literal SingleQuote "Foo") ] ) ] diff --git a/tests/Elm/Parser/TokenTests.elm b/tests/Elm/Parser/TokenTests.elm index fbd70c37f..f55f779c4 100644 --- a/tests/Elm/Parser/TokenTests.elm +++ b/tests/Elm/Parser/TokenTests.elm @@ -2,6 +2,7 @@ module Elm.Parser.TokenTests exposing (all) import Elm.Parser.TestUtil exposing (..) import Elm.Parser.Tokens as Parser +import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) import Expect import Test exposing (..) @@ -82,11 +83,11 @@ all = , test "multiline string" <| \() -> parse "\"\"\"Bar foo \n a\"\"\"" Parser.singleOrTripleQuotedStringLiteral - |> Expect.equal (Just "Bar foo \n a") + |> Expect.equal (Just ( TripleQuote, "Bar foo \n a" )) , test "multiline string escape" <| \() -> parse """\"\"\" \\\"\"\" \"\"\"""" Parser.singleOrTripleQuotedStringLiteral - |> Expect.equal (Just """ \"\"\" """) + |> Expect.equal (Just ( TripleQuote, """ \"\"\" """ )) , test "character escaped" <| \() -> parse "'\\''" Parser.characterLiteral @@ -106,11 +107,11 @@ all = , test "string escaped 3" <| \() -> parse "\"\\\"\"" Parser.singleOrTripleQuotedStringLiteral - |> Expect.equal (Just "\"") + |> Expect.equal (Just ( SingleQuote, "\"" )) , test "string escaped" <| \() -> parse "\"foo\\\\\"" Parser.singleOrTripleQuotedStringLiteral - |> Expect.equal (Just "foo\\") + |> Expect.equal (Just ( SingleQuote, "foo\\" )) , test "character escaped 3" <| \() -> parse "'\\n'" Parser.characterLiteral From 59e6df4af7d084f8779681e4372bb6204b41a747 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 27 Jun 2023 22:17:03 +0200 Subject: [PATCH 23/44] Rename IfBlock to If --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 6 +++--- tests/Elm/Parser/ExpressionTests.elm | 6 +++--- tests/Elm/Parser/ModuleTests.elm | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e009aeb7f..bc1dbd61d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` + - Renamed `IfBlock` to `If` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 4f98f8b64..dcfe7b835 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -770,7 +770,7 @@ ifBlockExpression = { comments = ifBlock.comments , syntax = Node { start = start, end = ifFalseRange.end } - (IfBlock + (If ifBlock.condition ifBlock.ifTrue ifBlock.ifFalse diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index dc121fb66..d55560772 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -81,7 +81,7 @@ type alias FunctionImplementation = - `Application`: `add a b` - `OperatorApplication`: `a + b` - `FunctionOrValue`: `add` or `True` - - `IfBlock`: `if a then b else c` + - `If`: `if a then b else c` - `PrefixOperator`: `(+)` - `Operator`: `+` (not possible to get in practice) - `Integer`: `42` @@ -107,7 +107,7 @@ type Expression = Application (Node Expression) (List (Node Expression)) | OperatorApplication String InfixDirection (Node Expression) (Node Expression) | FunctionOrValue ModuleName String - | IfBlock (Node Expression) (Node Expression) (Node Expression) + | If (Node Expression) (Node Expression) (Node Expression) | PrefixOperator String | Operator String | Integer Int @@ -202,7 +202,7 @@ isLet e = isIfElse : Expression -> Bool isIfElse e = case e of - IfBlock _ _ _ -> + If _ _ _ -> True _ -> diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 597e83608..9fa4e5146 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -186,7 +186,7 @@ all = "if True then foo else bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 26 } } - (IfBlock + (If (Node { start = { row = 1, column = 4 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "True")) (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 17 } } (FunctionOrValue [] "foo")) (Node { start = { row = 1, column = 23 }, end = { row = 1, column = 26 } } (FunctionOrValue [] "bar")) @@ -197,10 +197,10 @@ all = "if True then if False then foo else baz else bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 49 } } - (IfBlock + (If (Node { start = { row = 1, column = 4 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "True")) (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 40 } } - (IfBlock + (If (Node { start = { row = 1, column = 17 }, end = { row = 1, column = 22 } } (FunctionOrValue [] "False")) (Node { start = { row = 1, column = 28 }, end = { row = 1, column = 31 } } (FunctionOrValue [] "foo")) (Node { start = { row = 1, column = 37 }, end = { row = 1, column = 40 } } (FunctionOrValue [] "baz")) diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index d476d4c61..6c6c2206c 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -157,7 +157,7 @@ b = 3 , arguments = [] , expression = Node { start = { row = 4, column = 5 }, end = { row = 7, column = 10 } } - (IfBlock + (If (Node { start = { row = 4, column = 8 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "cond") ) From 2b1c107df25497028d77e354537eb4bb176d909a Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 27 Jun 2023 22:17:39 +0200 Subject: [PATCH 24/44] Rename Floatable to FloatLiteral --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc1dbd61d..402ec592f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` - Renamed `IfBlock` to `If` + - Renamed `Floatable` to `FloatLiteral` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index dcfe7b835..6030497c0 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -753,7 +753,7 @@ numberExpression = } ) (Elm.Parser.Numbers.floatOrIntOrHex - Floatable + FloatLiteral Integer Hex ) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index d55560772..216849bc4 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -86,7 +86,7 @@ type alias FunctionImplementation = - `Operator`: `+` (not possible to get in practice) - `Integer`: `42` - `Hex`: `0x1F` - - `Floatable`: `42.0` + - `FloatLiteral`: `42.0` - `Negation`: `-a` - `Literal`: `"text"` - `CharLiteral`: `'a'` @@ -112,7 +112,7 @@ type Expression | Operator String | Integer Int | Hex Int - | Floatable Float + | FloatLiteral Float | Negation (Node Expression) | Literal StringLiteralType String | CharLiteral Char From 5b586c054a7c71662cc917aceac0a5efceed6db3 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 27 Jun 2023 22:18:00 +0200 Subject: [PATCH 25/44] Rename Integer to IntegerLiteral --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 4 +- tests/Elm/Parser/CaseExpressionTests.elm | 22 +++++----- tests/Elm/Parser/DeclarationsTests.elm | 18 ++++---- tests/Elm/Parser/ExpressionTests.elm | 56 ++++++++++++------------ tests/Elm/Parser/FileTests.elm | 6 +-- tests/Elm/Parser/LetExpressionTests.elm | 22 +++++----- tests/Elm/Parser/ModuleTests.elm | 16 +++---- 9 files changed, 74 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 402ec592f..1a137840b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,7 @@ - Renamed `TupledExpression` to `TupleExpression` - Renamed `IfBlock` to `If` - Renamed `Floatable` to `FloatLiteral` + - Renamed `Integer` to `IntegerLiteral` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 6030497c0..db3bbbf63 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -754,7 +754,7 @@ numberExpression = ) (Elm.Parser.Numbers.floatOrIntOrHex FloatLiteral - Integer + IntegerLiteral Hex ) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 216849bc4..9e20d9216 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -84,7 +84,7 @@ type alias FunctionImplementation = - `If`: `if a then b else c` - `PrefixOperator`: `(+)` - `Operator`: `+` (not possible to get in practice) - - `Integer`: `42` + - `IntegerLiteral`: `42` - `Hex`: `0x1F` - `FloatLiteral`: `42.0` - `Negation`: `-a` @@ -110,7 +110,7 @@ type Expression | If (Node Expression) (Node Expression) (Node Expression) | PrefixOperator String | Operator String - | Integer Int + | IntegerLiteral Int | Hex Int | FloatLiteral Float | Negation (Node Expression) diff --git a/tests/Elm/Parser/CaseExpressionTests.elm b/tests/Elm/Parser/CaseExpressionTests.elm index 806122f3f..fd4924e23 100644 --- a/tests/Elm/Parser/CaseExpressionTests.elm +++ b/tests/Elm/Parser/CaseExpressionTests.elm @@ -51,13 +51,13 @@ True -> 1""" ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } <| NamedPattern (QualifiedNameRef [] "True") [] , Node { start = { row = 2, column = 11 }, end = { row = 2, column = 12 } } <| - Integer 1 + IntegerLiteral 1 ) , restOfCases = [ ( Node { start = { row = 3, column = 3 }, end = { row = 3, column = 8 } } <| NamedPattern (QualifiedNameRef [] "False") [] , Node { start = { row = 3, column = 12 }, end = { row = 3, column = 13 } } <| - Integer 2 + IntegerLiteral 2 ) ] } @@ -77,7 +77,7 @@ True -> 1""" ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 10 } } <| NamedPattern (QualifiedNameRef [ "Foo" ] "Bar") [] , Node { start = { row = 2, column = 14 }, end = { row = 2, column = 15 } } <| - Integer 1 + IntegerLiteral 1 ) , restOfCases = [] } @@ -97,7 +97,7 @@ True -> 1""" ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 4 } } <| VarPattern "x" , Node { start = { row = 2, column = 6 }, end = { row = 2, column = 7 } } <| - Integer 1 + IntegerLiteral 1 ) , restOfCases = [] } @@ -113,11 +113,11 @@ True -> 1""" { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "x") , firstCase = ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 15 } } (NamedPattern { moduleName = [], name = "True" } []) - , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (Integer 1) + , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (IntegerLiteral 1) ) , restOfCases = [ ( Node { start = { row = 2, column = 11 }, end = { row = 2, column = 16 } } (NamedPattern { moduleName = [], name = "False" } []) - , Node { start = { row = 2, column = 20 }, end = { row = 2, column = 21 } } (Integer 2) + , Node { start = { row = 2, column = 20 }, end = { row = 2, column = 21 } } (IntegerLiteral 2) ) ] } @@ -143,14 +143,14 @@ True -> 1""" (FunctionOrValue [] "x") , firstCase = ( Node { start = { row = 2, column = 9 }, end = { row = 2, column = 39 } } (StringPattern "single line triple quote") - , Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (Integer 1) + , Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (IntegerLiteral 1) ) , restOfCases = [ ( Node { start = { row = 4, column = 9 }, end = { row = 5, column = 28 } } (StringPattern "multi line\n triple quote") - , Node { start = { row = 6, column = 13 }, end = { row = 6, column = 14 } } (Integer 2) + , Node { start = { row = 6, column = 13 }, end = { row = 6, column = 14 } } (IntegerLiteral 2) ) , ( Node { start = { row = 7, column = 9 }, end = { row = 7, column = 10 } } AllPattern - , Node { start = { row = 7, column = 14 }, end = { row = 7, column = 15 } } (Integer 3) + , Node { start = { row = 7, column = 14 }, end = { row = 7, column = 15 } } (IntegerLiteral 3) ) ] } @@ -182,11 +182,11 @@ True -> 1""" { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 9 } } (FunctionOrValue [] "msg") , firstCase = ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 12 } } (NamedPattern { moduleName = [], name = "Increment" } []) - , Node { start = { row = 3, column = 5 }, end = { row = 3, column = 6 } } (Integer 1) + , Node { start = { row = 3, column = 5 }, end = { row = 3, column = 6 } } (IntegerLiteral 1) ) , restOfCases = [ ( Node { start = { row = 5, column = 3 }, end = { row = 5, column = 12 } } (NamedPattern { moduleName = [], name = "Decrement" } []) - , Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (Integer 2) + , Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (IntegerLiteral 2) ) ] } diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index fad2a4f53..730e9dc9a 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -150,7 +150,7 @@ foo = bar""" (OperatorApplication "+" Infix.Left (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (FunctionOrValue [] "x")) - (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 14 } } (Integer 1)) + (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 14 } } (IntegerLiteral 1)) ) } } @@ -184,7 +184,7 @@ foo = bar""" Node { start = { row = 3, column = 3 }, end = { row = 3, column = 8 } } { name = Node { start = { row = 3, column = 3 }, end = { row = 3, column = 4 } } "b" , arguments = [] - , expression = Node { start = { row = 3, column = 7 }, end = { row = 3, column = 8 } } (Integer 1) + , expression = Node { start = { row = 3, column = 7 }, end = { row = 3, column = 8 } } (IntegerLiteral 1) } } ) @@ -235,8 +235,8 @@ foo = bar""" ) (Node { start = { row = 3, column = 10 }, end = { row = 3, column = 16 } } (TupleExpression - [ Node { start = { row = 3, column = 11 }, end = { row = 3, column = 12 } } (Integer 1) - , Node { start = { row = 3, column = 14 }, end = { row = 3, column = 15 } } (Integer 2) + [ Node { start = { row = 3, column = 11 }, end = { row = 3, column = 12 } } (IntegerLiteral 1) + , Node { start = { row = 3, column = 14 }, end = { row = 3, column = 15 } } (IntegerLiteral 2) ] ) ) @@ -270,7 +270,7 @@ foo = bar""" (RecordExpr [ Node { start = { row = 2, column = 21 }, end = { row = 2, column = 30 } } ( Node { start = { row = 2, column = 21 }, end = { row = 2, column = 26 } } "model" - , Node { start = { row = 2, column = 29 }, end = { row = 2, column = 30 } } (Integer 0) + , Node { start = { row = 2, column = 29 }, end = { row = 2, column = 30 } } (IntegerLiteral 0) ) , Node { start = { row = 2, column = 32 }, end = { row = 2, column = 43 } } ( Node { start = { row = 2, column = 32 }, end = { row = 2, column = 36 } } "view" @@ -319,7 +319,7 @@ foo = bar""" (OperatorApplication "+" Left (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) - (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (Integer 1)) + (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (IntegerLiteral 1)) ) ) , restOfCases = @@ -328,7 +328,7 @@ foo = bar""" (OperatorApplication "-" Left (Node { start = { row = 7, column = 7 }, end = { row = 7, column = 12 } } (FunctionOrValue [] "model")) - (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (Integer 1)) + (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (IntegerLiteral 1)) ) ) ] @@ -553,7 +553,7 @@ foo = bar""" (OperatorApplication "+" Left (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) - (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (Integer 1)) + (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (IntegerLiteral 1)) ) ) , restOfCases = @@ -563,7 +563,7 @@ foo = bar""" (OperatorApplication "-" Left (Node { start = { row = 7, column = 7 }, end = { row = 7, column = 12 } } (FunctionOrValue [] "model")) - (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (Integer 1)) + (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (IntegerLiteral 1)) ) ) ] diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 9fa4e5146..fa3f280f9 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -18,10 +18,10 @@ all = \() -> "" |> expectInvalid - , test "Integer literal" <| + , test "IntegerLiteral literal" <| \() -> "101" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (Integer 101)) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (IntegerLiteral 101)) , test "String literal" <| \() -> "\"Bar\"" @@ -36,8 +36,8 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (TupleExpression - [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (Integer 1) - , Node { start = { row = 1, column = 4 }, end = { row = 1, column = 5 } } (Integer 2) + [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1) + , Node { start = { row = 1, column = 4 }, end = { row = 1, column = 5 } } (IntegerLiteral 2) ] ) ) @@ -47,8 +47,8 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } (TupleExpression - [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (Integer 1) - , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (Integer 2) + [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1) + , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (IntegerLiteral 2) ] ) ) @@ -99,7 +99,7 @@ all = (OperatorApplication "*" Left (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } - (Negation (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (Integer 1))) + (Negation (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1))) ) (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "sign")) ) @@ -123,7 +123,7 @@ all = OperatorApplication "+" Infix.Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } <| FunctionOrValue [] "model") - (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } <| Integer 1) + (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } <| IntegerLiteral 1) ) , test "application expression 2" <| \() -> @@ -217,7 +217,7 @@ all = (RecordExpr [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } ( Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } "model" - , Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } (Integer 0) + , Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } (IntegerLiteral 0) ) , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } ( Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } "view" @@ -239,11 +239,11 @@ all = (RecordExpr [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 10 } } ( Node { start = { row = 1, column = 3 }, end = { row = 1, column = 6 } } "foo" - , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (Integer 1) + , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (IntegerLiteral 1) ) , Node { start = { row = 2, column = 4 }, end = { row = 2, column = 12 } } ( Node { start = { row = 2, column = 4 }, end = { row = 2, column = 7 } } "baz" - , Node { start = { row = 2, column = 10 }, end = { row = 2, column = 11 } } (Integer 2) + , Node { start = { row = 2, column = 10 }, end = { row = 2, column = 11 } } (IntegerLiteral 2) ) ] ) @@ -275,7 +275,7 @@ all = { ast = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } } (ListExpr - [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (Integer 1) + [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1) ] ) , comments = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 13 } } "{- Foo-}" ] @@ -340,7 +340,7 @@ all = (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } "model") (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 20 } } ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } "count" - , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (Integer 1) + , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (IntegerLiteral 1) ) ) [ Node { start = { row = 1, column = 22 }, end = { row = 1, column = 37 } } @@ -359,7 +359,7 @@ all = (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } "model") (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 18 } } ( Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } "count" - , Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (Integer 1) + , Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (IntegerLiteral 1) ) ) [ Node { start = { row = 1, column = 20 }, end = { row = 1, column = 35 } } @@ -420,8 +420,8 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (OperatorApplication "-" Left - (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (Integer 2)) - (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (Integer 1)) + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (IntegerLiteral 2)) + (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1)) ) ) , test "negated expression for value" <| @@ -438,7 +438,7 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "toFloat")) [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 11 } } - (Negation (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } (Integer 5))) + (Negation (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } (IntegerLiteral 5))) ] ) ) @@ -472,23 +472,23 @@ all = (OperatorApplication "+" Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 3 } } - (Negation (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (Integer 1))) + (Negation (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1))) ) (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 18 } } (OperatorApplication "*" Left (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 9 } } - (Negation (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (Integer 10))) + (Negation (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (IntegerLiteral 10))) ) (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 18 } } (OperatorApplication "^" Right (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 16 } } (Negation - (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } (Integer 100)) + (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } (IntegerLiteral 100)) ) ) - (Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (Integer 2)) + (Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (IntegerLiteral 2)) ) ) ) @@ -496,7 +496,7 @@ all = ) ) (Node { start = { row = 1, column = 22 }, end = { row = 1, column = 29 } } - (Negation (Node { start = { row = 1, column = 23 }, end = { row = 1, column = 29 } } (Integer 100001))) + (Negation (Node { start = { row = 1, column = 23 }, end = { row = 1, column = 29 } } (IntegerLiteral 100001))) ) ) ) @@ -511,11 +511,11 @@ all = (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } (OperatorApplication "+" Left - (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (Integer 1)) - (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (Integer 2)) + (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1)) + (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (IntegerLiteral 2)) ) ) - (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } (Integer 3)) + (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } (IntegerLiteral 3)) ) ) , test "pipe operation" <| @@ -621,7 +621,7 @@ all = [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } (Negation (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } - (Integer 1) + (IntegerLiteral 1) ) ) , Node { start = { row = 1, column = 16 }, end = { row = 1, column = 25 } } (FunctionOrValue [] "generator") @@ -635,7 +635,7 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } (OperatorApplication "+" Left - (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (Integer 1)) + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (IntegerLiteral 1)) (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 16 } } (Negation (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 16 } } @@ -644,7 +644,7 @@ all = (RecordExpr [ Node { start = { row = 1, column = 7 }, end = { row = 1, column = 13 } } ( Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } "x" - , Node { start = { row = 1, column = 11 }, end = { row = 1, column = 13 } } (Integer 10) + , Node { start = { row = 1, column = 11 }, end = { row = 1, column = 13 } } (IntegerLiteral 10) ) ] ) diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index 049406495..1f916d653 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -163,11 +163,11 @@ caseWhitespace f = case f of { expression = Node { start = { row = 4, column = 25 }, end = { row = 4, column = 26 } } (FunctionOrValue [] "f") , firstCase = ( Node { start = { row = 5, column = 3 }, end = { row = 5, column = 7 } } (NamedPattern { moduleName = [], name = "True" } []) - , Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (Integer 1) + , Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (IntegerLiteral 1) ) , restOfCases = [ ( Node { start = { row = 7, column = 3 }, end = { row = 7, column = 8 } } (NamedPattern { moduleName = [], name = "False" } []) - , Node { start = { row = 11, column = 10 }, end = { row = 11, column = 11 } } (Integer 2) + , Node { start = { row = 11, column = 10 }, end = { row = 11, column = 11 } } (IntegerLiteral 2) ) ] } @@ -287,7 +287,7 @@ letWhitespace = let Node { start = { row = 5, column = 19 }, end = { row = 5, column = 26 } } { name = Node { start = { row = 5, column = 19 }, end = { row = 5, column = 20 } } "b" , arguments = [] - , expression = Node { start = { row = 5, column = 25 }, end = { row = 5, column = 26 } } (Integer 1) + , expression = Node { start = { row = 5, column = 25 }, end = { row = 5, column = 26 } } (IntegerLiteral 1) } } ) diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index 8a37cc749..fce6d7038 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -48,7 +48,7 @@ all = } ) ] - , expression = Node { start = { row = 4, column = 17 }, end = { row = 4, column = 18 } } (Integer 1) + , expression = Node { start = { row = 4, column = 17 }, end = { row = 4, column = 18 } } (IntegerLiteral 1) } ) ) @@ -70,7 +70,7 @@ all = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 10 } } { name = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 6 } } "bar" , arguments = [] - , expression = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } (Integer 1) + , expression = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } (IntegerLiteral 1) } } ) @@ -112,7 +112,7 @@ all = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 10 } } { name = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 6 } } "bar" , arguments = [] - , expression = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } (Integer 1) + , expression = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } (IntegerLiteral 1) } } ) @@ -148,7 +148,7 @@ all = Node { start = { row = 3, column = 5 }, end = { row = 3, column = 12 } } { name = Node { start = { row = 3, column = 5 }, end = { row = 3, column = 8 } } "bar" , arguments = [] - , expression = Node { start = { row = 3, column = 11 }, end = { row = 3, column = 12 } } (Integer 1) + , expression = Node { start = { row = 3, column = 11 }, end = { row = 3, column = 12 } } (IntegerLiteral 1) } } ) @@ -184,7 +184,7 @@ all = Node { start = { row = 5, column = 5 }, end = { row = 5, column = 12 } } { name = Node { start = { row = 5, column = 5 }, end = { row = 5, column = 8 } } "bar" , arguments = [] - , expression = Node { start = { row = 5, column = 11 }, end = { row = 5, column = 12 } } (Integer 1) + , expression = Node { start = { row = 5, column = 11 }, end = { row = 5, column = 12 } } (IntegerLiteral 1) } } ) @@ -237,7 +237,7 @@ all = [ Node { start = { row = 2, column = 15 }, end = { row = 2, column = 18 } } (NamedPattern_ { moduleName = [], name = "Bar" } []) , Node { start = { row = 2, column = 19 }, end = { row = 2, column = 20 } } (VarPattern_ "m") ] - , expression = Node { start = { row = 2, column = 23 }, end = { row = 2, column = 24 } } (Integer 1) + , expression = Node { start = { row = 2, column = 23 }, end = { row = 2, column = 24 } } (IntegerLiteral 1) } } ) @@ -340,7 +340,7 @@ all = (Node { start = { row = 5, column = 18 }, end = { row = 5, column = 19 } } (FunctionOrValue [] "g")) ) ] - , expression = Node { start = { row = 7, column = 5 }, end = { row = 7, column = 6 } } (Integer 1) + , expression = Node { start = { row = 7, column = 5 }, end = { row = 7, column = 6 } } (IntegerLiteral 1) } ) ) @@ -391,7 +391,7 @@ all = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 14 } } { name = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } "a" , arguments = [] - , expression = Node { start = { row = 2, column = 13 }, end = { row = 2, column = 14 } } (Integer 1) + , expression = Node { start = { row = 2, column = 13 }, end = { row = 2, column = 14 } } (IntegerLiteral 1) } } ) @@ -417,7 +417,7 @@ all = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 14 } } { name = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } "a" , arguments = [] - , expression = Node { start = { row = 2, column = 13 }, end = { row = 2, column = 14 } } (Integer 1) + , expression = Node { start = { row = 2, column = 13 }, end = { row = 2, column = 14 } } (IntegerLiteral 1) } } ) @@ -443,7 +443,7 @@ all = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 14 } } { name = Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } "a" , arguments = [] - , expression = Node { start = { row = 2, column = 13 }, end = { row = 2, column = 14 } } (Integer 1) + , expression = Node { start = { row = 2, column = 13 }, end = { row = 2, column = 14 } } (IntegerLiteral 1) } } ) @@ -453,7 +453,7 @@ all = (LambdaExpression { firstArg = Node { start = { row = 3, column = 8 }, end = { row = 3, column = 9 } } AllPattern_ , restOfArgs = [] - , expression = Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (Integer 1) + , expression = Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (IntegerLiteral 1) } ) } diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index 6c6c2206c..5aa830431 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -161,7 +161,7 @@ b = 3 (Node { start = { row = 4, column = 8 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "cond") ) - (Node { start = { row = 5, column = 9 }, end = { row = 5, column = 10 } } (Integer 1)) + (Node { start = { row = 5, column = 9 }, end = { row = 5, column = 10 } } (IntegerLiteral 1)) (Node { start = { row = 7 @@ -169,7 +169,7 @@ b = 3 } , end = { row = 7, column = 10 } } - (Integer 2) + (IntegerLiteral 2) ) ) } @@ -189,7 +189,7 @@ b = 3 } { name = Node { start = { row = 13, column = 1 }, end = { row = 13, column = 2 } } "b" , arguments = [] - , expression = Node { start = { row = 13, column = 5 }, end = { row = 13, column = 6 } } (Integer 3) + , expression = Node { start = { row = 13, column = 5 }, end = { row = 13, column = 6 } } (IntegerLiteral 3) } } ) @@ -245,7 +245,7 @@ b = 3 { start = { row = 4, column = 5 } , end = { row = 4, column = 6 } } - (Integer 2) + (IntegerLiteral 2) } } ) @@ -265,7 +265,7 @@ b = 3 { start = { row = 10, column = 5 } , end = { row = 10, column = 6 } } - (Integer 3) + (IntegerLiteral 3) } } ) @@ -315,7 +315,7 @@ a = 1 Node { start = { row = 5, column = 1 }, end = { row = 5, column = 6 } } { name = Node { start = { row = 5, column = 1 }, end = { row = 5, column = 2 } } "a" , arguments = [] - , expression = Node { start = { row = 5, column = 5 }, end = { row = 5, column = 6 } } (Integer 1) + , expression = Node { start = { row = 5, column = 5 }, end = { row = 5, column = 6 } } (IntegerLiteral 1) } } ) @@ -371,7 +371,7 @@ b = 2 Node { start = { row = 3, column = 1 }, end = { row = 3, column = 6 } } { name = Node { start = { row = 3, column = 1 }, end = { row = 3, column = 2 } } "a" , arguments = [] - , expression = Node { start = { row = 3, column = 5 }, end = { row = 3, column = 6 } } (Integer 1) + , expression = Node { start = { row = 3, column = 5 }, end = { row = 3, column = 6 } } (IntegerLiteral 1) } } ) @@ -399,7 +399,7 @@ b = 2 Node { start = { row = 6, column = 1 }, end = { row = 6, column = 6 } } { name = Node { start = { row = 6, column = 1 }, end = { row = 6, column = 2 } } "b" , arguments = [] - , expression = Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (Integer 2) + , expression = Node { start = { row = 6, column = 5 }, end = { row = 6, column = 6 } } (IntegerLiteral 2) } } ) From 56bc44bcf5507d294348e33ffb01d0cd861ef5c6 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 27 Jun 2023 22:18:32 +0200 Subject: [PATCH 26/44] Rename Hex to HexLiteral --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a137840b..6e27c805d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ - Renamed `IfBlock` to `If` - Renamed `Floatable` to `FloatLiteral` - Renamed `Integer` to `IntegerLiteral` + - Renamed `Hex` to `HexLiteral` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index db3bbbf63..b1c0d8fd1 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -755,7 +755,7 @@ numberExpression = (Elm.Parser.Numbers.floatOrIntOrHex FloatLiteral IntegerLiteral - Hex + HexLiteral ) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 9e20d9216..ff2ec3377 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -85,7 +85,7 @@ type alias FunctionImplementation = - `PrefixOperator`: `(+)` - `Operator`: `+` (not possible to get in practice) - `IntegerLiteral`: `42` - - `Hex`: `0x1F` + - `HexLiteral`: `0x1F` - `FloatLiteral`: `42.0` - `Negation`: `-a` - `Literal`: `"text"` @@ -111,7 +111,7 @@ type Expression | PrefixOperator String | Operator String | IntegerLiteral Int - | Hex Int + | HexLiteral Int | FloatLiteral Float | Negation (Node Expression) | Literal StringLiteralType String From 65ad689e5c74f9b4bd4498804503c7e6e1e316a1 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 27 Jun 2023 22:19:12 +0200 Subject: [PATCH 27/44] Rename ListExpr to ListLiteral --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 4 ++-- src/Elm/Syntax/Expression.elm | 4 ++-- tests/Elm/Parser/ExpressionTests.elm | 14 +++++++------- tests/Elm/Parser/LetExpressionTests.elm | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e27c805d..9e4dfecbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ - Renamed `Floatable` to `FloatLiteral` - Renamed `Integer` to `IntegerLiteral` - Renamed `Hex` to `HexLiteral` + - Renamed `ListExpr` to `ListLiteral` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index b1c0d8fd1..aa7cba2bd 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -188,14 +188,14 @@ expressionAfterOpeningSquareBracket = ) Layout.maybeLayout (ParserFast.oneOf2 - (ParserFast.symbol "]" { comments = Rope.empty, syntax = ListExpr [] }) + (ParserFast.symbol "]" { comments = Rope.empty, syntax = ListLiteral [] }) (ParserFast.map4 (\head commentsAfterHead tail () -> { comments = head.comments |> Rope.prependTo commentsAfterHead |> Rope.prependTo tail.comments - , syntax = ListExpr (head.syntax :: tail.syntax) + , syntax = ListLiteral (head.syntax :: tail.syntax) } ) expression diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index ff2ec3377..80501f12b 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -96,7 +96,7 @@ type alias FunctionImplementation = - `CaseExpression`: `case a of` followed by pattern matches - `LambdaExpression`: `(\a -> a)` - `RecordExpr`: `{ name = "text" }` - - `ListExpr`: `[ x, y ]` + - `ListLiteral`: `[ x, y ]` - `RecordAccess`: `a.name` - `RecordAccessFunction`: `.name` - `RecordUpdateExpression`: `{ a | name = "text" }` @@ -121,7 +121,7 @@ type Expression | CaseExpression CaseBlock | LambdaExpression Lambda | RecordExpr (List (Node RecordSetter)) - | ListExpr (List (Node Expression)) + | ListLiteral (List (Node Expression)) | RecordAccess (Node Expression) (Node String) | RecordAccessFunction String | RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter)) diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index fa3f280f9..824c97d22 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -112,7 +112,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } } <| Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } <| FunctionOrValue [ "List" ] "concat") - [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } <| ListExpr [] + [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } (ListLiteral []) ] ) , test "application expression with operator" <| @@ -139,14 +139,14 @@ all = [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 46 } } <| Application (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } (FunctionOrValue [ "List" ] "concat")) [ Node { start = { row = 1, column = 26 }, end = { row = 1, column = 46 } } <| - ListExpr + ListLiteral [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 40 } } <| - ListExpr + ListLiteral [ Node { start = { row = 1, column = 30 }, end = { row = 1, column = 38 } } <| FunctionOrValue [] "fileName" ] , Node { start = { row = 1, column = 42 }, end = { row = 1, column = 44 } } <| - ListExpr [] + ListLiteral [] ] ] ] @@ -254,7 +254,7 @@ all = "[ class \"a\", text \"Foo\"]" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } - (ListExpr + (ListLiteral [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } (Application (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class")) [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (Literal SingleQuote "a") @@ -274,7 +274,7 @@ all = |> expectAstWithComments { ast = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } } - (ListExpr + (ListLiteral [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1) ] ) @@ -284,7 +284,7 @@ all = \() -> "[{- Foo -}]" |> expectAstWithComments - { ast = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } (ListExpr []) + { ast = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } (ListLiteral []) , comments = [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 11 } } "{- Foo -}" ] } , test "qualified expression" <| diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index fce6d7038..2299327cd 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -396,7 +396,7 @@ all = } ) ] - , expression = Node { start = { row = 3, column = 7 }, end = { row = 3, column = 9 } } (ListExpr []) + , expression = Node { start = { row = 3, column = 7 }, end = { row = 3, column = 9 } } (ListLiteral []) } ) ) From be239e26c1ea9eadee612bd529c4dc9cf7b60846 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 27 Jun 2023 22:19:54 +0200 Subject: [PATCH 28/44] Rename Literal to StringLiteral --- CHANGELOG.md | 3 ++- src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 4 ++-- tests/Elm/Parser/DeclarationsTests.elm | 4 ++-- tests/Elm/Parser/ExpressionTests.elm | 14 +++++++------- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e4dfecbd..64413aaf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,8 +23,9 @@ - Changed `Elm.Syntax.Expression.Expression`: - **WARNING (will not result in compilation error)** Stripped the `.` in the `String` stored in `RecordAccessFunction` (for code like `.field`) - Example: `RecordAccessFunction ".field"` -> `RecordAccessFunction "field"` + - Renamed `Literal` to `StringLiteral` - Added information to `String` literal as to whether `"""` or `"` was used: - - `Literal String` -> `Literal StringLiteralType String` + - `Literal String` -> `StringLiteral StringLiteralType String` - Added `type StringLiteralType = TripleQuote | SingleQuote` - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index aa7cba2bd..d70d7ea66 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -330,7 +330,7 @@ literalExpression = ParserFast.mapWithStartAndEndPosition (\start ( stringLiteralType, string ) end -> { comments = Rope.empty - , syntax = Node { start = start, end = end } (Literal stringLiteralType string) + , syntax = Node { start = start, end = end } (StringLiteral stringLiteralType string) } ) Tokens.singleOrTripleQuotedStringLiteral diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 80501f12b..1a17d492a 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -88,7 +88,7 @@ type alias FunctionImplementation = - `HexLiteral`: `0x1F` - `FloatLiteral`: `42.0` - `Negation`: `-a` - - `Literal`: `"text"` + - `StringLiteral`: `"text"` or `"""text"""` - `CharLiteral`: `'a'` - `TupleExpression`: `(a, b)` or `(a, b, c)` - `ParenthesizedExpression`: `(a)` @@ -114,7 +114,7 @@ type Expression | HexLiteral Int | FloatLiteral Float | Negation (Node Expression) - | Literal StringLiteralType String + | StringLiteral StringLiteralType String | CharLiteral Char | TupleExpression (List (Node Expression)) | LetExpression LetBlock diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 730e9dc9a..71f2b00a0 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -426,7 +426,7 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } (Application (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal SingleQuote "Hello, World!") + [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (StringLiteral SingleQuote "Hello, World!") ] ) } @@ -450,7 +450,7 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } (Application (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (Literal SingleQuote "Hello, World!") + [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (StringLiteral SingleQuote "Hello, World!") ] ) } diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 824c97d22..6ab1b1a45 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -25,7 +25,7 @@ all = , test "String literal" <| \() -> "\"Bar\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (Literal SingleQuote "Bar")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (StringLiteral SingleQuote "Bar")) , test "character literal" <| \() -> "'c'" @@ -55,7 +55,7 @@ all = , test "String literal multiline" <| \() -> "\"\"\"Bar foo \n a\"\"\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 6 } } (Literal TripleQuote "Bar foo \n a")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 6 } } (StringLiteral TripleQuote "Bar foo \n a")) , test "Regression test for multiline strings with backslashes" <| \() -> "\"\"\"\\{\\}\"\"\"" @@ -63,11 +63,11 @@ all = , test "Regression test 2 for multiline strings with backslashes" <| \() -> "\"\"\"\\\\{\\\\}\"\"\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (Literal TripleQuote "\\{\\}")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (StringLiteral TripleQuote "\\{\\}")) , test "Regression test 3 for multiline strings with backslashes" <| \() -> "\"\"\"\\\\a-blablabla-\\\\b\"\"\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 24 } } (Literal TripleQuote "\\a-blablabla-\\b")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 24 } } (StringLiteral TripleQuote "\\a-blablabla-\\b")) , test "Type expression for upper case" <| \() -> "Bar" @@ -131,7 +131,7 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 48 } } <| TupleExpression - [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } <| Literal SingleQuote "" + [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } <| StringLiteral SingleQuote "" , Node { start = { row = 1, column = 6 }, end = { row = 1, column = 47 } } <| Application (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 47 } } <| @@ -257,12 +257,12 @@ all = (ListLiteral [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } (Application (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class")) - [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (Literal SingleQuote "a") + [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (StringLiteral SingleQuote "a") ] ) , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 24 } } (Application (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (Literal SingleQuote "Foo") + [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (StringLiteral SingleQuote "Foo") ] ) ] From 5005b4f295fa4f7272a0a58a2c23036c18e56334 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Tue, 27 Jun 2023 22:21:55 +0200 Subject: [PATCH 29/44] Rename OperatorApplication to Operation --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 6 ++-- tests/Elm/Parser/DeclarationsTests.elm | 14 ++++----- tests/Elm/Parser/ExpressionTests.elm | 34 +++++++++++----------- tests/Elm/Parser/FileTests.elm | 2 +- tests/Elm/Parser/LambdaExpressionTests.elm | 4 +-- tests/Elm/Parser/ModuleTests.elm | 2 +- tests/Elm/Parser/Samples.elm | 2 +- 9 files changed, 34 insertions(+), 33 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64413aaf5..442e5940f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,7 @@ - Renamed `Integer` to `IntegerLiteral` - Renamed `Hex` to `HexLiteral` - Renamed `ListExpr` to `ListLiteral` + - Renamed `OperatorApplication` to `Operation` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index d70d7ea66..21ff873ab 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -1135,7 +1135,7 @@ applyExtensionRight extensionRight ((Node { start } left) as leftNode) = extendRightOperation.expression in Node { start = start, end = end } - (OperatorApplication extendRightOperation.symbol extendRightOperation.direction leftNode right) + (Operation extendRightOperation.symbol extendRightOperation.direction leftNode right) abovePrecedence0 : Parser (WithComments ExtensionRight) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 1a17d492a..0f6bbfcb1 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -79,7 +79,7 @@ type alias FunctionImplementation = - `Unit`: `()` - `Application`: `add a b` - - `OperatorApplication`: `a + b` + - `Operation`: `a + b` - `FunctionOrValue`: `add` or `True` - `If`: `if a then b else c` - `PrefixOperator`: `(+)` @@ -105,7 +105,7 @@ type alias FunctionImplementation = -} type Expression = Application (Node Expression) (List (Node Expression)) - | OperatorApplication String InfixDirection (Node Expression) (Node Expression) + | Operation String InfixDirection (Node Expression) (Node Expression) | FunctionOrValue ModuleName String | If (Node Expression) (Node Expression) (Node Expression) | PrefixOperator String @@ -226,7 +226,7 @@ isCase e = isOperatorApplication : Expression -> Bool isOperatorApplication e = case e of - OperatorApplication _ _ _ _ -> + Operation _ _ _ _ -> True _ -> diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 71f2b00a0..2630cf962 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -147,7 +147,7 @@ foo = bar""" , arguments = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 6 } } (VarPattern_ "x") ] , expression = Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } - (OperatorApplication "+" + (Operation "+" Infix.Left (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (FunctionOrValue [] "x")) (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 14 } } (IntegerLiteral 1)) @@ -316,7 +316,7 @@ foo = bar""" , firstCase = ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } (NamedPattern { moduleName = [], name = "Increment" } []) , Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (IntegerLiteral 1)) @@ -325,7 +325,7 @@ foo = bar""" , restOfCases = [ ( Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } (NamedPattern { moduleName = [], name = "Decrement" } []) , Node { start = { row = 7, column = 7 }, end = { row = 7, column = 16 } } - (OperatorApplication "-" + (Operation "-" Left (Node { start = { row = 7, column = 7 }, end = { row = 7, column = 12 } } (FunctionOrValue [] "model")) (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (IntegerLiteral 1)) @@ -491,11 +491,11 @@ foo = bar""" , arguments = [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 19 } } (VarPattern_ "update"), Node { start = { row = 1, column = 20 }, end = { row = 1, column = 28 } } (VarPattern_ "sendPort") ] , expression = Node { start = { row = 1, column = 31 }, end = { row = 1, column = 83 } } - (OperatorApplication "<|" + (Operation "<|" Right (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 36 } } (FunctionOrValue [] "curry")) (Node { start = { row = 1, column = 40 }, end = { row = 1, column = 83 } } - (OperatorApplication ">>" + (Operation ">>" Right (Node { start = { row = 1, column = 40 }, end = { row = 1, column = 56 } } (TupleExpression @@ -550,7 +550,7 @@ foo = bar""" ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } (NamedPattern { moduleName = [], name = "Increment" } []) , Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (IntegerLiteral 1)) @@ -560,7 +560,7 @@ foo = bar""" [ ( Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } (NamedPattern { moduleName = [], name = "Decrement" } []) , Node { start = { row = 7, column = 7 }, end = { row = 7, column = 16 } } - (OperatorApplication "-" + (Operation "-" Left (Node { start = { row = 7, column = 7 }, end = { row = 7, column = 12 } } (FunctionOrValue [] "model")) (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (IntegerLiteral 1)) diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 6ab1b1a45..86882a783 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -96,7 +96,7 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } (TupleExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 11 } } - (OperatorApplication "*" + (Operation "*" Left (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } (Negation (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1))) @@ -120,7 +120,7 @@ all = "model + 1" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } } <| - OperatorApplication "+" + Operation "+" Infix.Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } <| FunctionOrValue [] "model") (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } <| IntegerLiteral 1) @@ -418,7 +418,7 @@ all = "2-1" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } - (OperatorApplication "-" + (Operation "-" Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (IntegerLiteral 2)) (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1)) @@ -451,7 +451,7 @@ all = (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 9 } } (TupleExpression [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } - (OperatorApplication "-" + (Operation "-" Left (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "x")) (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "y")) @@ -466,22 +466,22 @@ all = "-1 + -10 * -100^2 == -100001" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 29 } } - (OperatorApplication "==" + (Operation "==" Non (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 18 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 3 } } (Negation (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1))) ) (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 18 } } - (OperatorApplication "*" + (Operation "*" Left (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 9 } } (Negation (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (IntegerLiteral 10))) ) (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 18 } } - (OperatorApplication "^" + (Operation "^" Right (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 16 } } (Negation @@ -506,10 +506,10 @@ all = |> expectAst (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 11 } } - (OperatorApplication "-" + (Operation "-" Left (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1)) (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (IntegerLiteral 2)) @@ -523,7 +523,7 @@ all = "a |> b" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } - (OperatorApplication "|>" + (Operation "|>" Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (FunctionOrValue [] "a")) (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "b")) @@ -543,20 +543,20 @@ all = , restOfArgs = [] , expression = Node { start = { row = 1, column = 19 }, end = { row = 1, column = 53 } } - (OperatorApplication "||" + (Operation "||" Right (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 27 } } - (OperatorApplication "==" + (Operation "==" Non (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (FunctionOrValue [] "c")) (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 27 } } (CharLiteral ' ')) ) ) (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 53 } } - (OperatorApplication "||" + (Operation "||" Right (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 40 } } - (OperatorApplication "==" + (Operation "==" Non (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 32 } } (FunctionOrValue [] "c")) (Node { start = { row = 1, column = 36 }, end = { row = 1, column = 40 } } @@ -565,7 +565,7 @@ all = ) ) (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 53 } } - (OperatorApplication "==" + (Operation "==" Non (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 45 } } (FunctionOrValue [] "c")) (Node { start = { row = 1, column = 49 }, end = { row = 1, column = 53 } } @@ -633,7 +633,7 @@ all = "1 + -{x = 10}.x" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (IntegerLiteral 1)) (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 16 } } diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index 1f916d653..2518aa535 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -224,7 +224,7 @@ lambdaWhitespace = \\ a b -> a [ Node { start = { row = 4, column = 26 }, end = { row = 4, column = 27 } } (VarPattern_ "b") ] , expression = Node { start = { row = 4, column = 34 }, end = { row = 8, column = 6 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 4, column = 34 }, end = { row = 4, column = 35 } } (FunctionOrValue [] "a")) (Node { start = { row = 8, column = 5 }, end = { row = 8, column = 6 } } (FunctionOrValue [] "b")) diff --git a/tests/Elm/Parser/LambdaExpressionTests.elm b/tests/Elm/Parser/LambdaExpressionTests.elm index 9f7d5613e..0a74664bb 100644 --- a/tests/Elm/Parser/LambdaExpressionTests.elm +++ b/tests/Elm/Parser/LambdaExpressionTests.elm @@ -61,7 +61,7 @@ all = ] , expression = Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (FunctionOrValue [] "a")) (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 14 } } (FunctionOrValue [] "b")) @@ -85,7 +85,7 @@ all = , restOfArgs = [] , expression = Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } (FunctionOrValue [] "a")) (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "b")) diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index 5aa830431..f2e64aead 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -461,7 +461,7 @@ fun2 n = , arguments = [ Node { start = { row = 3, column = 6 }, end = { row = 3, column = 7 } } (VarPattern_ "n") ] , expression = Node { start = { row = 4, column = 3 }, end = { row = 5, column = 11 } } - (OperatorApplication "+" + (Operation "+" Left (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 9 } } (Application diff --git a/tests/Elm/Parser/Samples.elm b/tests/Elm/Parser/Samples.elm index d58bf598e..24adbce57 100644 --- a/tests/Elm/Parser/Samples.elm +++ b/tests/Elm/Parser/Samples.elm @@ -208,7 +208,7 @@ module B exposing (x) c = Maybe.map (\\( p, v, s ) -> - OperatorApplication + Operation ) From 0024f446e6bd846a681fa3a7ebcb38003df3835f Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Wed, 28 Jun 2023 08:54:54 +0200 Subject: [PATCH 30/44] Update docs for TupleExpression --- src/Elm/Syntax/Expression.elm | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 0f6bbfcb1..39c1d6ad4 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -77,7 +77,6 @@ type alias FunctionImplementation = {-| Custom type for all expressions such as: - - `Unit`: `()` - `Application`: `add a b` - `Operation`: `a + b` - `FunctionOrValue`: `add` or `True` @@ -90,8 +89,7 @@ type alias FunctionImplementation = - `Negation`: `-a` - `StringLiteral`: `"text"` or `"""text"""` - `CharLiteral`: `'a'` - - `TupleExpression`: `(a, b)` or `(a, b, c)` - - `ParenthesizedExpression`: `(a)` + - `TupleExpression`: Something wrapped in parentheses like unit `()`, parentheses `(a)`, or a tuple `( a, b )` - `LetExpression`: `let a = 4 in a` - `CaseExpression`: `case a of` followed by pattern matches - `LambdaExpression`: `(\a -> a)` From 7c38155e0fa209fe516a7549a2c9ec06006306d3 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Wed, 28 Jun 2023 08:58:03 +0200 Subject: [PATCH 31/44] Rename RecordUpdateExpression to RecordUpdate --- CHANGELOG.md | 3 ++- src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 4 ++-- tests/Elm/Parser/ExpressionTests.elm | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 442e5940f..f0ab04c20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,8 @@ - `Literal String` -> `StringLiteral StringLiteralType String` - Added `type StringLiteralType = TripleQuote | SingleQuote` - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) + - Renamed `RecordUpdateExpression` to `RecordUpdate` + - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdate (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` - Renamed `IfBlock` to `If` - Renamed `Floatable` to `FloatLiteral` diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 21ff873ab..ffa923986 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -244,7 +244,7 @@ recordContentsCurlyEnd = , syntax = case afterNameBeforeFields.syntax of RecordUpdateFirstSetter firstField -> - RecordUpdateExpression nameNode firstField tailFields.syntax + RecordUpdate nameNode firstField tailFields.syntax FieldsFirstValue firstFieldValue -> RecordExpr (Node.combine Tuple.pair nameNode firstFieldValue :: tailFields.syntax) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 39c1d6ad4..0cf306ace 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -97,7 +97,7 @@ type alias FunctionImplementation = - `ListLiteral`: `[ x, y ]` - `RecordAccess`: `a.name` - `RecordAccessFunction`: `.name` - - `RecordUpdateExpression`: `{ a | name = "text" }` + - `RecordUpdate`: `{ a | name = "text" }` - `GLSLExpression`: `[glsl| ... |]` -} @@ -122,7 +122,7 @@ type Expression | ListLiteral (List (Node Expression)) | RecordAccess (Node Expression) (Node String) | RecordAccessFunction String - | RecordUpdateExpression (Node String) (Node RecordSetter) (List (Node RecordSetter)) + | RecordUpdate (Node String) (Node RecordSetter) (List (Node RecordSetter)) | GLSLExpression String diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 86882a783..4d975e15c 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -336,7 +336,7 @@ all = "{ model | count = 1, loading = True }" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 38 } } - (RecordUpdateExpression + (RecordUpdate (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } "model") (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 20 } } ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } "count" @@ -355,7 +355,7 @@ all = "{model| count = 1, loading = True }" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 36 } } - (RecordUpdateExpression + (RecordUpdate (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } "model") (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 18 } } ( Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } "count" @@ -592,7 +592,7 @@ all = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 24 } } (RecordAccess (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 22 } } - (RecordUpdateExpression (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } "d") + (RecordUpdate (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } "d") (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 21 } } ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } "b" , Node { start = { row = 1, column = 15 }, end = { row = 1, column = 20 } } From b0176d94722b1618f175763f3584fb4c4f1af202 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 30 Jun 2023 19:48:55 +0200 Subject: [PATCH 32/44] Rename Expression.RecordExpr to Record --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 4 ++-- src/Elm/Syntax/Expression.elm | 4 ++-- tests/Elm/Parser/DeclarationsTests.elm | 16 ++++++++-------- tests/Elm/Parser/ExpressionTests.elm | 6 +++--- tests/Elm/Parser/LetExpressionTests.elm | 4 ++-- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0ab04c20..4677b23b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - Renamed `Hex` to `HexLiteral` - Renamed `ListExpr` to `ListLiteral` - Renamed `OperatorApplication` to `Operation` + - Renamed `RecordExpr` to `Record` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index ffa923986..40c4297b7 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -247,7 +247,7 @@ recordContentsCurlyEnd = RecordUpdate nameNode firstField tailFields.syntax FieldsFirstValue firstFieldValue -> - RecordExpr (Node.combine Tuple.pair nameNode firstFieldValue :: tailFields.syntax) + Record (Node.combine Tuple.pair nameNode firstFieldValue :: tailFields.syntax) } ) (Node.parserCore Tokens.functionName) @@ -279,7 +279,7 @@ recordContentsCurlyEnd = recordFields (Layout.maybeLayoutUntilIgnored ParserFast.symbolFollowedBy "}") ) - (ParserFast.symbol "}" { comments = Rope.empty, syntax = RecordExpr [] }) + (ParserFast.symbol "}" { comments = Rope.empty, syntax = Record [] }) type RecordFieldsOrUpdateAfterName diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 0cf306ace..6cba46dba 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -93,7 +93,7 @@ type alias FunctionImplementation = - `LetExpression`: `let a = 4 in a` - `CaseExpression`: `case a of` followed by pattern matches - `LambdaExpression`: `(\a -> a)` - - `RecordExpr`: `{ name = "text" }` + - `Record`: `{ name = "text" }` - `ListLiteral`: `[ x, y ]` - `RecordAccess`: `a.name` - `RecordAccessFunction`: `.name` @@ -118,7 +118,7 @@ type Expression | LetExpression LetBlock | CaseExpression CaseBlock | LambdaExpression Lambda - | RecordExpr (List (Node RecordSetter)) + | Record (List (Node RecordSetter)) | ListLiteral (List (Node Expression)) | RecordAccess (Node Expression) (Node String) | RecordAccessFunction String diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 2630cf962..c3158e785 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -4,12 +4,12 @@ import Elm.Parser.Declarations exposing (..) import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil exposing (parse) import Elm.Syntax.Declaration as Declaration exposing (..) import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) -import Elm.Syntax.Expression exposing (..) +import Elm.Syntax.Expression as Expression exposing (..) import Elm.Syntax.Infix as Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (..) import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) -import Elm.Syntax.TypeAnnotation exposing (..) +import Elm.Syntax.TypeAnnotation as TypeAnnotation exposing (..) import Expect import Test exposing (..) @@ -64,7 +64,7 @@ foo = bar""" Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } { name = Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } "foo" , arguments = [] - , expression = Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (RecordExpr []) + , expression = Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (Expression.Record []) } } ) @@ -267,7 +267,7 @@ foo = bar""" (Application (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 18 } } (FunctionOrValue [] "beginnerProgram")) [ Node { start = { row = 2, column = 19 }, end = { row = 2, column = 62 } } - (RecordExpr + (Expression.Record [ Node { start = { row = 2, column = 21 }, end = { row = 2, column = 30 } } ( Node { start = { row = 2, column = 21 }, end = { row = 2, column = 26 } } "model" , Node { start = { row = 2, column = 29 }, end = { row = 2, column = 30 } } (IntegerLiteral 0) @@ -612,7 +612,7 @@ update msg model = , generics = [] , typeAnnotation = Node { start = { row = 1, column = 18 }, end = { row = 1, column = 34 } } - (Record + (TypeAnnotation.Record [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 32 } } ( Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } "color" , Node { start = { row = 1, column = 26 }, end = { row = 1, column = 32 } } @@ -635,7 +635,7 @@ type alias Foo = {color: String }""" , generics = [] , typeAnnotation = Node { start = { row = 2, column = 18 }, end = { row = 2, column = 34 } } - (Record + (TypeAnnotation.Record [ Node { start = { row = 2, column = 19 }, end = { row = 2, column = 32 } } ( Node { start = { row = 2, column = 19 }, end = { row = 2, column = 24 } } "color" , Node { start = { row = 2, column = 26 }, end = { row = 2, column = 32 } } @@ -657,7 +657,7 @@ type alias Foo = {color: String }""" , generics = [] , typeAnnotation = Node { start = { row = 1, column = 16 }, end = { row = 1, column = 32 } } - (Record + (TypeAnnotation.Record [ Node { start = { row = 1, column = 17 }, end = { row = 1, column = 30 } } ( Node { start = { row = 1, column = 17 }, end = { row = 1, column = 22 } } "color" , Node { start = { row = 1, column = 24 }, end = { row = 1, column = 30 } } @@ -679,7 +679,7 @@ type alias Foo = {color: String }""" , generics = [ Node { start = { row = 1, column = 16 }, end = { row = 1, column = 17 } } "a" ] , typeAnnotation = Node { start = { row = 1, column = 20 }, end = { row = 1, column = 31 } } - (Record + (TypeAnnotation.Record [ Node { start = { row = 1, column = 21 }, end = { row = 1, column = 29 } } ( Node { start = { row = 1, column = 21 }, end = { row = 1, column = 25 } } "some" , Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (Var "a") diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 4d975e15c..65f052230 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -214,7 +214,7 @@ all = "{ model = 0, view = view, update = update }" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 44 } } - (RecordExpr + (Record [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } ( Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } "model" , Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } (IntegerLiteral 0) @@ -236,7 +236,7 @@ all = |> expectAstWithComments { ast = Node { start = { row = 1, column = 1 }, end = { row = 2, column = 13 } } - (RecordExpr + (Record [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 10 } } ( Node { start = { row = 1, column = 3 }, end = { row = 1, column = 6 } } "foo" , Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (IntegerLiteral 1) @@ -641,7 +641,7 @@ all = (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 16 } } (RecordAccess (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 14 } } - (RecordExpr + (Record [ Node { start = { row = 1, column = 7 }, end = { row = 1, column = 13 } } ( Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } "x" , Node { start = { row = 1, column = 11 }, end = { row = 1, column = 13 } } (IntegerLiteral 10) diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index 2299327cd..d81317e91 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -3,7 +3,7 @@ module Elm.Parser.LetExpressionTests exposing (all) import Elm.Parser.Expression exposing (expression) import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) -import Elm.Syntax.Expression exposing (..) +import Elm.Syntax.Expression as Expression exposing (..) import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation(..)) import Expect @@ -422,7 +422,7 @@ all = } ) ] - , expression = Node { start = { row = 3, column = 7 }, end = { row = 3, column = 9 } } (RecordExpr []) + , expression = Node { start = { row = 3, column = 7 }, end = { row = 3, column = 9 } } (Expression.Record []) } ) ) From 05e9ca4d1f2161fa8fe36c0716504b7404c8c407 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 30 Jun 2023 19:50:26 +0200 Subject: [PATCH 33/44] Rename Expression.CaseExpression to Case --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 6 +++--- tests/Elm/Parser/CaseExpressionTests.elm | 12 ++++++------ tests/Elm/Parser/DeclarationsTests.elm | 6 +++--- tests/Elm/Parser/FileTests.elm | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4677b23b5..b55677b17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ - Renamed `ListExpr` to `ListLiteral` - Renamed `OperatorApplication` to `Operation` - Renamed `RecordExpr` to `Record` + - Renamed `CaseExpression` to `Case` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 40c4297b7..708af95b6 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -428,7 +428,7 @@ caseExpression = in firstCaseExpressionRange.end } - (CaseExpression + (Case { expression = caseBlock.casedExpression , firstCase = caseBlock.firstCase , restOfCases = List.reverse caseBlock.lastToSecondCase diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 6cba46dba..0284430bb 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -91,7 +91,7 @@ type alias FunctionImplementation = - `CharLiteral`: `'a'` - `TupleExpression`: Something wrapped in parentheses like unit `()`, parentheses `(a)`, or a tuple `( a, b )` - `LetExpression`: `let a = 4 in a` - - `CaseExpression`: `case a of` followed by pattern matches + - `Case`: `case a of` followed by pattern matches - `LambdaExpression`: `(\a -> a)` - `Record`: `{ name = "text" }` - `ListLiteral`: `[ x, y ]` @@ -116,7 +116,7 @@ type Expression | CharLiteral Char | TupleExpression (List (Node Expression)) | LetExpression LetBlock - | CaseExpression CaseBlock + | Case CaseBlock | LambdaExpression Lambda | Record (List (Node RecordSetter)) | ListLiteral (List (Node Expression)) @@ -212,7 +212,7 @@ isIfElse e = isCase : Expression -> Bool isCase e = case e of - CaseExpression _ -> + Case _ -> True _ -> diff --git a/tests/Elm/Parser/CaseExpressionTests.elm b/tests/Elm/Parser/CaseExpressionTests.elm index fd4924e23..19868ae95 100644 --- a/tests/Elm/Parser/CaseExpressionTests.elm +++ b/tests/Elm/Parser/CaseExpressionTests.elm @@ -43,7 +43,7 @@ True -> 1""" False -> 2""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 3, column = 13 } } - (CaseExpression + (Case { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } <| FunctionOrValue [] "f" @@ -69,7 +69,7 @@ True -> 1""" Foo.Bar -> 1""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 15 } } - (CaseExpression + (Case { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } <| FunctionOrValue [] "f" @@ -89,7 +89,7 @@ True -> 1""" x->1""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 7 } } - (CaseExpression + (Case { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } <| FunctionOrValue [] "f" @@ -109,7 +109,7 @@ True -> 1""" False -> 2""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 2, column = 21 } } - (CaseExpression + (Case { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "x") , firstCase = ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 15 } } (NamedPattern { moduleName = [], name = "True" } []) @@ -134,7 +134,7 @@ True -> 1""" _ -> 3""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 7, column = 15 } } - (CaseExpression + (Case { expression = Node { start = { row = 1, column = 6 } @@ -178,7 +178,7 @@ True -> 1""" 2""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 6, column = 6 } } - (CaseExpression + (Case { expression = Node { start = { row = 1, column = 6 }, end = { row = 1, column = 9 } } (FunctionOrValue [] "msg") , firstCase = ( Node { start = { row = 2, column = 3 }, end = { row = 2, column = 12 } } (NamedPattern { moduleName = [], name = "Increment" } []) diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index c3158e785..68637c9cb 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -101,7 +101,7 @@ foo = bar""" , arguments = [] , expression = Node { start = { row = 4, column = 7 }, end = { row = 5, column = 18 } } - (CaseExpression + (Case { expression = Node { start = { row = 4, column = 12 }, end = { row = 4, column = 13 } } (FunctionOrValue [] "x") , firstCase = ( Node { start = { row = 5, column = 9 }, end = { row = 5, column = 13 } } (NamedPattern { moduleName = [], name = "True" } []) @@ -311,7 +311,7 @@ foo = bar""" ] , expression = Node { start = { row = 2, column = 3 }, end = { row = 7, column = 16 } } - (CaseExpression + (Case { expression = Node { start = { row = 2, column = 8 }, end = { row = 2, column = 11 } } (FunctionOrValue [] "msg") , firstCase = ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } (NamedPattern { moduleName = [], name = "Increment" } []) @@ -544,7 +544,7 @@ foo = bar""" ] , expression = Node { start = { row = 2, column = 3 }, end = { row = 7, column = 16 } } - (CaseExpression + (Case { expression = Node { start = { row = 2, column = 8 }, end = { row = 2, column = 11 } } (FunctionOrValue [] "msg") , firstCase = ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index 2518aa535..8e9629a72 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -159,7 +159,7 @@ caseWhitespace f = case f of , arguments = [ Node { start = { row = 4, column = 16 }, end = { row = 4, column = 17 } } (VarPattern_ "f") ] , expression = Node { start = { row = 4, column = 20 }, end = { row = 11, column = 11 } } - (CaseExpression + (Case { expression = Node { start = { row = 4, column = 25 }, end = { row = 4, column = 26 } } (FunctionOrValue [] "f") , firstCase = ( Node { start = { row = 5, column = 3 }, end = { row = 5, column = 7 } } (NamedPattern { moduleName = [], name = "True" } []) From d6abfbb8100d31459e4efff2b23c3f42d8fb69c6 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 30 Jun 2023 19:55:05 +0200 Subject: [PATCH 34/44] Rename Expression.LetExpression to Let --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 6 +++--- tests/Elm/Parser/DeclarationsTests.elm | 6 +++--- tests/Elm/Parser/FileTests.elm | 2 +- tests/Elm/Parser/LetExpressionTests.elm | 24 ++++++++++++------------ 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b55677b17..d8840a3ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ - Renamed `OperatorApplication` to `Operation` - Renamed `RecordExpr` to `Record` - Renamed `CaseExpression` to `Case` + - Renamed `LetExpression` to `Let` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 708af95b6..cf12feb64 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -519,7 +519,7 @@ letExpression = { comments = letBlock.comments , syntax = Node { start = start, end = expressionRange.end } - (LetExpression + (Let { declarations = letBlock.declarations , expression = letBlock.expression } diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 0284430bb..7e0fdc9f4 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -90,7 +90,7 @@ type alias FunctionImplementation = - `StringLiteral`: `"text"` or `"""text"""` - `CharLiteral`: `'a'` - `TupleExpression`: Something wrapped in parentheses like unit `()`, parentheses `(a)`, or a tuple `( a, b )` - - `LetExpression`: `let a = 4 in a` + - `Let`: `let a = 4 in a` - `Case`: `case a of` followed by pattern matches - `LambdaExpression`: `(\a -> a)` - `Record`: `{ name = "text" }` @@ -115,7 +115,7 @@ type Expression | StringLiteral StringLiteralType String | CharLiteral Char | TupleExpression (List (Node Expression)) - | LetExpression LetBlock + | Let LetBlock | Case CaseBlock | LambdaExpression Lambda | Record (List (Node RecordSetter)) @@ -188,7 +188,7 @@ isLambda e = isLet : Expression -> Bool isLet e = case e of - LetExpression _ -> + Let _ -> True _ -> diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 68637c9cb..edfc27db6 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -89,7 +89,7 @@ foo = bar""" , arguments = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 6 } } (VarPattern_ "x") ] , expression = Node { start = { row = 2, column = 3 }, end = { row = 7, column = 7 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 3, column = 5 }, end = { row = 5, column = 18 } } (LetFunction @@ -174,7 +174,7 @@ foo = bar""" , arguments = [] , expression = Node { start = { row = 2, column = 2 }, end = { row = 5, column = 4 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 3, column = 3 }, end = { row = 3, column = 8 } } (LetFunction @@ -222,7 +222,7 @@ foo = bar""" , arguments = [] , expression = Node { start = { row = 2, column = 2 }, end = { row = 5, column = 4 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 3, column = 3 }, end = { row = 3, column = 16 } } (LetDestructuring diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index 8e9629a72..daae8dfd6 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -277,7 +277,7 @@ letWhitespace = let , arguments = [] , expression = Node { start = { row = 4, column = 17 }, end = { row = 8, column = 3 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 5, column = 19 }, end = { row = 5, column = 26 } } (LetFunction diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index d81317e91..d1dff6b10 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -12,7 +12,7 @@ import Test exposing (..) all : Test all = - describe "LetExpressionTests" + describe "LetTests" [ test "let expression with multiple declarations" <| \() -> """let @@ -21,7 +21,7 @@ all = john n = n in 1""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 4, column = 18 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 3 }, end = { row = 2, column = 12 } } (LetFunction @@ -60,7 +60,7 @@ all = bar""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 4, column = 6 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 3 }, end = { row = 2, column = 10 } } (LetFunction @@ -102,7 +102,7 @@ all = bar""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 4, column = 7 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 3 }, end = { row = 2, column = 10 } } (LetFunction @@ -130,7 +130,7 @@ all = bar""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 5, column = 6 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 5 }, end = { row = 3, column = 12 } } (LetFunction @@ -168,7 +168,7 @@ all = bar""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 7, column = 6 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 5 }, end = { row = 5, column = 12 } } (LetFunction @@ -224,7 +224,7 @@ all = bar""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 4, column = 12 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 11 }, end = { row = 2, column = 24 } } (LetFunction @@ -302,7 +302,7 @@ all = 1""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 7, column = 6 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 5 }, end = { row = 2, column = 10 } } (LetDestructuring (Node { start = { row = 2, column = 5 }, end = { row = 2, column = 6 } } AllPattern_) (Node { start = { row = 2, column = 9 }, end = { row = 2, column = 10 } } (FunctionOrValue [] "b"))) @@ -349,7 +349,7 @@ all = "let indent = String.length s in indent" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 39 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 29 } } (LetFunction @@ -381,7 +381,7 @@ all = in[]""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 3, column = 9 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 9 }, end = { row = 2, column = 14 } } (LetFunction @@ -407,7 +407,7 @@ all = in{}""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 3, column = 9 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 9 }, end = { row = 2, column = 14 } } (LetFunction @@ -433,7 +433,7 @@ all = in\\_ -> 1""" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 3, column = 14 } } - (LetExpression + (Let { declarations = [ Node { start = { row = 2, column = 9 }, end = { row = 2, column = 14 } } (LetFunction From 4eed7d8afc574b3423f54fda521673f5763f19a7 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 30 Jun 2023 19:56:33 +0200 Subject: [PATCH 35/44] Rename Expression.GLSLExpression to GLSL --- CHANGELOG.md | 1 + src/Elm/Parser/Expression.elm | 2 +- src/Elm/Syntax/Expression.elm | 4 ++-- tests/Elm/Parser/GlslTests.elm | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8840a3ad..be85085fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,7 @@ - Renamed `RecordExpr` to `Record` - Renamed `CaseExpression` to `Case` - Renamed `LetExpression` to `Let` + - Renamed `GLSLExpression` to `GLSL` - `UnitExpr` -> `TupleExpression []` - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index cf12feb64..6d8780b6a 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -138,7 +138,7 @@ glslExpressionAfterOpeningSquareBracket = { start = { row = start.row, column = start.column - 6 } , end = { row = end.row, column = end.column + 2 } } - (GLSLExpression s) + (GLSL s) } ) (ParserFast.Advanced.loop "" untilGlslEnd) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 7e0fdc9f4..3f49ce58b 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -98,7 +98,7 @@ type alias FunctionImplementation = - `RecordAccess`: `a.name` - `RecordAccessFunction`: `.name` - `RecordUpdate`: `{ a | name = "text" }` - - `GLSLExpression`: `[glsl| ... |]` + - `GLSL`: `[glsl| ... |]` -} type Expression @@ -123,7 +123,7 @@ type Expression | RecordAccess (Node Expression) (Node String) | RecordAccessFunction String | RecordUpdate (Node String) (Node RecordSetter) (List (Node RecordSetter)) - | GLSLExpression String + | GLSL String {-| Expression for setting a record field diff --git a/tests/Elm/Parser/GlslTests.elm b/tests/Elm/Parser/GlslTests.elm index 83ec2c69e..1a4bd179b 100644 --- a/tests/Elm/Parser/GlslTests.elm +++ b/tests/Elm/Parser/GlslTests.elm @@ -16,7 +16,7 @@ all = "[glsl| precision mediump float; |]" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 37 } } - (GLSLExpression " precision mediump float; ") + (GLSL " precision mediump float; ") ) ] From 5b7866767b53cec1d2b1c39583b718796f38af9e Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 30 Jun 2023 20:07:11 +0200 Subject: [PATCH 36/44] Reorder expression definitions --- src/Elm/Syntax/Expression.elm | 36 +++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 3f49ce58b..77c0fb74d 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -77,53 +77,53 @@ type alias FunctionImplementation = {-| Custom type for all expressions such as: - - `Application`: `add a b` - - `Operation`: `a + b` - - `FunctionOrValue`: `add` or `True` - - `If`: `if a then b else c` - - `PrefixOperator`: `(+)` - - `Operator`: `+` (not possible to get in practice) + - `StringLiteral`: `"text"` or `"""text"""` + - `CharLiteral`: `'a'` - `IntegerLiteral`: `42` - `HexLiteral`: `0x1F` - `FloatLiteral`: `42.0` - `Negation`: `-a` - - `StringLiteral`: `"text"` or `"""text"""` - - `CharLiteral`: `'a'` + - `ListLiteral`: `[ x, y ]` + - `FunctionOrValue`: `add` or `True` + - `Application`: `add a b` + - `Operation`: `a + b` + - `PrefixOperator`: `(+)` + - `If`: `if a then b else c` - `TupleExpression`: Something wrapped in parentheses like unit `()`, parentheses `(a)`, or a tuple `( a, b )` - `Let`: `let a = 4 in a` - `Case`: `case a of` followed by pattern matches - `LambdaExpression`: `(\a -> a)` - `Record`: `{ name = "text" }` - - `ListLiteral`: `[ x, y ]` - `RecordAccess`: `a.name` - `RecordAccessFunction`: `.name` - `RecordUpdate`: `{ a | name = "text" }` - `GLSL`: `[glsl| ... |]` + - `Operator`: `+` (not possible to get in practice) -} type Expression - = Application (Node Expression) (List (Node Expression)) - | Operation String InfixDirection (Node Expression) (Node Expression) - | FunctionOrValue ModuleName String - | If (Node Expression) (Node Expression) (Node Expression) - | PrefixOperator String - | Operator String + = StringLiteral StringLiteralType String + | CharLiteral Char | IntegerLiteral Int | HexLiteral Int | FloatLiteral Float | Negation (Node Expression) - | StringLiteral StringLiteralType String - | CharLiteral Char + | ListLiteral (List (Node Expression)) + | FunctionOrValue ModuleName String + | PrefixOperator String + | Application (Node Expression) (List (Node Expression)) + | Operation String InfixDirection (Node Expression) (Node Expression) + | If (Node Expression) (Node Expression) (Node Expression) | TupleExpression (List (Node Expression)) | Let LetBlock | Case CaseBlock | LambdaExpression Lambda | Record (List (Node RecordSetter)) - | ListLiteral (List (Node Expression)) | RecordAccess (Node Expression) (Node String) | RecordAccessFunction String | RecordUpdate (Node String) (Node RecordSetter) (List (Node RecordSetter)) | GLSL String + | Operator String {-| Expression for setting a record field From 1f3aceaf27630048bab74360180117d0dad33d81 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Thu, 17 Aug 2023 18:01:36 +0200 Subject: [PATCH 37/44] Rename Application to FunctionCall --- CHANGELOG.md | 3 ++- src/Elm/Parser/Expression.elm | 6 ++--- src/Elm/Syntax/Expression.elm | 4 ++-- tests/Elm/Parser/DeclarationsTests.elm | 10 ++++---- tests/Elm/Parser/ExpressionTests.elm | 32 ++++++++++++------------- tests/Elm/Parser/LetExpressionTests.elm | 2 +- tests/Elm/Parser/ModuleTests.elm | 6 ++--- 7 files changed, 32 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be85085fc..9c2c8c77d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,8 @@ - Added information to `String` literal as to whether `"""` or `"` was used: - `Literal String` -> `StringLiteral StringLiteralType String` - Added `type StringLiteralType = TripleQuote | SingleQuote` - - `Application (List (Node Expression))` -> `Application (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) + - Renamed `Application` to `FunctionCall` + - `Application (List (Node Expression))` -> `FunctionCall (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) - Renamed `RecordUpdateExpression` to `RecordUpdate` - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdate (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 6d8780b6a..41caa3221 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -1122,11 +1122,11 @@ applyExtensionRight extensionRight ((Node { start } left) as leftNode) = ExtendRightByApplication ((Node { end } _) as right) -> Node { start = start, end = end } (case left of - Expression.Application called (firstArg :: secondArgUp) -> - Expression.Application called (firstArg :: (secondArgUp ++ [ right ])) + Expression.FunctionCall called (firstArg :: secondArgUp) -> + Expression.FunctionCall called (firstArg :: (secondArgUp ++ [ right ])) _ -> - Expression.Application leftNode [ right ] + Expression.FunctionCall leftNode [ right ] ) ExtendRightByOperation extendRightOperation -> diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 77c0fb74d..54b837a22 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -85,7 +85,7 @@ type alias FunctionImplementation = - `Negation`: `-a` - `ListLiteral`: `[ x, y ]` - `FunctionOrValue`: `add` or `True` - - `Application`: `add a b` + - `FunctionCall`: `add a b` - `Operation`: `a + b` - `PrefixOperator`: `(+)` - `If`: `if a then b else c` @@ -111,7 +111,7 @@ type Expression | ListLiteral (List (Node Expression)) | FunctionOrValue ModuleName String | PrefixOperator String - | Application (Node Expression) (List (Node Expression)) + | FunctionCall (Node Expression) (List (Node Expression)) | Operation String InfixDirection (Node Expression) (Node Expression) | If (Node Expression) (Node Expression) (Node Expression) | TupleExpression (List (Node Expression)) diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index edfc27db6..4a443df2e 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -264,7 +264,7 @@ foo = bar""" , arguments = [] , expression = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 62 } } - (Application + (FunctionCall (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 18 } } (FunctionOrValue [] "beginnerProgram")) [ Node { start = { row = 2, column = 19 }, end = { row = 2, column = 62 } } (Expression.Record @@ -424,7 +424,7 @@ foo = bar""" , arguments = [] , expression = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } - (Application + (FunctionCall (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (StringLiteral SingleQuote "Hello, World!") ] @@ -448,7 +448,7 @@ foo = bar""" , arguments = [] , expression = Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } - (Application + (FunctionCall (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (StringLiteral SingleQuote "Hello, World!") ] @@ -500,7 +500,7 @@ foo = bar""" (Node { start = { row = 1, column = 40 }, end = { row = 1, column = 56 } } (TupleExpression [ Node { start = { row = 1, column = 41 }, end = { row = 1, column = 55 } } - (Application + (FunctionCall (Node { start = { row = 1, column = 41 }, end = { row = 1, column = 48 } } (FunctionOrValue [] "uncurry")) [ Node { start = { row = 1, column = 49 }, end = { row = 1, column = 55 } } (FunctionOrValue [] "update") ] @@ -509,7 +509,7 @@ foo = bar""" ) ) (Node { start = { row = 1, column = 60 }, end = { row = 1, column = 83 } } - (Application (Node { start = { row = 1, column = 60 }, end = { row = 1, column = 74 } } (FunctionOrValue [] "batchStateCmds")) + (FunctionCall (Node { start = { row = 1, column = 60 }, end = { row = 1, column = 74 } } (FunctionOrValue [] "batchStateCmds")) [ Node { start = { row = 1, column = 75 }, end = { row = 1, column = 83 } } (FunctionOrValue [] "sendPort") ] ) diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 65f052230..8f0a898f7 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -111,7 +111,7 @@ all = "List.concat []" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } } <| - Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } <| FunctionOrValue [ "List" ] "concat") + FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } <| FunctionOrValue [ "List" ] "concat") [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } (ListLiteral []) ] ) @@ -133,11 +133,11 @@ all = TupleExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } <| StringLiteral SingleQuote "" , Node { start = { row = 1, column = 6 }, end = { row = 1, column = 47 } } <| - Application (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") + FunctionCall (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 47 } } <| TupleExpression [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 46 } } <| - Application (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } (FunctionOrValue [ "List" ] "concat")) + FunctionCall (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } (FunctionOrValue [ "List" ] "concat")) [ Node { start = { row = 1, column = 26 }, end = { row = 1, column = 46 } } <| ListLiteral [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 40 } } <| @@ -153,7 +153,7 @@ all = ] ] ) - , test "expressionNotApplication simple" <| + , test "expressionNotFunctionCall simple" <| \() -> "foo" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) @@ -162,7 +162,7 @@ all = "Task.succeed ()" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } - (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionOrValue [ "Task" ] "succeed")) + (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionOrValue [ "Task" ] "succeed")) [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 16 } } (TupleExpression []) ] ) @@ -172,7 +172,7 @@ all = "foo bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } - (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) + (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "bar") ] ) @@ -256,12 +256,12 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } (ListLiteral [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } - (Application (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class")) + (FunctionCall (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class")) [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (StringLiteral SingleQuote "a") ] ) , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 24 } } - (Application (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "text")) + (FunctionCall (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "text")) [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (StringLiteral SingleQuote "Foo") ] ) @@ -374,7 +374,7 @@ all = "List.map .name people" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 22 } } - (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } (FunctionOrValue [ "List" ] "map")) + (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } (FunctionOrValue [ "List" ] "map")) [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (RecordAccessFunction "name") , Node { start = { row = 1, column = 16 }, end = { row = 1, column = 22 } } (FunctionOrValue [] "people") ] @@ -387,7 +387,7 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 38 } } (TupleExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 37 } } - (Application + (FunctionCall (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 14 } } (RecordAccessFunction "spaceEvenly")) [ Node { start = { row = 1, column = 15 }, end = { row = 1, column = 37 } } (FunctionOrValue [ "Internal", "Style" ] "classes") ] @@ -408,7 +408,7 @@ all = "(::) x" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } - (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } (PrefixOperator "::")) + (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } (PrefixOperator "::")) [ Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "x") ] ) @@ -436,7 +436,7 @@ all = "toFloat -5" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } - (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "toFloat")) + (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "toFloat")) [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 11 } } (Negation (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } (IntegerLiteral 5))) ] @@ -534,7 +534,7 @@ all = "chompWhile (\\c -> c == ' ' || c == '\\n' || c == '\\r')" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 54 } } - (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "chompWhile")) + (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "chompWhile")) [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 54 } } (TupleExpression [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 53 } } @@ -588,7 +588,7 @@ all = "foo { d | b = f x y }.b" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 24 } } - (Application (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) + (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 24 } } (RecordAccess (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 22 } } @@ -596,7 +596,7 @@ all = (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 21 } } ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } "b" , Node { start = { row = 1, column = 15 }, end = { row = 1, column = 20 } } - (Application (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "f")) + (FunctionCall (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "f")) [ Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "x") , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (FunctionOrValue [] "y") ] @@ -616,7 +616,7 @@ all = "Random.list -1 generator" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } - (Application + (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } (FunctionOrValue [ "Random" ] "list")) [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } (Negation diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index d1dff6b10..19759ac00 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -361,7 +361,7 @@ all = , arguments = [] , expression = Node { start = { row = 1, column = 14 }, end = { row = 1, column = 29 } } - (Application + (FunctionCall (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 27 } } (FunctionOrValue [ "String" ] "length")) [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (FunctionOrValue [] "s") ] diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index f2e64aead..90de6255a 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -464,14 +464,14 @@ fun2 n = (Operation "+" Left (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 9 } } - (Application + (FunctionCall (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 7 } } (FunctionOrValue [] "fun2")) [ Node { start = { row = 4, column = 8 }, end = { row = 4, column = 9 } } (FunctionOrValue [] "n") ] ) ) (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 11 } } - (Application + (FunctionCall (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 9 } } (FunctionOrValue [] "fun2")) [ Node { start = { row = 5, column = 10 }, end = { row = 5, column = 11 } } (FunctionOrValue [] "n") ] @@ -491,7 +491,7 @@ fun2 n = , arguments = [ Node { start = { row = 7, column = 6 }, end = { row = 7, column = 7 } } (VarPattern_ "n") ] , expression = Node { start = { row = 8, column = 3 }, end = { row = 8, column = 9 } } - (Application + (FunctionCall (Node { start = { row = 8, column = 3 }, end = { row = 8, column = 7 } } (FunctionOrValue [] "fun1")) [ Node { start = { row = 8, column = 8 }, end = { row = 8, column = 9 } } (FunctionOrValue [] "n") ] From f133792f3abdb835bfc5524913bcfbc38ba4d437 Mon Sep 17 00:00:00 2001 From: Jeremie Gillet Date: Sat, 20 Jul 2024 12:32:43 +0900 Subject: [PATCH 38/44] Rename isOperatorApplication to isOperation --- CHANGELOG.md | 1 + src/Elm/Syntax/Expression.elm | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c2c8c77d..05f0923d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ - Renamed `Hex` to `HexLiteral` - Renamed `ListExpr` to `ListLiteral` - Renamed `OperatorApplication` to `Operation` + - Renamed `isOperatorApplication` to `isOperation` - Renamed `RecordExpr` to `Record` - Renamed `CaseExpression` to `Case` - Renamed `LetExpression` to `Let` diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 54b837a22..29e86d342 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -1,6 +1,6 @@ module Elm.Syntax.Expression exposing ( Expression(..), Lambda, LetBlock, LetDeclaration(..), RecordSetter, CaseBlock, Case, Function, FunctionImplementation - , functionRange, isLambda, isLet, isIfElse, isCase, isOperatorApplication + , functionRange, isLambda, isLet, isIfElse, isCase, isOperation ) {-| This syntax represents all that you can express in Elm. @@ -14,7 +14,7 @@ Although it is a easy and simple language, you can express a lot! See the `Expre ## Functions -@docs functionRange, isLambda, isLet, isIfElse, isCase, isOperatorApplication +@docs functionRange, isLambda, isLet, isIfElse, isCase, isOperation -} @@ -221,8 +221,8 @@ isCase e = {-| Check whether an expression is an operator application expression -} -isOperatorApplication : Expression -> Bool -isOperatorApplication e = +isOperation : Expression -> Bool +isOperation e = case e of Operation _ _ _ _ -> True From 862e0bf256f7a8dd4820b9ee2d2e719fc7e38f65 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 26 Jul 2024 01:17:13 +0200 Subject: [PATCH 39/44] Remove the Operator Expression variant --- CHANGELOG.md | 1 + src/Elm/Syntax/Expression.elm | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 05f0923d3..fd741097e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -47,6 +47,7 @@ - `ParenthesizedExpression x` -> `TupleExpression [ x ]` - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) - `Elm.Syntax.Expression.CaseBlock`'s `cases : List Case` field is split into `firstCase : Case` and `restOfCases : List Case` (takes a non-empty list of cases) + - Removed `Operator` (it was not possible to get) - Changed `Elm.Syntax.Pattern.Pattern`: - Removed `FloatPattern` (it was not possible to get) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 29e86d342..2678f904d 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -98,7 +98,6 @@ type alias FunctionImplementation = - `RecordAccessFunction`: `.name` - `RecordUpdate`: `{ a | name = "text" }` - `GLSL`: `[glsl| ... |]` - - `Operator`: `+` (not possible to get in practice) -} type Expression @@ -123,7 +122,6 @@ type Expression | RecordAccessFunction String | RecordUpdate (Node String) (Node RecordSetter) (List (Node RecordSetter)) | GLSL String - | Operator String {-| Expression for setting a record field From 0503e7418df5749303d56afaf8cda0fd9a9ca06a Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Fri, 26 Jul 2024 14:52:33 +0200 Subject: [PATCH 40/44] Remove Elm.Syntax.Range.emptyRange --- CHANGELOG.md | 2 ++ src/Elm/Syntax/Range.elm | 16 ---------------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fd741097e..1f5f599e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,8 @@ - Added module `Elm.Syntax.StringLiteralType` containing `type StringLiteralType = TripleQuote | SingleQuote` +- Removed deprecated `Elm.Syntax.Range.emptyRange`, use `Elm.Syntax.Range.empty` instead. + ## [7.3.4] - 2024-07-26 Parsing is faster by ~90%. A big thank you to [@lue-bird](https://github.com/lue-bird) for finding and introducing a huge amount of performance improvements. diff --git a/src/Elm/Syntax/Range.elm b/src/Elm/Syntax/Range.elm index 5f4e02b2c..5f91ef555 100644 --- a/src/Elm/Syntax/Range.elm +++ b/src/Elm/Syntax/Range.elm @@ -2,7 +2,6 @@ module Elm.Syntax.Range exposing ( Range, Location , empty, combine , compare, compareLocations - , emptyRange ) {-| @@ -24,11 +23,6 @@ See also [Basics.compare](https://package.elm-lang.org/packages/elm/core/latest/ @docs compare, compareLocations - -## Deprecated - -@docs emptyRange - -} @@ -57,16 +51,6 @@ empty = } -{-| **@deprecated** Use [`empty`](#empty) instead. It does the same thing but the name is more Elm-y. - -Construct an empty range - --} -emptyRange : Range -emptyRange = - empty - - {-| Compute the largest area of a list of ranges. -} combine : List Range -> Range From 41f3a4571b59b84ddca9e4a05bebe55a5c6e0c45 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sat, 3 Aug 2024 00:26:30 +0200 Subject: [PATCH 41/44] Make arguments for FunctionCall nonempty --- CHANGELOG.md | 2 +- src/Elm/Parser/Expression.elm | 6 +- src/Elm/Syntax/Expression.elm | 2 +- tests/Elm/Parser/DeclarationsTests.elm | 21 ++--- tests/Elm/Parser/ExpressionTests.elm | 105 ++++++++++++++---------- tests/Elm/Parser/LetExpressionTests.elm | 4 +- tests/Elm/Parser/ModuleTests.elm | 12 +-- 7 files changed, 86 insertions(+), 66 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f5f599e3..94e915950 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,7 +28,7 @@ - `Literal String` -> `StringLiteral StringLiteralType String` - Added `type StringLiteralType = TripleQuote | SingleQuote` - Renamed `Application` to `FunctionCall` - - `Application (List (Node Expression))` -> `FunctionCall (Node Expression) (List (Node Expression))` (takes a non-empty list of arguments) + - `Application (List (Node Expression))` -> `FunctionCall (Node Expression) (Node Expression) (List (Node Expression))` (function is separated, and takes a non-empty list of arguments) - Renamed `RecordUpdateExpression` to `RecordUpdate` - `RecordUpdateExpression (Node String) (List (Node RecordSetter))` -> `RecordUpdate (Node String) (Node RecordSetter) (List (Node RecordSetter))` (takes a non-empty list of fields) - Renamed `TupledExpression` to `TupleExpression` diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 41caa3221..9ebf34f50 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -1122,11 +1122,11 @@ applyExtensionRight extensionRight ((Node { start } left) as leftNode) = ExtendRightByApplication ((Node { end } _) as right) -> Node { start = start, end = end } (case left of - Expression.FunctionCall called (firstArg :: secondArgUp) -> - Expression.FunctionCall called (firstArg :: (secondArgUp ++ [ right ])) + Expression.FunctionCall called firstArg restOfArgs -> + Expression.FunctionCall called firstArg (restOfArgs ++ [ right ]) _ -> - Expression.FunctionCall leftNode [ right ] + Expression.FunctionCall leftNode right [] ) ExtendRightByOperation extendRightOperation -> diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 2678f904d..4917ce90c 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -110,7 +110,7 @@ type Expression | ListLiteral (List (Node Expression)) | FunctionOrValue ModuleName String | PrefixOperator String - | FunctionCall (Node Expression) (List (Node Expression)) + | FunctionCall (Node Expression) (Node Expression) (List (Node Expression)) | Operation String InfixDirection (Node Expression) (Node Expression) | If (Node Expression) (Node Expression) (Node Expression) | TupleExpression (List (Node Expression)) diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 4a443df2e..8deef89fa 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -266,7 +266,7 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 2, column = 62 } } (FunctionCall (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 18 } } (FunctionOrValue [] "beginnerProgram")) - [ Node { start = { row = 2, column = 19 }, end = { row = 2, column = 62 } } + (Node { start = { row = 2, column = 19 }, end = { row = 2, column = 62 } } (Expression.Record [ Node { start = { row = 2, column = 21 }, end = { row = 2, column = 30 } } ( Node { start = { row = 2, column = 21 }, end = { row = 2, column = 26 } } "model" @@ -282,7 +282,8 @@ foo = bar""" ) ] ) - ] + ) + [] ) } } @@ -426,8 +427,8 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } (FunctionCall (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (StringLiteral SingleQuote "Hello, World!") - ] + (Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (StringLiteral SingleQuote "Hello, World!")) + [] ) } } @@ -450,8 +451,8 @@ foo = bar""" Node { start = { row = 2, column = 3 }, end = { row = 2, column = 23 } } (FunctionCall (Node { start = { row = 2, column = 3 }, end = { row = 2, column = 7 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (StringLiteral SingleQuote "Hello, World!") - ] + (Node { start = { row = 2, column = 8 }, end = { row = 2, column = 23 } } (StringLiteral SingleQuote "Hello, World!")) + [] ) } } @@ -502,16 +503,16 @@ foo = bar""" [ Node { start = { row = 1, column = 41 }, end = { row = 1, column = 55 } } (FunctionCall (Node { start = { row = 1, column = 41 }, end = { row = 1, column = 48 } } (FunctionOrValue [] "uncurry")) - [ Node { start = { row = 1, column = 49 }, end = { row = 1, column = 55 } } (FunctionOrValue [] "update") - ] + (Node { start = { row = 1, column = 49 }, end = { row = 1, column = 55 } } (FunctionOrValue [] "update")) + [] ) ] ) ) (Node { start = { row = 1, column = 60 }, end = { row = 1, column = 83 } } (FunctionCall (Node { start = { row = 1, column = 60 }, end = { row = 1, column = 74 } } (FunctionOrValue [] "batchStateCmds")) - [ Node { start = { row = 1, column = 75 }, end = { row = 1, column = 83 } } (FunctionOrValue [] "sendPort") - ] + (Node { start = { row = 1, column = 75 }, end = { row = 1, column = 83 } } (FunctionOrValue [] "sendPort")) + [] ) ) ) diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 8f0a898f7..685a84913 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -111,9 +111,10 @@ all = "List.concat []" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 15 } } <| - FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } <| FunctionOrValue [ "List" ] "concat") - [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } (ListLiteral []) - ] + FunctionCall + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } <| FunctionOrValue [ "List" ] "concat") + (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } (ListLiteral [])) + [] ) , test "application expression with operator" <| \() -> @@ -133,12 +134,14 @@ all = TupleExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } <| StringLiteral SingleQuote "" , Node { start = { row = 1, column = 6 }, end = { row = 1, column = 47 } } <| - FunctionCall (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") - [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 47 } } <| + FunctionCall + (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 12 } } <| FunctionOrValue [] "always") + (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 47 } } <| TupleExpression [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 46 } } <| - FunctionCall (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } (FunctionOrValue [ "List" ] "concat")) - [ Node { start = { row = 1, column = 26 }, end = { row = 1, column = 46 } } <| + FunctionCall + (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 25 } } (FunctionOrValue [ "List" ] "concat")) + (Node { start = { row = 1, column = 26 }, end = { row = 1, column = 46 } } <| ListLiteral [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 40 } } <| ListLiteral @@ -148,9 +151,11 @@ all = , Node { start = { row = 1, column = 42 }, end = { row = 1, column = 44 } } <| ListLiteral [] ] - ] + ) + [] ] - ] + ) + [] ] ) , test "expressionNotFunctionCall simple" <| @@ -162,9 +167,10 @@ all = "Task.succeed ()" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } - (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionOrValue [ "Task" ] "succeed")) - [ Node { start = { row = 1, column = 14 }, end = { row = 1, column = 16 } } (TupleExpression []) - ] + (FunctionCall + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 13 } } (FunctionOrValue [ "Task" ] "succeed")) + (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 16 } } (TupleExpression [])) + [] ) ) , test "Function call" <| @@ -172,9 +178,10 @@ all = "foo bar" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } - (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) - [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "bar") - ] + (FunctionCall + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) + (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "bar")) + [] ) ) , test "Function call with argument badly indented" <| @@ -256,14 +263,16 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } (ListLiteral [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 12 } } - (FunctionCall (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class")) - [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (StringLiteral SingleQuote "a") - ] + (FunctionCall + (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "class")) + (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 12 } } (StringLiteral SingleQuote "a")) + [] ) , Node { start = { row = 1, column = 14 }, end = { row = 1, column = 24 } } - (FunctionCall (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "text")) - [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (StringLiteral SingleQuote "Foo") - ] + (FunctionCall + (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "text")) + (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 24 } } (StringLiteral SingleQuote "Foo")) + [] ) ] ) @@ -374,9 +383,10 @@ all = "List.map .name people" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 22 } } - (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } (FunctionOrValue [ "List" ] "map")) - [ Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (RecordAccessFunction "name") - , Node { start = { row = 1, column = 16 }, end = { row = 1, column = 22 } } (FunctionOrValue [] "people") + (FunctionCall + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 9 } } (FunctionOrValue [ "List" ] "map")) + (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 15 } } (RecordAccessFunction "name")) + [ Node { start = { row = 1, column = 16 }, end = { row = 1, column = 22 } } (FunctionOrValue [] "people") ] ) ) @@ -389,8 +399,8 @@ all = [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 37 } } (FunctionCall (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 14 } } (RecordAccessFunction "spaceEvenly")) - [ Node { start = { row = 1, column = 15 }, end = { row = 1, column = 37 } } (FunctionOrValue [ "Internal", "Style" ] "classes") - ] + (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 37 } } (FunctionOrValue [ "Internal", "Style" ] "classes")) + [] ) ] ) @@ -408,9 +418,10 @@ all = "(::) x" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } - (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } (PrefixOperator "::")) - [ Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "x") - ] + (FunctionCall + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 5 } } (PrefixOperator "::")) + (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "x")) + [] ) ) , test "subtraction without spaces" <| @@ -436,10 +447,12 @@ all = "toFloat -5" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } - (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "toFloat")) - [ Node { start = { row = 1, column = 9 }, end = { row = 1, column = 11 } } + (FunctionCall + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "toFloat")) + (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 11 } } (Negation (Node { start = { row = 1, column = 10 }, end = { row = 1, column = 11 } } (IntegerLiteral 5))) - ] + ) + [] ) ) , test "negated expression for parenthesized" <| @@ -534,8 +547,9 @@ all = "chompWhile (\\c -> c == ' ' || c == '\\n' || c == '\\r')" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 54 } } - (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "chompWhile")) - [ Node { start = { row = 1, column = 12 }, end = { row = 1, column = 54 } } + (FunctionCall + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 11 } } (FunctionOrValue [] "chompWhile")) + (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 54 } } (TupleExpression [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 53 } } (LambdaExpression @@ -580,7 +594,8 @@ all = ) ] ) - ] + ) + [] ) ) , test "application should be lower-priority than field access" <| @@ -588,17 +603,19 @@ all = "foo { d | b = f x y }.b" |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 24 } } - (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) - [ Node { start = { row = 1, column = 5 }, end = { row = 1, column = 24 } } + (FunctionCall + (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "foo")) + (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 24 } } (RecordAccess (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 22 } } (RecordUpdate (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } "d") (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 21 } } ( Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } "b" , Node { start = { row = 1, column = 15 }, end = { row = 1, column = 20 } } - (FunctionCall (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "f")) - [ Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "x") - , Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (FunctionOrValue [] "y") + (FunctionCall + (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "f")) + (Node { start = { row = 1, column = 17 }, end = { row = 1, column = 18 } } (FunctionOrValue [] "x")) + [ Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (FunctionOrValue [] "y") ] ) ) @@ -608,7 +625,8 @@ all = ) (Node { start = { row = 1, column = 23 }, end = { row = 1, column = 24 } } "b") ) - ] + ) + [] ) ) , test "should not consider a negative number parameter as the start of a new application" <| @@ -618,13 +636,14 @@ all = (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 25 } } (FunctionCall (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 12 } } (FunctionOrValue [ "Random" ] "list")) - [ Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } + (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 15 } } (Negation (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 15 } } (IntegerLiteral 1) ) ) - , Node { start = { row = 1, column = 16 }, end = { row = 1, column = 25 } } (FunctionOrValue [] "generator") + ) + [ Node { start = { row = 1, column = 16 }, end = { row = 1, column = 25 } } (FunctionOrValue [] "generator") ] ) ) diff --git a/tests/Elm/Parser/LetExpressionTests.elm b/tests/Elm/Parser/LetExpressionTests.elm index 19759ac00..ba3323cc2 100644 --- a/tests/Elm/Parser/LetExpressionTests.elm +++ b/tests/Elm/Parser/LetExpressionTests.elm @@ -363,8 +363,8 @@ all = Node { start = { row = 1, column = 14 }, end = { row = 1, column = 29 } } (FunctionCall (Node { start = { row = 1, column = 14 }, end = { row = 1, column = 27 } } (FunctionOrValue [ "String" ] "length")) - [ Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (FunctionOrValue [] "s") - ] + (Node { start = { row = 1, column = 28 }, end = { row = 1, column = 29 } } (FunctionOrValue [] "s")) + [] ) } } diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index 90de6255a..863275af7 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -466,15 +466,15 @@ fun2 n = (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 9 } } (FunctionCall (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 7 } } (FunctionOrValue [] "fun2")) - [ Node { start = { row = 4, column = 8 }, end = { row = 4, column = 9 } } (FunctionOrValue [] "n") - ] + (Node { start = { row = 4, column = 8 }, end = { row = 4, column = 9 } } (FunctionOrValue [] "n")) + [] ) ) (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 11 } } (FunctionCall (Node { start = { row = 5, column = 5 }, end = { row = 5, column = 9 } } (FunctionOrValue [] "fun2")) - [ Node { start = { row = 5, column = 10 }, end = { row = 5, column = 11 } } (FunctionOrValue [] "n") - ] + (Node { start = { row = 5, column = 10 }, end = { row = 5, column = 11 } } (FunctionOrValue [] "n")) + [] ) ) ) @@ -493,8 +493,8 @@ fun2 n = Node { start = { row = 8, column = 3 }, end = { row = 8, column = 9 } } (FunctionCall (Node { start = { row = 8, column = 3 }, end = { row = 8, column = 7 } } (FunctionOrValue [] "fun1")) - [ Node { start = { row = 8, column = 8 }, end = { row = 8, column = 9 } } (FunctionOrValue [] "n") - ] + (Node { start = { row = 8, column = 8 }, end = { row = 8, column = 9 } } (FunctionOrValue [] "n")) + [] ) } } From 80296d4493def0c1dd2624a4d251db3a87f1344f Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sat, 3 Aug 2024 00:49:44 +0200 Subject: [PATCH 42/44] Add information to Pattern about which quotes a StringPattern is made of --- CHANGELOG.md | 2 ++ src/Elm/Parser/Patterns.elm | 4 ++-- src/Elm/Syntax/Pattern.elm | 3 ++- tests/Elm/Parser/CaseExpressionTests.elm | 5 +++-- tests/Elm/Parser/PatternTests.elm | 7 ++++++- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 94e915950..64acad501 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,8 @@ - Changed `Elm.Syntax.Pattern.Pattern`: - Removed `FloatPattern` (it was not possible to get) + - Added information to `StringPattern` as to whether `"""` or `"` was used: + - `StringPattern String` -> `StringPattern StringLiteralType String` - Changed `Elm.Syntax.TypeAnnotation.TypeAnnotation`: - `Tupled` -> `Tuple` diff --git a/src/Elm/Parser/Patterns.elm b/src/Elm/Parser/Patterns.elm index 0cf563b9d..d1da3142e 100644 --- a/src/Elm/Parser/Patterns.elm +++ b/src/Elm/Parser/Patterns.elm @@ -235,10 +235,10 @@ stringPattern : Parser (WithComments (Node Pattern)) stringPattern = Tokens.singleOrTripleQuotedStringLiteral |> ParserFast.mapWithStartAndEndPosition - (\start ( _, string ) end -> + (\start ( stringLiteralType, string ) end -> { comments = Rope.empty , syntax = - Node { start = start, end = end } (StringPattern string) + Node { start = start, end = end } (StringPattern stringLiteralType string) } ) diff --git a/src/Elm/Syntax/Pattern.elm b/src/Elm/Syntax/Pattern.elm index a3cd8a8d0..ab02f1c8e 100644 --- a/src/Elm/Syntax/Pattern.elm +++ b/src/Elm/Syntax/Pattern.elm @@ -23,6 +23,7 @@ For example: import Elm.Syntax.ModuleName exposing (ModuleName) import Elm.Syntax.Node exposing (Node(..)) +import Elm.Syntax.StringLiteralType exposing (StringLiteralType) {-| Custom type for all patterns such as: @@ -48,7 +49,7 @@ type Pattern = AllPattern | UnitPattern | CharPattern Char - | StringPattern String + | StringPattern StringLiteralType String | IntPattern Int | HexPattern Int | TuplePattern (List (Node Pattern)) diff --git a/tests/Elm/Parser/CaseExpressionTests.elm b/tests/Elm/Parser/CaseExpressionTests.elm index 19868ae95..72be318ec 100644 --- a/tests/Elm/Parser/CaseExpressionTests.elm +++ b/tests/Elm/Parser/CaseExpressionTests.elm @@ -5,6 +5,7 @@ import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil import Elm.Syntax.Expression exposing (..) import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (..) +import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) import Expect import Test exposing (..) @@ -142,11 +143,11 @@ True -> 1""" } (FunctionOrValue [] "x") , firstCase = - ( Node { start = { row = 2, column = 9 }, end = { row = 2, column = 39 } } (StringPattern "single line triple quote") + ( Node { start = { row = 2, column = 9 }, end = { row = 2, column = 39 } } (StringPattern TripleQuote "single line triple quote") , Node { start = { row = 3, column = 13 }, end = { row = 3, column = 14 } } (IntegerLiteral 1) ) , restOfCases = - [ ( Node { start = { row = 4, column = 9 }, end = { row = 5, column = 28 } } (StringPattern "multi line\n triple quote") + [ ( Node { start = { row = 4, column = 9 }, end = { row = 5, column = 28 } } (StringPattern TripleQuote "multi line\n triple quote") , Node { start = { row = 6, column = 13 }, end = { row = 6, column = 14 } } (IntegerLiteral 2) ) , ( Node { start = { row = 7, column = 9 }, end = { row = 7, column = 10 } } AllPattern diff --git a/tests/Elm/Parser/PatternTests.elm b/tests/Elm/Parser/PatternTests.elm index cdb5857ab..321f2d275 100644 --- a/tests/Elm/Parser/PatternTests.elm +++ b/tests/Elm/Parser/PatternTests.elm @@ -4,6 +4,7 @@ import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil exposing import Elm.Parser.Patterns as Parser import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (..) +import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) import Expect import Test exposing (..) @@ -28,7 +29,11 @@ all = , test "String" <| \() -> "\"Foo\"" - |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (StringPattern "Foo")) + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } (StringPattern SingleQuote "Foo")) + , test "Multi-line string" <| + \() -> + "\"\"\"Foo\"\"\"" + |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } } (StringPattern TripleQuote "Foo")) , test "Char" <| \() -> "'f'" From 0f431321c61bbb0a4528ae72901ec029e51bb03e Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sat, 3 Aug 2024 01:01:15 +0200 Subject: [PATCH 43/44] Remove direction from Operator --- CHANGELOG.md | 5 ++++- src/Elm/Parser/Expression.elm | 13 ++++++------- src/Elm/Syntax/Expression.elm | 5 ++--- tests/Elm/Parser/DeclarationsTests.elm | 8 -------- tests/Elm/Parser/ExpressionTests.elm | 18 ------------------ tests/Elm/Parser/FileTests.elm | 2 -- tests/Elm/Parser/LambdaExpressionTests.elm | 3 --- tests/Elm/Parser/ModuleTests.elm | 2 -- 8 files changed, 12 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64acad501..c64e9efab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,10 @@ - Renamed `Integer` to `IntegerLiteral` - Renamed `Hex` to `HexLiteral` - Renamed `ListExpr` to `ListLiteral` - - Renamed `OperatorApplication` to `Operation` + - `OperatorApplication` + - Renamed `OperatorApplication` to `Operation` + - Removed the `InfixDirection` field + - `OperatorApplication String InfixDirection (Node Expression) (Node Expression)` -> `Operation String (Node Expression) (Node Expression)` - Renamed `isOperatorApplication` to `isOperation` - Renamed `RecordExpr` to `Record` - Renamed `CaseExpression` to `Case` diff --git a/src/Elm/Parser/Expression.elm b/src/Elm/Parser/Expression.elm index 9ebf34f50..729f7006f 100644 --- a/src/Elm/Parser/Expression.elm +++ b/src/Elm/Parser/Expression.elm @@ -9,7 +9,6 @@ import Elm.Parser.Tokens as Tokens import Elm.Parser.TypeAnnotation as TypeAnnotation import Elm.Syntax.DestructurePattern exposing (DestructurePattern) import Elm.Syntax.Expression as Expression exposing (Case, Expression(..), LetDeclaration(..), RecordSetter) -import Elm.Syntax.Infix as Infix import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Range exposing (Location) import Elm.Syntax.Signature exposing (Signature) @@ -1135,7 +1134,7 @@ applyExtensionRight extensionRight ((Node { start } left) as leftNode) = extendRightOperation.expression in Node { start = start, end = end } - (Operation extendRightOperation.symbol extendRightOperation.direction leftNode right) + (Operation extendRightOperation.symbol leftNode right) abovePrecedence0 : Parser (WithComments ExtensionRight) @@ -1213,7 +1212,7 @@ infixLeft precedence possibilitiesForPrecedence symbol = possibilitiesForPrecedence (ParserFast.symbolFollowedBy symbol) (\right -> - ExtendRightByOperation { symbol = symbol, direction = Infix.Left, expression = right } + ExtendRightByOperation { symbol = symbol, expression = right } ) @@ -1223,7 +1222,7 @@ infixNonAssociative precedence possibilitiesForPrecedence symbol = possibilitiesForPrecedence (ParserFast.symbolFollowedBy symbol) (\right -> - ExtendRightByOperation { symbol = symbol, direction = Infix.Non, expression = right } + ExtendRightByOperation { symbol = symbol, expression = right } ) @@ -1236,7 +1235,7 @@ infixRight precedence possibilitiesForPrecedenceMinus1 symbol = possibilitiesForPrecedenceMinus1 (ParserFast.symbolFollowedBy symbol) (\right -> - ExtendRightByOperation { symbol = symbol, direction = Infix.Right, expression = right } + ExtendRightByOperation { symbol = symbol, expression = right } ) @@ -1264,7 +1263,7 @@ infixLeftSubtraction precedence possibilitiesForPrecedence = ) ) (\right -> - ExtendRightByOperation { symbol = "-", direction = Infix.Left, expression = right } + ExtendRightByOperation { symbol = "-", expression = right } ) @@ -1296,6 +1295,6 @@ postfix precedence operator = type ExtensionRight - = ExtendRightByOperation { symbol : String, direction : Infix.InfixDirection, expression : Node Expression } + = ExtendRightByOperation { symbol : String, expression : Node Expression } | ExtendRightByApplication (Node Expression) | ExtendRightByRecordAccess (Node String) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 4917ce90c..5f20bd647 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -20,7 +20,6 @@ Although it is a easy and simple language, you can express a lot! See the `Expre import Elm.Syntax.DestructurePattern exposing (DestructurePattern) import Elm.Syntax.Documentation exposing (Documentation) -import Elm.Syntax.Infix exposing (InfixDirection) import Elm.Syntax.ModuleName exposing (ModuleName) import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (Pattern) @@ -111,7 +110,7 @@ type Expression | FunctionOrValue ModuleName String | PrefixOperator String | FunctionCall (Node Expression) (Node Expression) (List (Node Expression)) - | Operation String InfixDirection (Node Expression) (Node Expression) + | Operation String (Node Expression) (Node Expression) | If (Node Expression) (Node Expression) (Node Expression) | TupleExpression (List (Node Expression)) | Let LetBlock @@ -222,7 +221,7 @@ isCase e = isOperation : Expression -> Bool isOperation e = case e of - Operation _ _ _ _ -> + Operation _ _ _ -> True _ -> diff --git a/tests/Elm/Parser/DeclarationsTests.elm b/tests/Elm/Parser/DeclarationsTests.elm index 8deef89fa..aae448bfa 100644 --- a/tests/Elm/Parser/DeclarationsTests.elm +++ b/tests/Elm/Parser/DeclarationsTests.elm @@ -5,7 +5,6 @@ import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil exposing import Elm.Syntax.Declaration as Declaration exposing (..) import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Expression as Expression exposing (..) -import Elm.Syntax.Infix as Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (..) import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) @@ -148,7 +147,6 @@ foo = bar""" , expression = Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } (Operation "+" - Infix.Left (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (FunctionOrValue [] "x")) (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 14 } } (IntegerLiteral 1)) ) @@ -318,7 +316,6 @@ foo = bar""" ( Node { start = { row = 3, column = 5 }, end = { row = 3, column = 14 } } (NamedPattern { moduleName = [], name = "Increment" } []) , Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } } (Operation "+" - Left (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (IntegerLiteral 1)) ) @@ -327,7 +324,6 @@ foo = bar""" [ ( Node { start = { row = 6, column = 5 }, end = { row = 6, column = 14 } } (NamedPattern { moduleName = [], name = "Decrement" } []) , Node { start = { row = 7, column = 7 }, end = { row = 7, column = 16 } } (Operation "-" - Left (Node { start = { row = 7, column = 7 }, end = { row = 7, column = 12 } } (FunctionOrValue [] "model")) (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (IntegerLiteral 1)) ) @@ -493,11 +489,9 @@ foo = bar""" , expression = Node { start = { row = 1, column = 31 }, end = { row = 1, column = 83 } } (Operation "<|" - Right (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 36 } } (FunctionOrValue [] "curry")) (Node { start = { row = 1, column = 40 }, end = { row = 1, column = 83 } } (Operation ">>" - Right (Node { start = { row = 1, column = 40 }, end = { row = 1, column = 56 } } (TupleExpression [ Node { start = { row = 1, column = 41 }, end = { row = 1, column = 55 } } @@ -552,7 +546,6 @@ foo = bar""" (NamedPattern { moduleName = [], name = "Increment" } []) , Node { start = { row = 4, column = 7 }, end = { row = 4, column = 16 } } (Operation "+" - Left (Node { start = { row = 4, column = 7 }, end = { row = 4, column = 12 } } (FunctionOrValue [] "model")) (Node { start = { row = 4, column = 15 }, end = { row = 4, column = 16 } } (IntegerLiteral 1)) ) @@ -562,7 +555,6 @@ foo = bar""" (NamedPattern { moduleName = [], name = "Decrement" } []) , Node { start = { row = 7, column = 7 }, end = { row = 7, column = 16 } } (Operation "-" - Left (Node { start = { row = 7, column = 7 }, end = { row = 7, column = 12 } } (FunctionOrValue [] "model")) (Node { start = { row = 7, column = 15 }, end = { row = 7, column = 16 } } (IntegerLiteral 1)) ) diff --git a/tests/Elm/Parser/ExpressionTests.elm b/tests/Elm/Parser/ExpressionTests.elm index 685a84913..bf207f9fe 100644 --- a/tests/Elm/Parser/ExpressionTests.elm +++ b/tests/Elm/Parser/ExpressionTests.elm @@ -4,7 +4,6 @@ import Elm.Parser.Expression exposing (expression) import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Expression exposing (Expression(..)) -import Elm.Syntax.Infix as Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.StringLiteralType exposing (StringLiteralType(..)) import Expect @@ -97,7 +96,6 @@ all = (TupleExpression [ Node { start = { row = 1, column = 2 }, end = { row = 1, column = 11 } } (Operation "*" - Left (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 4 } } (Negation (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1))) ) @@ -122,7 +120,6 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 10 } } <| Operation "+" - Infix.Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 6 } } <| FunctionOrValue [] "model") (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } <| IntegerLiteral 1) ) @@ -430,7 +427,6 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 4 } } (Operation "-" - Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (IntegerLiteral 2)) (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (IntegerLiteral 1)) ) @@ -465,7 +461,6 @@ all = (TupleExpression [ Node { start = { row = 1, column = 3 }, end = { row = 1, column = 8 } } (Operation "-" - Left (Node { start = { row = 1, column = 3 }, end = { row = 1, column = 4 } } (FunctionOrValue [] "x")) (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 8 } } (FunctionOrValue [] "y")) ) @@ -480,22 +475,18 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 29 } } (Operation "==" - Non (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 18 } } (Operation "+" - Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 3 } } (Negation (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1))) ) (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 18 } } (Operation "*" - Left (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 9 } } (Negation (Node { start = { row = 1, column = 7 }, end = { row = 1, column = 9 } } (IntegerLiteral 10))) ) (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 18 } } (Operation "^" - Right (Node { start = { row = 1, column = 12 }, end = { row = 1, column = 16 } } (Negation (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 16 } } (IntegerLiteral 100)) @@ -520,10 +511,8 @@ all = (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 11 } } (Operation "-" - Left (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 7 } } (Operation "+" - Left (Node { start = { row = 1, column = 2 }, end = { row = 1, column = 3 } } (IntegerLiteral 1)) (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (IntegerLiteral 2)) ) @@ -537,7 +526,6 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 7 } } (Operation "|>" - Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (FunctionOrValue [] "a")) (Node { start = { row = 1, column = 6 }, end = { row = 1, column = 7 } } (FunctionOrValue [] "b")) ) @@ -558,20 +546,16 @@ all = , expression = Node { start = { row = 1, column = 19 }, end = { row = 1, column = 53 } } (Operation "||" - Right (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 27 } } (Operation "==" - Non (Node { start = { row = 1, column = 19 }, end = { row = 1, column = 20 } } (FunctionOrValue [] "c")) (Node { start = { row = 1, column = 24 }, end = { row = 1, column = 27 } } (CharLiteral ' ')) ) ) (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 53 } } (Operation "||" - Right (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 40 } } (Operation "==" - Non (Node { start = { row = 1, column = 31 }, end = { row = 1, column = 32 } } (FunctionOrValue [] "c")) (Node { start = { row = 1, column = 36 }, end = { row = 1, column = 40 } } (CharLiteral '\n') @@ -580,7 +564,6 @@ all = ) (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 53 } } (Operation "==" - Non (Node { start = { row = 1, column = 44 }, end = { row = 1, column = 45 } } (FunctionOrValue [] "c")) (Node { start = { row = 1, column = 49 }, end = { row = 1, column = 53 } } (CharLiteral '\u{000D}') @@ -653,7 +636,6 @@ all = |> expectAst (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 16 } } (Operation "+" - Left (Node { start = { row = 1, column = 1 }, end = { row = 1, column = 2 } } (IntegerLiteral 1)) (Node { start = { row = 1, column = 5 }, end = { row = 1, column = 16 } } (Negation diff --git a/tests/Elm/Parser/FileTests.elm b/tests/Elm/Parser/FileTests.elm index daae8dfd6..29e18b947 100644 --- a/tests/Elm/Parser/FileTests.elm +++ b/tests/Elm/Parser/FileTests.elm @@ -7,7 +7,6 @@ import Elm.Syntax.Declaration exposing (Declaration(..)) import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Exposing exposing (Exposing(..)) import Elm.Syntax.Expression exposing (Expression(..), LetDeclaration(..)) -import Elm.Syntax.Infix exposing (InfixDirection(..)) import Elm.Syntax.Module exposing (Module(..)) import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (Pattern(..)) @@ -225,7 +224,6 @@ lambdaWhitespace = \\ a b -> a , expression = Node { start = { row = 4, column = 34 }, end = { row = 8, column = 6 } } (Operation "+" - Left (Node { start = { row = 4, column = 34 }, end = { row = 4, column = 35 } } (FunctionOrValue [] "a")) (Node { start = { row = 8, column = 5 }, end = { row = 8, column = 6 } } (FunctionOrValue [] "b")) ) diff --git a/tests/Elm/Parser/LambdaExpressionTests.elm b/tests/Elm/Parser/LambdaExpressionTests.elm index 0a74664bb..b66a210f4 100644 --- a/tests/Elm/Parser/LambdaExpressionTests.elm +++ b/tests/Elm/Parser/LambdaExpressionTests.elm @@ -4,7 +4,6 @@ import Elm.Parser.Expression exposing (expression) import Elm.Parser.ParserWithCommentsTestUtil as ParserWithCommentsUtil import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Expression exposing (..) -import Elm.Syntax.Infix exposing (InfixDirection(..)) import Elm.Syntax.Node exposing (Node(..)) import Expect import Test exposing (..) @@ -62,7 +61,6 @@ all = , expression = Node { start = { row = 1, column = 9 }, end = { row = 1, column = 14 } } (Operation "+" - Left (Node { start = { row = 1, column = 9 }, end = { row = 1, column = 10 } } (FunctionOrValue [] "a")) (Node { start = { row = 1, column = 13 }, end = { row = 1, column = 14 } } (FunctionOrValue [] "b")) ) @@ -86,7 +84,6 @@ all = , expression = Node { start = { row = 1, column = 11 }, end = { row = 1, column = 16 } } (Operation "+" - Left (Node { start = { row = 1, column = 11 }, end = { row = 1, column = 12 } } (FunctionOrValue [] "a")) (Node { start = { row = 1, column = 15 }, end = { row = 1, column = 16 } } (FunctionOrValue [] "b")) ) diff --git a/tests/Elm/Parser/ModuleTests.elm b/tests/Elm/Parser/ModuleTests.elm index 863275af7..f5b208641 100644 --- a/tests/Elm/Parser/ModuleTests.elm +++ b/tests/Elm/Parser/ModuleTests.elm @@ -7,7 +7,6 @@ import Elm.Syntax.Declaration exposing (Declaration(..)) import Elm.Syntax.DestructurePattern exposing (DestructurePattern(..)) import Elm.Syntax.Exposing exposing (..) import Elm.Syntax.Expression exposing (Expression(..)) -import Elm.Syntax.Infix exposing (InfixDirection(..)) import Elm.Syntax.Module exposing (..) import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation(..)) @@ -462,7 +461,6 @@ fun2 n = , expression = Node { start = { row = 4, column = 3 }, end = { row = 5, column = 11 } } (Operation "+" - Left (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 9 } } (FunctionCall (Node { start = { row = 4, column = 3 }, end = { row = 4, column = 7 } } (FunctionOrValue [] "fun2")) From b9e532a453d4a344e107886c800901ee5a644f6b Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sun, 4 Aug 2024 00:06:04 +0200 Subject: [PATCH 44/44] Remove predicate functions from Expression --- CHANGELOG.md | 2 +- src/Elm/Syntax/Expression.elm | 64 ++--------------------------------- 2 files changed, 3 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c64e9efab..bfde3f3ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,6 @@ - Renamed `OperatorApplication` to `Operation` - Removed the `InfixDirection` field - `OperatorApplication String InfixDirection (Node Expression) (Node Expression)` -> `Operation String (Node Expression) (Node Expression)` - - Renamed `isOperatorApplication` to `isOperation` - Renamed `RecordExpr` to `Record` - Renamed `CaseExpression` to `Case` - Renamed `LetExpression` to `Let` @@ -51,6 +50,7 @@ - Removed `Elm.Syntax.Expression.Cases` type alias (it was `type alias Cases = List Case`) - `Elm.Syntax.Expression.CaseBlock`'s `cases : List Case` field is split into `firstCase : Case` and `restOfCases : List Case` (takes a non-empty list of cases) - Removed `Operator` (it was not possible to get) + - Renamed predicate functions `isLambda`, `isLet`, `isIfElse`, `isCase`, `isOperatorApplication` - Changed `Elm.Syntax.Pattern.Pattern`: - Removed `FloatPattern` (it was not possible to get) diff --git a/src/Elm/Syntax/Expression.elm b/src/Elm/Syntax/Expression.elm index 5f20bd647..8471c046d 100644 --- a/src/Elm/Syntax/Expression.elm +++ b/src/Elm/Syntax/Expression.elm @@ -1,6 +1,6 @@ module Elm.Syntax.Expression exposing ( Expression(..), Lambda, LetBlock, LetDeclaration(..), RecordSetter, CaseBlock, Case, Function, FunctionImplementation - , functionRange, isLambda, isLet, isIfElse, isCase, isOperation + , functionRange ) {-| This syntax represents all that you can express in Elm. @@ -14,7 +14,7 @@ Although it is a easy and simple language, you can express a lot! See the `Expre ## Functions -@docs functionRange, isLambda, isLet, isIfElse, isCase, isOperation +@docs functionRange -} @@ -166,63 +166,3 @@ type alias CaseBlock = -} type alias Case = ( Node Pattern, Node Expression ) - - -{-| Check whether an expression is a lambda-expression --} -isLambda : Expression -> Bool -isLambda e = - case e of - LambdaExpression _ -> - True - - _ -> - False - - -{-| Check whether an expression is a let-expression --} -isLet : Expression -> Bool -isLet e = - case e of - Let _ -> - True - - _ -> - False - - -{-| Check whether an expression is an if-else-expression --} -isIfElse : Expression -> Bool -isIfElse e = - case e of - If _ _ _ -> - True - - _ -> - False - - -{-| Check whether an expression is a case-expression --} -isCase : Expression -> Bool -isCase e = - case e of - Case _ -> - True - - _ -> - False - - -{-| Check whether an expression is an operator application expression --} -isOperation : Expression -> Bool -isOperation e = - case e of - Operation _ _ _ -> - True - - _ -> - False