Like Elm.Parser
but able to parse badly indented code and similar somewhat incorrect syntax,
similar to elm-format.
This is not a fault-tolerant parser! So if you write something it can't recognize in a file, the whole thing will fail.
Also, precise ranges of some parts in in the parsed result are not reliable.
Though they will still be correct when viewed relative to each other
and will tell you how many lines they span.
This means ElmSyntaxPrint
can pick this up and format it in a way compatible
with the compiler or Elm.Parser.
Some additional lenient parsing:
f | g → f |> g
a != b or a !== b → a /= b
a === b → a == b
a ** b → a ^ b
\a => b or \a. b → \a -> b
case ... of a. b or case ... of a b → case ... of a -> b
merges consecutive , in record, list or explicit exposing
removes extra , before first record field, list element or expose
merges consecutive | in choice type declaration
removes remove extra | before first variant declaration
merges consecutive -> in function type
port module to module if no ports exist and the other way round
(...) → (..) in exposing and type expose that includes its variants
removes empty exposing () after import
expression record field name-value separators
{ name : value } or { name value }
→ { name = value }
type record field name-value separators
{ name = value } or { name value }
→ { name : value }
expands expression record field punning
{ field } → { field = field }
-> to = in an expression declaration and let expression declaration
function parameters -> result
→ function parameters = result
corrects names that collide with keywords
Html.Attributes.type → Html.Attributes.type_
allows omitting the name before the type in an expression declaration or let expression declaration
: Type
function parameters =
result→
function : Type
function parameters =
resultallows matching everything before
3 |> String.toInt case
Nothing ->
0
Just n ->
n→
case 3 |> String.toInt of
Nothing ->
0
Just n ->
nmoves import statements anywhere at the top level to the import section
Turn a given source String into Just the parsed syntax
or Nothing if any unrecognizable part is found.
Parser for an Elm.Syntax.File.File
That's all you'll need most of the time.
Sometimes it's useful to parse only some part of the syntax, to, say, display only an expression in an article or reparse only the touched declarations on save.
A bag of comment nodes.
Each comment string contains the {-, -} or --.
Access with commentsToList
Extract a list of comment nodes from parse result Comments
Parser for a single Elm.Syntax.Exposing.TopLevelExpose
Parser for an Elm.Syntax.Exposing.Exposing
(the stuff after exposing in an import or module)
Parser for an Elm.Syntax.Module.Module
(confusingly, that's their name for only the module X exposing (Y) lines)
Parser for a single Elm.Syntax.Import.Import
Parser for a list of Elm.Syntax.Declaration.Declarations
and comments in between
Parser for an Elm.Syntax.Pattern.Pattern
Parser for a {-...-} comment,
also verifying that it itself isn't a documentation comment
Parser for a --... comment
Parser for the space between syntax tokens
which can contain spaces, linebreaks, multiLineComments
and singleLineComments
Parser for a name used for
record field names and unqualified function/value references
Parser for a name used for
type names, variant names, record type alias constructor function names and module names
Constantly appending lists of comments when combining parse can get expensive, so we summarize everything in this temporary structure and only convert to a list when we're done.
Inspired by miniBill/elm-rope
Can turn a String into syntax or Nothing. See
ElmSyntaxParserLenient.run(This is not related to
elm/parser. Open an issue if you need a way to covert to that)