start separating validation from parsing

This commit is contained in:
Dave Holoway
2020-06-16 12:59:08 +01:00
parent 1801a81c0f
commit b050f3a82d
4 changed files with 217 additions and 1039 deletions

View File

@@ -57,6 +57,19 @@ class TokenList {
return token; return token;
} }
/**
* Check if the current token matches the specified kind, returns and consumes it
* @param {string} kind
*/
getIfKind(kind) {
const token = this.current;
if (token && token.kind === kind) {
this.inc();
return token;
}
return null;
}
/** /**
* Check if the current token matches the specified value, returns and consumes it * Check if the current token matches the specified value, returns and consumes it
* @param {string} value * @param {string} value
@@ -83,11 +96,7 @@ class TokenList {
* @param {string} kind * @param {string} kind
*/ */
isKind(kind) { isKind(kind) {
if (this.current && this.current.kind === kind) { return this.getIfKind(kind) !== null;
this.inc();
return true;
}
return false;
} }
/** /**

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@ const { Token } = require('./tokenizer');
class ResolvedIdent { class ResolvedIdent {
/** /**
* @param {string} ident * @param {string} ident
* @param {(Local|Parameter|Field|ArrayElement|Value)[]} variables * @param {(Local|Parameter|Field|ArrayElement|ValueBase)[]} variables
* @param {Method[]} methods * @param {Method[]} methods
* @param {JavaType[]} types * @param {JavaType[]} types
* @param {string} package_name * @param {string} package_name
@@ -66,8 +66,9 @@ class Local {
* @param {Token} decltoken * @param {Token} decltoken
* @param {import('./source-type').SourceTypeIdent} typeIdent * @param {import('./source-type').SourceTypeIdent} typeIdent
* @param {number} postnamearrdims * @param {number} postnamearrdims
* @param {ResolvedIdent} init
*/ */
constructor(modifiers, name, decltoken, typeIdent, postnamearrdims) { constructor(modifiers, name, decltoken, typeIdent, postnamearrdims, init) {
this.finalToken = modifiers.find(m => m.source === 'final') || null; this.finalToken = modifiers.find(m => m.source === 'final') || null;
this.name = name; this.name = name;
this.decltoken = decltoken; this.decltoken = decltoken;
@@ -75,7 +76,7 @@ class Local {
typeIdent.resolved = new ArrayType(typeIdent.resolved, postnamearrdims); typeIdent.resolved = new ArrayType(typeIdent.resolved, postnamearrdims);
} }
this.typeIdent = typeIdent; this.typeIdent = typeIdent;
this.init = null; this.init = init;
} }
get type() { get type() {
@@ -132,12 +133,15 @@ class ArrayElement {
} }
} }
class Value { class ValueBase {}
class Value extends ValueBase {
/** /**
* @param {string} name * @param {string} name
* @param {JavaType} type * @param {JavaType} type
*/ */
constructor(name, type) { constructor(name, type) {
super();
this.name = name; this.name = name;
this.type = type; this.type = type;
} }
@@ -389,3 +393,4 @@ exports.MethodDeclarations = MethodDeclarations;
exports.ResolvedIdent = ResolvedIdent; exports.ResolvedIdent = ResolvedIdent;
exports.TernaryValue = TernaryValue; exports.TernaryValue = TernaryValue;
exports.Value = Value; exports.Value = Value;
exports.ValueBase = ValueBase;

View File

@@ -106,13 +106,15 @@ class SourceField extends Field {
* @param {Token[]} modifiers * @param {Token[]} modifiers
* @param {SourceTypeIdent} field_type_ident * @param {SourceTypeIdent} field_type_ident
* @param {Token} name_token * @param {Token} name_token
* @param {ResolvedIdent} init
*/ */
constructor(owner, modifiers, field_type_ident, name_token) { constructor(owner, modifiers, field_type_ident, name_token, init) {
super(modifiers.map(m => m.value), ''); super(modifiers.map(m => m.value), '');
this.owner = owner; this.owner = owner;
this.modifierTokens = modifiers; this.modifierTokens = modifiers;
this.fieldTypeIdent = field_type_ident; this.fieldTypeIdent = field_type_ident;
this.nameToken = name_token; this.nameToken = name_token;
this.init = init;
} }
get name() { get name() {