Skip to content

Commit b6e7f77

Browse files
committed
Remove regexnows method since it now requires more duplication of Scala parser combinator code
- in the longer term we are trying to have the parser combinator library support more flexile whitespace handling scala/scala-parser-combinators#25
1 parent f094525 commit b6e7f77

File tree

2 files changed

+10
-30
lines changed

2 files changed

+10
-30
lines changed

library/src/org/kiama/example/lambda3/Lambda.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,16 @@ trait SyntaxAnalyser extends PositionedParserUtilities {
145145
name ^^ Var
146146

147147
lazy val name =
148-
"[a-zA-Z]+".r ~ regexnows ("[0-9]*".r) ^^ {
149-
case base ~ index =>
150-
Name (base, if (index.isEmpty) None else Some (index.toInt))
151-
}
148+
"[a-zA-Z]+[0-9]+".r ^^ (
149+
fullname => {
150+
val (base, index) = fullname.span (_.isLetter)
151+
Name (base, Some (index.toInt))
152+
}
153+
) |
154+
"[a-zA-Z]+".r ^^ (
155+
base =>
156+
Name (base, None)
157+
)
152158

153159
}
154160

library/src/org/kiama/util/ParserUtilities.scala

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,32 +119,6 @@ trait ParserUtilities extends RegexParsers with PackratParsers {
119119
}
120120
}
121121

122-
/**
123-
* Create a parser that matches a regex string, but doesn't skip whitespace
124-
* first. This operation is useful if you want to recognise parts of a lexical
125-
* symbol with different regular expressions so you can use the parts
126-
* separately. Otherwise you have to parse with one regex and then split the
127-
* resulting string to get at its parts. Based on `RegexParser.regex` in the
128-
* Scala library.
129-
*/
130-
def regexnows (r : Regex) : Parser[String] =
131-
Parser { in =>
132-
val source = in.source
133-
val start = in.offset
134-
(r findPrefixMatchOf (source.subSequence (start, source.length))) match {
135-
case Some (matched) =>
136-
Success (source.subSequence (start, start + matched.end).toString,
137-
in.drop (matched.end))
138-
case None =>
139-
val found =
140-
if (start == source.length ())
141-
"end of source"
142-
else
143-
s"`${source.charAt (start)}'"
144-
Failure (s"string matching regex `$r' expected but $found found", in)
145-
}
146-
}
147-
148122
/**
149123
* Convenience conversion to lift parsers that return 2-tilde-tuples to parsers
150124
* that return regular 2-tuples.

0 commit comments

Comments
 (0)