diff --git a/src/parser/ast.yaml b/src/parser/ast.yaml index 3a954a8..4ce0f2a 100644 --- a/src/parser/ast.yaml +++ b/src/parser/ast.yaml @@ -607,3 +607,112 @@ ClosureParameter: - identifier - type_use: optional: true + +# Literals +Literal: + rules: + - NumberLiteral + - StringLiteral + - BooleanLiteral +NumberLiteral: + rules: + - DoubleLiteral + - LongLiteral + - IntLiteral +IntLiteral: + children: + - number_base +LongLiteral: + children: + - number_base +DoubleLiteral: + children: + - double_whole + - double_fractional +DoubleWhole: + children: + - decimal_base +DoubleFractional: + children: + - decimal_base +NumberBase: + rules: + - BinaryBase + - HexadecimalBase + - DecimalBase +DecimalBase: + children: + - literal: + build: + type: string + from: whole_pair +BinaryBase: + children: + - binary_digits +BinaryDigits: + children: + - literal: + build: + type: string + from: whole_pair +HexadecimalBase: + children: + - hexadecimal_digits +HexadecimalDigits: + children: + - literal: + build: + type: string + from: whole_pair +StringLiteral: + rules: + - SingleQuoteString + - DoubleQuoteString + - BacktickString +SingleQuoteString: + children: + - string_inner: + optional: true +DoubleQuoteString: + children: + - inners: + rule: DStringInner + vec: true + - expressions: + rule: DStringExpression + vec: true +StringInner: + children: + - literal: + build: + type: string + from: whole_pair +DStringInner: + children: + - literal: + build: + type: string + from: whole_pair +DStringExpression: + children: + - expression +BacktickString: + children: + - inners: + rule: BacktickInner + vec: true + - expressions: + rule: DStringExpression + vec: true +BacktickInner: + children: + - literal: + build: + type: string + from: whole_pair +BooleanLiteral: + children: + - literal: + build: + type: boolean + from: parse_whole_pair \ No newline at end of file diff --git a/src/parser/deimos.pest b/src/parser/deimos.pest index aefb7b6..8601eb6 100644 --- a/src/parser/deimos.pest +++ b/src/parser/deimos.pest @@ -823,7 +823,11 @@ IntLiteral = { NumberBase } LongLiteral = ${ NumberBase ~ "L" } -DoubleLiteral = ${ DecimalBase ~ "." ~ Digit+ } +DoubleLiteral = ${ DoubleWhole ~ "." ~ DoubleFractional } + +DoubleWhole = { DecimalBase } + +DoubleFractional = { DecimalBase } NumberBase = { BinaryBase @@ -831,18 +835,17 @@ NumberBase = { | DecimalBase } -DecimalBase = @{ - "0" - | DecimalStartDigit ~ Digit* -} +DecimalBase = @{ '0'..'9'+ } -BinaryBase = @{ "0b" ~ Digit+ } +BinaryBase = { "0b" ~ BinaryDigits } -DecimalStartDigit = { '1'..'9' } +BinaryDigits = @{ BinaryDigit+ } -Digit = @{ '0'..'9'+ } +BinaryDigit = { "0" | "1" } -HexadecimalBase = @{ "0x" ~ HexadecimalDigit+ } +HexadecimalBase = { "0x" ~ HexadecimalDigits } + +HexadecimalDigits = @{ HexadecimalDigit+ } HexadecimalDigit = { '0'..'9' | 'a'..'f' }