diff options
author | Eduardo Julian | 2020-12-11 22:40:31 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-12-11 22:40:31 -0400 |
commit | dff517cbdb9a1c80028782c62ad91c71ddb34909 (patch) | |
tree | f69b4005e8b6dc9699a410554ce4571f60d9e0ee /stdlib/source/lux/tool | |
parent | 9af671a34728b35c48bff2ba163c371dc5084946 (diff) |
Improved parsing speed for Lux code.
Diffstat (limited to 'stdlib/source/lux/tool')
4 files changed, 74 insertions, 77 deletions
diff --git a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux index 632cc91c2..d8859f767 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/phase/generation/js/runtime.lux @@ -781,4 +781,4 @@ (row.row ["0" (|> ..runtime _.code - encoding.to-utf8)])]))) + (\ encoding.utf8 encode))])]))) diff --git a/stdlib/source/lux/tool/compiler/language/lux/syntax.lux b/stdlib/source/lux/tool/compiler/language/lux/syntax.lux index 766e5cbf2..2b5cfd4a8 100644 --- a/stdlib/source/lux/tool/compiler/language/lux/syntax.lux +++ b/stdlib/source/lux/tool/compiler/language/lux/syntax.lux @@ -471,79 +471,76 @@ [..open-tuple ..close-tuple parse-tuple] [..open-record ..close-record parse-record] )] - ## TODO: Add text.space as just another case for "lux syntax char case!" ASAP. - ## It's currently failing for some reason. - (`` (if (!n/= (char (~~ (static text.space))) char/0) + (`` ("lux syntax char case!" char/0 + [[(~~ (static text.space)) + (~~ (static text.carriage-return))] <horizontal-move> - ("lux syntax char case!" char/0 - [[(~~ (static text.carriage-return))] - <horizontal-move> - - ## New line - [(~~ (static text.new-line))] - (recur (!vertical where offset/0 source-code)) - - <composites> - - ## Text - [(~~ (static ..text-delimiter))] - (parse-text where (!inc offset/0) source-code) - - ## Special code - [(~~ (static ..sigil))] - (let [offset/1 (!inc offset/0)] - (<| (!with-char+ source-code//size source-code offset/1 char/1 - (!end-of-file where offset/1 source-code current-module)) - ("lux syntax char case!" char/1 - [[(~~ (static ..name-separator))] - (!parse-short-name current-module <move-2> where #.Tag) - - ## Single-line comment - [(~~ (static ..sigil))] - (case ("lux text index" (!inc offset/1) (static text.new-line) source-code) - (#.Some end) - (recur (!vertical where end source-code)) - - _ - (!end-of-file where offset/1 source-code current-module)) - - (~~ (template [<char> <bit>] - [[<char>] - (#.Right [[(update@ #.column (|>> !inc/2) where) - (!inc offset/1) - source-code] - [where (#.Bit <bit>)]])] - - ["0" #0] - ["1" #1]))] - - ## else - (cond (!name-char?|head char/1) ## Tag - (!parse-full-name offset/1 <move-2> where aliases #.Tag) - - ## else - (!failure ..parse where offset/0 source-code))))) - - ## Coincidentally (= ..name-separator ..frac-separator) - [(~~ (static ..name-separator))] - (let [offset/1 (!inc offset/0)] - (<| (!with-char+ source-code//size source-code offset/1 char/1 - (!end-of-file where offset/1 source-code current-module)) - (if (!digit? char/1) - (parse-rev source-code//size offset/0 where (!inc offset/1) source-code) - (!parse-short-name current-module [where offset/1 source-code] where #.Identifier)))) - - [(~~ (static ..positive-sign)) - (~~ (static ..negative-sign))] - (!parse-signed source-code//size offset/0 where source-code aliases - (!end-of-file where offset/0 source-code current-module))] - - ## else - (if (!digit? char/0) - ## Natural number - (parse-nat source-code//size offset/0 where (!inc offset/0) source-code) - ## Identifier - (!parse-full-name offset/0 <consume-1> where aliases #.Identifier)) - )))) + + ## New line + [(~~ (static text.new-line))] + (recur (!vertical where offset/0 source-code)) + + <composites> + + ## Text + [(~~ (static ..text-delimiter))] + (parse-text where (!inc offset/0) source-code) + + ## Special code + [(~~ (static ..sigil))] + (let [offset/1 (!inc offset/0)] + (<| (!with-char+ source-code//size source-code offset/1 char/1 + (!end-of-file where offset/1 source-code current-module)) + ("lux syntax char case!" char/1 + [[(~~ (static ..name-separator))] + (!parse-short-name current-module <move-2> where #.Tag) + + ## Single-line comment + [(~~ (static ..sigil))] + (case ("lux text index" (!inc offset/1) (static text.new-line) source-code) + (#.Some end) + (recur (!vertical where end source-code)) + + _ + (!end-of-file where offset/1 source-code current-module)) + + (~~ (template [<char> <bit>] + [[<char>] + (#.Right [[(update@ #.column (|>> !inc/2) where) + (!inc offset/1) + source-code] + [where (#.Bit <bit>)]])] + + ["0" #0] + ["1" #1]))] + + ## else + (cond (!name-char?|head char/1) ## Tag + (!parse-full-name offset/1 <move-2> where aliases #.Tag) + + ## else + (!failure ..parse where offset/0 source-code))))) + + ## Coincidentally (= ..name-separator ..frac-separator) + [(~~ (static ..name-separator))] + (let [offset/1 (!inc offset/0)] + (<| (!with-char+ source-code//size source-code offset/1 char/1 + (!end-of-file where offset/1 source-code current-module)) + (if (!digit? char/1) + (parse-rev source-code//size offset/0 where (!inc offset/1) source-code) + (!parse-short-name current-module [where offset/1 source-code] where #.Identifier)))) + + [(~~ (static ..positive-sign)) + (~~ (static ..negative-sign))] + (!parse-signed source-code//size offset/0 where source-code aliases + (!end-of-file where offset/0 source-code current-module))] + + ## else + (if (!digit? char/0) + ## Natural number + (parse-nat source-code//size offset/0 where (!inc offset/0) source-code) + ## Identifier + (!parse-full-name offset/0 <consume-1> where aliases #.Identifier)) + ))) ))) )) diff --git a/stdlib/source/lux/tool/compiler/meta/io/context.lux b/stdlib/source/lux/tool/compiler/meta/io/context.lux index 74f0b4bd8..f8b31df58 100644 --- a/stdlib/source/lux/tool/compiler/meta/io/context.lux +++ b/stdlib/source/lux/tool/compiler/meta/io/context.lux @@ -127,7 +127,7 @@ (Promise (Try Input))) (do (try.with promise.monad) [[path binary] (..find-any-source-file system import contexts partial-host-extension module)] - (case (encoding.from-utf8 binary) + (case (\ encoding.utf8 decode binary) (#try.Success code) (wrap {#////.module module #////.file path diff --git a/stdlib/source/lux/tool/compiler/meta/packager/script.lux b/stdlib/source/lux/tool/compiler/meta/packager/script.lux index 5b826a4e0..543b2682a 100644 --- a/stdlib/source/lux/tool/compiler/meta/packager/script.lux +++ b/stdlib/source/lux/tool/compiler/meta/packager/script.lux @@ -55,7 +55,7 @@ (function (_ artifact so-far) (do (try.with monad) [content (..write-artifact monad file-system static [module artifact]) - content (\ monad wrap (encoding.from-utf8 content))] + content (\ monad wrap (\ encoding.utf8 decode content))] (wrap (sequence so-far (:share [directive] {directive @@ -84,4 +84,4 @@ row.to-list (list\map (|>> (get@ #artifact.id))))])) (monad.fold ! (..write-module monad file-system static sequence) header) - (\ ! map (|>> to-code encoding.to-utf8)))))) + (\ ! map (|>> to-code (\ encoding.utf8 encode))))))) |