thriftrw / thriftrw-node

A thrift binary encoding library using bufrw
MIT License
57 stars 25 forks source link

Comment Cause SyntaxError #162

Open lushijie opened 5 years ago

lushijie commented 5 years ago
// file content
struct PromotionRequest{
  1: optional string promotionId;
  2: optional string promotionName; // 名称 
}

// code
new Thriftrw({
    strict: false,
    entryPoint: path.resolve(filePath),
    allowOptionalArguments: true,
    defaultAsUndefined: false,
    allowIncludeAlias: true,
    allowFilesystemAccess: true,
}).toJSON();

// error output:  
SyntaxError: Expected "&", comment, end of line, identifier or whitespace but "'" found.
But if remove promotionName's comment, it will fine.
lushijie commented 5 years ago

May be it's multiple byte cause error here, but I don't know how to fix it.

// thrift-idl.pegjs
SingleLineComment
  = '//' comment:(!LineTerminator sc:SourceCharacter { return sc; })* {
    return new ast.Comment(comment);
  }
kriskowal commented 5 years ago

Thrift reads the entryPoint as ASCII, not UTF-8. We chose ASCII for inter-language compatibility. Apache Thrift for Python 2, for example, does not handle high glyphs.

I’m not sure we would even entertain changing the encoding of IDL, at least until a thorough review illustrates that all Thrift compliers, at least the ones we’re obliged to use, are all able to use UTF-8.

lushijie commented 5 years ago

So by now, what can I do to resolve my problem? Change the entryPoint from UTF-8 to ASCII ?