fix: do not allow negation of a positive int literal
This commit is contained in:
parent
2588c8287d
commit
da4b398bf0
@ -1,6 +1,7 @@
|
|||||||
package wacc
|
package wacc
|
||||||
|
|
||||||
import parsley.Parsley
|
import parsley.Parsley
|
||||||
|
import parsley.character
|
||||||
import parsley.token.{Basic, Lexer}
|
import parsley.token.{Basic, Lexer}
|
||||||
import parsley.token.descriptions.*
|
import parsley.token.descriptions.*
|
||||||
|
|
||||||
@ -45,6 +46,7 @@ object lexer {
|
|||||||
private val lexer = Lexer(desc)
|
private val lexer = Lexer(desc)
|
||||||
val ident = lexer.lexeme.names.identifier
|
val ident = lexer.lexeme.names.identifier
|
||||||
val integer = lexer.lexeme.integer.decimal32[Int]
|
val integer = lexer.lexeme.integer.decimal32[Int]
|
||||||
|
val negateCheck = lexer.nonlexeme.symbol("-") ~> character.digit
|
||||||
val charLit = lexer.lexeme.character.ascii
|
val charLit = lexer.lexeme.character.ascii
|
||||||
val stringLit = lexer.lexeme.string.ascii
|
val stringLit = lexer.lexeme.string.ascii
|
||||||
val implicits = lexer.lexeme.symbol.implicits
|
val implicits = lexer.lexeme.symbol.implicits
|
||||||
|
@ -2,7 +2,7 @@ package wacc
|
|||||||
|
|
||||||
import parsley.Result
|
import parsley.Result
|
||||||
import parsley.Parsley
|
import parsley.Parsley
|
||||||
import parsley.Parsley.{atomic, many, pure}
|
import parsley.Parsley.{atomic, many, notFollowedBy, pure}
|
||||||
import parsley.combinator.{countSome, sepBy}
|
import parsley.combinator.{countSome, sepBy}
|
||||||
import parsley.expr.{precedence, SOps, InfixL, InfixN, InfixR, Prefix, Atoms}
|
import parsley.expr.{precedence, SOps, InfixL, InfixN, InfixR, Prefix, Atoms}
|
||||||
import parsley.errors.combinator._
|
import parsley.errors.combinator._
|
||||||
@ -11,7 +11,7 @@ import cats.data.NonEmptyList
|
|||||||
|
|
||||||
object parser {
|
object parser {
|
||||||
import lexer.implicits.implicitSymbol
|
import lexer.implicits.implicitSymbol
|
||||||
import lexer.{ident, integer, charLit, stringLit}
|
import lexer.{ident, integer, charLit, stringLit, negateCheck}
|
||||||
import ast._
|
import ast._
|
||||||
|
|
||||||
def parse(input: String): Result[String, Program] = parser.parse(input)
|
def parse(input: String): Result[String, Program] = parser.parse(input)
|
||||||
@ -32,7 +32,7 @@ object parser {
|
|||||||
SOps(InfixL)(Mul from "*", Div from "/", Mod from "%") +:
|
SOps(InfixL)(Mul from "*", Div from "/", Mod from "%") +:
|
||||||
SOps(Prefix)(
|
SOps(Prefix)(
|
||||||
Not from "!",
|
Not from "!",
|
||||||
Negate from "-",
|
Negate from (notFollowedBy(negateCheck) ~> "-"),
|
||||||
Len from "len",
|
Len from "len",
|
||||||
Ord from "ord",
|
Ord from "ord",
|
||||||
Chr from "chr"
|
Chr from "chr"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user