Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

Parser

Tutorials

  • Building Language Front-Ends
  • Inside CodeAnalysis - How CodeStructure Parses C
  • Design and Compilation Strategy
  • Implementing the LaTeX Math Parser
  • MaTeX Comparison Showcase
  • The Parser Landscape - a Survey of What Exists Today
  • The Parser Zoo - language front-ends over a shared algebra
  • Parsing BNF Grammars (and bootstrapping a TPTP parser)
  • Parsing GrammarRules Locally
  • A Markdown Inline Parser in Parser Combinators
  • ParsingOpenQASM
  • Parsing TPTP, Auto-Generated from the Published BNF
  • PrattVsPEG
  • The Wolfram Box Typesetting Reference

Guides

  • Parsing in the Wolfram Language

Symbols

  • ASTAddSource
  • ASTAlgebra
  • ASTContainer
  • ASTLeafQ
  • ASTNodeQ
  • ASTStripSource
  • BinaryNode
  • BrainfuckAST
  • BrainfuckGrammar
  • BrainfuckRun
  • BrainfuckSemantic
  • CalculatorAST
  • CalculatorEval
  • CalculatorGrammar
  • CalculatorSemantic
  • CallNode
  • ContainerNode
  • EBNFParse
  • EBNFRules
  • ErrorNode
  • ExportLaTeX
  • GroupNode
  • InfixNode
  • JSONAST
  • JSONGrammar
  • JSONImport
  • JSONSemantic
  • LambdaAST
  • LambdaEval
  • LambdaGrammar
  • LambdaSemantic
  • LaTeXMathParse
  • LaTeXMathParser
  • LaTeXMathStyle
  • LeafNode
  • LispAST
  • LispGrammar
  • LispRead
  • LispSemantic
  • LispSymbol
  • MarkdownInlineParse
  • MarkdownInlineParser
  • MarkdownParse
  • MarkdownParser
  • ParseAction
  • ParseBetween
  • ParseChainLeft
  • ParseChainRight
  • ParseCharacter
  • ParseChoiceLongest
  • ParseChoice
  • ParseFail
  • ParseLiteral
  • ParseLookahead
  • ParseMany
  • Parse
  • ParseNotFollowedBy
  • ParseOperatorTable
  • ParseOptional
  • ParsePartial
  • ParsePosition
  • ParserCombinator
  • ParserCombinatorQ
  • ParserCompile
  • ParseRecursive
  • ParseRegex
  • ParseSepBy1
  • ParseSepBy
  • ParseSequence
  • ParseSome
  • ParseSucceed
  • ParseTry
  • PostfixNode
  • PrefixNode
  • RecCell
  • RecRef
  • SetRec
  • SpannedToken
  • TernaryNode
  • ToCodeParser
  • TPTPExport
  • TPTPImport

Overviews

  • WolframParser
Wolfram`Parser`
ParseChoiceLongest
​
ParseChoiceLongest
[
p
1
,
p
2
,…,
p
n
]
returns the
ParserCombinator
that runs every
p
i
at the current position and returns the result of the longest successful match.
​
Details and Options
▪
Where
ParseChoice
is PEG-ordered — it stops at the first alternative that matches —
ParseChoiceLongest
is POSIX-style: it runs every alternative and commits to the one that consumed the most input.
▪
Ties between equal-length successes resolve to the first listed alternative, mirroring
ParseChoice
's left-bias.
▪
It cannot early-exit at the first hit, so it always runs all branches; it is slower than
ParseChoice
by that constant factor.
▪
The case it exists for: alternatives that share a leaf-level prefix and differ only in what follows, so the shorter alternative is a prefix of the correct one. Ordering longest-first cannot fix this when the alternatives are factored across separate rules — TPTP's
<fof_atomic_formula>::=<fof_plain_atomic_formula>|<fof_defined_atomic_formula>
, where both branches consume the same leading term but only the second reaches a trailing
=rhs
.
▪
There is no operator overload:
p1|p2
lowers to
ParseChoice
(via
Alternatives
), never to
ParseChoiceLongest
. Call
ParseChoiceLongest
explicitly.
▪
A single-branch
ParseChoiceLongest
[p]
canonicalises to p.
▪
Nested same-type children flatten: a
ParseChoiceLongest
directly inside another merges into one.
▪
On total failure the reported error is the furthest-advanced failure across all branches, and its
Expected
set is the union of the per-branch expected sets at that position — the same diagnostic
ParseChoice
produces.
▪
Result type: whatever the winning branch returned.
▪
It is the combinator
EBNFParse
folds a rule's alternatives with under
"ChoiceMode""Longest"
and, for length-ambiguous rules,
"ChoiceMode""Auto"
.
​
Examples  
(13)
Basic Examples  
(3)
Two alternatives share the prefix
ab
; longest-match takes the branch that consumes the whole input:
In[1]:=
Parse

ParseChoiceLongest

ParseLiteral
["ab"],
ParseLiteral
["abc"],"abc"
Out[1]=
abc
​
The same two alternatives under
ParseChoice
pick the shorter branch first, leaving
c
unconsumed and failing the whole-input match:
In[1]:=
Parse

ParseChoice

ParseLiteral
["ab"],
ParseLiteral
["abc"],"abc"
Out[1]=
Failure

Message:
Parse failed at position 3: expected <end of input>, found c.
Tag:
ParseError

​
Longest-match is independent of the order the alternatives are listed — the longer branch wins even when it comes first:
In[1]:=
Parse

ParseChoiceLongest

ParseLiteral
["abc"],
ParseLiteral
["ab"],"abc"
Out[1]=
abc
Scope  
(3)

Properties & Relations  
(5)

Possible Issues  
(2)

SeeAlso
ParseChoice
 
▪
Parse
 
▪
ParseTry
 
▪
ParseOperatorTable
 
▪
EBNFParse
 
▪
ParserCombinator
RelatedGuides
▪
Parsing in the Wolfram Language
""

© 2026 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com