From 27eed2a94ff9446014564958439fc5381584568b Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 23 Aug 2018 07:45:16 -0400 Subject: Added Rev parsing. --- stdlib/source/lux/compiler/default/syntax.lux | 71 +++++++++++++-------------- 1 file changed, 33 insertions(+), 38 deletions(-) diff --git a/stdlib/source/lux/compiler/default/syntax.lux b/stdlib/source/lux/compiler/default/syntax.lux index c2d2bff29..7dc992471 100644 --- a/stdlib/source/lux/compiler/default/syntax.lux +++ b/stdlib/source/lux/compiler/default/syntax.lux @@ -84,29 +84,6 @@ (def: sign^ (l.one-of "+-")) -(do-template [ ] - [(def: #export ( where) - Syntax - (do p.Monad - [chunk ] - (case (:: decode chunk) - (#.Left error) - (p.fail error) - - (#.Right value) - (wrap [(update@ #.column (n/+ (text.size chunk)) where) - [where ( value)]]))))] - - [int #.Int - (l.and sign^ rich-digits^) - number.Codec] - - [rev #.Rev - (l.and (l.one-of ".") - rich-digits^) - number.Codec] - ) - (def: #export (frac where) Syntax (do p.Monad @@ -156,7 +133,6 @@ (function (ast' where) ($_ p.either (..frac where) - (..rev where) ))) (type: (Simple a) @@ -260,6 +236,21 @@ g!_ body)) +(def: (read-text [where offset source-code]) + (Simple Code) + (case ("lux text index" source-code (static ..text-delimiter) offset) + (#.Some end) + (let [content (!clip offset end source-code)] + (<| (!guarantee-no-new-lines content) + (#error.Success [[(update@ #.column (n/+ (!n/- offset end)) where) + (!inc end) + source-code] + [where + (#.Text content)]]))) + + _ + (ex.throw unrecognized-input where))) + (def: digit-bottom Nat (!dec (char "0"))) (def: digit-top Nat (!inc (char "9"))) @@ -332,6 +323,18 @@ _ (!discrete-output number.Codec #.Int)))) +(def: (parse-rev start [where offset source-code]) + (-> Offset (Simple Code)) + (loop [end offset] + (case ("lux text char" source-code end) + (#.Some char) + (if (!digit?+ char) + (recur (!inc end)) + (!discrete-output number.Codec #.Rev)) + + _ + (!discrete-output number.Codec #.Rev)))) + (template: (!parse-int offset where source-code) (let [g!offset/1 (!inc offset)] (<| (!with-char source-code g!offset/1 g!char/1) @@ -477,19 +480,7 @@ ## Text (^ (char (~~ (static ..text-delimiter)))) - (let [offset/1 (!inc offset)] - (case ("lux text index" source-code (static ..text-delimiter) offset/1) - (#.Some end) - (let [content (!clip offset/1 end source-code)] - (<| (!guarantee-no-new-lines content) - (#error.Success [[(update@ #.column (n/+ (!n/- offset/1 end)) where) - (!inc end) - source-code] - [where - (#.Text content)]]))) - - _ - (ex.throw unrecognized-input where))) + (read-text ) ## Special code (^ (char (~~ (static ..sigil)))) @@ -525,7 +516,11 @@ )))) (^ (char (~~ (static ..name-separator)))) - (!parse-short-name current-module where #.Identifier) + (let [offset/1 (!inc offset)] + (<| (!with-char source-code offset/1 char/1) + (if (!digit? char/1) + (parse-rev offset [where (!inc offset/1) source-code]) + (!parse-short-name current-module where #.Identifier)))) (^template [] (^ (char )) -- cgit v1.2.3