Got rid of un-needed tokens types.
This commit is contained in:
parent
82bb229eb8
commit
98086f89ac
@ -142,16 +142,16 @@ class ComponentParser {
|
||||
return this.doubleQuoteStringValue()
|
||||
} else if (this.peek(SINGLE_QUOTE)) {
|
||||
return this.singleQuoteStringValue()
|
||||
} else if (this.peek(DOLLAR) && this.peekSecond(GROOVY_IDENTIFIER)) {
|
||||
} else if (this.peek(GROOVY_IDENTIFIER)) {
|
||||
return this.dollarReferenceValue()
|
||||
} else if (this.peek(DOLLAR) && this.peekSecond(CURLY_OPEN)) {
|
||||
} else if (this.peek(GROOVY)) {
|
||||
return this.dollarScriptletValue()
|
||||
} else if (this.peek(LT) && this.peekSecond(PERCENT) && this.peekThird(EQUALS)) {
|
||||
return this.expressionScriptletValue()
|
||||
} else if (this.peek(LT) && this.peekSecond(PERCENT)) {
|
||||
return this.scriptletValue()
|
||||
} else {
|
||||
error([DOUBLE_QUOTE, SINGLE_QUOTE, DOLLAR, LT], this.tokens.poll())
|
||||
error([DOUBLE_QUOTE, SINGLE_QUOTE, GROOVY_IDENTIFIER, GROOVY, LT], this.tokens.poll())
|
||||
}
|
||||
throw new RuntimeException('should not get here')
|
||||
}
|
||||
@ -176,21 +176,17 @@ class ComponentParser {
|
||||
}
|
||||
}
|
||||
|
||||
@PeekBefore([DOLLAR, GROOVY_IDENTIFIER])
|
||||
@PeekBefore([GROOVY_IDENTIFIER])
|
||||
private DollarReferenceValue dollarReferenceValue() {
|
||||
this.expect(DOLLAR)
|
||||
def groovyIdentifierToken = this.expect(GROOVY_IDENTIFIER)
|
||||
new DollarReferenceValue().tap {
|
||||
reference = groovyIdentifierToken.text
|
||||
}
|
||||
}
|
||||
|
||||
@PeekBefore([DOLLAR, CURLY_OPEN])
|
||||
@PeekBefore([GROOVY])
|
||||
private DollarScriptletValue dollarScriptletValue() {
|
||||
this.expect(DOLLAR)
|
||||
this.expect(CURLY_OPEN)
|
||||
def groovyToken = this.expect(GROOVY)
|
||||
this.expect(CURLY_CLOSE)
|
||||
new DollarScriptletValue().tap {
|
||||
scriptlet = groovyToken.text
|
||||
}
|
||||
|
@ -14,10 +14,7 @@ class ComponentToken {
|
||||
DOUBLE_QUOTE,
|
||||
SINGLE_QUOTE,
|
||||
STRING,
|
||||
DOLLAR,
|
||||
CURLY_OPEN,
|
||||
GROOVY,
|
||||
CURLY_CLOSE,
|
||||
GROOVY_IDENTIFIER,
|
||||
PERCENT,
|
||||
FORWARD_SLASH
|
||||
|
@ -37,7 +37,6 @@ class ComponentTokenizer {
|
||||
KEYS_AND_VALUES,
|
||||
DOUBLE_QUOTE_STRING,
|
||||
SINGLE_QUOTE_STRING,
|
||||
DOLLAR_GROOVY,
|
||||
EXPRESSION_SCRIPTLET_GROOVY,
|
||||
DONE
|
||||
}
|
||||
@ -88,15 +87,11 @@ class ComponentTokenizer {
|
||||
tokens << new ComponentToken(Type.SINGLE_QUOTE, it)
|
||||
}
|
||||
on dollarReference exec { String s ->
|
||||
tokens << new ComponentToken(Type.DOLLAR, s[0])
|
||||
tokens << new ComponentToken(Type.GROOVY_IDENTIFIER, s.substring(1))
|
||||
tokens << new ComponentToken(Type.GROOVY_IDENTIFIER, s.substring(1)) // skip opening $
|
||||
}
|
||||
on dollarOpen shiftTo State.DOLLAR_GROOVY exec { String s ->
|
||||
tokens << new ComponentToken(Type.DOLLAR, s[0])
|
||||
tokens << new ComponentToken(Type.CURLY_OPEN, s[1])
|
||||
}
|
||||
on DollarGroovyParser.&parse exec {
|
||||
|
||||
//noinspection GroovyAssignabilityCheck // for some reason IntelliJ is confused by this
|
||||
on DollarGroovyParser::parse exec { String s ->
|
||||
tokens << new ComponentToken(Type.GROOVY, s.substring(2, s.length() - 1))
|
||||
}
|
||||
on percent shiftTo State.EXPRESSION_SCRIPTLET_GROOVY exec {
|
||||
tokens << new ComponentToken(Type.PERCENT, it)
|
||||
@ -133,16 +128,6 @@ class ComponentTokenizer {
|
||||
}
|
||||
}
|
||||
|
||||
whileIn(State.DOLLAR_GROOVY) {
|
||||
on DollarGroovyParser.&parse shiftTo State.KEYS_AND_VALUES exec { String s ->
|
||||
tokens << new ComponentToken(Type.GROOVY, s.substring(0, s.length() - 1))
|
||||
tokens << new ComponentToken(Type.CURLY_CLOSE, '}')
|
||||
}
|
||||
onNoMatch() exec {
|
||||
throw new IllegalArgumentException()
|
||||
}
|
||||
}
|
||||
|
||||
whileIn(State.EXPRESSION_SCRIPTLET_GROOVY) {
|
||||
on expressionScriptletGroovy shiftTo State.KEYS_AND_VALUES exec { String s ->
|
||||
tokens << new ComponentToken(Type.GROOVY, s.substring(0, s.length() - 2))
|
||||
|
@ -1,10 +1,6 @@
|
||||
package com.jessebrault.ssg.template.gspe.component
|
||||
|
||||
import com.jessebrault.ssg.template.gspe.component.node.ComponentNode
|
||||
import com.jessebrault.ssg.template.gspe.component.node.GStringValue
|
||||
import com.jessebrault.ssg.template.gspe.component.node.KeyAndValue
|
||||
import com.jessebrault.ssg.template.gspe.component.node.KeysAndValues
|
||||
import com.jessebrault.ssg.template.gspe.component.node.Node
|
||||
import com.jessebrault.ssg.template.gspe.component.node.*
|
||||
import groovy.transform.stc.ClosureParams
|
||||
import groovy.transform.stc.FirstParam
|
||||
import groovy.transform.stc.SimpleType
|
||||
@ -68,7 +64,7 @@ class ComponentParserTests {
|
||||
|
||||
def <T extends Node> void expect(
|
||||
Class<T> childNodeClass,
|
||||
@DelegatesTo(value = NodeTester, strategy = Closure.DELEGATE_ONLY)
|
||||
@DelegatesTo(value = NodeTester, strategy = Closure.DELEGATE_FIRST)
|
||||
@ClosureParams(FirstParam.FirstGenericType)
|
||||
Closure<Void> furtherTests
|
||||
) {
|
||||
@ -84,7 +80,7 @@ class ComponentParserTests {
|
||||
private final ComponentParser parser = new ComponentParser()
|
||||
|
||||
private void selfClosing(
|
||||
List<ComponentToken> tokens,
|
||||
Queue<ComponentToken> tokens,
|
||||
@DelegatesTo(value = NodeTester, strategy = Closure.DELEGATE_FIRST)
|
||||
@ClosureParams(value = SimpleType, options = ['com.jessebrault.ssg.template.gspe.component.node.ComponentNode'])
|
||||
Closure<Void> tests
|
||||
@ -99,12 +95,12 @@ class ComponentParserTests {
|
||||
|
||||
@Test
|
||||
void selfClosingNoKeysOrValues() {
|
||||
this.selfClosing([
|
||||
this.selfClosing(new LinkedList<>([
|
||||
new ComponentToken(LT),
|
||||
new ComponentToken(IDENTIFIER, 'Test'),
|
||||
new ComponentToken(FORWARD_SLASH),
|
||||
new ComponentToken(GT)
|
||||
]) {
|
||||
])) {
|
||||
assertEquals('Test', it.identifier)
|
||||
expect(KeysAndValues) {
|
||||
assertEquals(0, it.children.size())
|
||||
@ -114,7 +110,7 @@ class ComponentParserTests {
|
||||
|
||||
@Test
|
||||
void selfClosingWithGStringValue() {
|
||||
this.selfClosing([
|
||||
this.selfClosing(new LinkedList<>([
|
||||
new ComponentToken(LT),
|
||||
new ComponentToken(IDENTIFIER, 'Test'),
|
||||
new ComponentToken(KEY, 'test'),
|
||||
@ -124,7 +120,7 @@ class ComponentParserTests {
|
||||
new ComponentToken(DOUBLE_QUOTE),
|
||||
new ComponentToken(FORWARD_SLASH),
|
||||
new ComponentToken(GT)
|
||||
]) {
|
||||
])) {
|
||||
assertEquals('Test', it.identifier)
|
||||
expect(KeysAndValues) {
|
||||
expect(KeyAndValue) {
|
||||
|
@ -123,10 +123,7 @@ class ComponentTokenizerTests {
|
||||
expect IDENTIFIER, 'Test'
|
||||
expect KEY, 'key'
|
||||
expect EQUALS
|
||||
expect DOLLAR
|
||||
expect CURLY_OPEN
|
||||
expect GROOVY, ' test '
|
||||
expect CURLY_CLOSE
|
||||
expect FORWARD_SLASH
|
||||
expect GT
|
||||
}
|
||||
@ -139,10 +136,7 @@ class ComponentTokenizerTests {
|
||||
expect IDENTIFIER, 'Test'
|
||||
expect KEY, 'key'
|
||||
expect EQUALS
|
||||
expect DOLLAR
|
||||
expect CURLY_OPEN
|
||||
expect GROOVY, ' test.each { it.test() } '
|
||||
expect CURLY_CLOSE
|
||||
expect FORWARD_SLASH
|
||||
expect GT
|
||||
}
|
||||
@ -155,7 +149,6 @@ class ComponentTokenizerTests {
|
||||
expect IDENTIFIER, 'Test'
|
||||
expect KEY, 'key'
|
||||
expect EQUALS
|
||||
expect DOLLAR
|
||||
expect GROOVY_IDENTIFIER, 'test'
|
||||
expect FORWARD_SLASH
|
||||
expect GT
|
||||
|
Loading…
Reference in New Issue
Block a user