hoaproject / Compiler

The Hoa\Compiler library.
https://hoa-project.net/
453 stars 47 forks source link

PHP Warning in Parser class #71

Closed SerafimArts closed 7 years ago

SerafimArts commented 7 years ago

Error message

PHP Warning:  strrpos(): Offset is greater than the length of haystack string in ~/vendor/hoa/compiler/Llk/Parser.php on line 198

Grammar.pp:

%skip  T_IGNORE                 [\xfeff\x20\x09\x0a\x0d]+

%token T_COLON                  :
%token T_BRACE_OPEN             {
%token T_BRACE_CLOSE            }

%token T_NAME                   ([_A-Za-z][_0-9A-Za-z]*)
%token T_SCHEMA_DEFINITION      schema
%token T_TYPE_DEFINITION        type
%token T_ENUM_DEFINITION        enum
%token T_UNION_DEFINITION       union
%token T_INTERFACE_DEFINITION   interface

%token T_SCALAR_INTEGER         Int
%token T_SCALAR_FLOAT           Float
%token T_SCALAR_STRING          String
%token T_SCALAR_BOOLEAN         Boolean
%token T_SCALAR_ID              ID

#Document:
    TypeDefinition()*

#TypeDefinition:
    ::T_TYPE_DEFINITION:: <T_NAME>? ::T_BRACE_OPEN:: Fields()* ::T_BRACE_CLOSE::

#Fields:
    <T_NAME> ::T_COLON:: FieldValue()

#FieldValue:
    <T_SCALAR_INTEGER> | <T_SCALAR_FLOAT> | <T_SCALAR_STRING> | <T_SCALAR_BOOLEAN> | <T_SCALAR_ID> | <T_NAME>

Source code for parsing:

type Test {

}
SerafimArts commented 7 years ago

The error is fixes when move T_NAME to the bottom of the token declarations. But it would be nice not to throw the any warnings (add a check and throws an Error?).