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`
ParseTry
​
ParseTry
[p]
returns the
ParserCombinator
that runs p and, if p fails, restores the input position to where p began, so that an enclosing
ParseChoice
can try its next alternative.
​
Details and Options
▪
On success
ParseTry[p]
returns p's result unchanged; on failure it reports p's failure with the position reset to where
ParseTry
started.
▪
ParseTry
marks p as a backtracking point. In a committed-PEG parser an ordered choice whose alternative consumes input and then fails is committed to that consumption and the whole choice fails; wrapping the alternative in
ParseTry
restores the position so the next alternative is tried.
▪
In this parser
ParseChoice
already restarts every alternative from the position where the choice began, so it recovers from partial consumption on its own. Wrapping an alternative in
ParseTry
therefore does not change the result.
▪
The combinator is preserved through
ParserCompile
, so a grammar's shape stays identical to one written for a backtracking-by-default combinator library.
▪
ParseTry
does not change
ParseChoice
's ordering - the first alternative that matches still wins; it is not a longest-match.
​
Examples  
(8)
Basic Examples  
(4)
The combinator wraps its argument:
In[1]:=
ParseTry

ParseLiteral
["foo"]
Out[1]=
ParserCombinator
Type: Try
Arity: 1
Compiled: False

​
On success
ParseTry
is transparent - it returns its parser's result unchanged:
In[1]:=
Parse

ParseTry

ParseLiteral
["foo"],"foo"
Out[1]=
foo
​
The result passes through whatever the wrapped parser built, here a
ParseSequence
list:
In[1]:=
Parse

ParseTry

ParseLiteral
["a"]~~
ParseLiteral
["b"],"ab"
Out[1]=
{a,b}
​
On failure it reports the wrapped parser's own diagnostic:
In[1]:=
Parse

ParseTry

ParseLiteral
["foo"],"bar"
Out[1]=
Failure

Message:
Parse failed at position 1: expected foo, found b.
Tag:
ParseError

Scope  
(1)

Properties & Relations  
(2)

Possible Issues  
(1)

SeeAlso
ParseChoice
 
▪
ParseSequence
 
▪
ParseLookahead
 
▪
ParserCompile
 
▪
ParserCombinator
RelatedGuides
▪
Parsing in the Wolfram Language
""

© 2026 Wolfram. All rights reserved.

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