From 1fabe19f7eacb668ef26cccde681dce5e2f98072 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 26 Oct 2017 14:48:05 -0400 Subject: - WIP: Wiring everything to get the compiler to work fully. - Fixed a bug when combining field/method/class modifiers. --- new-luxc/source/luxc/parser.lux | 51 +++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 25 deletions(-) (limited to 'new-luxc/source/luxc/parser.lux') diff --git a/new-luxc/source/luxc/parser.lux b/new-luxc/source/luxc/parser.lux index b58038e7d..93800c1b7 100644 --- a/new-luxc/source/luxc/parser.lux +++ b/new-luxc/source/luxc/parser.lux @@ -48,19 +48,19 @@ ## chunk of white-space. (def: (space^ where) (-> Cursor (l;Lexer [Cursor Text])) - (do p;Monad - [head (l;some (l;one-of white-space))] - ## New-lines must be handled as a separate case to ensure line - ## information is handled properly. - (p;either (p;after (l;one-of new-line) - (do @ - [[end tail] (space^ (|> where - (update@ #;line n.inc) - (set@ #;column +0)))] - (wrap [end - (format head tail)]))) - (wrap [(update@ #;column (n.+ (text;size head)) where) - head])))) + (p;either (do p;Monad + [content (l;many (l;one-of white-space))] + (wrap [(update@ #;column (n.+ (text;size content)) where) + content])) + ## New-lines must be handled as a separate case to ensure line + ## information is handled properly. + (do p;Monad + [content (l;many (l;one-of new-line))] + (wrap [(|> where + (update@ #;line (n.+ (text;size content))) + (set@ #;column +0)) + content])) + )) ## Single-line comments can start anywhere, but only go up to the ## next new-line. @@ -144,13 +144,14 @@ ## The cursor gets updated, but the padding gets ignored. (def: (left-padding^ where) (-> Cursor (l;Lexer Cursor)) - (p;either (do p;Monad - [[where comment] (comment^ where)] - (left-padding^ where)) - (do p;Monad - [[where white-space] (space^ where)] - (wrap where)) - )) + ($_ p;either + (do p;Monad + [[where comment] (comment^ where)] + (left-padding^ where)) + (do p;Monad + [[where white-space] (space^ where)] + (left-padding^ where)) + (:: p;Monad wrap where))) ## Escaped character sequences follow the usual syntax of ## back-slash followed by a letter (e.g. \n). @@ -599,11 +600,11 @@ (text where) ))) -(def: #export (parse [where code]) - (-> [Cursor Text] (e;Error [[Cursor Text] Code])) - (case (p;run [+0 code] (ast where)) +(def: #export (parse [where offset source]) + (-> Source (e;Error [Source Code])) + (case (p;run [offset source] (ast where)) (#e;Error error) (#e;Error error) - (#e;Success [[_ remaining] [where' output]]) - (#e;Success [[where' remaining] output]))) + (#e;Success [[offset' remaining] [where' output]]) + (#e;Success [[where' offset' remaining] output]))) -- cgit v1.2.3