Package org.sonar.sslr.grammar
Class LexerlessGrammarBuilder
java.lang.Object
org.sonar.sslr.grammar.LexerlessGrammarBuilder
A builder for creating Parsing Expression Grammars for lexerless parsing.
Objects of following types can be used as an atomic parsing expressions:
- GrammarRuleKey
- String
- Character
- Since:
- 1.18
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbuild()Constructs grammar.Creates parsing expression - "comment trivia".protected ParsingExpressionstatic LexerlessGrammarBuildercreate()Creates parsing expression - "end of input".final ObjectCreates parsing expression - "first of".final ObjectCreates parsing expression - "first of".final ObjectCreates parsing expression - "next".final ObjectCreates parsing expression - "next".final ObjectCreates parsing expression - "next not".final ObjectCreates parsing expression - "next not".final Objectnothing()Creates parsing expression - "nothing".final ObjectCreates parsing expression - "one or more".final ObjectCreates parsing expression - "one or more".final ObjectCreates parsing expression - "optional".final ObjectCreates parsing expression - "optional".Creates parsing expression based on regular expression.rule(GrammarRuleKey ruleKey) Allows to describe rule.final ObjectCreates parsing expression - "sequence".final ObjectCreates parsing expression - "sequence".voidsetRootRule(GrammarRuleKey ruleKey) Allows to specify that given rule should be root for grammar.Creates parsing expression - "skipped trivia".Creates parsing expression - "token".final ObjectzeroOrMore(Object e) Creates parsing expression - "zero or more".final ObjectzeroOrMore(Object e1, Object... rest) Creates parsing expression - "zero or more".
-
Method Details
-
create
-
rule
Allows to describe rule. Result of this method should be used only for execution of methods in it, i.e. you should not save reference on it. No guarantee that this method always returns the same instance for the same key of rule. -
setRootRule
Allows to specify that given rule should be root for grammar. -
build
Constructs grammar.- Returns:
- grammar
- Throws:
GrammarException- if some of rules were used, but not defined
-
regexp
Creates parsing expression based on regular expression.- Parameters:
regexp- regular expression- Throws:
PatternSyntaxException- if the expression's syntax is invalid
-
endOfInput
Creates parsing expression - "end of input". This expression succeeds only if parser reached end of input. -
token
Creates parsing expression - "token".- Parameters:
e- sub-expression- Throws:
IllegalArgumentException- if given argument is not a parsing expression
-
commentTrivia
Creates parsing expression - "comment trivia".- Parameters:
e- sub-expression- Throws:
IllegalArgumentException- if given argument is not a parsing expression
-
skippedTrivia
Creates parsing expression - "skipped trivia".- Parameters:
e- sub-expression- Throws:
IllegalArgumentException- if given argument is not a parsing expression
-
convertToExpression
-
sequence
Creates parsing expression - "sequence". During execution of this expression parser will sequentially execute all sub-expressions. This expression succeeds only if all sub-expressions succeed.- Parameters:
e1- first sub-expressione2- second sub-expression- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression
-
sequence
Creates parsing expression - "sequence". Seesequence(Object, Object)for more details.- Parameters:
e1- first sub-expressione2- second sub-expressionrest- rest of sub-expressions- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression
-
firstOf
Creates parsing expression - "first of". During the execution of this expression parser execute sub-expressions in order until one succeeds. This expressions succeeds if any sub-expression succeeds.Be aware that in expression
firstOf("foo", sequence("foo", "bar"))second sub-expression will never be executed.- Parameters:
e1- first sub-expressione2- second sub-expression- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression
-
firstOf
Creates parsing expression - "first of". SeefirstOf(Object, Object)for more details.- Parameters:
e1- first sub-expressione2- second sub-expressionrest- rest of sub-expressions- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression
-
optional
Creates parsing expression - "optional". During execution of this expression parser will execute sub-expression once. This expression always succeeds, with an empty match if sub-expression fails.Be aware that this expression is greedy, i.e. expression
sequence(optional("foo"), "foo")will never succeed.- Parameters:
e- sub-expression- Throws:
IllegalArgumentException- if given argument is not a parsing expression
-
optional
Creates parsing expression - "optional". Convenience method equivalent to callingoptional(sequence(e, rest)).- Parameters:
e1- first sub-expressionrest- rest of sub-expressions- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression- See Also:
-
oneOrMore
Creates parsing expression - "one or more". During execution of this expression parser will repeatedly try sub-expression until it fails. This expression succeeds only if sub-expression succeeds at least once.Be aware that:
- This expression is a greedy, i.e. expression
sequence(oneOrMore("foo"), "foo")will never succeed. - Sub-expression must not allow empty matches, i.e. for expression
oneOrMore(optional("foo"))parser will report infinite loop.
- Parameters:
e- sub-expression- Throws:
IllegalArgumentException- if given argument is not a parsing expression
- This expression is a greedy, i.e. expression
-
oneOrMore
Creates parsing expression - "one or more". Convenience method equivalent to callingoneOrMore(sequence(e1, rest)).- Parameters:
e1- first sub-expressionrest- rest of sub-expressions- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression- See Also:
-
zeroOrMore
Creates parsing expression - "zero or more". During execution of this expression parser will repeatedly try sub-expression until it fails. This expression always succeeds, with an empty match if sub-expression fails.Be aware that:
- This expression is greedy, i.e. expression
sequence(zeroOrMore("foo"), "foo")will never succeed. - Sub-expression must not allow empty matches, i.e. for expression
zeroOrMore(optional("foo"))parser will report infinite loop.
- Parameters:
e- sub-expression- Throws:
IllegalArgumentException- if given argument is not a parsing expression
- This expression is greedy, i.e. expression
-
zeroOrMore
Creates parsing expression - "zero or more". Convenience method equivalent to callingzeroOrMore(sequence(e1, rest)).- Parameters:
e1- sub-expressionrest- rest of sub-expressions- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression- See Also:
-
next
Creates parsing expression - "next". During execution of this expression parser will execute sub-expression once. This expression succeeds only if sub-expression succeeds, but never consumes any input.- Parameters:
e- sub-expression- Throws:
IllegalArgumentException- if given argument is not a parsing expression
-
next
Creates parsing expression - "next". Convenience method equivalent to callingnext(sequence(e1, rest)).- Parameters:
e1- first sub-expressionrest- rest of sub-expressions- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression- See Also:
-
nextNot
Creates parsing expression - "next not". During execution of this expression parser will execute sub-expression once. This expression succeeds only if sub-expression fails.- Parameters:
e- sub-expression- Throws:
IllegalArgumentException- if given argument is not a parsing expression
-
nextNot
Creates parsing expression - "next not". Convenience method equivalent to callingnextNot(sequence(e1, rest)).- Parameters:
e1- sub-expressionrest- rest of sub-expressions- Throws:
IllegalArgumentException- if any of given arguments is not a parsing expression- See Also:
-
nothing
Creates parsing expression - "nothing". This expression always fails.
-