Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaller optimizations for custom parser since before incorrect force push #257

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
254 commits
Select commit Hold shift + click to select a range
d77adfa
introduce Layout.maybeLayoutUntilIgnored
lue-bird Aug 1, 2024
1db6d84
simplify maybeLayoutUntilIgnored
lue-bird Aug 2, 2024
bf6a5e0
inline the node parser part of singleLineCommentCore to save a map
lue-bird Aug 2, 2024
870f94f
speed up and correct maybeLayoutUntil
lue-bird Aug 2, 2024
3d100f0
save unnecessary maybeLayout for empty record content
lue-bird Aug 2, 2024
e559caf
remove unused members
lue-bird Aug 2, 2024
fc94a45
switch to Parser.Advanced.loop to save a map for every step
lue-bird Aug 2, 2024
bf3551b
assume function declaration without documentation is more common
lue-bird Aug 2, 2024
24abbf7
try infix declarations last
lue-bird Aug 2, 2024
05d477b
reduce unnecessary lambda
lue-bird Aug 3, 2024
742999f
replace i |> continueWith (map f k) by map (\() -> f) i |= k, it's a …
lue-bird Aug 3, 2024
8d5510b
move closing record type } inside oneOf
lue-bird Aug 3, 2024
eb47807
move shared Just out of case of
lue-bird Aug 3, 2024
eaa4492
move closing pattern } into oneOf
lue-bird Aug 3, 2024
f636707
remove unused
lue-bird Aug 3, 2024
dea4593
1-to-1 conversion to custom parser
lue-bird Aug 4, 2024
3e1864a
partially introduce mapNs
lue-bird Aug 4, 2024
4a01045
replace most keep/ignore-pipelines by mapN
lue-bird Aug 4, 2024
1f0da4e
replace all keep/ignore-pipelines by mapN
lue-bird Aug 4, 2024
caff2c0
remove unused Elm.Parser.Node.parserCoreMap
lue-bird Aug 4, 2024
2639c2d
avoid Elm.Parser.Node.parserMap
lue-bird Aug 4, 2024
b2da54d
remove unused CustomParser.Advanced.keep
lue-bird Aug 4, 2024
95f9a53
introduce succeedLazy
lue-bird Aug 4, 2024
2896588
don't split mapN lambdas
lue-bird Aug 4, 2024
345bd64
introduce columnIndentAndThen for faster indentation checks
lue-bird Aug 4, 2024
d0d7eda
simplify moduleLevelIndentation
lue-bird Aug 4, 2024
305cfd0
style: replace <| by parens
lue-bird Aug 4, 2024
babb4cd
CustomParser.number is already backtrackable
lue-bird Aug 5, 2024
b3143b3
introduce offsetSourceAndThen
lue-bird Aug 5, 2024
ff25378
introduce columnAndThen
lue-bird Aug 5, 2024
ebcc000
replace some continueWith by map2
lue-bird Aug 5, 2024
28a25b3
remove unused import
lue-bird Aug 5, 2024
5acb6a4
use DeadEnd, Problem from elm/parser
lue-bird Aug 5, 2024
e949082
update tests to new DeadEnd
lue-bird Aug 5, 2024
cc25a6f
remove alias "token" for symbol
lue-bird Aug 5, 2024
38991d9
avoid map after symbol/keyword
lue-bird Aug 5, 2024
e25702d
avoid a map in postfix
lue-bird Aug 5, 2024
fbe02fe
avoid intermediate Token type
lue-bird Aug 5, 2024
62badb3
avoid unnecessary DeadEnd and Problem types
lue-bird Aug 5, 2024
89bd80b
introduce symbolFollowedBy and keywordFollowedBy
lue-bird Aug 5, 2024
6d00a59
use symbolFollowedBy, keywordFollowedBy more
lue-bird Aug 5, 2024
95f51a8
remove unused tokens
lue-bird Aug 5, 2024
84daa41
avoid a few ignore
lue-bird Aug 5, 2024
588264b
use followed-by style more for infix expressions
lue-bird Aug 5, 2024
0d1d1f7
skip checks for empty symbol/keyword String
lue-bird Aug 5, 2024
4469832
move fast isAlphaNum to new Char.Extra and use in CustomParser.Advanced
lue-bird Aug 5, 2024
61da2c6
speed up isSubChar
lue-bird Aug 5, 2024
3b60f45
use lookahead for multilineCommentString
lue-bird Aug 5, 2024
c88ad74
faster negationOperation
lue-bird Aug 5, 2024
bfb5574
introduce mapWithStart&/EndPosition
lue-bird Aug 5, 2024
8507d77
remove unused CustomParser.Extra.continueWith
lue-bird Aug 5, 2024
6892273
replace single-line range calculations using Node.parserCore
lue-bird Aug 5, 2024
f3ae754
pattern parsers handle start and end themselves to sometimes save a map
lue-bird Aug 5, 2024
0bfb83d
handle range in type parsers themselves to sometimes save a map
lue-bird Aug 5, 2024
76f582d
handle range in expression parsers themselves to sometimes save a map
lue-bird Aug 5, 2024
fa9ffc6
exposable parsers handle range themselves to sometimes save a map
lue-bird Aug 5, 2024
8cf0d52
elm-review: sort fields
lue-bird Aug 5, 2024
19d0c7f
make letDestructuringDeclaration more strict
lue-bird Aug 5, 2024
feddb62
correctly don't parse composed destructuring pattern
lue-bird Aug 5, 2024
cc6eb7b
correctly parse argument patterns as non-composing
lue-bird Aug 5, 2024
412e00c
remove unused imports
lue-bird Aug 5, 2024
b556a0c
replace last instances of getPosition
lue-bird Aug 5, 2024
819bb49
eliminate get... parsers
lue-bird Aug 5, 2024
368880d
introduce faster choice primitives
lue-bird Aug 5, 2024
8e430e3
Inline CustomParser.Extra.withIndent
jfmengels Aug 5, 2024
291177b
Add CustomParser.withIndentSetToColumn
jfmengels Aug 5, 2024
cf09c49
add basic benchmark
jiegillet Jul 9, 2024
c7c45ac
Revert "add basic benchmark"
lue-bird Aug 6, 2024
a8ec44f
integrate withIndentSetToColumn into doc tags
lue-bird Aug 6, 2024
4616b68
Use JS comparison where possible
jfmengels Aug 5, 2024
646ac89
Use JS comparison where possible
jfmengels Aug 5, 2024
36e8bb2
Make Good and Bad have the same shape
jfmengels Aug 5, 2024
4399513
convert onTopIndentation to -FollowedBy
lue-bird Aug 6, 2024
d71f5e2
convert moduleLevelIndentation to -FollowedBy
lue-bird Aug 6, 2024
53b38cd
replace positivelyIndented uses by -FollowedBy
lue-bird Aug 6, 2024
58b4e63
convert positivelyIndentedPlus to -FollowedBy
lue-bird Aug 6, 2024
7806a35
more consistent types
lue-bird Aug 6, 2024
b834557
replace positivelyIndentedPlusResultingIn use by -FollowedBy
lue-bird Aug 6, 2024
0a1e97f
add layoutStrict followed by versions
lue-bird Aug 6, 2024
1b00988
apply case-of comment order correction from master
lue-bird Aug 6, 2024
dc2e9df
introduce chompIfFollowedBy, simplify nestableHelp
lue-bird Aug 6, 2024
11c9f96
rewrite mention of removed getOffset
lue-bird Aug 6, 2024
9ed2b1b
tupledExpressionInnerAfterOpeningParens correct
lue-bird Aug 6, 2024
a5d6499
rename "CustomParser" to "ParserFast" to make its purpose clear
lue-bird Aug 6, 2024
dade86b
switch to oneOf2
lue-bird Aug 6, 2024
2e9481b
move mapWithStartPosition to sub-parsers to avoid bigger intermediate…
lue-bird Aug 7, 2024
9b112b7
replace record type alias constructor by record fields
lue-bird Aug 7, 2024
4dd8ff8
abuse the fact that isSubString doesn't accept newlines
lue-bird Aug 7, 2024
33645bd
remove column from isSubString
lue-bird Aug 7, 2024
8284457
simplify how to add length to state
lue-bird Aug 7, 2024
3c6ad0d
slightly speed up isSubChar by using String.any
lue-bird Aug 7, 2024
07a4559
introduce variableWithoutReserved
lue-bird Aug 7, 2024
58c818f
remove unused imports
lue-bird Aug 7, 2024
7c1b7d8
unify varHelp and chompWhileHelp
lue-bird Aug 7, 2024
4ca843b
faster whitespaceAndCommentsOrEmpty
lue-bird Aug 7, 2024
f54f4c3
introduce specialized fast chompWhileWhitespace
lue-bird Aug 7, 2024
b53c1e7
introduce chompAnyChar
lue-bird Aug 7, 2024
3ff3348
re-use record for advanced parser
lue-bird Aug 9, 2024
6123d55
let loop take already constructed parsers
lue-bird Aug 9, 2024
1c1ef75
introduce oneOf2Map
lue-bird Aug 9, 2024
7c2c9f9
introduce mapOrSucceed
lue-bird Aug 9, 2024
0bc2a11
simplify whitespaceAndCommentsUntilEndComments
lue-bird Aug 9, 2024
a0b9334
avoid a parser map using oneOf2Map
lue-bird Aug 9, 2024
ef6b233
replace chompWhileWhitespace |> andThen by chompWhileWhitespaceFollow…
lue-bird Aug 9, 2024
068f6bb
inline from comment parsers
lue-bird Aug 9, 2024
01e795a
clear up confusing comment
lue-bird Aug 9, 2024
1cd1634
introduce chompWhileMap
lue-bird Aug 9, 2024
b832165
pre-define nestable multi comment closing symbol
lue-bird Aug 9, 2024
6d2945c
pre-define nestable multi comment opening symbol
lue-bird Aug 9, 2024
77f7dce
remove misleading link
lue-bird Aug 9, 2024
1d52a0c
replace String.dropLeft by the faster String.slice
lue-bird Aug 9, 2024
8a28f75
move anyChar to Elm.Parser.Tokens
lue-bird Aug 9, 2024
8433450
define ParserFast.run to directly use advanced
lue-bird Aug 16, 2024
ccd9cdb
reuse bad in withIndent*
lue-bird Aug 16, 2024
eaa6447
format benchmark file
lue-bird Aug 16, 2024
61a81e3
replace parser ignore by map2
lue-bird Aug 16, 2024
593510f
add test sample pdamoc/elm-syntax-sscce
lue-bird Aug 16, 2024
739598d
introduce faster anyChar parser
lue-bird Aug 16, 2024
01ff127
drop empty variant from parser errors
lue-bird Aug 16, 2024
d81ad77
call "Bag" "RopeFilled" for consistency
lue-bird Aug 16, 2024
a7aa5c5
introduce parser validate
lue-bird Aug 16, 2024
56193de
introduce parser validateEndColumnIndentation
lue-bird Aug 16, 2024
ed8a8ea
replace last parser andThens using many*
lue-bird Aug 16, 2024
a6b6ebb
avoid unnecessary optimisticLayout
lue-bird Aug 16, 2024
2a60022
rename andThenOneOf
lue-bird Aug 16, 2024
7eb18d2
rename subExpressionMap
lue-bird Aug 16, 2024
e81c961
remove outdated code comment
lue-bird Aug 16, 2024
f974fce
replace variableWithoutReserve by ifThenWhile
lue-bird Aug 17, 2024
eb1315e
introduce ParserFast.oneOf3
lue-bird Aug 17, 2024
96b93ab
introduce parser oneOf2OrSucceed
lue-bird Aug 17, 2024
1fa2c10
avoid a getChompedString in favor of chompWhileMap
lue-bird Aug 17, 2024
e51e79b
rename chompWhileMap to whileMap
lue-bird Aug 17, 2024
d56d5bd
redefine nestableMultiComment to not require getChompedString
lue-bird Aug 17, 2024
77363eb
remove/use unused things
lue-bird Aug 17, 2024
d8c204c
internally introduce anyCharFollowedByWhileMap
lue-bird Aug 17, 2024
af2c877
replace skip symbol by symbolFollowedBy
lue-bird Aug 17, 2024
7a2f0b8
choose nicer named for committed parameters
lue-bird Aug 17, 2024
c96a41d
nestableMultiComment speed up the common case
lue-bird Aug 17, 2024
0cc6432
convert a oneOf2Map to oneOf2
lue-bird Aug 17, 2024
9c6b5a0
replace parser variable by ifFollowedByWhileExcept
lue-bird Aug 17, 2024
f8c4763
use more specific names for PStep parameters
lue-bird Aug 17, 2024
1b7a8d5
move whileMap docs tag to primitives
lue-bird Aug 17, 2024
66f3787
introduce parser oneOf4
lue-bird Aug 17, 2024
5226e4b
introduce parser loopWhileSucceeds
lue-bird Aug 17, 2024
f0a5778
introduce parser loopUntil
lue-bird Aug 17, 2024
8fad3df
remove unused things
lue-bird Aug 17, 2024
f08a4ee
glslExpressionAfterOpeningSquareBracket replace loop by loopUntil
lue-bird Aug 17, 2024
5b43e49
singleOrTripleQuotedStringLiteral replace loop by loopUntil
lue-bird Aug 17, 2024
808b223
add map to escapedCharValue to save a ParserFast.map
lue-bird Aug 17, 2024
755bd53
remove unused things
lue-bird Aug 17, 2024
d697059
speed up isSubChar by assuming the given predicate accounts for doubl…
lue-bird Aug 21, 2024
8ffd5e9
introduce internal isSubCharSinglePart
lue-bird Aug 21, 2024
4577395
correct isSubCharSinglePart uses
lue-bird Aug 21, 2024
ee6e8c5
inline isSubChar into chompWhileHelp to save checks
lue-bird Aug 21, 2024
aa98c11
inline backtrackable, nicer maybeLayoutUntilIgnored
lue-bird Aug 22, 2024
93787df
simplify lets
lue-bird Aug 22, 2024
f73440c
remove unused parser backtrackable, fix broken links
lue-bird Aug 22, 2024
f0dfa29
introduce parser mapNWithStart
lue-bird Aug 23, 2024
836772b
inline isSubString
lue-bird Aug 23, 2024
1cc824d
specialize isSubCharSinglePart to its only current use case
lue-bird Aug 23, 2024
b8baf9c
introduce parser symbolWithEndPosition
lue-bird Aug 23, 2024
afd1f8c
introduce parser mapNWithStartAndEndPosition
lue-bird Aug 23, 2024
b3d5813
move comment range parsing to Comments module
lue-bird Aug 23, 2024
fdbcbd5
merge ParserFast.Advanced and ParserFast modules
lue-bird Aug 23, 2024
59c4e2a
remove unused imports
lue-bird Aug 23, 2024
e109fd2
introduce ifFollowedByWhileExceptMapWithStartAndEndPositions
lue-bird Aug 23, 2024
c5d24f6
introduce ParserFast.symbolWithStartAndEndPosition
lue-bird Aug 23, 2024
50c26e4
expose ParserFast.while
lue-bird Aug 23, 2024
0078e10
inline ParserWithComments.sepBy1
lue-bird Aug 23, 2024
71635c7
inline a Layout.maybeAroundBothSides into existing mapN
lue-bird Aug 23, 2024
a1e9026
avoid unnecessary linebreak checks
lue-bird Aug 24, 2024
8fc2b76
introduce ParserFast.followedBySymbol
lue-bird Aug 24, 2024
56bfed1
move range parsing to Modules to save a Node.parser
lue-bird Aug 24, 2024
435242c
move range parsing to Expose to save Node.parsers
lue-bird Aug 24, 2024
6556cdd
correct exposeDefinition range
lue-bird Aug 24, 2024
71e01da
include Elm.Parser.Numbers in ParserFast
lue-bird Aug 24, 2024
ee1e410
introduce ParserFast.mapNOrSucceed
lue-bird Aug 24, 2024
92817f9
avoid a few Node.parserCores
lue-bird Aug 24, 2024
108bae3
remove unused ParserFast.number
lue-bird Aug 24, 2024
8340d49
remove unused ParserFast.mapNs
lue-bird Aug 24, 2024
5704f7b
correct commit behavior of ParserFast.followedBySymbol
lue-bird Aug 24, 2024
9391664
removed unused import
lue-bird Aug 24, 2024
c3feeaa
introduce ParserFast.oneOfN
lue-bird Aug 24, 2024
c63c9aa
ParserFast switch to Location type for positions
lue-bird Aug 24, 2024
182aa30
number parsers add quick lookahead
lue-bird Aug 25, 2024
fc3316f
optimize name char checks
lue-bird Aug 25, 2024
f5239a8
faster hex parsing
lue-bird Aug 25, 2024
9839403
correct hexStringToInt
lue-bird Aug 25, 2024
53fbffd
very slightly speed up a few mapN ranges
lue-bird Aug 25, 2024
2c977e8
check for function calls much earlier
lue-bird Aug 25, 2024
3754916
infixLeftSubtraction pre-define andThen branch parsers
lue-bird Aug 25, 2024
46958ef
optimize infixLeftSubtraction by only validating whitespace after bac…
lue-bird Aug 25, 2024
661feb9
recordAccessFunctionExpression save a map
lue-bird Aug 25, 2024
d7f67cb
correct symbolBacktrackableFollowedBy
lue-bird Aug 26, 2024
c5d4d5e
check for correct whitespace after backtracking-ly parsing dot of rec…
lue-bird Aug 26, 2024
a2e7cf1
rename ParserFast.*Position to *Location
lue-bird Aug 26, 2024
81975fd
supply ranges instead of start+end when possible
lue-bird Aug 26, 2024
40a1139
replace Node.parserCore by ParserFast.mapWithRange Node
lue-bird Aug 26, 2024
18d3197
actually supply Range if name includes Range
lue-bird Aug 26, 2024
8ddee0a
check for keywords using case instead of Set
lue-bird Aug 26, 2024
bd9527b
remove unused imports
lue-bird Aug 26, 2024
f45f3f2
switch to custom problem type to make failing temporarily cheaper
lue-bird Aug 26, 2024
45f348f
inline intermediate let helper
lue-bird Aug 26, 2024
5170b03
optimize alphanum checks further
lue-bird Aug 26, 2024
5fdd37e
save some ParserFast.mapWithRanges
lue-bird Aug 27, 2024
0d5b016
make lookahead for documentation slightly faster
lue-bird Aug 27, 2024
253e60b
make ParserFast.nestableMultiComment a -MapWithRange
lue-bird Aug 27, 2024
0fb30d7
inline slashEscapedCharValue
lue-bird Aug 27, 2024
1b81bcd
simplify record access and function calls
lue-bird Aug 27, 2024
ef23ead
inline and simplify applyExtensionsRightReverse
lue-bird Aug 27, 2024
4c21311
eliminate need to check for subtraction before functionCall
lue-bird Aug 27, 2024
e127658
simplify negation parser
lue-bird Aug 27, 2024
ec18845
remove unused stuff
lue-bird Aug 27, 2024
fcb30d5
make functionCall consume all possible arguments at once
lue-bird Aug 28, 2024
d49b407
inline the check for function calls into extendedSubExpression
lue-bird Aug 28, 2024
4965f60
infixHelp ony map after operator
lue-bird Aug 28, 2024
df4b6a7
convert extendedSubExpression to -Map to save a map
lue-bird Aug 28, 2024
981e276
only destructure in the relevant neanch
lue-bird Aug 28, 2024
b4b0c22
simplify :: lambda
lue-bird Aug 28, 2024
70cb0cf
introduce oneOf2MapWithStartRowColumnAndEndRowColumn to save a few maps
lue-bird Aug 28, 2024
e5da073
shortcut-fail directly on first symbol/keyword if possible
lue-bird Aug 28, 2024
fbecc0a
simplify subtraction a lot (possible thanks to negation checks)
lue-bird Aug 28, 2024
5b208c7
convert number parsers to -MapWithRange to save a few maps
lue-bird Aug 28, 2024
a9a8865
revert exposing ParserFast internals
lue-bird Aug 28, 2024
9987a68
update docs tag
lue-bird Aug 28, 2024
7522b3e
remove unused chompIfWhitespaceFollowedBy
lue-bird Aug 28, 2024
9af0165
remove unnecessary negation into record access check (since subExpres…
lue-bird Aug 29, 2024
a5f5670
only parse record access when needed
lue-bird Aug 29, 2024
98f36bc
disallow > 3 tuple parts
lue-bird Aug 29, 2024
c686e9d
don't allow record access after 2/3-tuples
lue-bird Aug 29, 2024
5f37fdb
avoid prepending Rope.empty if known
lue-bird Aug 29, 2024
d16fdb0
inline fromMultilineCommentNode
lue-bird Aug 29, 2024
6bd68a8
fix stack overflow for consecutive comments
lue-bird Aug 29, 2024
cc53f00
update ParserFast docs
lue-bird Aug 29, 2024
b538a0a
clean up based on review errors
lue-bird Aug 29, 2024
bcd24fd
add succeeding test for a file with 3000 comments
lue-bird Aug 30, 2024
d0b696e
correct multi-record-access
lue-bird Aug 30, 2024
566f765
introduce multiRecordAccessMap to save a map
lue-bird Aug 30, 2024
12955d4
remove unused helper
lue-bird Aug 30, 2024
d75bac9
disallow record access on variant/record type alias constructor
lue-bird Aug 30, 2024
0ca98fd
introduce ParserFast.withIndentSetToColumnMinus to allow failing earlier
lue-bird Aug 30, 2024
e34e1cc
basic outline of unreleased changes
lue-bird Aug 30, 2024
84533d3
correct letExpression result start location
lue-bird Aug 30, 2024
ee75e57
use maybeLayoutUntilIgnored in a few more places
lue-bird Aug 30, 2024
01a147e
remove ParserWithComments.until* helpers because they aren't faster
lue-bird Aug 30, 2024
15f37cb
correct ranges that include 2-part utf-16 chars (making the parser sl…
lue-bird Aug 30, 2024
22a4592
add test for range of comments that include 2-part utf-16 character
lue-bird Aug 30, 2024
120fa1e
explain Char.Extra.isUtf16Surrogate
lue-bird Aug 30, 2024
43ca516
Sort records
jfmengels Aug 30, 2024
6ee4865
Fix Simplify errors
jfmengels Aug 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

- more strict in a few cases where code that was incorrect code (according to the elm compiler) was successfully parsed: tuples with >3 parts, record access on most things
- better performance, parsing should now be a lot faster

## [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.
Expand Down
2 changes: 1 addition & 1 deletion benchmark/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -10905,4 +10905,4 @@ maybeToList maybe =
Just content ->
[ content ]

"""
"""
3 changes: 1 addition & 2 deletions elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@
"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",
"stil4m/structured-writer": "1.0.1 <= v < 2.0.0"
},
"test-dependencies": {
"elm-explorations/test": "2.0.0 <= v < 3.0.0"
}
}
}
373 changes: 365 additions & 8 deletions src/Char/Extra.elm

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions src/Elm/Parser/Base.elm
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
module Elm.Parser.Base exposing (moduleName)

import Elm.Parser.Node as Node
import Elm.Parser.Tokens as Tokens
import Elm.Syntax.ModuleName exposing (ModuleName)
import Elm.Syntax.Node exposing (Node)
import Elm.Syntax.Node exposing (Node(..))
import ParserFast


moduleName : ParserFast.Parser (Node ModuleName)
moduleName =
ParserFast.map2 (\head tail -> head :: tail)
ParserFast.map2WithRange
(\range head tail ->
Node range (head :: tail)
)
Tokens.typeName
moduleNameOrEmpty
|> Node.parserCore


moduleNameOrEmpty : ParserFast.Parser ModuleName
moduleNameOrEmpty =
ParserFast.orSucceed
(ParserFast.map2 (\head tail -> head :: tail)
(ParserFast.symbolFollowedBy "." Tokens.typeName)
(ParserFast.lazy (\() -> moduleNameOrEmpty))
)
ParserFast.map2OrSucceed
(\head tail -> head :: tail)
(ParserFast.symbolFollowedBy "." Tokens.typeName)
(ParserFast.lazy (\() -> moduleNameOrEmpty))
[]
51 changes: 21 additions & 30 deletions src/Elm/Parser/Comments.elm
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
module Elm.Parser.Comments exposing (declarationDocumentation, moduleDocumentation, multilineCommentString, singleLineCommentCore)
module Elm.Parser.Comments exposing (declarationDocumentation, moduleDocumentation, multilineComment, singleLineComment)

import Elm.Parser.Node as Node
import Char.Extra
import Elm.Syntax.Documentation exposing (Documentation)
import Elm.Syntax.Node exposing (Node)
import Elm.Syntax.Node exposing (Node(..))
import ParserFast exposing (Parser)


singleLineCommentCore : ParserFast.Parser String
singleLineCommentCore =
singleLineComment : ParserFast.Parser (Node String)
singleLineComment =
ParserFast.symbolFollowedBy "--"
(ParserFast.chompWhile (\c -> c /= '\u{000D}' && c /= '\n'))
|> ParserFast.getChompedString
(ParserFast.whileMap
(\c -> c /= '\u{000D}' && c /= '\n' && not (Char.Extra.isUtf16Surrogate c))
(\content -> "--" ++ content)
)
|> ParserFast.mapWithRange Node


multilineCommentString : ParserFast.Parser String
multilineCommentString =
multilineComment : ParserFast.Parser (Node String)
multilineComment =
ParserFast.offsetSourceAndThen
(\offset source ->
case source |> String.slice offset (offset + 3) of
"{-|" ->
case String.slice (offset + 2) (offset + 3) source of
"|" ->
problemUnexpectedDocumentation

_ ->
multiLineCommentStringNoCheck
multiLineCommentNoCheck
)


Expand All @@ -31,10 +34,11 @@ problemUnexpectedDocumentation =
ParserFast.problem "unexpected documentation comment"


multiLineCommentStringNoCheck : Parser String
multiLineCommentStringNoCheck =
ParserFast.nestableMultiComment "{-" "-}"
|> ParserFast.getChompedString
multiLineCommentNoCheck : Parser (Node String)
multiLineCommentNoCheck =
ParserFast.nestableMultiCommentMapWithRange Node
( '{', "-" )
( '-', "}" )


moduleDocumentation : Parser (Node String)
Expand All @@ -47,17 +51,4 @@ declarationDocumentation =
-- technically making the whole parser fail on multi-line comments would be "correct"
-- but in practice, all declaration comments allow layout before which already handles
-- these.
-- Here's how a "safe" version would look:
-- ParserFast.oneOf
--[ -- if the next symbol isn't "{-|", we commit to failure
-- (ParserFast.symbol "{-" |> ParserFast.ignore ParserFast.chompIf (\c -> c /= '|'))
-- |> ParserFast.backtrackable
-- |> ParserFast.Extra.continueWith (ParserFast.problem "multiline comment should be documentation comment")
--, ParserFast.multiComment "{-" "-}" Nestable
-- |> ParserFast.getChompedString
-- |> Node.parserCore
--]
-- |> ParserFast.backtrackable
ParserFast.nestableMultiComment "{-" "-}"
|> ParserFast.getChompedString
|> Node.parserCore
multiLineCommentNoCheck
Loading
Loading