From f46f8cc03a8c0d0694240023d3a0f5dbd24b8fe4 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 18 Apr 2019 23:34:30 -0400 Subject: Fixed a bug where it was possible to write invalid identifiers if they ended in the separator character (e.g. "invalid."). --- stdlib/source/lux/tool/compiler/default/syntax.lux | 37 +++++++++++----------- 1 file changed, 19 insertions(+), 18 deletions(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux/tool/compiler/default/syntax.lux b/stdlib/source/lux/tool/compiler/default/syntax.lux index 2962a5ea8..4a3ee89d2 100644 --- a/stdlib/source/lux/tool/compiler/default/syntax.lux +++ b/stdlib/source/lux/tool/compiler/default/syntax.lux @@ -149,6 +149,14 @@ (exception.report ["Text" (%t text)])) +(template: (!failure parser where offset source-code) + (#.Left [[where offset source-code] + (exception.construct unrecognized-input [where (%name (name-of parser)) source-code offset])])) + +(template: (!end-of-file where offset source-code current-module) + (#.Left [[where offset source-code] + (exception.construct ..end-of-file current-module)])) + (type: (Parser a) (-> Source (Either [Source Text] [Source a]))) @@ -249,8 +257,7 @@ (#.Text g!content)]]))) _ - (#.Left [[where offset source-code] - (exception.construct unrecognized-input [where "Text" source-code offset])]))) + (!failure ..!read-text where offset source-code))) (def: digit-bottom Nat (!dec (char "0"))) (def: digit-top Nat (!inc (char "9"))) @@ -306,8 +313,7 @@ (with-expansions [ (as-is (!number-output start end int.decimal #.Int)) (as-is (!number-output start end frac.decimal #.Frac)) - (#.Left [[where offset source-code] - (exception.construct unrecognized-input [where "Frac" source-code offset])])] + (!failure ..parse-frac where offset source-code)] (def: (parse-frac source-code//size start [where offset source-code]) (-> Nat Offset (Parser Code)) (loop [end offset @@ -378,14 +384,6 @@ (recur (!inc end)) )))))) -(template: (!failure where offset source-code) - (#.Left [[where offset source-code] - (exception.construct unrecognized-input [where "General" source-code offset])])) - -(template: (!end-of-file where offset source-code current-module) - (#.Left [[where offset source-code] - (exception.construct ..end-of-file current-module)])) - (with-expansions [ (as-is [where (!inc offset/0) source-code]) (as-is [where (!inc/2 offset/0) source-code])] @@ -395,7 +393,7 @@ (#.Right [source' [@module name]])) ## else - (!failure where @offset source-code))) + (!failure ..!parse-half-name where @offset source-code))) (`` (def: (parse-short-name current-module [where offset/0 source-code]) (-> Text (Parser Name)) @@ -421,10 +419,13 @@ (if (!n/= (char (~~ (static ..name-separator))) char/separator) (let [offset'' (!inc offset')] (!letE [source'' complex] (..parse-name-part offset'' [where' offset'' source-code']) - (#.Right [source'' [(|> aliases - (dictionary.get simple) - (maybe.default simple)) - complex]]))) + (if ("lux text =" "" complex) + (let [[where offset source-code] source] + (!failure ..parse-full-name where offset source-code)) + (#.Right [source'' [(|> aliases + (dictionary.get simple) + (maybe.default simple)) + complex]])))) ))))))) (template: (!parse-full-name @offset @source @where @aliases @tag) @@ -520,7 +521,7 @@ (!parse-full-name offset/1 where aliases #.Tag) ## else - (!failure where offset/0 source-code))))) + (!failure ..parse where offset/0 source-code))))) ## Coincidentally (= name-separator frac-separator) [(~~ (static ..name-separator))] -- cgit v1.2.3