Skip to content

Commit

Permalink
fix: escape sequences (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
menduz authored Dec 20, 2019
1 parent b45df7a commit f2fdf6a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
20 changes: 10 additions & 10 deletions examples/tests/string-ffi.spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import support::ffi
#[export] fun validateNonEmptyString(str: UnsafeCPointer): boolean = {
val received = UCS2.fromPtr(str)
received == "TesT!"
received == "TesT!\""
}
#[export] fun getEmptyString(): UnsafeCPointer = {
Expand Down Expand Up @@ -59,15 +59,15 @@ getInstance => {
errors.push('validateEmptyString1')
}

if (!exports.validateNonEmptyString(write("TesT!"))) {
if (!exports.validateNonEmptyString(write("TesT!\""))) {
errors.push('validateNonEmptyString1')
}

if (!exports.validateEmptyString(write(""))) {
errors.push('validateEmptyString2')
}

if (!exports.validateNonEmptyString(write("TesT!"))) {
if (!exports.validateNonEmptyString(write("TesT!\""))) {
errors.push('validateNonEmptyString2')
}

Expand All @@ -79,17 +79,17 @@ getInstance => {
errors.push('getNonEmptyString')
}

['', "a", "1234", "", "🥶"].forEach(t => {
['', "a", "1234", "", "🥶", "\n\r\t\""].forEach(t => {
if (read(write(t)) != t) {
errors.push(`read(write(${t}))`)
}
})
});

// ['', "a", "1234", "௸", "🥶"].forEach(t => {
// if (read(exports.identity(write(t))) != t) {
// errors.push(`identity ${t}`)
// }
// })
['', "a", "1234", "", "🥶", "\n\r\t\""].forEach(t => {
if (read(exports.identity(write(t))) != t) {
errors.push(`identity ${t}`)
}
})

if (errors.length) {
throw new Error(errors.join(', '))
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/phases/codeGenerationPhase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,9 +478,9 @@ export class CodeGenerationPhaseResult {
module.optimize();
let next = module.emitBinary();
if (next.length >= last.length) {
if (next.length > last.length) {
this.parsingContext.system.write('Last converge was suboptimial.\n');
}
// a if (next.length > last.length) {
// a this.parsingContext.system.write('Last converge was suboptimial.\n');
// a }
break;
}
last = next;
Expand Down
5 changes: 3 additions & 2 deletions src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ PostfixNumber ::= (HexLiteral | NumberLiteral) Reference? {pin=1,simplifyWhe
NumberLiteral ::= !('0x') ("0" | [1-9] [0-9]*) ("." [0-9]+)? (("e" | "E") ( "-" | "+" )? ("0" | [1-9] [0-9]*))? {pin=2}
NegNumberLiteral ::= '-'? NumberLiteral {pin=2}
HexLiteral ::= "0x" [0-9A-Fa-f]+ {pin=1}
StringLiteral ::= '"' (!'"' [#x20-#xFFFF])* '"' | "'" (!"'" [#x20-#xFFFF])* "'"
StringLiteral ::= STRING_DELIMITER ((![\\\\"] [#x20-#xFFFF])* | ('\\\\' (STRING_DELIMITER | '\\\\' | '/' | 'b' | 'f' | 'n' | 'r' | 't' | 'u' HEXDIG HEXDIG HEXDIG HEXDIG)?))* STRING_DELIMITER
Literal ::= StringLiteral
| PostfixNumber
| BooleanLiteral {fragment=true}
Expand Down Expand Up @@ -316,6 +316,7 @@ CLOSE_PAREN ::= ')'
OPEN_ARRAY ::= '['
OPEN_DECORATION ::= '#[' {pin=1}
CLOSE_ARRAY ::= ']' {pin=1}
STRING_DELIMITER ::= '"' {pin=1}
OPEN_BRACKET ::= '{'
CLOSE_BRACKET ::= '}'
THIN_ARROW ::= '->'
Expand All @@ -328,7 +329,7 @@ COMMENT ::= '//' (![#x0A#x0D] [#x00-#xFFFF])* EOL
MULTI_COMMENT ::= OPEN_DOC_COMMENT DOC_COMMENT* CLOSE_DOC_COMMENT {pin=1}
WS ::= COMMENT | MULTI_COMMENT | [#x20#x09#x0A#x0D]+ {fragment=true}
EOL ::= [#x0A#x0D]+
HEXDIG ::= [a-fA-F0-9]
NEW_LINE ::= [#x20#x09]* (EOL | COMMENT)
`;
Expand Down
7 changes: 6 additions & 1 deletion test/Parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,13 @@ describe('Parser', () => {
var c = true
var d = false
var f = "a string 'single' quote"
// var g = 'a string "double" quote'
var g = "an \\"escaped string"
// var h = 'a string "double" quote'
`;

test`
fun x(): string = "\\"'\`\\\\"
`
});

describe('bin op', () => {
Expand Down

0 comments on commit f2fdf6a

Please sign in to comment.