Skip to content
Permalink
Browse files

IMPROVED - unquoted strings (wordStrings, hashStrings, propNames) log…

…ic is changed again, but really tightned up finally. The main chagne is :wordStrings have absolute priority. If an unquoted string starts with a colon, it's a word-string, not a propname.
  • Loading branch information...
shanebdavis committed Sep 3, 2019
1 parent 937283a commit c78831c21aeb7ba1f0789c5aede44c2837f4261e
@@ -84,14 +84,19 @@ import Extensions
"valueProp optionalComma propertyList"
"valuePropWithComplexExpression"

implicitObjectStart: "propName _colon_"
implicitObjectStart: "" propName propNameEndColon

@rule
literalProp: "propName _colon_ propValue:literal"
valueProp: "propName _colon_ propValue:singleValueOrImplicitArrayWithoutImplicitObjects"
propNameEndColon:
"" /:/ _?
"" _ /:/ _

@rule
literalProp: "propName propNameEndColon propValue:literal"
valueProp: "propName propNameEndColon propValue:singleValueOrImplicitArrayWithoutImplicitObjects"

valuePropWithComplexExpression:
"propName _colon_ propValue:singleValueOrImplicitArrayWithoutImplicitObjects"
"propName propNameEndColon propValue:singleValueOrImplicitArrayWithoutImplicitObjects"

{}
name: "literalObjectProperty"
@@ -112,11 +117,6 @@ import Extensions
pattern: "openBracket_ expression _closeBracket"
stnFactory: "ObjectLiteralAccessorStn"

@rule
stringLiteralPropNameTail:
"" _ /:/ !unquotedString
/:/

@rule
thisPropName: "/@/ propNameExtension*"
{}
@@ -125,19 +125,19 @@ import Extensions

@rule
propName:
"" !/then\\s/ thisPropName &_colon_
"" !/then\\s/ thisPropName &propNameEndColon
{}
stnFactory: "ObjectPropNameStn"
stnProps: ~>
isThisProp: true

@rule
propNameExtension:
"" /:*/ unquotedPropNameToken &/:/
"" /:*/ unquotedPropNameToken &propNameEndColon

@rule
propName:
"" !regExpLiteral !/then\\s/ propNameExtension+
"" !regExpLiteral !/then\\s/ unquotedPropNameToken &propNameEndColon propNameExtension*
{}
stnFactory: :ObjectPropNameStn
stnProps: ~>
@@ -146,7 +146,7 @@ import Extensions

@rule
propName:
"" quotedString:stringLiteral &stringLiteralPropNameTail
"" quotedString:stringLiteral &propNameEndColon

{}
stnFactory: :ObjectPropNameStn
@@ -71,7 +71,7 @@ blockStringStartChar = /// (\ | \n | [^.\n\s,)\]\}] )
> Syntax Error

{}
pattern: "" /:(?!:)/ unquotedString2
pattern: "" /:(?!:)/ unquotedString
getStn: ~> StringStn parseTreeNode: @, value: @toString().slice 1

## #hashStrings (primary use: hashtag and colors)
@@ -93,7 +93,7 @@ blockStringStartChar = /// (\ | \n | [^.\n\s,)\]\}] )
The starting '#' is preserved.
reserved: '##' for comments
{}
pattern: "" /\#(?!\#)/ unquotedString2
pattern: "" /\#(?!\#)/ unquotedStringWithoutTrailingColon
getStn: ~> StringStn parseTreeNode: @, value: @toString()

# number-with-unit strings
@@ -144,17 +144,6 @@
///
( (?!\s) [-\/$\w\u007f-\uffff] )+

##
SBD Feb2017: still debating exactly what should be included in unquoted strings

- definitly not: space, comma, [], (), {}
- could, could not: '', "", ``
- questionables: |, \
- should we allow escaping?
- should we allow #{} interpolation?

unquotedString: /// [-~!@\#$%^&*_+=|\\<>?\/.$\w\u007f-\uffff]+

##
SBD Aug2019: I'm coming to these conclusions:
- all except: space, comma, [], (), {}, ;
@@ -177,31 +166,62 @@
- escaping: YES
- interpolation: YES (WIP)

unquotedString2:
unquotedStringCharacter: unquotedStringCharacter =
///
(?:

[^;:\n\s,)\]\}]
(?! # don't match interpolation here
\#
\{
)

(?:
[^ \s \0-\x20 \x7f ; , () [ \] {} \\ ]
|
\\ . # escapes automatically consume next character
)

)

unquotedString:
///
(?:

#{unquotedStringCharacter.source}

)+

unquotedStringWithoutTrailingColon:
///
(?:

(?![:])

#{unquotedStringCharacter.source}

|

: [^;\n\s,)\]\}]
: #{unquotedStringCharacter.source}

)+

unquotedPropNameToken:
# /// (?: (?! [\s \x7f () [\] {} ; : , ]) [ \0x21-\uffff] )+
# /// [a-zA-Z0-9]
///

(?:

[^ \s \0-\x20 \x7f [ \] {} () ; : , ' " ` \\]
(?![ : ' " ` \\ ])

#{unquotedStringCharacter.source}

(?:
[^ \s \0-\x20 \x7f [ \] {} () ; : , \\]
|
\\ .
(?![ : ])
# Colons are actually allowed, but they are
# matched in the propName rule.

# (they cannot be consumed here in case they are
# the final colon)

#{unquotedStringCharacter.source}
)*

)
@@ -1,5 +1,6 @@
{
"author": "Shane Brinkman-Davis Delamore, Imikimi LLC",
"bugs": "https:/github.com/caffeine-suite/caffeine-script/issues",
"config": {
"blanket": {
"pattern": "source"
@@ -34,11 +35,12 @@
"webpack-node-externals": "^1.7.2",
"webpack-stylish": "^0.1.8"
},
"homepage": "https://github.com/caffeine-suite/caffeine-script",
"license": "ISC",
"name": "caffeine-script",
"repository": {
"type": "git",
"url": "git@github.com:shanebdavis/caffeine-script.git"
"url": "https://github.com/caffeine-suite/caffeine-script.git"
},
"scripts": {
"build": "caf -v -p -c cafInCaf -o source",
@@ -74,15 +74,16 @@ Caf.defMod(module, () => {
"valueProp optionalComma propertyList",
"valuePropWithComplexExpression"
],
implicitObjectStart: "propName _colon_"
implicitObjectStart: "propName propNameEndColon"
});
this.rule({ propNameEndColon: ["/:/ _?", "_ /:/ _"] });
this.rule(
{
literalProp: "propName _colon_ propValue:literal",
literalProp: "propName propNameEndColon propValue:literal",
valueProp:
"propName _colon_ propValue:singleValueOrImplicitArrayWithoutImplicitObjects",
"propName propNameEndColon propValue:singleValueOrImplicitArrayWithoutImplicitObjects",
valuePropWithComplexExpression:
"propName _colon_ propValue:singleValueOrImplicitArrayWithoutImplicitObjects"
"propName propNameEndColon propValue:singleValueOrImplicitArrayWithoutImplicitObjects"
},
{
name: "literalObjectProperty",
@@ -106,9 +107,6 @@ Caf.defMod(module, () => {
stnFactory: "ObjectLiteralAccessorStn"
}
});
this.rule({
stringLiteralPropNameTail: ["_ /:/ !unquotedString", /:/]
});
this.rule(
{ thisPropName: "/@/ propNameExtension*" },
{
@@ -124,17 +122,22 @@ Caf.defMod(module, () => {
}
);
this.rule(
{ propName: "!/then\\s/ thisPropName &_colon_" },
{ propName: "!/then\\s/ thisPropName &propNameEndColon" },
{
stnFactory: "ObjectPropNameStn",
stnProps: function() {
return { isThisProp: true };
}
}
);
this.rule({ propNameExtension: "/:*/ unquotedPropNameToken &/:/" });
this.rule({
propNameExtension: "/:*/ unquotedPropNameToken &propNameEndColon"
});
this.rule(
{ propName: "!regExpLiteral !/then\\s/ propNameExtension+" },
{
propName:
"!regExpLiteral !/then\\s/ unquotedPropNameToken &propNameEndColon propNameExtension*"
},
{
stnFactory: "ObjectPropNameStn",
stnProps: function() {
@@ -143,10 +146,7 @@ Caf.defMod(module, () => {
}
);
return this.rule(
{
propName:
"quotedString:stringLiteral &stringLiteralPropNameTail"
},
{ propName: "quotedString:stringLiteral &propNameEndColon" },
{
stnFactory: "ObjectPropNameStn",
stnProps: function() {
@@ -61,7 +61,7 @@ Caf.defMod(module, () => {
}
},
{
pattern: "/:(?!:)/ unquotedString2",
pattern: "/:(?!:)/ unquotedString",
getStn: function() {
return StringStn({
parseTreeNode: this,
@@ -70,7 +70,7 @@ Caf.defMod(module, () => {
}
},
{
pattern: "/#(?!#)/ unquotedString2",
pattern: "/#(?!#)/ unquotedStringWithoutTrailingColon",
getStn: function() {
return StringStn({
parseTreeNode: this,
@@ -2,7 +2,7 @@
let Caf = require("caffeine-script-runtime");
Caf.defMod(module, () => {
return function() {
let assignmentOperator;
let unquotedStringCharacter, assignmentOperator;
this.rule({
_equals_: /\ *= */,
_colon_: /: *| +:( +|(?=\n))/,
@@ -33,9 +33,20 @@ Caf.defMod(module, () => {
}
],
pathedRequire: /((?!\s)[-\/$\w\u007f-\uffff])+/,
unquotedString: /[-~!@\#$%^&*_+=|\\<>?\/.$\w\u007f-\uffff]+/,
unquotedString2: /(?:[^;:\n\s,)\]\}]|:[^;\n\s,)\]\}])+/,
unquotedPropNameToken: /(?:[^\s\0-\x20\x7f[\]{}();:,'"`\\](?:[^\s\0-\x20\x7f[\]{}();:,\\]|\\.)*)/,
unquotedStringCharacter: (unquotedStringCharacter = /(?:(?!\#\{)(?:[^\s\0-\x20\x7f;,()[\]{}\\]|\\.))/),
unquotedString: RegExp(
`(?:${Caf.toString(unquotedStringCharacter.source)})+`
),
unquotedStringWithoutTrailingColon: RegExp(
`(?:(?![:])${Caf.toString(
unquotedStringCharacter.source
)}|:${Caf.toString(unquotedStringCharacter.source)})+`
),
unquotedPropNameToken: RegExp(
`(?:(?![:'"\`\\\\])${Caf.toString(
unquotedStringCharacter.source
)}(?:(?![:])${Caf.toString(unquotedStringCharacter.source)})*)`
),
unaryTailOperator: /\?/,
unaryOperator_: /([!~]|not\b|delete\b) *|-(?![-:])/,
binaryOperator: /&&|\|\||&(?=\s)|\||\^|\?|((and|or|in|is|isnt|instanceof)\b)|<<|>>>|>>|==|!=|<=|>=|<|>|\/\/|%%|\*\*|[-+*\/%]/,

0 comments on commit c78831c

Please sign in to comment.
You can’t perform that action at this time.