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;
}
/**
* 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
* @param {string} value
@@ -83,11 +96,7 @@ class TokenList {
* @param {string} kind
*/
isKind(kind) {
if (this.current && this.current.kind === kind) {
this.inc();
return true;
}
return false;
return this.getIfKind(kind) !== null;
}
/**

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -106,13 +106,15 @@ class SourceField extends Field {
* @param {Token[]} modifiers
* @param {SourceTypeIdent} field_type_ident
* @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), '');
this.owner = owner;
this.modifierTokens = modifiers;
this.fieldTypeIdent = field_type_ident;
this.nameToken = name_token;
this.init = init;
}
get name() {