space
This object is concerned with special treatment of whitespace.
For the vast majority of cases, the functionality within this object shouldn't be needed, as whitespace is consistently handled by lexeme
and fully
. However, for grammars where whitespace is significant (like indentation-sensitive languages), this object provides some more fine-grained control over how whitespace is consumed by the parsers within lexeme
.
Attributes
- Since
-
4.0.0
- Source
- Lexer.scala
- Graph
-
- Supertypes
- Self type
-
space.type
Members list
Value members
Concrete methods
This combinator changes how whitespace is parsed by lexemes for the duration of a given parser.
This combinator changes how whitespace is parsed by lexemes for the duration of a given parser.
So long as spaceDesc.whiteSpaceIsContextDependent
is set to true
, this combinator will be able to locally change the definition of whitespace during the given parser.
Value parameters
- newSpace
-
the new implementation of whitespace to be used during the execution of
within
. - within
-
the parser that should be parsed using the updated whitespace.
Attributes
- Since
-
4.0.0
- Note
-
the whitespace will not be restored to its original implementation if the given parser fails having consumed input.
- Example
-
In indentation sensitive languages, the indentation sensitivity is often ignored within parentheses or braces. In these cases
lexeme.enclosing.parens(space.alter(withNewline)(p))
would allow unrestricted newlines within parentheses. - Source
- Lexer.scala
This parser initialises the whitespace used by the lexer when spaceDesc.whiteSpaceIsContextDependent
is set to true
.
This parser initialises the whitespace used by the lexer when spaceDesc.whiteSpaceIsContextDependent
is set to true
.
The whitespace is set to the implementation given by the lexical description. This parser must be used, by fully
or otherwise, as the first thing the global parser does or an UnfilledRegisterException
will occur.
Attributes
- See also
-
alter
for how to change whitespace during a parse. - Since
-
4.0.0
- Note
-
this parser is automatically invoked by the
fully
combinator when applicable. - Source
- Lexer.scala
Concrete fields
This parser skips zero or more comments.
This parser skips zero or more comments.
The implementation of this combinator does not vary with whitespaceIsContextDependent
. It will use the hide
combinator as to not appear as a valid alternative in an error message: adding a comment is often legal, but not a useful solution for how to make the input syntactically valid.
Attributes
- Since
-
4.0.0
- Source
- Lexer.scala
This parser skips zero or more (insignificant) whitespace characters as well as comments.
This parser skips zero or more (insignificant) whitespace characters as well as comments.
The implementation of this parser depends on whether whitespaceIsContextDependent
is set: when it is, this parser may change based on the use of the alter
combinator. This parser will always use the hide
combinator as to not appear as a valid alternative in an error message: it's likely always the case whitespace can be added at any given time, but that doesn't make it a useful suggestion unless it is significant.
Attributes
- Since
-
4.0.0
- Source
- Lexer.scala