From e11facbd0e4095ec7810e4edfeef958f105e51d0 Mon Sep 17 00:00:00 2001 From: "Brian T. Rice" Date: Thu, 17 Feb 2011 20:02:13 -0800 Subject: [PATCH] Defined a QuoteMacro token with an initial setup for words{foo bar baz} => {'foo'. 'bar'. 'baz'}. --- src/syntax/lexer.slate | 22 ++++++++++++++++++++-- src/syntax/token.slate | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/syntax/lexer.slate b/src/syntax/lexer.slate index f48144b..69b55da 100644 --- a/src/syntax/lexer.slate +++ b/src/syntax/lexer.slate @@ -9,6 +9,10 @@ Also, debugging information is stored for now in terms of the line number that the current stream position has reached." Lexer traits define: #WordTerminatingTokens -> '()[]{}@,.|!#$`"\'%'. +Lexer traits define: #QuoteMacros -> Dictionary new. + +Lexer QuoteMacros at: #words put: [| :contents | contents split]. + l@(Lexer traits) on: stream "Target the lexer to the particular stream and initialize it." [ @@ -226,6 +230,12 @@ Escaping is accounted for." t for: (l nextSegmentUntil: $\") ]. +l@(Lexer traits) nextQuoteMacroNamed: sel until: terminator +[| contents | + contents := l nextSegmentUntil: terminator. + tokens QuoteMacro for: ((l QuoteMacros at: sel value) applyWith: contents) +]. + l@(Lexer traits) nextWordCharactersInto: s@(WriteStream traits) [| c | [l hasMoreCharacters @@ -241,7 +251,6 @@ l@(Lexer traits) read: type@(tokens Selector traits) [| :result | l hasMoreCharacters /\ [l peekCharacter isDigit] ifFalse: [l nextWordCharactersInto: result]] writingAs: '') isEmpty - ifTrue: [] ifFalse: [type for: result] ]. @@ -335,7 +344,16 @@ read-table." ifTrue: [l undoCharacter: c. l readNumber] ifFalse: [l undoCharacter: c. (l read: tokens Selector) - ifNil: [l error: 'Message selector must not be empty.']]]] + ifNil: [l error: 'Message selector must not be empty.'] + ifNotNilDo: + [| :sel | + (c := l nextCharacter) caseOf: { + $\' -> [l nextQuoteMacroNamed: sel until: $\']. + $\" -> [l nextQuoteMacroNamed: sel until: $\"]. + $\{ -> [l nextQuoteMacroNamed: sel until: $\}]. + $\( -> [l nextQuoteMacroNamed: sel until: $\)]. + $/ -> [l nextQuoteMacroNamed: sel until: $/ ] + } otherwise: [l undoCharacter: c. sel]]]]] ifFalse: [tokens EndStream] ]. diff --git a/src/syntax/token.slate b/src/syntax/token.slate index e23c90a..0dd22fc 100644 --- a/src/syntax/token.slate +++ b/src/syntax/token.slate @@ -37,6 +37,8 @@ _@(tokens Whitespace traits) signifier [' ']. tokens define: #Selector &parents: {tokens TokenWithValue}. +tokens define: #QuoteMacro &parents: {tokens TokenWithValue}. + "Parser optimization" _@(tokens Selector traits) is: _@(tokens Selector traits) [True]. _@(tokens Token traits) is: _@(tokens Selector traits) [False]. -- 2.11.4.GIT